treecl

Clustering phylogenetic trees with python

https://github.com/kgori/treecl

Science Score: 23.0%

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

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    7 of 9 committers (77.8%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.6%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

Clustering phylogenetic trees with python

Basic Info
  • Host: GitHub
  • Owner: kgori
  • License: mit
  • Language: C++
  • Default Branch: master
  • Size: 2.63 MB
Statistics
  • Stars: 25
  • Watchers: 5
  • Forks: 12
  • Open Issues: 4
  • Releases: 0
Created over 13 years ago · Last pushed almost 2 years ago
Metadata Files
Readme License

README.md

treeCl - Phylogenetic Tree Clustering

Travis build status

treeCl is a python package for clustering gene families by phylogenetic similarity. It takes a collection of alignments, infers their phylogenetic trees, and clusters them based on a matrix of between-tree distances. Finally, it calculates a single representative tree for each cluster.

You can read the paper here

Installation

Preparing dependencies

If your system already has python 2.7, cython, numpy and a C++11-capable compiler (e.g. gcc >= 4.7), then you're ready to install.

The remaining python dependencies will be automatically installed during the build process.

External dependencies

To be able to build trees, treeCl needs to call on some external software. The choices are RAxML, PhyML, FastTree or PLL (using pllpy). If any of these are installed, available in your path, and keep the standard names they were installed with, they should work.

Installing treeCl

All remaining dependencies will be installed automatically using pip

pip install treeCl

Example Analysis

``` python

import treeCl

""" The first point of call is the treeCl.Collection class. This handles loading your data, and calculating the trees and distances that will be used later.

This is how to load your data. This should be a directory full of sequence alignments in fasta '.fas' or phylip '.phy' formats. These can also be zipped using gzip or bzip2, treeCl will load them directly. """ c = treeCl.Collection(inputdir='inputdir', file_format='phylip')

""" Now it's time to calculate some trees. The simplest way to do this is """ c.calc_trees()

""" This uses RAxML to infer a tree for each alignment. We can pass arguments to RAxML using keywords. """ c.calctrees(executable='raxmlHPC-PTHREADS-AVX', # specify raxml binary to use threads=8, # use multithreaded raxml model='PROTGAMMAWAGX', # this model of evolution fasttree=True) # use raxml's experimental fast tree search option

""" We can use PhyML instead of RAxML. Switching programs is done using a TaskInterface """

phyml = treeCl.tasks.PhymlTaskInterface() c.calctrees(taskinterface=phyml)

""" PhyML doesn't support multithreading, but treeCl can run multiple instances using JobHandlers """

threadpool = treeCl.parutils.ThreadpoolJobHandler(8) # external software can be run in parallel # using a threadpool.

c.calctrees(jobhandler=threadpool, taskinterface=phyml)

""" Trees are expensive to calculate. Results can be cached to disk, and reloaded. """ c.writeparameters('cache') c = treeCl.Collection(inputdir='inputdir', paramdir='cache')

""" Once trees have been calculated, we can measure all the distances between them. treeCl implements Robinson-Foulds (rf), weighted Robinson-Foulds (wrf), Euclidean (euc), and geodesic (geo) distances. """ dm = c.getintertree_distances('geo')

Alternatively

processes = treeCl.parutils.ProcesspoolJobHandler(8) # with pure python code, it is better to use processpools to parallelise for speed dm = c.getintertree_distances('geo', jobhandler=processes, batchsize=100) # jobs are done in batches to # reduce overhead

""" Hierarchical Clustering """ hclust = treeCl.Hierarchical(dm) partition = hclust.cluster(3) # partition into 3 clusters

To use different linkage methods

from treeCl.clustering import linkage partition = hclust.cluster(3, linkage.AVERAGE) partition = hclust.cluster(3, linkage.CENTROID) partition = hclust.cluster(3, linkage.COMPLETE) partition = hclust.cluster(3, linkage.MEDIAN) partition = hclust.cluster(3, linkage.SINGLE) partition = hclust.cluster(3, linkage.WARD) # default, Ward's method partition = hclust.cluster(3, linkage.WEIGHTED)

""" Spectral Clustering """ spclust = treeCl.Spectral(dm) partition = spclust.cluster(3)

Alternative calls

from treeCl.clustering import spectral, methods spclust.cluster(3, algo=spectral.SPECTRAL, method=methods.KMEANS) # these are the defaults spclust.cluster(3, algo=spectral.KPCA, method=methods.GMM) # alternatives use kernel PCA and a Gaussian Mixture Model

Getting transformed coordinates

spclust.spectralembedding(2) # spectral embedding in 2 dimensions spclust.kpcaembedding(3) # kernel PCA embedding in 3 dimensions

""" Multidimensional scaling """ mdsclust = treeCl.MultidimensionalScaling(dm) partition = mdsclust.cluster(3)

Alternatives: classical or metric MDS

from treeCl.clustering import mds partition = mdsclust.cluster(3, algo=mds.CLASSICAL, method=methods.KMEANS) partition = mdsclust.cluster(3, algo=mds.METRIC, method=methods.GMM)

Getting transformed coordinates

mdsclust.dm.embedding(3, 'cmds') # Classical MDS, 3 dimensions mdsclust.dm.embedding(2, 'mmds') # Metric MDS, 2 dimensions

""" Score the result via likelihood """ raxml = treeCl.tasks.RaxmlTaskInterface() sc = treeCl.Scorer(c, cachedir='scorer', taskinterface=raxml) sc.writepartition(partition) results = sc.analysecache_dir(executable='raxmlHPC-PTHREADS-AVX', threads=8)

""" Get the results """

Get concatenated sequence alignments for each group

concats = [c.concatenate(grp) for grp in partition.get_membership()] alignments = [conc.alignment for conc in concats]

Get a list of the loci in each group

loci = sc.getpartitionmembers(partition)

Get trees for each group

trees = sc.getpartitiontrees(partition)

Get full model parameters for each group

fullresults = sc.getpartitionresults(partition) # same as returned by analysecache_dir

Owner

  • Name: Kevin Gori
  • Login: kgori
  • Kind: user

GitHub Events

Total
  • Watch event: 1
Last Year
  • Watch event: 1

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 598
  • Total Committers: 9
  • Avg Commits per committer: 66.444
  • Development Distribution Score (DDS): 0.281
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Kevin Gori k****i@e****k 430
kgori k****i@g****m 74
Malcolm Perry m****2@c****k 70
Kevin Gori k****i@e****k 13
David Dylus d****s@g****m 5
Malcolm Perry m****y@e****k 3
Kevin Gori k****5@c****k 1
Malcolm Perry m****y@e****k 1
Malcolm Perry m****y@e****k 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 27
  • Total pull requests: 0
  • Average time to close issues: 4 months
  • Average time to close pull requests: N/A
  • Total issue authors: 19
  • Total pull request authors: 0
  • Average comments per issue: 2.63
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • kgori (5)
  • jlblancopastor (2)
  • davidemms (2)
  • alexweisberg (2)
  • fbemm (2)
  • szitenberg (1)
  • eik-dahms (1)
  • osuchanglab (1)
  • SashaNikolaevaBerkeley (1)
  • hdetering (1)
  • williamhuntpalmer (1)
  • fanliang123 (1)
  • dvdylus (1)
  • mossmatters (1)
  • rohanmaddamsetti (1)
Pull Request Authors
Top Labels
Issue Labels
bug (2) build error (1) enhancement (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 328 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 41
  • Total maintainers: 1
pypi.org: treecl

Phylogenetic Clustering Package

  • Versions: 41
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 328 Last month
Rankings
Dependent packages count: 10.0%
Forks count: 10.2%
Stargazers count: 12.4%
Average: 19.7%
Dependent repos count: 21.7%
Downloads: 44.1%
Maintainers (1)
Last synced: 12 months ago

Dependencies

setup.py pypi
  • PyYaml *
  • biopython *
  • cython >=0.19.0
  • dendropy >=4.0.0
  • fastcluster *
  • futures *
  • ipython *
  • matplotlib *
  • nose *
  • numpy *
  • pandas *
  • phylo_utils ==0.0.5
  • progressbar-latest ==2.4
  • scikit-learn *
  • scipy *
  • tree_distance >=1.0.6