Trouble with API feature-table visualizer

Hello,

I’m a new QIIME2 user, and I’ve been experimenting with the Python Artifact API and trying to get through an analysis with it.

I’m trying to use the feature_table.visualizers.summarize() and feature_table.visualizers.tabulate_seqs method on the the artifacts I’ve produced with data2.methods.denoise_paired(), though I’m running into the following error messages:

TypeError: Argument to parameter 'table' is not a subtype of FeatureTable[Frequency | PresenceAbsence | RelativeFrequency].
TypeError: Argument to parameter 'data' is not a subtype of FeatureData[Sequence].

This is confusing to me because when I check the objects, they show their respective data types correctly. Here’s my code:

dada2_filtered = dada2.methods.denoise_paired(demultiplexed_seqs=all_data, 
                                              trunc_len_f=0, 
                                              trunc_len_r=0)
dada2_filtered.table.save('table-dada2.qza')
dada2_filtered.representative_sequences.save('rep-seqs-dada2.qza')

print(dada2_filtered.table.type)  # returns FeatureTable[Frequency]
print(dada2_filtered.representative_sequences.type) # returns FeatureData[Sequence]

And here is the code that produces the errors:

feature_table_summary = feature_table.visualizers.summarize(table='table-dada2.qza', sample_metadata='sample-metadata.csv')

feature_table_seqs = feature_table.visualizers.tabulate_seqs(data='rep-seqs-dada2.qza')

I’ve checked the Artifact API tutorial and the plugin documentation but I’m still at a loss… Any help would be appreciated!

1 Like

As an update, I’ve managed to solve this myself. Hopefully this will help someone else in the future.

The trick was simply to load the files I had previously saved (‘table-dada2.qza’ and ‘rep-seqs-dada2.qza’) as Artifacts individually.

feature_table_artifact = Artifact.load('table-dada2.qza')
rep_seq_artifact = Artifact.load('rep-seqs-dada2.qza')

From there I was able to successfully run the following:

feature_table_summary = feature_table.visualizers.summarize(table=feature_table_metadata)
feature_table_seqs = feature_table.visualizers.tabulate_seqs(data=rep_seq_artifact)
feature_table_summary.visualization.save('table-dada2-summary.qzv')
feature_table_seqs.visualization.save('rep-seqs-summary.qzv')

I haven’t been able to figure out how to pass my sample metadata into the sample_metadata parameter of feature_table_visualizers.summarize() yet, but that will come later :slight_smile:.

Hi @forestd! Thanks for posting a follow-up! While that totally works, I just want to point out, you were super close in your original post, you were just using strings instead of the actual objects in your method calls:

 feature_table_seqs = feature_table.visualizers.tabulate_seqs(data='rep-seqs-dada2.qza')

this could have been:

feature_table_seqs = feature_table.visualizers.tabulate_seqs(data=dada2_filtered.representative_sequences)

!!! So close!

Personally, I like to use python’s destructuring here:

(table, rep_seqs) = dada2.methods.denoise_paired(demultiplexed_seqs=all_data, 
                                                 trunc_len_f=0, 
                                                 trunc_len_r=0)

Regarding loading your metadata:

sample_metadata = qiime2.Metadata.load('sample-metadata.csv')
feature_table_summary = feature_table.visualizers.summarize(table=dada2_filtered.representative_sequences,
                                                            sample_metadata=sample_metadata)

Sorry this is a bit short, so please let me know if you need any gaps filled in! Thanks! :t_rex:

1 Like

Fantastic, thank you for the follow up. The API is great to work with now that I’ve got that hang of it.

1 Like

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