API type conversion

In short, is there any way to convert
qiime2.sdk.results.Results to qiime2.sdk.result.Artifact?

Details:
I needed to trim my database sequence and then blast my ASVs against the trimmed database. The codes I used were

a1 = Artifact.import_data('FeatureData[Sequence]','ref_db.fasta')

a1_1 = qiime2.plugins.feature_classifier.methods.extract_reads(a1, f_primer = 'CCTACGGGNGGCWGCAG', r_primer = 'GACTACNVGGGTWTCTAATCC', min_length = 350, max_length = 500, n_jobs = 20, identity = 0.8)

a1_t = Artifact.import_data('FeatureData[Taxonomy]','ref_db.tax', view_type='HeaderlessTSVTaxonomyFormat')

But next when I run

a1_blast = classify_consensus_blast(qr, a1_1, a1_t, maxaccepts = 1, perc_identity = 0.99, query_cov = 0.8, strand = 'both', evalue = 0.001)

I get

TypeError: Parameter 'reference_reads' received Results (name = value)
reads = <artifact: FeatureData[Sequence] uuid: ca704db3-e42a-4ac7-8547-3053ce4d6476> as an argument, which is incompatible with parameter type: FeatureData[Sequence]`

So how to be able to do the blast on the trimmed data set using the API?

Yes — the artifact will be an attribute of the Results object. In this case your extracted reads will be in a1_1.reads

Two things you can do:

  1. add a comma after the output name to discard the rest of the Results. a1_1 will now the an Artifact object:
a1_1, = qiime2.plugins.feature_classifier.methods.extract_reads(a1, f_primer = 'CCTACGGGNGGCWGCAG', r_primer = 'GACTACNVGGGTWTCTAATCC', min_length = 350, max_length = 500, n_jobs = 20, identity = 0.8)

OR
Select the attribute you want:

a1_blast = classify_consensus_blast(qr, a1_1.reads, a1_t, maxaccepts = 1, perc_identity = 0.99, query_cov = 0.8, strand = 'both', evalue = 0.001)
1 Like

Also, there are some API docs here that might be helpful:

qiime2.sdk.results.Results

qiime2.sdk.result.Artifact

3 Likes

Thanks a lot for the solution. I absolutely forgot to dir().

If I may ask, is there any multithreading option for the blast?
I usually use -num_threads for blastn. But couldn’t find one here.

the classify-consensus-blast method does not have multithreading enabled — I'm not sure why but I would welcome you to contribute to the source code to add this option!

if you need multithreading, try the classify-consensus-vsearch method — it is a global aligner but could get you what you need, and has some other useful options that the blast-based classifier lacks.

1 Like