# importing MAGs into moshpit

**URL:** <https://forum.qiime2.org/t/importing-mags-into-moshpit/33269>\
**Category:** User Support\
**Tags:** moshpit\
**Created:** [June 8, 2025, 1:36pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269 "2025-06-08T13:36:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![shira](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@shira](https://forum.qiime2.org/u/shira)\
**Post date:** [June 8, 2025, 1:36pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/1 "2025-06-08T13:36:35Z")

</div>

# Error while importing MAGs into MOSHPIT

I am trying to import metagenomic sequencing results from a single sample. I received a MAGs fasta file from the sequencing center, and moved it into a new folder. I tried importing the MAGs using the following command -  
mosh tools cache-import   
--cache ./cache   
--key mags   
--type "FeatureData[MAGs]"   
--input-path data/mags

and got the following error message -

Semantic type FeatureData[MAGs] is invalid, either because it doesn't have a compatible directory format, or because it's not registered.

What is the correct way to import MAGs from a fasta file into the MOSHPIT pipeline?

Thanks!

---

<div class="post-metadata">

**Author:** ![ebolyen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ebolyen/32/11_2.png) [@ebolyen](https://forum.qiime2.org/u/ebolyen)\
**Post date:** [June 9, 2025, 5:52pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/2 "2025-06-09T17:52:30Z")

</div>

Hi @shira,

I think the issue is that you want the type `SampleData[MAGs]` which has the `s` and does not yet presume to know what your features are, instead of `FeatureData[MAG]` which doesn't have the `s` and does presume each record is an interesting feature.

My assumption here is that you have a fasta file for each sample in your `data/mags` directory.  
It is also likely that you will want to use:

`--input-format 'MultiFASTADirectoryFormat'`

Unless your sequencing provider happened to include a MANIFEST file which is unlikely.

---

<div class="post-metadata">

**Author:** ![shira](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@shira](https://forum.qiime2.org/u/shira)\
**Post date:** [June 10, 2025, 12:58pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/3 "2025-06-10T12:58:27Z")

</div>

Thanks @ebolyen  
I tried your suggestion and got the following error

> Files should be organised in per-sample directories

This is the code I ran:

> qiime tools cache-import   
> --type 'SampleData[MAGs]'   
> --input-path data/mags   
> --cache ./cache   
> --input-format 'MultiFASTADirectoryFormat'   
> --key mags

I have a single sample, so initially I had just a single fasta file within my data/mags directory. I also tried creating a sub directory called sample1 and moving the fasta file there, but I get the same error. I searched through the help files but could not find an example for the structure of a `'MultiFASTADirectoryFormat'` input format.

---

<div class="post-metadata">

**Author:** ![ebolyen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ebolyen/32/11_2.png) [@ebolyen](https://forum.qiime2.org/u/ebolyen)\
**Post date:** [June 10, 2025, 9:18pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/4 "2025-06-10T21:18:30Z")

</div>

Hi @shira,

I took a quick peek at the code which raises that error, and it does seem like it would work with the sub-directory you tried, but did you import `sample1/` or `data/mags` (which has sample1 inside). I think it's the latter one which will get through the error (it wants a directory with directories inside it).

---

<div class="post-metadata">

**Author:** ![shira](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@shira](https://forum.qiime2.org/u/shira)\
**Post date:** [June 11, 2025, 12:49pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/5 "2025-06-11T12:49:18Z")

</div>

Hi @ebolyen,

I am attempting to import a directory. The directory has one directory in it named sample1. This directory has one file in it, it's a fasta file (tried both .fasta and .fa extensions). The error reads

> Files should be organised in per-sample directories

---

<div class="post-metadata">

**Author:** ![ebolyen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ebolyen/32/11_2.png) [@ebolyen](https://forum.qiime2.org/u/ebolyen)\
**Post date:** [June 11, 2025, 5:21pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/6 "2025-06-11T17:21:42Z")

</div>

Thanks for confirming @shira!

@misialq, I can't really work out why this is happening. I think the above process should avoid this error:

> <https://github.com/qiime2/q2-types/blob/553bf8ea60904e692b78d87cbc795beeb0acdccf/q2_types/per_sample_sequences/_formats.py#L535-L541>

But clearly that isn't happening. Any ideas?

---

<div class="post-metadata">

**Author:** ![ebolyen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ebolyen/32/11_2.png) [@ebolyen](https://forum.qiime2.org/u/ebolyen)\
**Post date:** [June 11, 2025, 5:21pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/7 "2025-06-11T17:21:50Z")

</div>



---

<div class="post-metadata">

**Author:** ![shira](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/s/aeb1de/32.png) [@shira](https://forum.qiime2.org/u/shira)\
**Post date:** [June 12, 2025, 11:39am UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/8 "2025-06-12T11:39:09Z")

</div>

@ebolyen @misialq  
Problem solved! 😀  
Found a hidden **.DS\_Store** file in the directory. Once I deleted it all was fine. It's a bit tricky since macOS keeps making these hidden files every time you open the folder.

---

<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:** [June 12, 2025, 5:45pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/9 "2025-06-12T17:45:21Z")

</div>



---

<div class="post-metadata">

**Author:** ![ebolyen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ebolyen/32/11_2.png) [@ebolyen](https://forum.qiime2.org/u/ebolyen)\
**Post date:** [June 12, 2025, 5:50pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/10 "2025-06-12T17:50:48Z")

</div>

Holy moly, great job @shira!.

I can't believe `.DS_Store` reared its head. A lot of our internal code ignores that (having learned our lesson long ago), but I guess the validate mixin above isn't aware.

We should probably provide an "iter" API internally that skips these. (We definitely ignore them when we move the data into a zip file.)

---

<div class="post-metadata">

**Author:** ![ebolyen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ebolyen/32/11_2.png) [@ebolyen](https://forum.qiime2.org/u/ebolyen)\
**Post date:** [June 12, 2025, 5:56pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/11 "2025-06-12T17:56:18Z")

</div>

I've made an issue to fix this: [Some validators use `self.path.iterdir()` which trips over `.DS_store` · Issue #362 · qiime2/q2-types · GitHub](https://github.com/qiime2/q2-types/issues/362)

Thanks again @shira !

---

<div class="post-metadata">

**Author:** ![system](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/3X/2/1/21af5fe23cb6f4579467c66a9ed94e55274ca7bd.svg) [@system](https://forum.qiime2.org/u/system)\
**Post date:** [July 13, 2025, 11:56pm UTC](https://forum.qiime2.org/t/importing-mags-into-moshpit/33269/12 "2025-07-13T23:56:48Z")

</div>

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
