Package: lolipop
A set of scripts to cluster mutational trajectories into genotypes and cluster genotypes by backgroundContentsA set of scripts to cluster mutational trajectories into genotypes and cluster genotypes by backgroundContentsInstallationRequirementsOptional PackagesSample UsageGeneral WorkflowScript OptionsGeneral OptionsFiltering OptionsClustering OptionsLineage OptionsGraphics OptionsInput DatasetOutputTablesTimeseries tablesTables for ggmullerLinkage matrixDistance MatrixFiguresMuller PlotsLineage DiagramsTimeseries plotsDistance HeatmapDendrogramScriptsSupplementary filesInstallationThese scripts are available onpypiand can be installed withpipinstalllolipopTo update the scripts to the newest version, simply runpipinstalllolipop--upgradeThen run the scripts usinglolipop lineage [args]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/lolipop.git
cd lolipop
lolipop lineage [args]RequirementsThe scripts require a few python packages to work. Each of these can be installed usingpip install [package]orconda install [package].dataclasses (if using a python version below 3.7)logurumatplotlibpandaspygraphvizscipyseabornxlrd (to read excel files)If the packagepygraphvizthrows an error during installation, it is usually because it can't find the correct dependencies in the current environment.
Install the dependencies usingLinux:sudoapt-getinstallpython-devgraphvizlibgraphviz-devpkg-configMac:brewinstallgraphvizor the equivalent package manager on your system.Optional Packagestqdm: Iftqdmis also installed, the scripts will display a progressbar for large datasets.beautifulsoup4: Sometimes the encoding of csv files is ambiguous (the scripts throw a UnicodeDecodeError). Ifbeautifulsoup4is installed the scripts will attempt to correct encoding errors.Sample UsageThe 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:lolipop lineage --input [input filename] --output [output folder]Run with default parameters.lolipop lineage --input [filename] --frequencies 0.05 --detected 0.10Groups 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. Since the--ouputflag was not given, the output will be generated in the same folder as the input dataset.General WorkflowFlowcharts for each individual step can be found under docs/flowcharts.Script OptionsGeneral Options-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.
--threads                   [2] 
                            The number of processes to use. This is only relevant for very large datasets.
-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. This will skip the filtering and clustering steps.
--sheetname                 
                            Specifies the sheet to use when the input is an excel file. Defaults to
                            the first sheet in the spreadsheet.
--gene-alias ALIAS_FILENAME
                            An optional two-column file with more accurate gene
                            names. This is useful when using a reference
                            annotated via prokka.Filtering Options--dasable-all-filters                 
                            Disables the genotype filtering step.
--disable-filter-single            
                            Keep trajectories only detected at a single timepoint.
--disable-filter-startsfixed
                            Keeps mutational trajectories which begin the experiment fixed.
--filter-constant           
                            [0.10] Sets the delta value by which a mutational trajectory must vary by to not 
                            be removed for being a constant mutation. Set to 0 to disableClustering Options-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.
--filename-pairwise         
                            A table of pairwise distance calculations computed in a previous run using
                            identical input parameters. This is only usefull if the dataset being re-run 
                            would other wise take a very onlg time to process (such as data from the 
                            Long Term Evolution Experiment).Lineage Options--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.Graphics Options--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.
--no-outline
                            Disables the white ouline surrounding each series in the muller plots.
--no-render                 
                            Disables `.svg` renders.
--highlight                
                            A comma-separated list of genotype names or annotations to highlight in the generated graphics.
--highlight-color 
                            [#F34A20] What the color of highlighted genotypes should be. Only HEX color codes are supported.Input DatasetThe script operates on a table listing all mutations and their corresponding frequencies at each timepoint (referred 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 namedTrajectorywith labels for each mutational trajectory (orGenotypewhen 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.
TheTrajectoryandGenotypecolumns can contain any kind of label, but must be unique for each trajectory/genotype.PopulationTrajectoryChromosomePositionClassMutation0172544667590B21138102SNPC>T0026.1%100%100%100%100%B22162997SNPT>G00052.5%45.4%91.1%91%B23178671SNPA>C00014.7%45%92.4%88.7%B24196585SNPT>G000021.1%81.1%81.3%B251115010SNPG>T00040.3%48.9%5.7%8%B2t161299332SNPC>T000020.9%20.9%0B261156783SNPC>G00000100%100%B271176231SNPT>A00027.3%78.1%100%100%B281205211SNPC>T000034.5%83.3%79.3%B291223199SNPC>G0000026.9%34%B2trajectory-101262747SNPT>C0011.7%00010.3%B2trajectory-111264821SNPC>T00010.8%15.1%00B2trajectory-121298548SNPG>A012.5%015.3%18.1%17.5%19.1%B2trajectory-131299331SNPG>A000025.8%5.7%7.5%B2trajectory-141299332SNPC>T038%43.2%0000B2t151299332SNPC>T006.6%10.4%6.2%00B2t161299332SNPC>T000020.9%20.9%0B2t171299332SNPC>T0000026.6%31.2%B2t181299332SNPC>T00011.5%013.1%0B2t191299332SNPC>T00018.8%17.1%23.2%24.4%B2201299332SNPC>T00013.8%29.5%08.1%B2211299332SNPC>T00011.4%011%12.3%OutputAll files are prefixed by the name of the original input table if the--nameparameter is unfilled.TablesTimeseries tablestables/lineage.genotypes.tsvtables/lineage.trajectories.tsvTables 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:Genotype0.00017.00025.00044.00066.00075.00090.000genotype-10.0000.3800.4320.0000.0000.0000.000genotype-20.0000.0000.0000.4030.4890.0570.080genotype-30.0000.0000.0000.0000.0001.0001.000genotype-40.0000.0000.2611.0001.0001.0001.000genotype-50.0000.0000.0000.2730.7811.0001.000genotype-60.0000.0000.0920.0520.0310.0000.052genotype-70.0000.0000.0000.0000.2780.8220.803genotype-80.0000.0000.0000.3360.4520.9180.899genotype-90.0000.0000.0000.0760.0430.2190.255genotype-100.0000.0210.0000.0860.1820.0950.058Tables for ggmullertables/lineage.populations.tsvtables/lineage.edges.tsvThese tables are designed for use with the ggmuller r package. Thepopulationstable describes the population/abundance of each genotype at each timepoint while theedgestable describes the ancestry relationship between genotypes.Linkage matrixtables/lineage.linkagetable.tsvThis table is generated using thescipypython 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:left,right: The two sub-clusters merged to create the current clustersclusterId: 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:leftrightdistanceobservationsresultingCluster7180.03421913170.1752208110.199221250.2392221030.2792239120.3702242360.52932522210.6244262610.70852724160.76032814250.78642915200.98833029271.09493131191.358113230281.3626334321.49912343302.12573534354.9431936Distance Matrixtables/lineage.distancematrix.tsvA table of pairwise distance values between each trajectory.FiguresEach 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 convenience.Muller Plots(lineage|unique)/muller.annotated.(png|svg)(lineage|unique)/muller.unannotated.(png|svg)The main value of a muller plot is to quickly visualize abundance and geneology of genotypes over the course of an evolution experiment.Lineage Diagrams(lineage|unique)/lineage.lineageplot.(png|svg)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(lineage|unique)/lineage.timeseries.genotypes.(png|svg)(lineage|unique)/lineage.timeseriespanel.(png|svg)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.pngfile includes trajectories that were filtered out during the filtering step (clored black).Distance Heatmapheatmap.pngA 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.Dendrogramdendrogram.png
Shows the arrangement and distance between clusters and member trajectories. Not available with--method twostep.Scriptsscripts/example.rOne external script is used during the course of this analysis. The r script is based on theggmullerpackage 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.Supplementary filessupplementary-files/.jsonA json-formatted file with all parameters used in the analysis.supplementary-files/.nestscores.tsvLists the scores between each genotype and the corresponding candidate ancestry genotypes. The highest score above or equal to 1 determines the parent genotype.