biocore / DEICODE

Robust Aitchison PCA from sparse count data
Other
33 stars 17 forks source link

How to use OptSpace function in Python? No fit_transform method #46

Open jolespin opened 5 years ago

jolespin commented 5 years ago

I'm trying to use U,s,V = OptSpace().fit_transform(A_) but there are no defaults for OptSpace and there is also no fit_transform method.

How can I use your DEICODE Python package without using qiime2?

Side question, is OptSpace only intended for aitchison transformed compositional data?

mortonjt commented 5 years ago

I don't think there are any python tutorials on how to run optspace - it was designed to run in the command line.

But there are some unittests that may help you run it : see here

jolespin commented 5 years ago

Thanks, I was basing it off of this tutorial here: https://github.com/biocore/DEICODE/blob/master/ipynb/introduction.ipynb

I vaguely remember trying out DEICODE (maybe it was named something different) in the past before it was integrated into QIIME2

cameronmartino commented 5 years ago

We/I should add some docs on how to do this. @mortonjt The only problem I see with running optspace in this way is it would bypass the recentering done in the rpca script. However, you could run rpca as a python API and return a skbio OrdinationResults and DistanceMatrix.

mortonjt commented 5 years ago

Right, basically use the qiime2 function in python. That can be done via

from deicode.rpca import rpca
ord_res, dist_res = rpca(microbes_biom)
jolespin commented 5 years ago

Is rpca a preprocessing step for OptSpace? Is it possible to run OptSpace with the input as either a pandas dataframe or numpy array?

cameronmartino commented 4 years ago

Hi @jolespin, You will still need to import your data into biom format (see example below on how to do that from a data frame) but I added a tutorial on how to do this. You can find that tutorial here. Hope this helps. (Note: the biplot function I used is just a helper for that tutorial and is not unit-tested, so use that with caution). Also, the version in that tutorial is not released yet so run pip install git+https://github.com/biocore/DEICODE to get the right version installed.

import pandas as pd
from biom import Table

# a table where the index are features (i.e. ASVs) and columns are samples
table_df = pd.read_csv("path/to/table/table.tsv", sep="\t", index_col=0)
# make biom table
bt = Table(table_df.values, table_df.index, table_df.columns)