Skip to main content

A package for finding the exact median triplet tree (in the context of phylogenetics)

Project description

mtrip

mtrip (well, actually, rtist--we renamed the command for a laugh before publication, but never renamed the command!) is a package for finding exact median triplet trees.

This work is based on: Trying out a million genes to find the perfect pair with RTIST:

@article{zhelezov2022trying,
  title={Trying out a million genes to find the perfect pair with RTIST},
  author={Zhelezov, Gleb and Degnan, James H},
  journal={Bioinformatics},
  volume={38},
  number={14},
  pages={3565--3573},
  year={2022},
  publisher={Oxford University Press}
}

Installation

From GitHub:

$ pip install git+https://github.com/glebzhelezov/rtist.git

Prerequisites

  • CMake (version 3.12 or higher)
  • C/C++ compiler (recommended: with OpenMP support)
  • Python 3.6 or higher
  • Cython 3.0.0 or higher

OpenMP on macOS

On macOS, OpenMP support requires installing libomp with Homebrew:

$ brew install libomp

Building and installation

  1. Clone the repository:

    $ git clone https://github.com/glebzhelezov/rtist.git
    $ cd rtist
    
  2. Install using pip (recommended):

    $ pip install -e .
    

This will automatically:

  • Run CMake to configure the build
  • Compile the C extensions (with OpenMP support where available)
  • Install the package in development mode

Building and installation using traditional build process

Alternatively, you can use the traditional build process.

  1. Generate a build script with CMake:

    $ cmake -B build
    
  2. Build C library:

    $ cmake --build build
    
  3. Install mtrip:

    $ pip install .
    
  4. mtrip will be available as a command whenever you activate the virtual environment that was used during installation. To verify that this is the case, run:

    $ mtrip -h
    

    which should output:

    mtrip -h
    usage: mtrip [-h] [-v] [-t THREADS] [--novalidate] [-n] [-p] [-b BINARY] i [o]
    
    Reads in a file of Newick strings, and outputs a file with all the median triplet trees.
    
    positional arguments:
      i                     input file with one Newick string per line
      o                     output file (warning: any existing file will be overwritten!). Defaults to out_<input file>
    
    options:
      -h, --help            show this help message and exit
      -v, --version         show program's version number and exit
      -t, --threads THREADS
                            maximum number of concurrent threads (defaults to number of CPUs, or 1 if undetermined). Must be a positive integer or
                            -1 for the default guess
      --novalidate          don't perform line-by-line sanity check for each input Newick string (for a small speedup)
      -n, --nosave          don't save the output to a file (must be used with --print)
      -p, --print           print the output to the screen
      -b, --binary BINARY   save the weights array to a binary file. This file can be used to find additional trees. Traditionally this file has the
                            extension .p
    

How to use

Run the commands mtrip, mtrip-suboptimal, mtrip-combine without any arguments to get information on how to use them. The first one is for finding the median tree(s), the second one is for finding the suboptimal trees, and the last one is for combining weights.

Testing

The package includes a comprehensive test suite to verify correct functionality of all components.

Running Tests

To run the full test suite:

# Run all tests
$ python tests/run_tests.py

# Run a specific test file
$ python -m unittest tests/test_newick_parsing.py

See the tests/README.md file for more details on running and creating tests.

Example Usage

Finding Median Triplet Trees

# Process input file of Newick strings and write results to default output file
$ mtrip examples/example_5tips.nwk
Using 8 threads.
14/14 complete (100.00)
Input parameters:
Newick file: examples/example_5tips.nwk
Output file: out_example_5tips.nwk
Max threads: 8

Parsing input text file.
* Stripping Newick strings.
* Checking for matching parentheses and semicolon in each GT.

Finding median tree. This might take a while!
* Parsing Newick strings and recording bipartitions in GTs.
* Finding all unique names.
* Calculating each GT bipartition's weight.
* Matching bipartitions to subsets.
* Forming arrays for computations.
* Finding each possible bipartition's weight:
Starting parallel comptuation with a max of 8 threads.
* Finding maximal possible weight of each bipartition.
Best possible triplet count is 26, out of a maximum of 50.

Done!
* Wrote all median triplet trees to out_example_5tips.nwk.
🤖💬 Beep boop, finished in 0.00 seconds.

Finding Suboptimal Trees

First, run mtrip with the -b flag to save the weights:

# Save weights to a binary file for later use with mtrip-suboptimal
$ mtrip examples/example_5tips.nwk -b example_5tips_weights.p

Then use mtrip-suboptimal to find trees that are close to optimal:

$ mtrip-suboptimal -y example_5tips_weights.p
Input parameters:
Input file  : example_5tips_weights.p
Output file : outputting to stdout instead
Use stdout  : True
Min fraction: 0.99
Max n trees : 100
Burnin count: 400
RNG seed    : 0

Processing pickle
* Loading pickle
* Verifying
File was created using version 0.26.5 of the utility.
Data for 5 species and maximum triplet score 26.
* Setting minimum viable tree score to 25 (max of -m and -f flags)

Finding trees
* Finding initial splits
* Beginning burn-in
* Could only find 3 trees satisfying the constraint (100 requested)
* Refining all splits
* Sorting by score

Done!
Found 3 trees satisfying the given constraints. 🪆
* Translating to Newick format
* Writing output to stdout.

#26
((A,B),((C,D),E));
#26
((A,B),(C,(D,E)));
#25
((A,B),(D,(C,E)));

The output shows three trees with their scores (#26 means the tree satisfies 26 out of 50 possible triplets).

Developer Documentation

For information on contributing to the project, CI/CD setup, and release process, see README.dev.md.

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

mtrip-0.3.0.tar.gz (302.4 kB view details)

Uploaded Source

Built Distributions

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

mtrip-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

mtrip-0.3.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ i686

mtrip-0.3.0-cp313-cp313-macosx_14_0_x86_64.whl (707.1 kB view details)

Uploaded CPython 3.13macOS 14.0+ x86-64

mtrip-0.3.0-cp313-cp313-macosx_14_0_arm64.whl (669.3 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

mtrip-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

mtrip-0.3.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686

mtrip-0.3.0-cp312-cp312-macosx_14_0_x86_64.whl (709.3 kB view details)

Uploaded CPython 3.12macOS 14.0+ x86-64

mtrip-0.3.0-cp312-cp312-macosx_14_0_arm64.whl (671.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

mtrip-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

mtrip-0.3.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686

mtrip-0.3.0-cp311-cp311-macosx_14_0_x86_64.whl (706.8 kB view details)

Uploaded CPython 3.11macOS 14.0+ x86-64

mtrip-0.3.0-cp311-cp311-macosx_14_0_arm64.whl (669.4 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

mtrip-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

mtrip-0.3.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ i686

mtrip-0.3.0-cp310-cp310-macosx_14_0_x86_64.whl (706.9 kB view details)

Uploaded CPython 3.10macOS 14.0+ x86-64

mtrip-0.3.0-cp310-cp310-macosx_14_0_arm64.whl (669.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file mtrip-0.3.0.tar.gz.

File metadata

  • Download URL: mtrip-0.3.0.tar.gz
  • Upload date:
  • Size: 302.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for mtrip-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0b1416ac85e0461129aa5cb93a9653b5888b700129362896a2bfea07a071b2c8
MD5 4d820d07f2517876ac120a17ebe5f5fd
BLAKE2b-256 088e20532bceb227be7b86d5a1e45ec9324e2183e59a8ddb36e5196090139518

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a58ff8fcfd12e56a936a7d270bf3c4c7601ef4c9c0b32b3fd21564c2f465351f
MD5 378545818ce5d6406a5369f372a4243d
BLAKE2b-256 cef1f87823b98e61fdd781c6a5cfa6ca2272532351841ecc1658fcda49298112

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6e333e8a9520a13749bded22ef83213ab01c44b9f0cbfef2727e275b06a03bea
MD5 d27dccae00752ed723415cb0b1a78dad
BLAKE2b-256 8b255f5b367bc3f9d33be8a485afe5f16478cee7a3837ca4f1fced638806df5f

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp313-cp313-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp313-cp313-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 b99f69a689fec5dfe07a186c4c9776f40ca6b15933b3ccc8388e1897b2d70a9a
MD5 e00a1a05cd6168024d142274258fb578
BLAKE2b-256 6dc34f773ee7581b7d88284c2b60c1bfa1a00c34a146af14d6a24b3425cb2736

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5605d01177af5dc6e9004c6412a683aabce7e08ead25684c659dff3d56e3bd24
MD5 c1ff59f527f3cae7308d535a7a2ee81a
BLAKE2b-256 d0d6b83e4b455ca8dd3ed265a2a366ac2aeddc3b81f224258bbda4cf7ca821da

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5e3dc1306f2112e98e24f488bac1376af7d17b0d54b9dd476025348da85cdba1
MD5 a9d6df55b92005d1a466d56a36249deb
BLAKE2b-256 caccaafd5edce38a4280406015f03bad7a800fcbb924e00209ea3edf9fb86eb8

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 d429b1a47ce2a4521658bfcd0cd8312aae44d04ad17c82d5c6bc37f94131af3f
MD5 b28faa5ff925992f359f5b2c9e1acfa4
BLAKE2b-256 60899611d0f7cc64faa42183bb68c9902553a0c427c83e5c9683631c5012cef4

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp312-cp312-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp312-cp312-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 4abf226fbc4fe135ffd64eb11eb526bcb6d3a4911eb063bf7b715661eb252273
MD5 1b420908e836377c79322b8ef3c0d5f1
BLAKE2b-256 23569d04f157fe3b6e72494e44bddd587112f5460d2a49ad706dba628b380e27

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e61d79e21e5b11f1883e3dd38a83a378c9fef8f815df9adf80b4d207c4d97841
MD5 a8e4e1b1675a3c5aa0dc56b894d87c9f
BLAKE2b-256 fa37b944b99a787ef3d7ab4606535f41dc7d353ecd0b913e39f0e2e8c40af9ab

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae8ad4792b0b0f417e6005bd1f3aad79023c8d8d32cba47ff7135abc9bc6d142
MD5 ff22cfacb75bdbaa2df2249ca07e4e9d
BLAKE2b-256 fcd6898d3f866614f9fc1775abfe310a61c43572f1a27081dacf8a7e04984b2f

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 3813388a6fb39be5cebf40049aa97b2f3113d4e032a23a862e1b7a0fbb839372
MD5 ed1a991cee0c0d5f0b1a9033a0ac7cb5
BLAKE2b-256 026db0c7138d7fdb0f6fff0a1b8eb9b38983e0b414c0ba14d028cd955782935b

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp311-cp311-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp311-cp311-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 1206f229be1680ad5f62dbee2baa91763664939436c195a971171e9762470a92
MD5 cffc5438878e225ad3370dcfdf69b6e3
BLAKE2b-256 7c0b8f5d55b8ae90c493c328512fed4bb63c2bebace3c15e1cd14fd17797ac00

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f79449f783d67310fc5014b41cc64507373d0bcd31ef5a03525e71ab7cc7366b
MD5 157aca0b8e123957fd975f2ded289ec2
BLAKE2b-256 4bbd0b3599fcd9cdb810a78eb7807e81ffb29aa7117b605304c04bf2b78ab347

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 31b7ab0c425d21833a0ff1e179e6a1bcae60dfc4c2d61b57502f471166985611
MD5 1ec944ef60e85c886bb4ba2bc4063b94
BLAKE2b-256 a771695af85680faa55b501ac43417dab9c5f1f4078eae44aab19fbb3269819f

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f18a5ffae2d4021ab9be71220079382da3aef1d3cb2ab463841ee17e0d47f5ed
MD5 650798957712bfc4000bb7975aa0794a
BLAKE2b-256 c339dac432d9dc17faf79289ae26b9169baf287eafa1ffb4670a1de7b7b0d7a4

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp310-cp310-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp310-cp310-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 8037e86c8329c9ed963ef88c1cc9bfde658f565bf320bd5ca7ee4145f2e30881
MD5 7a54d06acd1d15c61990f706110c4ede
BLAKE2b-256 593b1c1c0d98805083788e3fc25106bf779295282c61dd7391878d4bbeee81f1

See more details on using hashes here.

File details

Details for the file mtrip-0.3.0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mtrip-0.3.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6f8042ee57ab2e6c06319d2e2f2b5b95beaa46ab60c279143bd69e87d19c9caa
MD5 7da8d9ac6e07734a4425f7b2e9f9e06b
BLAKE2b-256 f7e780aeb4902638447d7c08edd5d4ce5d14369de09c90f4f7ff580adae8886b

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