extracting spliced/unspliced matrix from annData object #483
-
Hi I am running scvelo on my single cell RNA-seq data. I need to get the spliced and unspliced sparse matrix. I see it is saved as layers in and data object. When I export whole Anndata objcet to csv file ( adata.write_csvs('adata')), layers do not get extracted. I tried to specifically extract spliced and unspliced matrxes unsing other way like following, however it extracts the unreadable file: >>> import pickle
>>> x=adata.layers['spliced']
>>> with open('spliced.txt', 'wb') as spliced:
... pickle.dump(x, spliced) I would like to export those highlighted data >>> adata
AnnData object with n_obs × n_vars = 37001 × 54532
var: 'Accession', 'Chromosome', 'End', 'Start', 'Strand'
layers: 'ambiguous', 'matrix', **'spliced', 'unspliced'** How can I do that? Looking forward to hearing from you. Khagani |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
@eynullazada, you could do the following import pandas as pd
unspliced_df = pd.DataFrame(adata.layers['unspliced'], index=adata.obs_names, columns=adata.var_names)
unspliced_df.to_csv(PATH_TO_DATA / 'unspliced.csv')
spliced_df = pd.DataFrame(adata.layers['spliced'], index=adata.obs_names, columns=adata.var_names)
spliced_df.to_csv(PATH_TO_DATA / 'spliced.csv') If your AnnData is loaded and |
Beta Was this translation helpful? Give feedback.
@eynullazada, you could do the following
If your AnnData is loaded and
PATH_TO_DATA
is defined as apathlib.Path
pointing to the directory where your CSV files are to be saved, the code snipped should run as is.