# Per-sample media/diets in q2-micom¶

Under the hood micom and q2-micom do have support for sample-specific media. In fact, that is micom only knows sample-specific media. If a media is not sample-speciic it is internally copied for each sample in the data set. To get an understanding of how to create a per-sample medium for q2-micom let's first have a look at the actual format. Media/diets in micom are just DataFrames with at least the columns metabolite, reaction and flux.

In [1]:
import qiime2 as q2
import pandas as pd

medium = arti.view(pd.DataFrame)

Out[1]:
flux dilution metabolite reaction
0 0.014899 0.1 fru_m EX_fru_m
1 0.014899 0.1 glc_m EX_glc_m
2 0.014899 0.1 gal_m EX_gal_m
3 0.014899 0.1 man_m EX_man_m
4 0.014899 0.1 mnl_m EX_mnl_m

As you see you may also add additional columns to annotate your data. This is a global medium:

In [3]:
arti.type

Out[3]:
MicomMedium[Global]

For a per sample medium you will need an additional column called sample_id. There should be a row for each metabolite that is consumed in each sample. So for instance let's assume we want to convert the current medium into sample-specific media for a normal and a diabetic sample that has higher glucose availability. For this we duplicate the medium, modify the glucose flux bound, add the sample IDs and concatenate the media.

In [5]:
diabetic = medium.copy()
diabetic.loc[diabetic.metabolite == "glc_m", "flux"] = 0.1
diabetic["sample_id"] = "diabetic"
medium["sample_id"] = "normal"

per_sample_medium = pd.concat([medium, diabetic])

Out[5]:
flux dilution metabolite reaction sample_id
0 0.014899 0.1 fru_m EX_fru_m normal
1 0.014899 0.1 glc_m EX_glc_m normal
2 0.014899 0.1 gal_m EX_gal_m normal
3 0.014899 0.1 man_m EX_man_m normal
4 0.014899 0.1 mnl_m EX_mnl_m normal

Not that the sample IDs have to correspond to your sample names used in your OTU table paased to qiime micom build.

Now we can save the medium as a per=sample q2-micom medium:

In [8]:
new_arti = q2.Artifact.import_data("MicomMedium[PerSample]", per_sample_medium)
new_arti.save("my_media.qza")

Out[8]:
'my_media.qza'

And that's it 🎉 If you use this saved media with qiime micom grow it will automatically apply the correct medium for each sample.

In [ ]: