### Load example dataset Source: https://missionbio.github.io/mosaic/notebooks/additional-plots-and-customizations.html Loads the Multisample PBMC example dataset. ```python sample = ms.load_example_dataset("Multisample PBMC", single=True) ``` -------------------------------- ### Execute Linux Installer Source: https://missionbio.github.io/mosaic/manual/install.html Run the downloaded shell script to begin the installation process on Linux. ```bash $ sh mosaic-v3.12.2-Linux-x86_64.sh ``` -------------------------------- ### Initialize SampleGroup Source: https://missionbio.github.io/mosaic/pages/missionbio.mosaic.samplegroup.SampleGroup.html Load an example dataset to create a SampleGroup instance. ```python >>> import missionbio.mosaic as ms >>> group = ms.load_example_dataset('Multisample PBMC') ``` -------------------------------- ### Install Mosaic package Source: https://missionbio.github.io/mosaic/manual/install.html Create the mosaic environment and install the required missionbio packages. ```bash $ conda create --name mosaic -c missionbio -c conda-forge "missionbio.tertiary" "python-kaleido=0.1.0" ``` -------------------------------- ### Load an example dataset Source: https://missionbio.github.io/mosaic/pages/functions/missionbio.mosaic.io.load_example_dataset.html Loads a specific example dataset by name and retrieves its name property. ```python >>> import missionbio.mosaic as ms >>> sample = ms.load_example_dataset("3 cell mix") >>> sample.name ... "3 cell mix" ``` -------------------------------- ### Download Linux Installer Source: https://missionbio.github.io/mosaic/manual/install.html Use wget to download the Mosaic installer script directly to a Linux server. ```bash $ wget https://dl.missionbio.io/mosaic/mosaic-v3.12.2-Linux-x86_64.sh ``` -------------------------------- ### Load example dataset Source: https://missionbio.github.io/mosaic/notebooks/filtering.html Initializes the Mosaic environment and loads a sample dataset for analysis. ```python # Import mosaic and load the data import missionbio.mosaic as ms sample = ms.load_example_dataset("3 cell mix") ``` -------------------------------- ### Install Rosetta 2 Source: https://missionbio.github.io/mosaic/manual/install.html Use this command to install Rosetta 2 if it is not detected on the system. ```bash $ softwareupdate --install-rosetta ``` -------------------------------- ### Example environment list output Source: https://missionbio.github.io/mosaic/manual/install.html Sample output showing the active environment marked with an asterisk. ```text /Users/name/miniconda3 base * /Users/name/mosaic ``` -------------------------------- ### Import Mosaic and Define Path Source: https://missionbio.github.io/mosaic/manual/getting_started.html Initial setup to import the library and specify the local file path. ```python import missionbio.mosaic as ms h5path = '/path/to/your/h5/file' ``` -------------------------------- ### Launch Jupyter Notebook in mosaic environment Source: https://missionbio.github.io/mosaic/manual/install.html Activate the environment and start the Jupyter notebook server. ```bash $ conda activate mosaic $ jupyter notebook ``` -------------------------------- ### YAML Configuration File Source: https://missionbio.github.io/mosaic/manual/cohort.html Example configuration file defining pipeline parameters and input file paths. ```yaml spike_in: variants: /path/to/spike_in_variants.csv # Optional - required for genome-wide CNV demultiplex: variants: /path/to/demultiplexing.csv # Optional - required for multiplexed samples tertiary: variants: /path/to/somatic_variants.csv # Optional - if whitelist/blacklist is needed report: hem-onc input: - h5: /path/to/sample1.dna+protein.h5 name: Sample1 patient: ["Patient1", "Patient2", "Patient3"] timepoint: [1, 1, 1] - h5: /path/to/sample2.dna+protein.h5 name: Sample2 patient: ["Patient1", "Patient2"] timepoint: [2, 2] ``` -------------------------------- ### missionbio.mosaic.io.load_example_dataset(path: str, single: bool = False) Source: https://missionbio.github.io/mosaic/pages/functions/missionbio.mosaic.io.load_example_dataset.html Loads a sample dataset from a provided link or a predefined example name. ```APIDOC ## missionbio.mosaic.io.load_example_dataset ### Description Loads a sample dataset. The function accepts either a link to an h5 file or a predefined example name such as '3 cell mix', '2 PBMC mix', or 'Multisample PBMC'. ### Signature `load_example_dataset(path: str, single: bool = False) -> Union[Sample, SampleGroup]` ### Parameters - **path** (str) - Required. Either a link to an h5 file or a predefined dataset name ('3 cell mix', '2 PBMC mix', 'Multisample PBMC'). - **single** (bool) - Optional. Whether to load as a single sample despite being a multi-sample h5 file. Defaults to False. Only recommended for debugging. ### Returns - **Sample/SampleGroup** - An example sample object. ### Example ```python import missionbio.mosaic as ms sample = ms.load_example_dataset("3 cell mix") print(sample.name) # Output: "3 cell mix" ``` ``` -------------------------------- ### Get Help for Clone vs Analyte Source: https://missionbio.github.io/mosaic/notebooks/curated_notebooks/dna.html Displays documentation for the clone_vs_analyte method. ```python help(sample.clone_vs_analyte) ``` -------------------------------- ### CSV Format Example Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.demultiplex.dna.truth.Truth.read_csv.html Example of the expected CSV structure for the Truth.read_csv method. ```csv variant_id,genotype,type,sample_id chr1:115256669:G/A,0,germline,SampleA chr1:115256669:G/A,2,germline,SampleA ``` -------------------------------- ### Example of prompt change during activation Source: https://missionbio.github.io/mosaic/manual/install.html Visual representation of the command prompt changing from base to mosaic. ```bash (base) C:\WINDOWS\system32> conda activate mosaic (mosaic) C:\WINDOWS\system32> jupyter notebook ``` -------------------------------- ### Get Help for Signature Map Source: https://missionbio.github.io/mosaic/notebooks/curated_notebooks/dna.html Displays documentation for the signaturemap method. ```python help(sample.signaturemap) ``` -------------------------------- ### VariantSubcloneTable.run() Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.workflows.variant_subclone_table.VariantSubcloneTable.run.html Starts the VariantSubcloneTable workflow with configurable display modes and Dash parameters. ```APIDOC ## VariantSubcloneTable.run() ### Description Starts the workflow for the VariantSubcloneTable. ### Signature `VariantSubcloneTable.run(mode: str = 'inline', **kwargs: Any) -> None` ### Parameters - **mode** (str) - Optional - One of 'inline', 'external', or 'jupyterlab'. Determines where the workflow is displayed. - **kwargs** (dict) - Optional - Additional arguments passed to Dash.run (e.g., height, width, debug). ### Raises - **ValueError** - Raised if the provided port value is already in use by another workflow or application. ``` -------------------------------- ### Install compatible python-kaleido version Source: https://missionbio.github.io/mosaic/manual/install.html Use this command to resolve image saving failures on Windows 11 by installing a specific version of the kaleido package. ```bash $ conda install -c conda-forge "python-kaleido=0.1.0" ``` -------------------------------- ### Get help for DNA clustering methods Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/dna.ipynb Access documentation for the DNA clustering functionality. ```python # Review other clustering methods help(sample.dna.cluster) ``` -------------------------------- ### Conda Initialization Prompt Source: https://missionbio.github.io/mosaic/manual/install.html The installer will prompt to initialize the environment via conda; choose yes or no based on your preference for setting the default environment. ```text Do you wish the installer to initialize mosaic by running conda init? [yes|no] ``` -------------------------------- ### Install labeled Mosaic version via conda Source: https://missionbio.github.io/mosaic/manual/install.html Use this command to install versions tagged with specific labels by modifying the channel path. ```bash $ conda create --name mosaic -c missionbio/label/unsupported -c plotly -c conda-forge missionbio.mosaic=1.7.1 notebook ``` -------------------------------- ### Check for Rosetta 2 installation Source: https://missionbio.github.io/mosaic/manual/install.html Run this command to verify if Rosetta 2 is currently installed on an Apple device. ```bash $ /usr/bin/pgrep -q oahd && echo Yes || echo No ``` -------------------------------- ### Verify Mosaic environment installation Source: https://missionbio.github.io/mosaic/manual/install.html List all available conda environments to confirm the mosaic directory exists. ```bash $ conda env list ``` -------------------------------- ### VariantSubcloneTable.run() Source: https://missionbio.github.io/mosaic/v3.12.2/pages/methods/missionbio.mosaic.workflows.variant_subclone_table.VariantSubcloneTable.run.html Starts the variant subclone table workflow. ```APIDOC ## VariantSubcloneTable.run() ### Description Starts the workflow for the VariantSubcloneTable. ### Signature `VariantSubcloneTable.run(mode: str = 'inline', **kwargs: Any) -> None` ### Parameters - **mode** (str) - Optional - One of ‘inline’, ‘external’, or ‘jupyterlab’. If it’s ‘inline’ then the workflow is displayed in the notebook itself otherwise it’s displayed in a new tab in the browser or a new jupyterlab window. - **kwargs** (dict) - Optional - Passed to Dash.run. E.g. height, width, debug, etc. ### Raises - **ValueError** - If the provided port value is already in use by another workflow or application. ``` -------------------------------- ### Get help for variant filtering Source: https://missionbio.github.io/mosaic/v3.12.2/_sources/notebooks/curated_notebooks/dna.ipynb Displays the help documentation for the filter_variants method. ```python help(sample.dna.filter_variants) ``` -------------------------------- ### Get DNA Annotation Help Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/dna.ipynb Displays the help documentation for the get_annotations method. ```python help(sample.dna.get_annotations) ``` -------------------------------- ### CopyNumber.run() Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.workflows.copy_number.CopyNumber.run.html Starts the copy number workflow with specified display mode and configuration options. ```APIDOC ## missionbio.mosaic.workflows.copy_number.CopyNumber.run ### Description Starts the copy number workflow. ### Signature `CopyNumber.run(mode: str = 'inline', **kwargs: Any) -> None` ### Parameters - **mode** (str) - Optional - One of 'inline', 'external', or 'jupyterlab'. Determines where the workflow is displayed. - **kwargs** (dict) - Optional - Additional arguments passed to Dash.run (e.g., height, width, debug). ### Raises - **ValueError** - If the provided port value is already in use by another workflow or application. ``` -------------------------------- ### Running SPARC Phylogeny Prediction Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.sample.Sample.sparc.html Example demonstrating how to load a sample, execute the SPARC algorithm with specified variants, label the clones, and visualize the resulting phylogenetic tree. ```python >>> import missionbio.mosaic as ms >>> sample = ms.load("/path/to/file.h5") >>> result = sample.sparc(variants=['var1', 'var2', 'var3']) >>> sample.dna.set_labels(result.labels.values) # Adds the clones to the assay >>> result.draw() # Draws the phylogenetic tree ``` -------------------------------- ### Display Gene Name Array Source: https://missionbio.github.io/mosaic/notebooks/additional-plots-and-customizations.html Example output showing the array of gene names mapped to amplicons. ```python array(['ASXL1', 'ASXL1', 'ASXL1', 'ASXL1', 'ASXL1', 'ASXL1', 'ASXL1', 'ASXL1', 'ASXL1', 'ASXL1', 'ATM', 'ATM', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BCOR', 'BRAF', 'BRAF', 'BRAF', 'BRAF', 'BRAF', 'BRAF', 'BRAF', 'BRAF', 'BRAF', 'BRAF', 'BRAF', 'BRAF', 'CALR', 'CBL', 'CBL', 'CBL', 'CHEK2', 'CHEK2', 'CSF3R', 'CSF3R', 'CSF3R', 'CSF3R', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'DNMT3A', 'ERG', 'ERG', 'ETV6', 'ETV6', 'ETV6', 'ETV6', 'ETV6', 'ETV6', 'ETV6', 'ETV6', 'ETV6', 'ETV6', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'EZH2', 'FLT3', 'FLT3', 'FLT3', 'FLT3', 'FLT3', 'GATA2', 'GATA2', 'GNAS', 'IDH1', 'IDH2', 'JAK2', 'JAK2', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KDM6A', 'KIT', 'KIT', 'KIT', 'KIT', 'KIT', 'KIT', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KMT2A', 'KRAS', 'KRAS', 'KRAS', 'MPL', 'MYC', 'MYC', 'MYC', 'MYC', 'MYC', 'MYC', 'MYD88', 'MYD88', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NF1', 'NPM1', 'NRAS', 'NRAS', 'PHF6', 'PHF6', 'PHF6', 'PHF6', 'PHF6', 'PHF6', 'PHF6', 'PHF6', 'PPM1D', 'PPM1D', 'PTEN', 'PTEN', 'PTPN11', 'PTPN11', 'PTPN11', 'PTPN11', 'RAD21', 'RAD21', 'RAD21', 'RAD21', 'RUNX1', 'RUNX1', 'RUNX1', 'RUNX1', 'RUNX1', 'RUNX1', 'RUNX1', 'RUNX1', 'SETBP1', 'SETBP1', 'SETBP1', 'SETBP1', 'SETBP1', 'SETBP1', 'SF3B1', 'SF3B1', 'SF3B1', 'SF3B1', 'SF3B1', 'SMC1A', 'SMC1A', 'SMC1A', 'SMC3', 'SMC3', 'SMC3', 'SMC3', 'STAG2', 'STAG2', 'STAG2', 'STAG2', 'STAG2', 'STAG2', 'STAG2', 'STAG2', 'STAG2', 'STAG2', 'STAG2', 'STAT3', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TET2', 'TP53', 'TP53', 'TP53', 'TP53', 'TP53', 'TP53', 'TP53', 'TP53', 'TP53', 'TP53', 'TP53', 'U2AF1', 'U2AF1', 'WT1', 'WT1', 'WT1', 'ZRSR2', 'ZRSR2', 'ZRSR2', 'ZRSR2', 'ZRSR2', 'ZRSR2', 'ZRSR2', 'ZRSR2', 'ZRSR2', 'ZRSR2', 'ZRSR2'], dtype='>> sample.dna[sample.dna.samples().pop()]["palette"] # Accessing the palette dictionary >>> sample.dna.sampleinfo["palette"] # Shorthand to access the info for single sample assays ``` -------------------------------- ### Check Mosaic Version Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/dna.ipynb Verifies the installed version of the Mosaic library, which should be v3.17 or higher for this notebook. ```python # Check version; this notebook is designed for Mosaic v3.17 or higher print(ms.__version__) ``` -------------------------------- ### Initialize and Run COMPASS Source: https://missionbio.github.io/mosaic/pages/missionbio.mosaic.algorithms.compass.COMPASS.html Demonstrates how to instantiate the COMPASS class with a sample and somatic variants, then execute the analysis. ```python >>> import missionbio.mosaic as ms >>> from missionbio.mosaic.algorithms.compass import COMPASS >>> sample = ms.load_example_dataset("2 PBMC mix") >>> compass = COMPASS(sample, somatic_variants=["chr4:55599436:T/C", "chr5:170837457:A/G"]) >>> compass.run() ``` -------------------------------- ### Initialize and Run CopyNumber Workflow Source: https://missionbio.github.io/mosaic/pages/missionbio.mosaic.workflows.copy_number.CopyNumber.html Demonstrates how to load a sample and execute the CopyNumber workflow. ```python >>> import missionbio.mosaic as ms >>> sample = ms.load_example_dataset("3 cell mix") >>> wfc = ms.workflows.CopyNumber(sample) >>> wfc.run() ``` -------------------------------- ### Install specific Mosaic version via conda Source: https://missionbio.github.io/mosaic/manual/install.html Use this command to install a specific version of Mosaic from the missionbio conda channel. ```bash $ conda create --name mosaic -c missionbio -c plotly -c conda-forge missionbio.mosaic=1.8.1 notebook ``` -------------------------------- ### Prepare Compass Input Source: https://missionbio.github.io/mosaic/v3.12.2/_sources/notebooks/curated_notebooks/dna-protein-multisample.ipynb Initializes the input directory for the Compass analysis tool. ```python compass.prepare_input(prefix="./compass_input") ``` -------------------------------- ### Rename Protein Labels Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/ge-protein.ipynb Example of how to rename protein labels in the sample. ```python # sample.protein.rename_labels({ # "1": "Cell-type1", # "2": "Cell-type2", # "3": "Cell-type3", # "4": "Cell-type4", # "5": "Cell-type5", # }) ``` -------------------------------- ### Rna.get_markers() Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.rna.Rna.get_markers.html Get the markers for each RNA cluster using DE analysis. ```APIDOC ## Rna.get_markers(layer='normalized_counts', split_by='label', method='welch', top_n_markers=5, min_cluster_size=10) ### Description Get the markers for each RNA cluster using DE analysis. ### Parameters - **layer** (str) - Optional - The RNA data layer to use. Default is 'normalized_counts'. - **split_by** (str) - Optional - RNA row attribute to call markers on. Default is 'label'. - **method** (str) - Optional - The DE method to use. 'welch' or 'wilcoxon' currently implemented. Default is 'welch'. - **top_n_markers** (int) - Optional - How many top markers from each grouping (RNA label) to include in markers table. Default is 5. - **min_cluster_size** (int) - Optional - Minimum # of cells in smallest group. Will raise ValueError if the smallest group has fewer than min_cells cells. Default is 10. ### Returns - **missionbio.mosaic.algorithms.rna.cluster_markers.RNAClusterMarkers** - The resulting markers object. ``` -------------------------------- ### Initialize and run VariantSubcloneTable Source: https://missionbio.github.io/mosaic/pages/missionbio.mosaic.workflows.variant_subclone_table.VariantSubcloneTable.html Instantiate the workflow with a sample object and execute the interactive table interface. ```python >>> import missionbio.mosaic as ms >>> sample = ms.load_example_dataset("3 cell mix") >>> wfv = ms.workflows.VariantSubcloneTable(sample) >>> wfv.run() ``` -------------------------------- ### Save sample Source: https://missionbio.github.io/mosaic/pages/missionbio.mosaic.sample.Sample.html Save the current state of the sample to disk. ```python >>> mio.save(sample) ``` -------------------------------- ### run() Source: https://missionbio.github.io/mosaic/pages/missionbio.mosaic.algorithms.compass.COMPASS.html Executes the COMPASS algorithm on the provided sample. ```APIDOC ## run(path, prefix, cnv, kwargs) ### Description Processes the sample using the COMPASS algorithm. ``` -------------------------------- ### load_example_dataset Source: https://missionbio.github.io/mosaic/pages/missionbio.mosaic.io.html Loads a sample dataset for testing or demonstration purposes. ```APIDOC ## load_example_dataset(path, single=False) ### Description Load a sample dataset. ### Parameters - **path** (str) - Required - Path to the sample dataset. - **single** (bool) - Optional - Whether to load a single dataset. ``` -------------------------------- ### Importing Mosaic and IPython utilities Source: https://missionbio.github.io/mosaic/notebooks/multi-sample-analysis.html Initializes the Mosaic library and IPython display tools required for the analysis. ```python import missionbio.mosaic as ms from IPython.display import display, HTML ``` -------------------------------- ### Load dependencies and configure environment Source: https://missionbio.github.io/mosaic/notebooks/curated_notebooks/dna-multisample.html Imports necessary libraries for data analysis and visualization, and configures notebook display settings. ```python import warnings warnings.filterwarnings('ignore') # Import mosaic libraries import missionbio.mosaic as ms # Import these to display entire dataframes from IPython.display import display, HTML # 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 numpy as np import seaborn as sns from missionbio.plotting.multimap import MultiMap from missionbio.plotting.heatmap import Heatmap # Note: when exporting the notebook as an HTML, plots that use the "go.Figure(fig)" command are saved ``` ```python # This code is optional, but will make the notebook cells/figures display across the entire width of the browser from IPython.display import display, HTML display(HTML("")) ``` -------------------------------- ### Initialize and Visualize Built-in Truth Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/dna-protein.ipynb Load the built-in truth structure and visualize its configuration. ```python # Import for protein assignment from missionbio.demultiplex.protein.truth import Truth # Visualize the structure of the built-in truth # The names that are underlines are links to the source of truth truth = Truth.builtin() truth.plot() ``` -------------------------------- ### Initialize SampleGroup and inspect assays Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.samplegroup.SampleGroup.merge_assay.html Load a multisample dataset and verify the titles of the DNA assays present in the group. ```python >>> import missionbio.mosaic as ms >>> grp = ms.load_example_dataset("Multisample PBMC") >>> [s.dna.title for s in grp] # Group of assays ['Sample 1', 'Sample 2'] ``` -------------------------------- ### Sample list output Source: https://missionbio.github.io/mosaic/v3.12.2/notebooks/multi-sample-analysis.html The resulting list of sample names from the loaded dataset. ```text ['Sample 1', 'Sample 2'] ``` -------------------------------- ### Generate a crosstab heatmap Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.assay._Assay.crosstabmap.html Displays a heatmap of the cross-tabulation between DNA and protein labels from a loaded example dataset. ```python >>> import missionbio.mosaic as ms >>> sample = ms.load_example_dataset("3 cell mix") >>> sample.dna.crosstabmap(sample.protein.get_labels()) ``` -------------------------------- ### Load Mosaic Dependencies Source: https://missionbio.github.io/mosaic/notebooks/curated_notebooks/dna-rna.html Imports essential libraries for data manipulation, visualization, and reporting. Note that initialization may take several minutes. ```python import warnings warnings.filterwarnings('ignore') # Import mosaic libraries import missionbio.mosaic as ms from missionbio.mosaic.assay import _Assay from missionbio.mosaic.constants import READS, LABEL, NORMALIZED_READS # 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.config.config import Config from missionbio.tertiary.config.prepare import DEFAULTS from missionbio.tertiary.step.report import create_single_patient_report from typing import Sequence, Optional, Tuple pd.set_option("display.max_rows", 400) # Note: when exporting the notebook as an HTML, plots that use the "go.Figure(fig)" command are saved ``` -------------------------------- ### Initialize and Run SPARC Inference Source: https://missionbio.github.io/mosaic/pages/missionbio.demultiplex.phylogeny.sparc.SPARC.html Demonstrates how to load a dataset, initialize the SPARC model, and predict clonal structure using specific SNV variants. ```python >>> import missionbio.mosaic as ms >>> from missionbio.demultiplex.phylogeny.sparc import SPARC >>> sample = ms.load_example_dataset("2 PBMC mix") >>> sparc = SPARC() >>> result = sparc.predict(sample.dna, variants=["chr4:55599436:T/C", "chr5:170837457:A/G"]) ``` -------------------------------- ### Initialize and Run COMPASS Source: https://missionbio.github.io/mosaic/v3.12.2/_sources/notebooks/curated_notebooks/dna-multisample.ipynb Initializes the COMPASS object using the full_combined dataset and somatic variants, then executes the analysis. ```python # Use compass to assume the subclone architecture and phylogeny # Depending on the size and complexity of the data, this step can take ~1-10 minutes # Use the full_combined object to utilize all cells and unannotated variants compass = COMPASS(full_combined, somatic_variants=variants) compass.run() ``` -------------------------------- ### Access Help Documentation Source: https://missionbio.github.io/mosaic/notebooks/curated_notebooks/dna-protein.html Retrieve help information for specific protein analysis methods. ```python help(sample.protein.run_pca) ``` ```python help(sample.protein.scatterplot) ``` -------------------------------- ### Configure libmamba solver Source: https://missionbio.github.io/mosaic/manual/install.html Set up the faster libmamba solver and strict channel priority for conda. ```bash $ conda install -n base conda-libmamba-solver $ conda config --set channel_priority strict $ conda config --set solver libmamba ``` -------------------------------- ### Handle attribute shape mismatch Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.assay._Assay.get_attribute.html Shows an example where an attribute cannot be reshaped to satisfy the provided constraint, resulting in a ValueError. ```python >>> assay = assay[:, :9] >>> print(assay.shape) (100, 9) >>> attr = assay.get_attribute('barcode', constraint='col') ValueError - 'The given attribute does not have the expected shape nor could be reshaped appropriately.' ``` -------------------------------- ### Splitting a Sample by Attribute Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.sample.Sample.split.html Demonstrates splitting a sample into multiple samples based on the 'label' attribute and creating a SampleGroup. ```python >>> import missionbio.mosaic as ms >>> sample = ms.load_example_dataset("3 cell mix") >>> samples = sample.split("label") # List of 4 samples for each `label` >>> ms.SampleGroup(samples) Group of 4 samples ``` -------------------------------- ### Accessing individual samples Source: https://missionbio.github.io/mosaic/notebooks/multi-sample-analysis.html Demonstrates how to access specific samples within a SampleGroup and list their names. ```python # To analyze one sample at a time access, them using the samples attribute sample = group.samples[1] # These are the samples in the h5 file [s.name for s in group.samples] ``` ```python ['Sample 1', 'Sample 2'] ``` -------------------------------- ### Compute cross-tabulation of DNA clones and protein clusters Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.assay._Assay.crosstab.html Computes the number of cells in each DNA clone and protein cluster using the example dataset. ```python >>> import missionbio.mosaic as ms >>> sample = ms.load_example_dataset("2 PBMC mix") >>> sample.dna.crosstab(sample.protein.get_labels()) ``` -------------------------------- ### Export variants to CSV Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/ge-protein.ipynb Provides commented-out examples for exporting the variants table to a single CSV or multiple CSV files grouped by target. ```python # Write the all variants table to a file # Uncomment the following line to write out the all_vairants_table (containing information for all targets) to a CSV file # all_vars_table.to_csv(f"{sample.name}_all_variants.csv") # Uncomment the following for-loop to write out 1 all_variants CSV file per target to the current working directory # for target, mini_df in all_vars_table.groupby('target'): # mini_df.to_csv(f"{sample.name}_{target}_all_variants.csv") ``` -------------------------------- ### SPARCResult.serialize_clones() Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.demultiplex.phylogeny.state.SPARCResult.serialize_clones.html Renames the clones within the SPARCResult object to a sequential naming convention starting with Wildtype followed by Clone 1, Clone 2, etc. ```APIDOC ## SPARCResult.serialize_clones() ### Description Renames the clones as Wildtype, Clone 1, Clone 2, Clone 3… ### Signature `SPARCResult.serialize_clones() -> SPARCResult` ### Returns - **SPARCResult** - The updated SPARCResult object with renamed clones. ``` -------------------------------- ### NSP.__init__ Source: https://missionbio.github.io/mosaic/pages/missionbio.demultiplex.protein.nsp.NSP.html Initializes the NSP normalization method with parameters for jitter, random state, sample size, and zero-read cell thresholds. ```APIDOC ## class NSP(jitter=0.5, random_state=None, sample_size=inf, max_zero_read_cells=0.05) ### Description Initializes the Noise corrected and Scaled Protein counts (NSP) normalization object. ### Parameters - **jitter** (float) - Optional - The standard deviation of the jitter added to read counts. - **random_state** (int) - Optional - The random state for reproducibility. - **sample_size** (float) - Optional - Number of cells used to estimate linear models; defaults to all cells (inf). - **max_zero_read_cells** (float) - Optional - Maximum percentage of cells allowed to have 0 reads after scaling. ``` -------------------------------- ### COMPASS Class Initialization Source: https://missionbio.github.io/mosaic/pages/missionbio.mosaic.algorithms.compass.COMPASS.html Initializes the COMPASS wrapper with a sample and a list of somatic variants. ```APIDOC ## COMPASS(sample, somatic_variants, min_prob_diff=0.9) ### Description Initializes the COMPASS wrapper to prepare for phylogenetic analysis on a given sample. ### Parameters - **sample** (Sample) - Required - The sample object on which COMPASS is to be processed. - **somatic_variants** (Sequence) - Required - The list of variants used to find the clones, formatted as 'chrom:pos:ref/alt'. - **min_prob_diff** (float) - Optional - The minimum difference in probability of assignment of nodes for the cell to be assigned a label. ``` -------------------------------- ### Access Scatterplot Help Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/dna-protein.ipynb Displays documentation for the scatterplot method. ```python help(sample.protein.scatterplot) ``` -------------------------------- ### Load Dependencies Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/clonal-insights.ipynb Imports necessary libraries for data analysis, visualization, and report generation. Note that this process may take several minutes. ```python 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 ``` -------------------------------- ### CopyNumber.__init__ Source: https://missionbio.github.io/mosaic/pages/missionbio.mosaic.workflows.copy_number.CopyNumber.html Initializes the CopyNumber workflow with a sample object and optional layout configuration. ```APIDOC ## missionbio.mosaic.workflows.copy_number.CopyNumber(sample, layout_kwargs=None) ### Description Initializes the Copy Number estimation workflow. This workflow filters cells and amplicons, computes ploidy, and provides visualization tools. ### Parameters - **sample** (Sample) - Required - The Sample object used in the workflow. Clone creation actions modify labels in the Dna object. - **layout_kwargs** (Dict) - Optional - Arguments passed to fig.update_layout for generated visualizations. ``` -------------------------------- ### Fishplot.__init__ Source: https://missionbio.github.io/mosaic/v3.12.2/pages/missionbio.plotting.fishplot.Fishplot.html Initializes a new Fishplot instance with labels, parent relationships, sample ordering, and barcode data. ```APIDOC ## class missionbio.plotting.fishplot.Fishplot ### Description Initializes the Fishplot container for visualizing clonal evolution. ### Parameters - **labels** (Sequence[str]) - Required - The list of unique labels (subclones) to include in the plot. - **parents** (Sequence[Optional[str]]) - Required - The list of parents for each clone. Use None for the root clone. - **sample_order** (Sequence[str]) - Required - The names and order of samples to include in the plot. - **times** (Optional[List[float]]) - Optional - Relative time points for the samples, normalized to between 0 and 1. - **barcode_labels** (Sequence[str]) - Required - Labels for all barcodes used to determine clone proportions. - **barcode_samples** (Sequence[str]) - Required - Sample identifiers for all barcodes used to determine clone proportions. ``` -------------------------------- ### missionbio.mosaic.io.load() Source: https://missionbio.github.io/mosaic/pages/functions/missionbio.mosaic.io.load.html Loads data from an h5 file. Returns a Sample or SampleGroup object, or raises an Exception if the file format is unsupported. ```APIDOC ## missionbio.mosaic.io.load() ### Description Loads data from an h5 file into a `missionbio.mosaic.sample.Sample` or `missionbio.mosaic.samplegroup.SampleGroup` object. ### Parameters - **assays** (Optional[Sequence[str]]) - The assays to load. If None, all assays are loaded. Examples include "dna_variants", "dna_read_counts", "protein_read_counts", and "rna_read_counts". - **raw_counts** (Optional[Sequence[str]]) - The raw counts to load. If None, all raw counts are loaded. Examples include "dna_read_counts" and "protein_read_counts". ### Returns - **missionbio.mosaic.sample.Sample / missionbio.mosaic.samplegroup.SampleGroup** - The loaded sample or sample group object. ### Errors - **Exception** - Raised when the h5 file format is not supported. ``` -------------------------------- ### Access RNA Normalization Help Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/dna-rna.ipynb Retrieve documentation for the rna.normalize_reads method. ```python # To get more information on the available parameters in rna.normalize_reads help(sample.rna.normalize_reads) ``` -------------------------------- ### Load sample H5 file Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/ge-protein.ipynb Loads the sample data from a specified H5 file path. ```python sample = mio.load('/Users/user_name/Documents/edited-t-cells.h5') ``` -------------------------------- ### Initialize and draw a BarGraph Source: https://missionbio.github.io/mosaic/pages/missionbio.plotting.bargraph.BarGraph.html Demonstrates the basic instantiation of a BarGraph using a pandas Series and rendering it with the draw method. ```python >>> from missionbio.plotting.bargraph import BarGraph >>> import pandas as pd >>> import numpy as np >>> data = pd.Series([75, 25], index=["a", "b"]) >>> bg = BarGraph(data, text=data.values / 100) >>> bg.draw() ``` -------------------------------- ### Create and draw a phylogenetic tree Source: https://missionbio.github.io/mosaic/pages/missionbio.plotting.phylotree.PhyloTree.html Initializes a PhyloTree with 4 nodes and renders it with a custom color palette. ```python >>> from missionbio.plotting.phylotree import PhyloTree >>> labels = ["1", "2", "3", "4"] >>> parents = [None, "1", "1", "2"] >>> descriptions = ["WT", "KIT HET", "KIT HET
TP53 HET", "KIT LOH"] >>> graph = PhyloTree(labels, parents, descriptions) >>> graph.draw(palette={"1": "#000000", "2": "crimson", "3": "skyblue", "4": "red"}) ``` -------------------------------- ### Sample.clone_vs_analyte(analyte='cnv', plot_width=0, subclone_order=None, protein_order=None, cbar=True) Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.sample.Sample.clone_vs_analyte.html Generates a set of summary plots to provide a run overview. The visualization includes a VAF vs subclone/variant table, cell population distribution, and either a read count distribution (for CNV) or a violin plot (for protein). ```APIDOC ## Sample.clone_vs_analyte ### Description Generates a set of summary plots to provide a run overview. The plots consist of a VAF vs subclone/variant table, a cell population count/fraction plot, and an analyte-specific plot (read count distribution for CNV or violin plot for protein). ### Signature `Sample.clone_vs_analyte(analyte='cnv', plot_width=0, subclone_order=None, protein_order=None, cbar=True)` ### Parameters - **analyte** (str) - Optional - 'cnv' or 'protein' to be used in the third plot. - **plot_width** (float) - Optional - The width of the plot in points. - **subclone_order** (list) - Optional - A list containing the order in which subclones should be displayed in the resulting figure. - **protein_order** (list) - Optional - A list containing the order in which proteins should be displayed in the resulting figure. - **cbar** (bool) - Optional - Toggle to display or hide the colorbar for the heatmap. ``` -------------------------------- ### Access Function Documentation Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/dna.ipynb Uses the built-in help function to retrieve parameter information and default values for specific Mosaic functions. ```python # Any function's parameters and default values can be looked up via the 'help' function # Here, the function is 'ms.load' help(ms.load) ``` -------------------------------- ### Load dependencies Source: https://missionbio.github.io/mosaic/notebooks/additional-plots-and-customizations.html Imports necessary libraries for data manipulation, visualization, and display. ```python # Import mosaic libraries import missionbio.mosaic as ms # Import these to display entire dataframes from IPython.display import display, HTML # Import numpy for statistics import numpy as np # Import additional packages for specific visuals import matplotlib.pyplot as plt # Import the colors import seaborn as sns # Import the Heatmap class to create heatmaps of custom data from missionbio.plotting.heatmap import Heatmap ``` -------------------------------- ### Save Sample Source: https://missionbio.github.io/mosaic/manual/getting_started.html Persist the analyzed sample object to a specified file path. ```python ms.save(sample,'/path/to/save/h5') ``` -------------------------------- ### Inspect PCA Help Source: https://missionbio.github.io/mosaic/notebooks/curated_notebooks/dna-protein-multisample.html Displays documentation for the PCA function. ```python help(sample.protein.run_pca) ``` -------------------------------- ### Modeling amplicons and applying results Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.cnv.Cnv.model_amplicons.html Demonstrates fitting a CNV model using a spike-in assay, saving it to a sample assay, and adding the resulting labels and ploidy layers to the sample. ```python >>> import missionbio.mosaic as ms >>> spikein = ms.load("/path/to/spikein.h5") >>> sample = ms.load("/path/to/sample.h5") >>> >>> lm = spikein.cnv.model_amplicons() >>> lm.save_model(sample.cnv) >>> result = sample.sparc([], cnamps=sample.cnv.ids(), min_loh_group_size=2) >>> >>> # Add the results to the assay >>> sample.cnv.add_labels(result.labels.values) # Add the cluster labels to the assay >>> sample.cnv.add_layer("flat-ploidy", result.profile.flat_ploidy.values) # Integer CNV >>> sample.cnv.add_layer("ploidy", result.profile.relative_ploidy.values) >>> sample.cnv.signaturemap("ploidy", kind="mean") ``` -------------------------------- ### missionbio.mosaic.io.to_zip(sample, path) Source: https://missionbio.github.io/mosaic/pages/functions/missionbio.mosaic.io.to_zip.html Exports a Sample or SampleGroup to a zip file with a specific directory structure for assays. ```APIDOC ## missionbio.mosaic.io.to_zip ### Description Export the sample to a zip file. Within the zip file, there is a folder for each assay (Dna, Cnv, Protein). The folder structure mirrors the assay, containing layers, row attributes, column attributes, and a metadata.json file. ### Signature `to_zip(sample: Union[Sample, SampleGroup], path: Union[str, Path]) -> None` ### Parameters - **sample** (Union[Sample, SampleGroup]) - Required - The sample to be exported. SampleGroup objects are merged using `merge()` before exporting. - **path** (Union[str, pathlib.Path]) - Required - The path to the zip file. ``` -------------------------------- ### Iterate and visualize per-sample heatmaps Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/dna-multisample.ipynb Loop through a SampleGroup to generate and display a heatmap for each sample. ```python # Heatmap per sample for sample in group: fig = sample.dna.heatmap(attribute='NGT_FILTERED',splitby="label") fig.update_layout(title = sample.name) go.Figure(fig) fig.show() ``` -------------------------------- ### List sample order Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/dna-multisample.ipynb Print the names of samples in the group object to verify their processing order. ```python # Establish the order of the samples in the group object # Note: timepoint one will not automatically be the first sample for sample in group: print(sample.name) ``` -------------------------------- ### Sample.raw_heatmaps() Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.sample.Sample.raw_heatmaps.html Generates three heatmaps showing the distribution of barcodes, protein reads, and DNA reads. Requires cnv_raw and protein_raw to be loaded. ```APIDOC ## Sample.raw_heatmaps() ### Description Generates three heatmaps with barcodes mapped by total DNA reads (x-axis) and total protein reads (y-axis). The first heatmap shows the number of barcodes in each bin, the second shows the number of protein reads, and the third shows the number of DNA reads. This method is useful for understanding the distribution of barcodes, protein reads, and DNA reads within specific clusters. ### Requirements - cnv_raw must be loaded - protein_raw must be loaded ``` -------------------------------- ### to_zip Source: https://missionbio.github.io/mosaic/pages/missionbio.mosaic.io.html Exports a sample to a zip file. ```APIDOC ## to_zip(sample, path) ### Description Export the sample to a zip file. ### Parameters - **sample** (object) - Required - The sample object to export. - **path** (str) - Required - Destination path. ``` -------------------------------- ### Load H5 File Source: https://missionbio.github.io/mosaic/manual/getting_started.html Load data into a sample object with configurable filtering parameters. ```python sample = ms.load( h5path, raw=False, filter_variants=True, filter_cells=False, single=True ) ``` ```python sample = ms.load( h5path, raw=False, filter_variants=True, single=True, whitelist=["chr1:115258747:C/T", "chr2:198266834:T/C", "chrX:133547940:C/T"], ) ``` -------------------------------- ### Sample.heatmap() Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.sample.Sample.heatmap.html Plots heatmaps (cluster vs target) for each available assay next to each other. ```APIDOC ## Sample.heatmap(clusterby=None, attributes=None, features=None, x_groups=None, bars_order=None, widths=None, order=('dna', 'protein', 'cnv', 'rna', 'ge')) ### Description Plots heatmaps (cluster vs target) for each available assay next to each other. ### Parameters - **clusterby** (list, str) - Optional - The assays to plot. If None, all assays are plotted. - **attributes** (tuple) - Optional - The layers or row attributes to plot for each assay. - **features** (tuple) - Optional - The features to plot for each assay. If None, all features are plotted. - **x_groups** (tuple) - Optional - The groups to plot on the x-axis for each assay. If None, the x-axis is not grouped. - **bars_order** (Sequence) - Optional - The order of the barcodes to plot. If None, the barcodes are sorted by the sortby assay. - **widths** (list) - Optional - The width of each heatmap. If None, the width is automatically determined. - **order** (tuple) - Optional - The order of the assays to plot. ### Returns - **fig** (plotly.graph_objects.Figure) - The generated multi-assay heatmap figure. ``` -------------------------------- ### Configure Notebook Display Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/dna.ipynb Optional configuration to force notebook cells and figures to span the full width of the browser window. ```python # This code is optional, but will make the notebook cells/figures display across the entire width of the browser from IPython.display import display, HTML display(HTML("")) ``` -------------------------------- ### Load Data Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/clonal-insights.ipynb Loads the h5 file into the Mosaic sample object. ```python # 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) ``` -------------------------------- ### Inspect Normalization Function Source: https://missionbio.github.io/mosaic/notebooks/curated_notebooks/dna-protein.html Displays help documentation for the protein normalization method. ```python help(sample.protein.normalize_reads) ``` -------------------------------- ### Merge samples in a SampleGroup Source: https://missionbio.github.io/mosaic/pages/methods/missionbio.mosaic.samplegroup.SampleGroup.merge.html Demonstrates loading a multisample dataset and merging the samples into a single object. ```python >>> import missionbio.mosaic as ms >>> grp = ms.load_example_dataset("Multisample PBMC") >>> [s.name for s in grp] # Group of samples ['Sample 1', 'Sample 2'] ``` ```python >>> sample = grp.merge() >>> sample.name # A single sample with all the cells 'Sample 1, Sample 2' ``` -------------------------------- ### Initialize Combined Heatmap Source: https://missionbio.github.io/mosaic/_sources/notebooks/curated_notebooks/dna-protein-multisample.ipynb Placeholder for generating a combined DNA, CNV, and protein heatmap. ```python # DNA + CNV + Protein heatmap for sample in group: ```