# Trouble importing MegaHit assemblies

**URL:** https://forum.qiime2.org/t/trouble-importing-megahit-assemblies/11648
**Category:** Technical Support
**Tags:** importing, import
**Created:** [September 24, 2019, 7:57am UTC](https://forum.qiime2.org/t/trouble-importing-megahit-assemblies/11648 "2019-09-24T07:57:42Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Nick\_D](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nick_d/32/5970_2.png) [@Nick\_D](https://forum.qiime2.org/u/Nick_D)
#### Post date: [September 24, 2019, 7:57am UTC](https://forum.qiime2.org/t/trouble-importing-megahit-assemblies/11648/1 "2019-09-24T07:57:42Z")

</div>

I recently finished assembling some meta-genomic shotgun sequencing data using MegaHit 1.2.8 and now I'm attempting to import the "final.contigs.fa" files into Qiime2 for analysis, but I just can't seem to get it to work. I've gone through the importing tutorial, and managed to import the files as FeatureData[Sequence], but I cannot import them as SampleData[Sequence] (which is the format I actually need to run the qiime vsearch dereplicate-sequences command).

## Here's one of the commands I've tried and the resulting error message:

(qiime2-2019.4) nick@nick-MS-7994:~$ qiime tools import --type 'SampleData[Sequence]' --input-path '/home/nick/SequencingData/MGS-Data/1. Assembled/Raw/N-LLL.fa' --output-path '/home/nick/SequencingData/MGS-Data/1. Assembled/Imported/N-LLL.qza'  
Traceback (most recent call last):  
File "/home/nick/miniconda3/envs/qiime2-2019.4/lib/python3.6/site-packages/q2cli/builtin/tools.py", line 152, in import\_data  
view\_type=input\_format)  
File "/home/nick/miniconda3/envs/qiime2-2019.4/lib/python3.6/site-packages/qiime2/sdk/result.py", line 213, in import\_data  
output\_dir\_fmt = pm.get\_directory\_format(type\_)  
File "/home/nick/miniconda3/envs/qiime2-2019.4/lib/python3.6/site-packages/qiime2/sdk/plugin\_manager.py", line 157, in get\_directory\_format  
% semantic\_type)  
TypeError: Semantic type SampleData[Sequence] does not have a compatible directory format.

An unexpected error has occurred:

Semantic type SampleData[Sequence] does not have a compatible directory format.

## See above for debug info.

I've also tried this command, with the same result:

(qiime2-2019.4) nick@nick-MS-7994:~$ qiime tools import --type 'SampleData[Sequence]' --input-path '/home/nick/SequencingData/MGS-Data/1. Assembled/Raw/N-LLL.fa' --input-format DNASequencesDirectoryFormat --output-path '/home/nick/SequencingData/MGS-Data/1. Assembled/Imported/N-LLL.qza'

I originally thought the issue was due to the file headers having excess data in them other than just `<sample-id>_<seq-id>`, so I went through and deleted everything except for that; giving headers and sequences like this:

> k141\_0  
> GCCAATCCTTACCTTCATAGAACTGGACAGGCTCAAGATCGAGACCTATATACCAGAGGAAGTCGCCTTACACTTATATGATAAAGAAAAACAGAAACTATGTCAAGTAGGAATCCATTTCGATACAGATCCCGAACGGACAATCACCCCTTCCGATTTATATGTGTCTAAAAGTACGACAAACAATAACCTCTCTTATCTACTGACCGCCATTATCCCCAACCCCGATATGGAATGGCTGGGCGGAATGAGTGGAATCCTCTCGATCGACCTACCCAAAGAAGAGCGGTCTCAAAATCTATGGCTTCCCTTAACGGCTATCTGTCATCGCCCCCAAAAAGG  
> k141\_42822  
> CGGGTACTGTTGTCATGAATGGAAAGCAATATATGTGGAATACATGGGGAGAAATACTGATTCCCGCATCAGATTCGCAGGTTTGGGCGACGTATGCCAATGAATTCTATGAAGGTGGTCCTGCCGTCACGTTCCGCAAGCTGGGCAAAGGCACGGTGACATATGTCGGAGTGGACAGCCATAATGGTGCATTGGAAAAAGATATCTTGAAGAAATTATATGCGCAACTGAGTATTCCCGTTATGGATTTGCCTTATGGAGTTACGGTGGAATACCGGAATGGTTTGGGGATAGTGCTGAATTATGCTGATCGTCCTTATACATTCAACTTACCTGAAGGAAGTAAGGTTTTGATAGGGACGAAAGAGATTCCGACAGCAGGGGTATTGGT

Any help with this would be greatly appreciated.

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [September 24, 2019, 4:12pm UTC](https://forum.qiime2.org/t/trouble-importing-megahit-assemblies/11648/2 "2019-09-24T16:12:41Z")

</div>

Welcome to the forum, @Nick_D!

> [@Nick\_D](#):
>
> TypeError: Semantic type SampleData[Sequence] does not have a compatible directory format.

Try `FeatureData[Sequence]`

Let us know if that works for you!

---

<div class="post-metadata">

### Author: ![Nick\_D](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nick_d/32/5970_2.png) [@Nick\_D](https://forum.qiime2.org/u/Nick_D)
#### Post date: [September 25, 2019, 7:29am UTC](https://forum.qiime2.org/t/trouble-importing-megahit-assemblies/11648/3 "2019-09-25T07:29:19Z")

</div>

Hi Nicholas,

Thanks for the help, I was able to successfully import the data using FeatureData[Sequence]. Unfortunately, when I try to use "vsearch dereplicate-sequences" it throws the following error:

(1/1) Invalid value for "--i-sequences": Expected an artifact of at least  
type SampleData[Sequences] | SampleData[SequencesWithQuality] |  
SampleData[JoinedSequencesWithQuality]. An artifact of type  
FeatureData[Sequence] was provided.

Is there any way to import the assemblies as SampleData[Sequences], or convert the FeatureData[Sequences] file to SampleData[Sequences] so that I can dereplicate it?

---

<div class="post-metadata">

### Author: ![thermokarst](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@thermokarst](https://forum.qiime2.org/u/thermokarst)
#### Post date: [September 25, 2019, 2:23pm UTC](https://forum.qiime2.org/t/trouble-importing-megahit-assemblies/11648/4 "2019-09-25T14:23:43Z")

</div>

> [@Nick\_D](#):
>
> Is there any way to import the assemblies as SampleData[Sequences]

The megahit assemblies are per-sample, right? You could multiplex all the samples (while modifying the reflines to match the [necessary format](http://qiime.org/documentation/file_formats.html#post-split-libraries-fasta-file-overview)), then you can import as `SampleData[Sequences]`. Its a bit of an awkward workflow though, I wonder if there is a better way for you to dereplicate outside of QIIME 2.

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [September 25, 2019, 3:34pm UTC](https://forum.qiime2.org/t/trouble-importing-megahit-assemblies/11648/5 "2019-09-25T15:34:25Z")

</div>

Sorry @Nick_D I read too quickly before and now see you already told me that:

> [@Nick\_D](#):
>
> I cannot import them as SampleData[Sequence] (which is the format I actually need to run the qiime vsearch dereplicate-sequences command).

Essentially you are trying to run [this tutorial](https://docs.qiime2.org/2019.7/tutorials/otu-clustering/), except that you have per-sample fasta, whereas the fasta format expected should be in a single file, rather than a directory of per-sample fasta files. So as @thermokarst advised:

> [@thermokarst](#):
>
> You could multiplex all the samples (while modifying the reflines to match the [necessary format](http://qiime.org/documentation/file_formats.html#post-split-libraries-fasta-file-overview)), then you can import as `SampleData[Sequences]`

---

<div class="post-metadata">

### Author: ![Nick\_D](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nick_d/32/5970_2.png) [@Nick\_D](https://forum.qiime2.org/u/Nick_D)
#### Post date: [September 26, 2019, 5:35am UTC](https://forum.qiime2.org/t/trouble-importing-megahit-assemblies/11648/6 "2019-09-26T05:35:55Z")

</div>

> [@thermokarst](#):
>
> The megahit assemblies are per-sample, right?

> [@Nicholas\_Bokulich](#):
>
> Essentially you are trying to run [this tutorial](https://docs.qiime2.org/2019.7/tutorials/otu-clustering/), except that you have per-sample fasta, whereas the fasta format expected should be in a single file, rather than a directory of per-sample fasta files. So as @thermokarst advised:

Sorry, I don't think I was very clear about the format of the assemblies and it's causing a bit of confusion. I'm trying to import each FASTA file separately rather than as a directory, because they are from different metagenomic samples. Also, each discrete FASTA sample/file has about 50,000 assemblies in it. (See screenshot below)

![Screenshot%20from%202019-09-26%2015-44-50](https://forum.qiime2.org/images/transparent.png)

---

<div class="post-metadata">

### Author: ![thermokarst](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@thermokarst](https://forum.qiime2.org/u/thermokarst)
#### Post date: [September 26, 2019, 1:20pm UTC](https://forum.qiime2.org/t/trouble-importing-megahit-assemblies/11648/7 "2019-09-26T13:20:38Z")

</div>

Hey @Nick_D!

> [@Nick\_D](#):
>
> Sorry, I don’t think I was very clear about the format of the assemblies

I disagree, I think you explained it very well!

> [@Nick\_D](#):
>
> it’s causing a bit of confusion

I don't think so, I think @Nicholas_Bokulich & I are on the same page as you (more below).

> [@Nick\_D](#):
>
> they are from different metagenomic samples

This is what we mean by "per-sample assemblies" --- you have one file per sample containing the assembly sequences. As I mentioned above, in order to dereplicate in QIIME 2 you will need to _multiplex_ (which is a step in the reverse direction) before importing and dereplicating.

For what its worth, I think in the future it will make sense for us to create a new import format in q2-types to support this schema.

* * *

## Sample workflow

```bash
cd path/to/fasta/files

touch merged.fasta

for f in *.fasta; do fn="${$(basename -- "$f")%.*}"; sed "s/^>\(.*\)$/>\\$fn\_\1/" $f >> merged.fasta; done

qiime tools import \
  --input-path merged.fasta \
  --output-path seqs.qza \
  --type 'SampleData[Sequences]'

qiime vsearch dereplicate-sequences \
  --i-sequences seqs.qza \
  --o-dereplicated-table table.qza \
  --o-dereplicated-sequences rep-seqs.qza \
  --verbose

qiime feature-table summarize \
  --i-table table.qza \
  --o-visualization table.qzv

```

---

<div class="post-metadata">

### Author: ![Nick\_D](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nick_d/32/5970_2.png) [@Nick\_D](https://forum.qiime2.org/u/Nick_D)
#### Post date: [September 27, 2019, 5:41am UTC](https://forum.qiime2.org/t/trouble-importing-megahit-assemblies/11648/8 "2019-09-27T05:41:07Z")

</div>

Thank you so much for the help, I really appreciate it! I think I mixed up the terminology and confused myself, I'm glad you guys knew what I was talking about anyway 😅.

I tried the workflow you posted, but when I pasted the code in the terminal it threw this error:

 ![Screenshot%20from%202019-09-27%2016-25-26](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/b/bfc8eacd8ec9fb8a2810cedb8a9d76844569e3c2.png)

Did I do that correctly?

---

<div class="post-metadata">

### Author: ![Nick\_D](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nick_d/32/5970_2.png) [@Nick\_D](https://forum.qiime2.org/u/Nick_D)
#### Post date: [September 30, 2019, 3:39am UTC](https://forum.qiime2.org/t/trouble-importing-megahit-assemblies/11648/9 "2019-09-30T03:39:27Z")

</div>

Just in case anyone else runs into the same problem as I did, I found another work-around to get the sequences imported:

1. Download bbtools ([https://jgi.doe.gov/data-and-tools/bbtools/bb-tools-user-guide/reformat-guide/](https://jgi.doe.gov/data-and-tools/bbtools/bb-tools-user-guide/reformat-guide/))
2. Decompress the tool archive.
3. cd to the main tool directory.
4. Drag/Drop reformat.sh into terminal.
5. Type: in='InputFileLocation.fa' out='WhereYouWantTheOutputFile.fasta' fastawrap=10000
6. Done  
The "fastawrap=" needs to be set high enough to not word-wrap any sequences in your .fa file.

It's a bit of a clumsy (I'm not a programmer) method to fix the Megahit assemblies so that they import as SampleData[Sequence], but it gets the job done.
