Repository navigation
Description
With the implementation of the new datastructure (#327), it becomes rather tricky to get information
from the airr rearrangment schema (e.g. what is the "c_call" of the primary "VJ" chain?).
Previously this was possible simply with
adata.obs["IR_VJ_1_c_call"]With the new datastructure
adata[:, "c_call"].Xjust yields an awkward array with a variable number of chains per cell. The information which
chain is VJ/VDJ and primary or secondary is hidden away in adata.obsm.
This motivates the implementation of long-proposed easy-access getter/setter functions. At the very least to
- retrieve AIRR rearrangement variables for a certain chain.
But possibly also with convenience functions, e.g.
- to retrieve the most abundant categories (previously discussed in Straightforward way for getting most abundant categories #51).
The latter is of less importance, but the interface needs to be designed jointly, therefore this is also a topic in this issue.
To get AIRR data, we need something like
ir.get(adata, "locus", "VJ_1") -> pd.SeriesWe need it regulary to get the top n of a category, e.g. v-gene or clonotype.
This can be achieved in a pandas onliner, if one knows how to do it...
# This is probably hacky, we might think about a better way, but we need the most abundant clonotypes
top_clonotypes = adata.obs.clonotype.value_counts()[:8].index.tolist() # A better way might be needed especailly to take normalization into account
top_vgenes = adata.obs.TRB_1_v_gene.value_counts()[:8].index.tolist()It would be more user-friendly to have a convenience function to this,
for instance:
ir.tl.top_n(col="clonotype", n=10)Use it for plotting:
sc.pl.umap(adata, color="clonotype", groups=ir.tl.top_n("clonotype", 10))To discuss
- retrieve multiple columns at once / vectorization?
- what about "extra" chains?
- plotting
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
grst commentedon Aug 18, 2022
Suggestion:
Implement a "getter" class that supports method chaining.
putative API:
grst commentedon Aug 18, 2022
Issues:
the
top_ndoesn't generalize well. What if you want an airr variable sorted by clonotype modularity? Or a column from another mudata modality? In most cases you'd be down to plain pandas again anyway, or the complexity of those function would increase drastically.most_frequentis quite easy to get with plain pandas:series.value_counts()[:n].index.tolist(). Maybe this is an over-abstraction?should getting AIRR variables be simpler (as this is the most common use-case)?. From obs you can retrieve stuff with direct indexing...
grst commentedon Aug 18, 2022
For the convenience functions
is more flexible, as it can be applied to any pandas series. Also one that was retrieved from the airr data, e.g
grst commentedon Aug 18, 2022
Should get be a module, or a function?
I think
ir.getas a module is flexible and future-proof. There might be more functions added in the future.Even if there will be no additional functions
is not too hard to type and it is pretty explicit about what it's doing.
grst commentedon Aug 19, 2022
For easy plotting with scanpy functions, we could do one of the following.
grst commentedon Aug 19, 2022
I like options (1) and (3), and they are not mutually exclusive.
(2) seems like it's to inflexible and leads to too many special cases.
grst commentedon Mar 21, 2023
The context manager and a get function are implemented in #356.
I decided against a
top_normost_frequentfunction as the same can be achieved quite easily with plain pandas/numpy.