From 878c1a0a8796ef36b6e8f1881d280777c497fd5a Mon Sep 17 00:00:00 2001 From: Zewen Kelvin Tuong Date: Fri, 3 Feb 2023 19:55:09 +1000 Subject: [PATCH] Return gamma delta notebook (#250) * Create gamma_delta.ipynb * black updated... * Update gamma_delta.ipynb typo --- dandelion/plotting/_plotting.py | 6 +-- dandelion/preprocessing/_preprocessing.py | 19 ++------ dandelion/tools/_diversity.py | 6 +-- dandelion/tools/_network.py | 4 -- dandelion/utilities/_core.py | 1 - docs/notebooks/gamma_delta.ipynb | 54 +++++++++++++++++++++++ 6 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 docs/notebooks/gamma_delta.ipynb diff --git a/dandelion/plotting/_plotting.py b/dandelion/plotting/_plotting.py index 786dfc9f4..f7832939d 100644 --- a/dandelion/plotting/_plotting.py +++ b/dandelion/plotting/_plotting.py @@ -138,11 +138,7 @@ def clone_rarefaction( n = np.append(n, tot[i]) rarecurve[res_.index[i]] = [ rarefun( - np.array( - res_.iloc[ - i, - ] - ), + np.array(res_.iloc[i,]), z, ) for z in n diff --git a/dandelion/preprocessing/_preprocessing.py b/dandelion/preprocessing/_preprocessing.py index aa759540d..73db7de43 100644 --- a/dandelion/preprocessing/_preprocessing.py +++ b/dandelion/preprocessing/_preprocessing.py @@ -2005,12 +2005,8 @@ def _create_germlines_object( # Define Receptor iterator receptor_iter = ( ( - data.data.loc[ - x, - ].sequence_id, - data.data.loc[ - x, - ], + data.data.loc[x,].sequence_id, + data.data.loc[x,], ) for x in data.data.index ) @@ -2042,12 +2038,8 @@ def _create_germlines_object( # Define Receptor iterator receptor_iter = ( ( - data.loc[ - x, - ].sequence_id, - data.loc[ - x, - ], + data.loc[x,].sequence_id, + data.loc[x,], ) for x in data.index ) @@ -2741,7 +2733,6 @@ def quantify_mutations( if region_definition is None: reg_d = NULL else: - reg_d = base.get(region_definition) if mutation_definition is None: @@ -3392,7 +3383,6 @@ def __init__( h_locus_p = list(data1["locus"]) if len(h_p) > 1: if "sequence_alignment" in data1: - ( data1, h_p, @@ -3423,7 +3413,6 @@ def __init__( sum_umi = sum(h_umi_p) if "IGHD" in h_ccall_p: if all(x in ["IGHM", "IGHD"] for x in h_ccall_p): - h_ccall_p_igm_count = dict( data1[data1["c_call"] == "IGHM"][ "duplicate_count" diff --git a/dandelion/tools/_diversity.py b/dandelion/tools/_diversity.py index 719a654a0..35ffc0808 100644 --- a/dandelion/tools/_diversity.py +++ b/dandelion/tools/_diversity.py @@ -104,11 +104,7 @@ def clone_rarefaction( n = np.append(n, tot[i]) rarecurve[res_.index[i]] = [ rarefun( - np.array( - res_.iloc[ - i, - ] - ), + np.array(res_.iloc[i,]), z, ) for z in n diff --git a/dandelion/tools/_network.py b/dandelion/tools/_network.py index 79790bbff..be9112f54 100644 --- a/dandelion/tools/_network.py +++ b/dandelion/tools/_network.py @@ -1125,7 +1125,6 @@ def nx2gt(nxG): # Add the node properties first nprops = set() # cache keys to only add properties once for node, data in list(nxG.nodes(data=True)): - # Go through all the properties if not seen and add them. for key, val in data.items(): if key in nprops: @@ -1148,7 +1147,6 @@ def nx2gt(nxG): # Add the edge properties second eprops = set() # cache keys to only add properties once for src, dst, data in list(nxG.edges(data=True)): - # Go through all the edge properties if not seen and add them. for key, val in data.items(): if key in eprops: @@ -1167,7 +1165,6 @@ def nx2gt(nxG): # Add the nodes vertices = {} # vertex mapping for tracking edges later for node, data in list(nxG.nodes(data=True)): - # Create the vertex and annotate for our edges later v = gtG.add_vertex() vertices[node] = v @@ -1179,7 +1176,6 @@ def nx2gt(nxG): # Add the edges for src, dst, data in list(nxG.edges(data=True)): - # Look up the vertex structs from our vertices mapping and add edge. e = gtG.add_edge(vertices[src], vertices[dst]) diff --git a/dandelion/utilities/_core.py b/dandelion/utilities/_core.py index 7488c3348..fa2396d71 100644 --- a/dandelion/utilities/_core.py +++ b/dandelion/utilities/_core.py @@ -2351,7 +2351,6 @@ def initialize_metadata( vdj_gene_calls = ["v_call", "d_call", "j_call"] if collapse_alleles: for x in vdj_gene_calls: - if x in vdj_data.data: for c in tmp_metadata: if x in c: diff --git a/docs/notebooks/gamma_delta.ipynb b/docs/notebooks/gamma_delta.ipynb new file mode 100644 index 000000000..83e03910c --- /dev/null +++ b/docs/notebooks/gamma_delta.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Dandelion for TCR gamma/delta reannotation\n", + "\n", + "![dandelion_logo](img/dandelion_logo_illustration.png)\n", + "\n", + "In Cell Ranger 3.1.0, the VDJ algorithm was changed to favour TCR alpha/beta annotation. Since then, calling gamma/delta chains has become challenging, and 10X support recommends using Cell Ranger 3.0.2 when working with gamma/delta-rich libraries. \n", + "\n", + "However, the contigs themselves are still accurately reconstructed, just not annotated correctly. It may be desirable to use a newer Cell Ranger version for access to some previously unavailable run options, like specifying custom enrichment primers. In those cases, the contigs can be reannotated via `dandelion` to yield functional output.\n", + "\n", + "Just follow [standard protocol](https://sc-dandelion.readthedocs.io/en/latest/notebooks/Q1-singularity-preprocessing.html) for preparing and running the preprocessing. The parameterisation recommendation is applicable here as well:\n", + "\n", + "```bash\n", + "singularity run -B $PWD /path/to/sc-dandelion_latest.sif dandelion-preprocess \\\n", + " --chain TR \\\n", + " --file_prefix all \\\n", + " --filter_to_high_confidence\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}