Clonal Insights snippets#
This notebook is set up to work with Clonal Insights h5 files, generated with v3 chemistry. This notebook will only work with Mosaic versions 3.17 and higher.
Objective: To showcase steps to adjust output from the Clonal Insights report and generate a new report, and perform CNV analysis.
Sections:
Setup
DNA Analysis
CNV Analysis
Protein Clustering
Export and Save Data
Not shown:
All available methods and options - documented here
Setup#
Topics covered
Load dependencies
Load data
Load Dependencies#
NOTE: importing dependencies can sometimes take a couple of minutes.
import warnings
warnings.filterwarnings('ignore')
# Import mosaic libraries
import missionbio.mosaic as ms
from missionbio.config.config import Config
from missionbio.mosaic.assay import _Assay
# Import graph_objects from the plotly package to display figures when saving the notebook as an HTML
import plotly as px
import plotly.graph_objects as go
# Import additional packages for specific visuals
import matplotlib.pyplot as plt
import plotly.offline as pyo
pyo.init_notebook_mode()
import pandas as pd
import numpy as np
import seaborn as sns
from missionbio.plotting.multimap import MultiMap
from missionbio.plotting.heatmap import Heatmap
import plotly.graph_objects as go
from IPython.display import display, HTML
from sklearn.decomposition import PCA
# Import dependencies to create a new report
from pathlib import Path
from missionbio.tertiary.config.prepare import DEFAULTS
from missionbio.tertiary.step.report import create_single_patient_report, create_cohort_report
# Read in the configuration file
config = Config.read({}, DEFAULTS)
# Note: when exporting the notebook as an HTML, plots that use the "go.Figure(fig)" command are saved
Load the data#
# Specify the h5 file to be used in this analysis: h5path = '/path/to/h5/file/test.h5'
# If working with Windows, an 'r' may need to be added before the path: h5path = r'/path/to/h5/file/test.h5'
h5path = './Example.h5'
sample = ms.load(h5path)
DNA Analysis#
Review variants included in the Clonal Insights report and remove unwanted variants.
# List all DNA variants
sample.dna.ids()
# Blacklist any variants you would like to remove
blacklist_vars = ['chr2:25469913:C/T','chr2:25457242:C/T']
sample.dna = sample.dna.drop(blacklist_vars)
# Check that variants were dropped from the sample
sample.dna.ids()
CNV Analysis#
Topics covered
Amplicon and cell filtering and ploidy estimation
Visualization of ploidy across subclones present
# Get gene names for amplicons
sample.cnv.get_gene_names();
CNV workflow#
This workflow will normalize all reads and filter amplicons/cells based on the settings set at the beginning of the workflow:
Amplicon completeness: refers to the minimum percentage of cells that must have reads greater than or equal to the minimum read depth set. By default this is set to 50.
Amplicon read depth: refers to the minimum read depth for each amplicon-barcode combination to not be considered missing. By default this is set to 10.
Mean cell read depth: refers the minimum mean read depth for a cell to be included in the analysis, otherwise the cell will be removed. By default this is set to 40.
Diploid clone in DNA: refers to which subclone is used as the true diploid population. All ploidy estimates will be calculated in relation to this diploid population. We recommend setting this to the ‘WT’ population or earliest clone present.
NOTE: If large copy number events are expected, Amplicon Completeness and Amplicon Read Depth may need to be reduced.
Once the above filters are set, the visualizations can be changed.
Plot: Can be changed from Heatmap positions, to Heatmap genes, Line-plot positions, Line-plot genes.
Clone for line plot: If one of the line-plot visualizations is selected, only one clone can be shown at a time. This determines which one is plotted.
X-axis features: To plot a subset of the data (chromosomes or genes), select which chromosomes/genes should be plotted with this function. Chromosomes can be selected for ‘positions’ type plots, and Genes can be selected for ‘genes’ type plots.
More on this workflow can be found here.
# CNV workflow to filter, normalize and estimate ploidy
wfc = ms.workflows.CopyNumber(sample)
wfc.run()
NOTE: When continuing onto the next piece of the notebook, the workflow will stop working.
# Heatmap with the features ordered by the default amplicon order
# To plot a subset of chromosome, the chromosomes can be put in list format in the features argument
fig = sample.cnv.heatmap('ploidy', features='positions') #features=['7', '17', '20']
# Optionally, restrict the range of ploidy values based on observed/expected CNV events (commented out)
#fig.layout.coloraxis.cmax = 4
#fig.layout.coloraxis.cmin = 0
# Optionally, change the size of the figure:
#fig.layout.width = 1600
#fig.layout.height = 1500
go.Figure(fig)
# Heatmap with the features grouped by the genes
# To plot just a subset of genes, put them in list format for features
fig = sample.cnv.heatmap('ploidy', features='genes', convolve=1) #features=["ASXL1", "EZH2",'TP53']
# Optionally, update the separating lines to be black
#for shape in fig.layout.shapes:
# shape.line.color = '#000000'
go.Figure(fig)
# Show heatmap with convolve and subclustering turned off
bars = sample.cnv.clustered_barcodes('ploidy', subcluster=False)
# This is useful to create "convolved" heatmaps which are easier to interpret
# With the subclustering off and convolve=20, the noise will be reduced and real signals will be easier to visualize
fig = sample.cnv.heatmap('ploidy', bars_order=bars, convolve=20)
fig.layout.width = 900
fig.show()
Protein Analysis#
Review protein clustering and recluster by modifying parameters.
# load default config and update parameters if desired
config["tertiary.rna.normalize.min_reads_per_cell"] = 10
config["tertiary.rna.cluster.n_neighbors"] = 40
Export and Save Data#
In this section the data can export a filtered .h5 file, which will contain all new labels/layers, and contain only the filtered barcodes/cells remaining. All data can be exported (row attributes, column attributes and layers) for every assay (DNA, CNV and Protein) into easily parsable .csv tables. Additionally, an updated .html report can be generated based on the analysis performed in this notebook.
# Save new h5 file that includes only the final, cleaned dataset
ms.save(sample, 'FilteredData.h5')
# Export data into csv formats
ms.to_zip(sample, 'filename')
# make report
create_single_patient_report(
sample,
location=Path("CI_output/report.html"),
config=config,
)