Skip to content

Commit

Permalink
Merge branch 'feat/sparse-dist' into 'master'
Browse files Browse the repository at this point in the history
Scale up TCR dist

Closes #38 and #41

See merge request icbi-lab/pipelines/singlecell_tcr!22

Former-commit-id: 0b60de2d242c8c5297fb676e162e1d06e6eadfe2
  • Loading branch information
grst committed Mar 24, 2020
2 parents 8c64fb9 + 680cead commit 9680741
Show file tree
Hide file tree
Showing 13 changed files with 1,032 additions and 611 deletions.
3 changes: 2 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Preprocessing: `pp`
:toctree: .

merge_with_tcr
tcr_dist
tcr_neighbors


Tools: `tl`
Expand All @@ -54,7 +56,6 @@ Tools: `tl`

define_clonotypes
clonotype_network
tcr_dist
chain_pairing
clip_and_count
alpha_diversity
Expand Down
13 changes: 7 additions & 6 deletions docs/tutorials/tutorial_3k_tcr.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ It just has additional TCR-related columns in `obs`:
adata.obs
```

```python

```

## Preprocess Transcriptomics data

Transcriptomics data needs to be filtered and preprocessed as with any other single-cell dataset.
Expand Down Expand Up @@ -128,7 +124,11 @@ All connected nodes form a clonotype.
* With the `chains` parameter, we can specify if we want to consider only the most abundant TRA and TRB sequences (`primary_only`), or all four CDR3 sequences, if available (`all`).

```python
st.tl.define_clonotypes(adata, strategy="all", chains="primary_only", cutoff=0)
st.pp.tcr_neighbors(adata, strategy="all", chains="primary_only", cutoff=0)
```

```python
st.tl.define_clonotypes(adata)
```

Let's visualize the resulting graph.
Expand All @@ -148,7 +148,8 @@ Now, we allow a TCR-distance of 20. That's the equivalent of 4 `R`s mutating int
Also we now use `chains='all'`

```python
st.tl.define_clonotypes(adata, strategy="all", chains="all", cutoff=20)
st.pp.tcr_neighbors(adata, strategy="all", chains="all", cutoff=20)
st.tl.define_clonotypes(adata)
```

```python
Expand Down
8 changes: 5 additions & 3 deletions sctcrpy/_plotting/_tcr_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from anndata import AnnData
import igraph as ig
import numpy as np
from .._tools._tcr_dist import get_igraph_from_adjacency
from .._util import get_igraph_from_adjacency


def clonotype_network(adata, color, *, key="clonotype", obsm_key="X_clonotype_network"):
def clonotype_network(
adata, color, *, neighbors_key="neighbors", obsm_key="X_clonotype_network"
):
"""Plot the clonotype network"""
idx = np.where(~np.any(np.isnan(adata.obsm[obsm_key]), axis=1))[0]
adj = adata.uns["sctcrpy"][key + "_connectivities"][idx, :][:, idx]
adj = adata.uns["sctcrpy"][neighbors_key]["connectivities"][idx, :][:, idx]
g = get_igraph_from_adjacency(adj)
layout = ig.Layout(adata.obsm[obsm_key][idx, :].tolist())
# return g, layout
Expand Down
2 changes: 2 additions & 0 deletions sctcrpy/_preprocessing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from ._merge_adata import merge_with_tcr
from ._tcr_dist import tcr_dist, tcr_neighbors
File renamed without changes.
Loading

0 comments on commit 9680741

Please sign in to comment.