Add column in Obs. in anndata using scanpy
0
0
Entering edit mode
15 months ago
Nai ▴ 50

I separate the cells on the basis of a gene expression and now i would like to add column in obs where the genes are highly expressed then mention high and where it is low...then mentioned low. I am using anndata in scanpy

adata_H = adata_tumor[adata_tumor:, 'P53']. X > 0.5, :] adata_L = adata_tumor[adata_tumor:, 'P53']. X == 0, :] adata_tumor.obs["class"] = "high" adata_tumor.obs.loc[adata_L, "class"] = "low"

Then it shows

TypeError Traceback (most recent call last) /tmp/ipykernel_97150/1305879651.py in <module> ----> 1 adata_TUMOR.obs.loc[low_1,'class'] = "low"

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexing.py in __setitem__(self, key, value) 717 else: 718 key = com.apply_if_callable(key, self.obj) --> 719 indexer = self._get_setitem_indexer(key) 720 self._has_valid_setitem_indexer(key) 721

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexing.py in _get_setitem_indexer(self, key) 658 if isinstance(key, tuple): 659 with suppress(IndexingError): --> 660 return self._convert_tuple(key, is_setter=True) 661 662 if isinstance(key, range):

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexing.py in _convert_tuple(self, key, is_setter) 783 self._validate_key_length(key) 784 for i, k in enumerate(key): --> 785 idx = self._convert_to_indexer(k, axis=i, is_setter=is_setter) 786 keyidx.append(idx) 787

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexing.py in _convert_to_indexer(self, key, axis, is_setter) 1258 else: 1259 try: -> 1260 return labels.get_loc(key) 1261 except LookupError: 1262 # allow a not found key only if we are a setter

~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 3359 casted_key = self._maybe_cast_indexer(key) 3360 try: -> 3361 return self._engine.get_loc(casted_key) 3362 except KeyError as err: 3363 raise KeyError(key) from err

~/anaconda3/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

~/anaconda3/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

TypeError: 'View of AnnData object with n_obs × n_vars = 1679 × 33538 obs: 'age', 'barcode', 'batch', 'group', 'highest_GLEASON_score', 'mri_grading', 'name', 'patient', 'pool', 'psa', 'sample', 'scrublet_score', 'scrublet_cluster_score', 'bh_pval', 'is_doublet', 'n_genes', 'percent_mito', 'n_counts', 'S_score', 'G2M_score', 'phase', 'leiden', 'celltype', 'Biopsy Location DETAIL', 'Biopsy Location BRIEF', 'Biopsy Location Co-ordinate', 'PMHx', 'celltype-immune', 'class' var: 'gene_ids', 'feature_types' uns: 'celltype-immune_colors', 'celltype_colors', 'dendrogram_leiden', 'group_colors', 'leiden', 'neighbors', 'patient_colors', 'pca', 'phase_colors', 'rank_genes_groups', 'umap', 'leiden_colors' obsm: 'X_pca', 'X_umap' layers: 'cellranger_counts', 'soupx_counts'' is an invalid key

scanpy • 903 views
ADD COMMENT

Login before adding your answer.

Traffic: 2934 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6