Scanpy: annotating anndata object with clusters and tnse info from .csv file

Created on 17 Dec 2018  路  2Comments  路  Source: theislab/scanpy

Dear,

Thanks for this fantastic package. I saved one of my analysis to get .csv files output using the cmd adata.write_csv('./ouput'). I modified some of these files (the obs.csv and obsm) for pecific purposes related to a collaborative project while respecting the dimensions and the order of the cells. How can I reload back these files into an anndata object?

adata = sc.read_csv('./ouput/*') ??

Most helpful comment

From a gene matrix, tsne and cluster .csv files obtained from cell ranger output I was able to load these into scanpy and display a tsne plot that look exactly like the output of cellranger cloupe file. This is great thanks!

screen shot 2018-12-18 at 14 32 39

All 2 comments

The documentation for AnnData.write_csvs tells you

It is not possible to recover the full AnnData from the output of this function. Use write() for this.

Sorry for that! We thought that not having a function to read back those CSVs, we won鈥檛 lull people into the false security that the AnnData object can be safely restored from CSVs.

But if you have nothing else but those files, you can of course try to use pandas.read_csv to read the .obs and .var dataframes and do something like

adata = AnnData(
    pd.read_csv('output/X.csv').asarray(),
    pd.read_csv('output/obs.csv'),
    pd.read_csv('output/var.csv'),
    { # adata.uns
        'some_thing': pd.read_csv('output/some_thing.csv'),
    },
    pd.read_csv('output/obsm.csv'),
    pd.read_csv('output/varm.csv'),
)

You might have to fiddle with parameters to pandas.read_csv, like index_col, and obsm/varm might not be able to be specified as data frames.

From a gene matrix, tsne and cluster .csv files obtained from cell ranger output I was able to load these into scanpy and display a tsne plot that look exactly like the output of cellranger cloupe file. This is great thanks!

screen shot 2018-12-18 at 14 32 39

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MichaelPeibo picture MichaelPeibo  路  6Comments

Olivia117 picture Olivia117  路  4Comments

zhangguy picture zhangguy  路  5Comments

giovp picture giovp  路  4Comments

juugii picture juugii  路  3Comments