phylostan

Phylogenetic inference using Stan

https://github.com/4ment/phylostan

Science Score: 59.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 13 DOI reference(s) in README
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
    1 of 2 committers (50.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.2%) to scientific vocabulary

Keywords

bayes hmc phylogenetics pystan stan variational-inference
Last synced: 6 months ago · JSON representation

Repository

Phylogenetic inference using Stan

Basic Info
  • Host: GitHub
  • Owner: 4ment
  • License: gpl-3.0
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 13.3 MB
Statistics
  • Stars: 23
  • Watchers: 9
  • Forks: 5
  • Open Issues: 2
  • Releases: 1
Topics
bayes hmc phylogenetics pystan stan variational-inference
Created over 9 years ago · Last pushed 12 months ago
Metadata Files
Readme License

README.md

phylostan: phylogenetic inference using Stan

Introduction

phylostan is a tool written in python for inferring phylogenetic trees from nucleotide datasets. It generates a variety of phylogenetic models using the Stan language. Through the pystan library, phylostan has access to Stan's variational inference and sampling (NUTS and HMC) engines. The program has been described and its performance evaluated in an article. The data and scripts used to generate the results can be found here.

Features

Phylogenetic model components: - Nucleotide substitution models: JC69, HKY, GTR - Rate heterogeneity: discretized Weibull distribution and general discrete distribution - Tree without clock constraint with uniform prior on topology - Time tree: - Homochronous sequences: same sampling date - Heterochronous sequences: sequences sampled at different time points - Molecular clocks: - Strict - Autocorrelated - Uncorrelated: log-normal hierarchical prior - Coalescent models: - Constant population size - Skyride - Skygrid

Algorithms provided by Stan: - Variational inference: - Mean-field distribution - Full-rank distribution - No U-Turn Sampler (NUTS) - Hamiltonian Monte Carlo (HMC)

Prerequisites

| Program/Library | Version | Description | |----------- | --------| -- | | python | Tested on python 3.6, 3.7, 3.9 | | | pystan | >=2.19 <3 | API for [Stan](https://mc-stan.org) | | [dendropy](https://www.dendropy.org) | | Library for manipulating trees and alignments| | numpy | >=1.7 | |

You can install phylostan using pip

bash pip install phylostan

You can also run it locally

bash python -m phylostan.phylostan <COMMAND> where <COMMAND> is either the build or run command.

Command-line usage

phylostan is decomposed into two sub-commands: - build: creates a Stan file: a text file containing the model. - run: runs a Stan file with the data.

These two steps are separated so the user can edit the Stan model. The main reason would be to modify the priors.

To get some help about the build or run commands: bash phylostan build --help phylostan run --help

Quickstart

We are going to use the fluA.fa alignment and fluA.tree tree files. This dataset contains 69 influenza A virus haemagglutinin nucleotide sequences isolated between 1981 and 1998.

First, a Stan script needs to be generated using the build command: bash cd examples/fluA phylostan build -s fluA-GTR-W4.stan -m HKY -C 4 \ --heterochronous --estimate_rate --clock strict --coalescent constant

This command is going to create a Stan file fluA-GTR-W4.stan with the following model: - Hasegawa, Kishino and Yano (HKY) nucleotide substitution model - Rate heterogeneity with 4 rate categories using the Weibull distribution - Assumes that sequences were sampled are different time points (heterochronous) - Constant effective population size - The substitution rate will be estimated

In the second step we compile and run the script with our data bash phylostan run -s fluA-GTR-W4.stan -m HKY -C 4 \ --heterochronous --estimate_rate --clock strict --coalescent constant \ -i fluA.fa -t fluA.tree -o fluA -q meanfield

The run command requires the data (tree and alignment) and an output parameter. It also needs the parameters that were provided to the build command. The output will consists of 4 files: - fluA: this file is the output file of Stan. It contains the samples drawn from the variational distribution (or MCMC samples). - fluA.diag: this file is also generated by Stan and it contains some information such as the ELBO at each iteration. - fluA.trees: this file is a nexus file containing trees. It can be opened with a program such as FigTree or summarized using treeannotator from BEAST or BEAST2. - fluA-GTR-W4.pkl: the Stan script is compiled into this binary file. This file can be reused automatically by phylostan unless it must be recompiled, then the option --compile can be used.

At the end of the run, phylostan will print on the screen the mean and 95% credibility interval of the parameters of interest: Weibull (shape) mean: 0.488 95% CI: (0.383,0.616) Strict clock (rate) mean: 0.00499 95% CI: (0.00432,0.00577) Constant population size (theta) mean: 4.03 95% CI: (3.14,5.05) HKY (kappa) mean: 5.58 95% CI: (4.37 7.039) Root height mean: 18.96 95% CI: (18.36 19.74) In this example we have used a mean-field distribution (-q meanfield) to approximate the posterior using variational inference. The Stan model is already compiled so we can run the NUTS algorithm without re-generating the script file, simply issue the command: bash phylostan run -s fluA-GTR-W4.stan -m HKY -C 4 \ --heterochronous --estimate_rate --clock strict --coalescent constant \ -i fluA.fa -t fluA.tree -o fluA -a nuts

The NUTS algorithm is much slower (and more accurate) than variational inference so it should be used on a small dataset.

Citing phylostan

Mathieu Fourment and Aaron E. Darling. Evaluating Probabilistic Programming and Fast Variational Bayesian Inference in Phylogenetics. 2019 PeerJ. doi: 10.7717/peerj.8272.

@article{fourment2019phylostan, title = "Evaluating probabilistic programming and fast variational {B}ayesian inference in phylogenetics", author = "Fourment, Mathieu and Darling, Aaron E", journal = "PeerJ", volume = 7, pages = "e8272", month = dec, year = 2019 }

Owner

  • Name: Mathieu Fourment
  • Login: 4ment
  • Kind: user
  • Location: Australia
  • Company: University of Technology Sydney

GitHub Events

Total
  • Issues event: 2
  • Push event: 1
Last Year
  • Issues event: 2
  • Push event: 1

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 74
  • Total Committers: 2
  • Avg Commits per committer: 37.0
  • Development Distribution Score (DDS): 0.216
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Mathieu Fourment m****t@g****m 58
Aaron Darling a****g@u****u 16
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 5
  • Total pull requests: 1
  • Average time to close issues: about 1 year
  • Average time to close pull requests: N/A
  • Total issue authors: 5
  • Total pull request authors: 1
  • Average comments per issue: 0.8
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • leonkt (1)
  • lorenzocapp (1)
  • koadman (1)
  • Anaphory (1)
  • 4ment (1)
Pull Request Authors
  • maxbiostat (1)
Top Labels
Issue Labels
bug (2) question (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 14 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 6
  • Total maintainers: 1
pypi.org: phylostan

Phylogenetic inference with Stan

  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 14 Last month
Rankings
Dependent packages count: 10.1%
Stargazers count: 13.1%
Forks count: 14.2%
Average: 19.8%
Dependent repos count: 21.6%
Downloads: 39.8%
Maintainers (1)
Last synced: 6 months ago

Dependencies

examples/Dockerfile docker
  • ubuntu latest build
pyproject.toml pypi
setup.py pypi