# API type conversion

**URL:** <https://forum.qiime2.org/t/api-type-conversion/12879>\
**Category:** Developer Discussion\
**Tags:** artifact-api\
**Created:** [December 13, 2019, 5:57pm UTC](https://forum.qiime2.org/t/api-type-conversion/12879 "2019-12-13T17:57:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhishake](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/a/a6a055/32.png) [@abhishake](https://forum.qiime2.org/u/abhishake)\
**Post date:** [December 13, 2019, 5:57pm UTC](https://forum.qiime2.org/t/api-type-conversion/12879/1 "2019-12-13T17:57:58Z")

</div>

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?

---

<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:** [December 14, 2019, 4:06pm UTC](https://forum.qiime2.org/t/api-type-conversion/12879/2 "2019-12-14T16:06:23Z")

</div>

> [@abhishake](#):
>
> In short, is there any way to convert  
> `qiime2.sdk.results.Results` to `qiime2.sdk.result.Artifact` ?

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:

```python
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:

```python
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)

```

---

<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:** [December 14, 2019, 5:59pm UTC](https://forum.qiime2.org/t/api-type-conversion/12879/3 "2019-12-14T17:59:22Z")

</div>

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

[`qiime2.sdk.results.Results`](https://dev.qiime2.org/latest/api-reference/sdk/#qiime2.sdk.Results)

[`qiime2.sdk.result.Artifact`](https://dev.qiime2.org/latest/api-reference/sdk/#qiime2.sdk.Artifact)

---

<div class="post-metadata">

**Author:** ![abhishake](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/a/a6a055/32.png) [@abhishake](https://forum.qiime2.org/u/abhishake)\
**Post date:** [December 15, 2019, 3:19pm UTC](https://forum.qiime2.org/t/api-type-conversion/12879/4 "2019-12-15T15:19:18Z")

</div>

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.

---

<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:** [December 15, 2019, 4:08pm UTC](https://forum.qiime2.org/t/api-type-conversion/12879/5 "2019-12-15T16:08:39Z")

</div>

> [@abhishake](#):
>
> If I may ask, is there any multithreading option for the blast?

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.
