Skip to main content

Migration Analysis of Clonal Histories 2

Project description

MACH2

A mathematical framework for inferring migration histories of metastatic cancer from clone phylogeny and the location of extant clones.

Table of contents

  1. Installation
    - Prerequisite
    - Install using pip
  2. Usage instruction
    - From JupyterLab
    - From Command Line

1. Installation

Prerequisites

  • Python - MACH2 requires Python 3.7 or newer.
  • ILP solver - MACH2 requires an ILP solver installed to solve PMH-TR. Currently MACH2 only supports Gurobi optimizer, but we are going to add support for more ILP solvers in the future. MACH2 requires a valid Gurobi installation and license key. The location of Gurobi should be present in LD_LIBRARY_PATH (linux) or DYLD_LIBRARY_PATH (macOS) the license key should be saved in the environment variable GRB_LICENSE_KEY.

Install using conda

MACH2 can be installed using conda. We advise to create a new environment in conda. If creating a new environment, dependencies can be installed simultaneously.

            $ conda create -n mach2 python=3 pandas networkx gurobi jupyterlab graphviz pygraphviz -c conda-forge -c gurobi
            $ conda activate mach2

If using existing conda environment, the following command installs the dependencies.

            $ conda install -c conda-forge -c gurobi pandas networkx gurobi jupyterlab graphviz pygraphviz

Next, we install MACH2. To that end, we download MACH2 repository from GitHub and install it.

            $ git clone https://github.com/elkebir-group/MACH2.git
            $ cd MACH2
            $ pip install . --no-deps

Usage Instruction

I/O formats

We describe various formats used by MACH2.

  1. Tree file : The tree file contains a list of edges that define the structure of a tree. Each line in the file represents an edge, and the edges should be in the format: node1 node2. For example:

     1   2
     2   3
     2   4 
     3   5
    
  2. Tree file with timing/comigrations : Tree file with timestamps. Edges with the same timestamp belong to the same comigration, and a timestamp with -1 represents non-migration. Each line corresponds to an edge in the format: node1 node2 timestamp. For example:

     1   2   -1
     2   3   1
     2   4   1
     3   5   2
    
  3. Observed labeling file : The observed labeling file contains zero or more location labels assigned to each node of the input clonal tree. Each line in the file corresponds to a node and the labels assigned to it in the format: node label1 label2 .... If a node is not observed anywhere, it may be skipped. For example:

     1   A   B
     3   B
     4   A   C
     5   C
    
  4. Location labeling file : The location labeling file contains the unique location label of origin assigned to each node. Each line in the file corresponds to a node and the location label of origin are in the format: node label. For example:

     1   A
     2   B
     3   C
    
  5. Node of origin file : The node of origin file maps the nodes of the refined tree to the nodes of the input tree. Each line in the file corresponds to a vertex and the labels are in the format: leaf label. For example:

     1   A
     2   B
     3   C
    

Additionaly, MACH2 can output files in Graphviz DOT format or JSON format.

Usage

MACH2 takes as input two files -

  1. Tree file : Tree file describing the input clone tree.
  2. Observed labeling file : Labeling file describing the observed labeling of input clone tree.

MACH2 Can be run using command line, or can be directly accessed from JupyterLab.

From JupyterLab

The following code snippet imports MACH2, runs it for input tree file input.tree and input observed labeling file input.observed.labeling, and saves the solutions to a variable solutions.

            import mach2
            tree = mach2.MultiLabeledTree.from_files('input.tree', 'input.observed.labeling')
            solutions = mach2.MACH2(tree, primary_location='primary', criteria_ordering='UMC').solve()
            print(len(solutions))
            solutions.summary()

solutions is a SolutionSet object that behaves as a set. print(len(solutions)) prints the number of retrived solutions. The last line draws the summary graph for `solutions. It is possible to inspect individual solutions too.

            solution1 = [sol for sol in solutions][0]
            solution1.draw()
            solution1.migration_graph().draw()

The second line draws the tree with node labeling, and the third line draws the corresponding migration graph. For more details, check the documentation for each function.

From Terminal

For each solution, MACH2 can output three types of files.

  1. Tree file with timing/comigrations : Refined tree file with timestamps/comigrations.
  2. Location labeling file : Location labeling file describing the location labeling of the refined tree.
  3. Node of origin file : Node of origin file mapping refined tree nodes to input tree nodes.

Additionaly MACH2 can return JSON file encoding all the solutions. The JSON file can be directly passed to MACH2-viz. The exact format of the JSON file is described here.

MACH2 also prints <primary location> <number of migrations> <number of comigrations> Optimal <running time (in seconds)> on console.

MACH2 can be run using python.

            usage: mach2 [-h] [-c CRITERIA] [-s] [-p PRIMARY] [--colormap COLORMAP] [--log] [-o OUTPUT] [--max_solutions MAX_SOLUTIONS] [-t THREADS] [--viz]
                    clonal_tree observed_labeling

            MACH2

            positional arguments:
            clonal_tree           Input clonal tree
            observed_labeling     Input observed labeling

            optional arguments:
            -h, --help            show this help message and exit
            -c CRITERIA, --criteria CRITERIA
                                    Criteria ordering
            -s, --seeding_locations
                                    Prioritize solutions with the least number of seeding locations (default=False)
            -p PRIMARY, --primary PRIMARY
                                    Primary anatomical location
            --colormap COLORMAP   Color map file
            --log                 Outputs Gurobi logging (default=False)
            -o OUTPUT, --output OUTPUT
                                    Output folder (default=current folder)
            --max_solutions MAX_SOLUTIONS
                                    Maximum number of solutions retained (default=37888)
            -t THREADS, --threads THREADS
                                    Number of threads
            --viz, --open_in_viz  Open the locations on MACH2-viz (default=False) 

An example execution

    $ mach2 data/ovarian/patient2.tree data/ovarian/patient2.observed.labeling --colormap data/ovarian/coloring.txt

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mach2-1.0.1.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mach2-1.0.1-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file mach2-1.0.1.tar.gz.

File metadata

  • Download URL: mach2-1.0.1.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mach2-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cd32d7adb752533630bc4360c20eb1b85bda13b18043a41cb736ea974927e535
MD5 342ab8f7c932866d1ac3e460ad470a12
BLAKE2b-256 a19ce0d7630c83de79e0e81c1ece779fbd9b68ff5dbe1a8157435a6a04f6568d

See more details on using hashes here.

File details

Details for the file mach2-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mach2-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mach2-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 415c8f8347aca385e271337daf21a8694e7db5a8908f3b7fef9016f1dd5023d6
MD5 7f6d9bfa55812bf6fceb7ae410dcba09
BLAKE2b-256 5176aaef509f5ee791b9c6cb0c82b4f861bfce405d366dd5fc4c84fc74b79ac6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page