Comments (3)
Of course, asking for help is often the fastest way to find the answer on your own. This works:
selected = adata[:, adata.var_names.isin(['Tcea1',])]
# This is for a complete matrix
for g, gene in enumerate(selected.var_names):
for c, cell in enumerate(selected.obs_names):
print("{0}\t{1}\t{2}".format(cell, gene, selected.X[c]))
It seems like using "isin()" when you're only going after one gene is suboptimal though.
from anndata.
Hi Joshua!
When you select one row or column, the matrix will get flattened, as this is numpy's behavior and often very practical. See the following comment in the Notes
section http://anndata.readthedocs.io/en/latest/anndata.AnnData.html
adata = AnnData(np.ones((2, 2)))
adata[:, 0].X == adata.X[:, 0]
So, if you're only going for single gene, then you get a 1d vector and not a matrix. Would you like to see this behavior different? Your trick with ['Tcea1', ]
is definitely a very good workaround if you want something two-dimensional.
PS: You can also use 'Tcea1' == adata.var_names
instead of using .isin(...)
when you only have a single element.
from anndata.
Of course, asking for help is often the fastest way to find the answer on your own.
haha yeah, it’s called rubber duck debugging
When you select one row or column, the matrix will get flattened, as this is numpy's behavior and often very practical.
Oh, once upon a time I made sure that this doesn’t happen in AnnData, since AnnData is always a 2D structure (You should always have (at least one) named cell(s) and gene(s), never just a 1D vector of expression values without knowing what dimension it is along)
from anndata.
Related Issues (20)
- `to_df` docstrings
- dask.array.store but with anndata schema HOT 1
- Indexing With a Dask Array HOT 5
- adata.raw = adata HOT 1
- GPU CI tests failing HOT 2
- Add working `GroupStorageType` type annotation
- 0.10.6 - Cannot write files due to implicit conversion to str dtype. HOT 2
- Saving .h5ad with pd.Series in .uns results in IORegistryError HOT 3
- `read_elem_as_dask` HOT 8
- `FileNotFoundError: [Errno 2] No such file or directory: 'llvm-config'` on CI HOT 2
- Upcoming Scipy 1.13 incompatible with file-backed sparse matrices
- CZI files' `var` count changd
- `/` in column names makes AnnData Zarr object unreadable on windows HOT 12
- String indexes in var lead to UserWarning HOT 1
- Move tests out of the package
- Refactor `BaseCompressedSparseDataset` and subclasses to remove `backed_{csr,csc}_matrix`
- concat_on_disk should use int64 indptrs by default so that it can concatenate large files HOT 4
- TypeError: Can't implicitly convert non-string objects to strings HOT 4
- Error concatenating scRNA with visium dataset
- Error: Expected a python object, received a character HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anndata.