# Python API semantic type under the hood?

**URL:** https://forum.qiime2.org/t/python-api-semantic-type-under-the-hood/13711
**Category:** User Support
**Tags:** python-api
**Created:** [February 20, 2020, 8:10pm UTC](https://forum.qiime2.org/t/python-api-semantic-type-under-the-hood/13711 "2020-02-20T20:10:15Z")
**Posts on this page:** 1
**Showing post:** 6

<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: [March 6, 2020, 4:30pm UTC](https://forum.qiime2.org/t/python-api-semantic-type-under-the-hood/13711/6 "2020-03-06T16:30:57Z")

</div>

Hello @jwdebelius, sorry for the slow reply!

> [@jwdebelius](#):
>
> Specifically, I’m trying to figure out how to make a `FeatureData[Sequence]` type out of a pandas Series where my index is the sequence identifier and the value is the sequence without quality information.

Fortunately there is a [transformer](https://dev.qiime2.org/latest/glossary/#term-transformer) defined in q2-types that does this:

> <https://github.com/qiime2/q2-types/blob/261cb96f2c7af2c671e6e1a1011f0502b7604817/q2_types/feature_data/_transformer.py#L339-L346>

I only share the snippet above so that you can get a sense of where those kinds of things might be defined, code-wise.

Since transformers are defined in a plugin, but then registered for use within an entire deployment of QIIME 2, it is usually easiest to look up the transformer from an instance of the [`sdk.PluginManager`](https://dev.qiime2.org/latest/api-reference/sdk/#qiime2.sdk.PluginManager):

```python
# Rather than importing an individual plugin, we
# can get information about the _entire_ environment
# by using
from qiime2 import sdk, Artifact
from qiime2.plugin import util

import pandas as pd

# This instance of the PluginManager will be
# our "Virgil" on this descent into madness.
pm = sdk.PluginManager()

# We need to build a better interface for this, but in
# the meantime this should work... I am looking up
# the view type that you want to go _from_.
for fmt in pm.transformers[pd.Series].keys():
    print(fmt. __name__ )
print()

# Okay, so it looks like we have a transformer:
# from pd.Series -> DNAFASTAFormat
# Let's use it!
data = pd.Series(['AAAA', 'GGGG'], index=['f1', 'f2'])

fasta_format_record = pm.formats['DNAFASTAFormat']
fasta_file = util.transform(data, to_type=fasta_format_record.format)

with fasta_file.open() as fh:
    print(fh.read())

# Two important things to note here:
# 1) The exercise of "searching" for transformers
# above isn't a requirement for just trying to
# invoke a transformer.
# 2) This example just uses QIIME 2 machinery, without
# actually creating a QIIME 2 result (Artifact).

# Alternatively, if you need an Artifact, you can just import
# the series, invoking the transformer automatically

artifact = Artifact.import_data('FeatureData[Sequence]',
                                data, view_type=pd.Series)

print(artifact)

```

Stdout:

```python
FirstDifferencesFormat
AlphaDiversityFormat
TSVTaxonomyFormat
DNAFASTAFormat
BooleanSeriesFormat
PredictionsFormat

>f1
AAAA
>f2
GGGG

<artifact: FeatureData[Sequence] uuid: 96be024e-6a1d-44d6-a814-540e1294e0d9>

```

We are currently working on making modifications to the SDK to allow for a more streamlined transformer lookup (maybe landing in 2020?). Also, our [CZI-funded Library work](https://forum.qiime2.org/t/qiime-2-czi-essential-open-source-software-for-science-announcement/12604) aims to expose information (on a plugin level) about what formats, types, and transformers are registered.

Hope that helps!

---

_[View the full topic](https://forum.qiime2.org/t/python-api-semantic-type-under-the-hood/13711)._
