A set of scripts to cluster mutational trajectories into genotypes and cluster genotypes by background
A set of scripts to cluster mutational trajectories into genotypes and cluster genotypes by background
- Sample Usage
- General Workflow
- Script Options
- Input Parameters
- Output Files
These scripts are available on (pypi)[https://pypi.org/project/muller/] and can be installed with
pip install muller
To update the scripts to the newest version, simply run
pip install muller --upgrade
It is also possible to simply clone the package, although the additional required packages would then need to be installed separately.
git clone https://github.com/cdeitrick/muller_diagrams.git cd muller_diagrams Muller.py [args]
The scripts require a few python packages to work. Each of these can be installed using
pip install [package] or
conda install [package].
- dataclasses (if using a python version below 3.7)
- xlrd (to read excel files)
If the package
pygraphviz throws an error during installation, it is usually because it can't find the correct dependancies in the current environment.
Install the dependancies using
sudo apt-get install python-dev graphviz libgraphviz-dev pkg-config
brew install graphviz
or the equivalent package manager on your system.
r should be installed on your system in order to run the generated rscript file with the packages
tqdm is also installed, the scripts will display a progressbar for large datasets.
Sometimes the encoding of csv files is ambiguous (the scripts throw a UnicodeDecodeError). If
beautifulsoup4 is installed the scripts will attempt to correct encoding errors.
The scripts currently default to hierarchical clustering using the binomial distance. More information is available in the "description" folder. Use python to call the "muller" folder:
Muller.py --input [input filename] --output [output folder]
Run with default parameters.
Muller.py --input [filename] --frequencies 0.05 --detected 0.10
Groups genotypes in groups of 0.05 (i.e.
[0.00, 0.05, 0.10, ... , 0.90, 0.95, 1.00]) based on each genotype's maximum frequency. Each genotype in each group is then sorted by the timepoint it was first detected (the first timepoint where the frequency was greater than 0.10). Output files are saved to the same folder as the input table.
Flowcharts for each individual step can be found under docs/flowcharts.
-h, --help Show a help message and exit --name Prefix to use when naming the output files. defaults to the dataset filename. -i, --input The table of trajectories to cluster. Must be an excel file or csv/tsv file. The delimiter will be inferred from the file extension. -o, --output The output folder to save the files to. -d, --detection The uncertainty to apply when performing frequency-based calculations. For example, a frequency at a given timepoint is considered undetected if it falls below 0 + `detection`. --fixed The minimum frequency at which to consider a mutation fixed. Defaults to 1 - `uncertainty` -s, --significant [0.15] The frequency at which to consider a genotype significantly greater than zero. -f, --frequencies [0.10] The frequency cutoff or step to use when sorting genotypes. May be a comma-separated string of frequencies, or a set inverval to use when generating the frequency breakpoints. This affects the filtering step and the nesting step. For example, a value of 0.15 will use the frequencies 0,.15,.30,.45... --genotypes Indicates that the input table contains genotypes rather than mutational trajectories. --no-filter Disables the genotype filtering step. --include-single Disables the filter which rejects trajectories detected at a single timepoint. --sheetname Specifies the sheet to use when the input is an excel file. Defaults to 'Sheet1' --strict-filter By default, the filters allow trajectories to appear both before and after a genotype fixes as long as they were undetected at the timepoint the sweep occurs. This generally represents mutations which appear, are removed during a genotype sweep, and reappear afterwards. Using `--strict-filter` would remove these trajectories. --genotype-colors Path to a file with a custom genotype colorscheme. The file should be tab-delimited with a genotype name (ex. 'genotype-13') in the first column and a HEX color code (ex. '#F5674A') in the second. These colors will override the default colorscheme. --gene-alias ALIAS_FILENAME An optional two-column file with more accurate gene names. This is useful when using a reference annotated via prokka.
-m, --method Selects the clustering method to use. 'two-step' will use the original two-step method of sorting trajectories into genotypes while 'hierarchy' will use hierarchical clustering to do the clustering. Defaults to 'matlab' --metric Used to select the distance metric when `--method` is set to 'hierarchy'. Available Options: 'similarity', 'binomial' [Default] Uses the binomial test implemented in the original matlab scripts as a distance metric. 'jaccard' Uses the Jaccard distance between two series to determine the distance metric. 'minkowski' Uses the minkowski distance as a distance metric. Primarily influenced by the difference between two series. 'pearson' Uses the pearson correlation coefficient as the distance metric. Primarily influenced by the correlation of two series against each other. 'combined' A combination of the 'pearson' and 'minkowski' distances to account for the correlation of two series as well as the difference between them. -r --similarity-cutoff [0.05] Used when grouping trajectories into genotypes. Maximum p-value difference to consider trajectories related when using the two-step method, and selects the maximum distance to consider trajectories related when `--method` is `hierarchy`. -d, --difference-cutoff [0.10] Only used when `--method` is `twostep`. Used to unlink unrelated trajectories present in a genotype. Is not used when using hierarchical clustering. -g, --known-genotypes Path to a file listing trajectories which are known to be in the same genotype. Each line in the file represents a single genotype, and each line should be a comma-separated list of trajectory labels as they appear in the input dataset.
--additive [0.03] Controls how the additive score between a nested and unnested genotype is calculated. Defaults to the detection cutoff value. --subtractive Controls when the combined frequencies of a nested and unnested genotype are considered consistently larger than the fixed cutoff.Defaults to the detection cutoff value. (default: None) --derivative Controls how much a nested and unnested genotype should be correlated/anticorrelated to be considered significant (default: 0.01). Correlation implies a positive relationship between the nested/unnested genotypes while anticorrelation is evidence against nesting the unnested genotype under the nested genotype. --known-ancestry A tab-delimited file designating the known ancestry of certain genotypes. The left column should be the genotype to nest, right column should be its parent. Column names are ignored. Genotype names are generated during the clustering step, so this is only useful when re-running the analysis.
--no-outline Disables the white ouline surrounding each series in the muller plots.
The script operates on a table listing all mutations and their corresponding frequencies at each timepoint (refered to as "trajectories" in this script) or a table with each genotype and frequency at each timepoint (ex. the genotype table in the examples folder).
The table must have a column named
Trajectory with labels for each mutational trajectory (or
Genotype when using
--genotype) and integer columns for each timepoint. The labels are solely used to identify trajectories belonging to a specific genotype, and must be integers. All other columns will be ignored when calculating genotypes and genotype clusters.
The frequencies can be represented as either a number between 0 - 1,
a number between 0 - 100 or as percentage.
Genotype columns can contain any kind of label, but must be unique for each trajectory/genotype.
All files are prefixed by the name of the original input table if the
--name parameter is unfilled.
Tables listing the genotypes and trajectories encountered in the analysis. The trajectory tables also link each trajectory to its respective genotype. There are two versions of these tables: one set with the original input trajectories and the initial calculated genotypes and another set with the final trajectories and genotypes left in the analysis after the filtering step. The trajectory tables include all columns from the input trajectory table as well as the timeseries and annotation columns used in the analysis.
Example Genotype Table:
Tables for ggmuller
These tables are designed for use with the ggmuller r package. The
populations table describes the population/abundance of each genotype at each timepoint while the
edges table describes the ancestry relationship between genotypes.
This table is generated using the scipy python package. It describes the agglomeration of clusters starting with the individual trajectories, as well as the mean, variance, and trajectory count of each cluster. Columns:
right: The two sub-clusters merged to create the current clusters
clusterId: The id assigned to this cluster. Note that since the individual genotypes are not included in the table, the clusters are numbered in order starting with 1 + the total number of genotypes.
distance: The distance between the two sub-clusters.
observations: The number of mutational trajectories contained in this cluster.
Example linkage matrix:
A table of pairwise distance values between each trajectory.
The converted form of the
.ggmuller.edges.tsv used to generate the muller plots. This file is created from the r script, described later.
Each of the output plots use the same palette for genotypes and trajectories. A genotype colored a shade of blue will share that color across all graphs and diagrams which depict that genotype. There are two palettes: one to indicate each clade in the geneology and one to easily distinguish between different genotypes. Each graphic is created with both palettes, and some are provided in multiple formats for convienience.
The main value of a muller plot is to quickly visualize abundance and geneology of genotypes over the course of an evolution experiment.
These are simple flowcharts indicating the relationship between genotypes and clades. The original genotype of each clade are shown to arise in "genotype-0", the root background. The ancestry of all other genotypes are then shown relative to these clades.
Timeseries plots of the frequency of each trajectory and genotype at each timepoint. Trajectories are colored according to which genotype they were grouped into. The
.genotypes.filtered.png file includes trajectories that were filtered out during the filtering step (clored black).
A pairwise comparison of the calculated distance between each mutational trajectory. Trajectories are grouped by the final genotype. The heatmap will be annotated with the distance values if there are fewer than thirty total trajectories in the analysis.
Shows the arrangement and distance between clusters and member trajectories. Not available with
One external script is used during the course of this analysis. The r script is based on the ggmuller package implemented in r, and is used to convert the genotypes data into a format required to generate the muller plots. This script also generates a basic muller plot (/graphics/distinctive/.muller.png), although all other muller plots are created with the python implementation.
A json-formatted file with all parameters used in the analysis.
Lists the scores between each genotype and the corresponding candidate ancestry genotypes. The highest score above or equal to 1 determines the parent genotype.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.