Filtering chimeras with Python API

Hi there, I had the following issue after using uchime_ref in Python API:
· I have my OTU table: OTU_table.qza (OTU_table variable).
· I have my nonchimeric sequences returned by uchime_ref: nonchim_seqs.qza (nonchim_seqs variable).
I have succesfully filtered my OTU table using Linux commands:

qiime feature-table filter-features --i-table OTU_table.qza --m-metadata-file nonchim_seqs.qza ...

The problem appears when I try to do this using Python API, when I try to use the nonchimeric sequences as metadata for the function:

from qiime2.plugins.feature_table.methods import filter_features
filter_features(OTU_table, metadata = nonchim_seqs)

This gives me the following error:
Parameter 'metadata' received an argument of type FeatureData[Sequence]. An argument of subtype Metadata is required.

Hi @Ruben_Gomez-Gordo,

Another API user! Hi :wave: !

The error is relatively descriptive: your nonchim_seqs object needs to be the Metadata class, rather than the Artifact class you currently have. My hack-tastic solution would be to export the FeatureData[Sequence] to a pandas DataFrame and then pass it into the qiime2.Metadata object. There may be a slicker solution, but I think it should solve your problem? (If not, maybe try passing it as a MetadataCategory object out of the Metadata object.)

Best,
Justine

1 Like
filter_features(OTU_table, metadata = nonchim_seqs.view(qiime2.Metadata))
4 Likes

Hi Justine, thanks for your response. You were right, using the qiime2. Metadata object was the way to do this.
I've transformed the FeatureData[Sequence] artifact into Metadata using this method:
FeatureData[Sequence].view(qiime2.Metadata)

Now it works :smile:

3 Likes

@Nicholas_Bokulich, @Ruben_Gomez-Gordo,

Thank you! I learned something new today!

2 Likes

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