scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.92k stars 600 forks source link

interaction with loom object #933

Open koalap-2018 opened 4 years ago

koalap-2018 commented 4 years ago

Hi guys,

I have opened a loom file on scanpy by running: sc.read_loom. Once i try to see what is in there this is what pops up:

AnnData object with n_obs × n_vars = 56902 × 17473 obs: 'Age', 'Clusterings', 'Embedding', 'Embeddings_X', 'Embeddings_Y', 'Gender', 'Genotype', 'RegulonsAUC', 'Replicate', 'nGene', 'nUMI' var: 'ClusterMarkers_0', 'ClusterMarkers_0_sub_0', 'ClusterMarkers_0_sub_1', 'ClusterMarkers_0_sub_10', 'ClusterMarkers_0_sub_11', 'ClusterMarkers_0_sub_12', 'ClusterMarkers_0_sub_13', 'ClusterMarkers_0_sub_14', 'ClusterMarkers_0_sub_15', 'ClusterMarkers_0_sub_16', 'ClusterMarkers_0_sub_17', 'ClusterMarkers_0_sub_18', 'ClusterMarkers_0_sub_19', 'ClusterMarkers_0_sub_2', 'ClusterMarkers_0_sub_20', 'ClusterMarkers_0_sub_21', 'ClusterMarkers_0_sub_22', 'ClusterMarkers_0_sub_23', 'ClusterMarkers_0_sub_24', 'ClusterMarkers_0_sub_25', 'ClusterMarkers_0_sub_26', 'ClusterMarkers_0_sub_27', 'ClusterMarkers_0_sub_28', 'ClusterMarkers_0_sub_29', 'ClusterMarkers_0_sub_3', 'ClusterMarkers_0_sub_30', 'ClusterMarkers_0_sub_31', 'ClusterMarkers_0_sub_32', 'ClusterMarkers_0_sub_33', 'ClusterMarkers_0_sub_34', 'ClusterMarkers_0_sub_35', 'ClusterMarkers_0_sub_36', 'ClusterMarkers_0_sub_37', 'ClusterMarkers_0_sub_38', 'ClusterMarkers_0_sub_39', 'ClusterMarkers_0_sub_4', 'ClusterMarkers_0_sub_40', 'ClusterMarkers_0_sub_41', 'ClusterMarkers_0_sub_42', 'ClusterMarkers_0_sub_43', 'ClusterMarkers_0_sub_44', 'ClusterMarkers_0_sub_45', 'ClusterMarkers_0_sub_46', 'ClusterMarkers_0_sub_47', 'ClusterMarkers_0_sub_48', 'ClusterMarkers_0_sub_49', 'ClusterMarkers_0_sub_5', 'ClusterMarkers_0_sub_50', 'ClusterMarkers_0_sub_51', 'ClusterMarkers_0_sub_52', 'ClusterMarkers_0_sub_53', 'ClusterMarkers_0_sub_54', 'ClusterMarkers_0_sub_55', 'ClusterMarkers_0_sub_56', 'ClusterMarkers_0_sub_57', 'ClusterMarkers_0_sub_58', 'ClusterMarkers_0_sub_59', 'ClusterMarkers_0_sub_6', 'ClusterMarkers_0_sub_60', 'ClusterMarkers_0_sub_61', 'ClusterMarkers_0_sub_62', 'ClusterMarkers_0_sub_63', 'ClusterMarkers_0_sub_64', 'ClusterMarkers_0_sub_65', 'ClusterMarkers_0_sub_66', 'ClusterMarkers_0_sub_67', 'ClusterMarkers_0_sub_68', 'ClusterMarkers_0_sub_69', 'ClusterMarkers_0_sub_7', 'ClusterMarkers_0_sub_70', 'ClusterMarkers_0_sub_71', 'ClusterMarkers_0_sub_72', 'ClusterMarkers_0_sub_8', 'ClusterMarkers_0_sub_9', 'ClusterMarkers_1', 'ClusterMarkers_2', 'ClusterMarkers_3', 'ClusterMarkers_4', 'ClusterMarkers_5', 'ClusterMarkers_6', 'ClusterMarkers_7', 'Regulons' obsm: 'ClusterID'

This is from publicaly available data. so what i would like to do is plot their published tsne or umap and compare a few things from it. If I simply run sc.pl.tsne(loom_file, color=['louvain']) I get error msg: ValueError: no field of name X_tsne

This makes sense as there is not X_tsne on the object. How could I get pass this without re-clustering myself? At the moment I am only interested in pulling out 2 of their annotated clusters... if there is an easy way to do this via scanpy please let me know.

ivirshup commented 4 years ago

Without knowing more about the file, I'm guessing you're going to want to do something like:

# Assuming these are the tsne coordinates
adata.obsm["X_tsne"] = adata.obs[["Embeddings_X", "Embeddings_Y"]]  
sc.pl.tsne(adata, color="clusterings")

After setting this you could probably save this file, then use cellxgene to view it more easily.

To subset, do something like:

subset = adata[adata.obs["clusterings"].isin(cluster_ids), :]