Skip to content

Commit

Permalink
updating to version 0.2.0; docs for some fxns and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pblischak committed Jun 25, 2017
1 parent 57021dc commit fe3762e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
12 changes: 10 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Requirements:
- Seaborn
- C++ compiler (g++ >= v4.8)

HyDe is a software package that detects a signal for hybridization in phylogenomic
HyDe is a software package that detects hybridization in phylogenomic
data sets using phylogenetic invariants. The primary interface for HyDe is a Python
module called ``phyde`` (**P**\ ythonic **Hy**\ bridization **De**\ tection).
``phyde`` provides a suite of tools for performing hypothesis tests on triples of taxa
Expand Down Expand Up @@ -51,6 +51,14 @@ as `Miniconda <https://conda.io/miniconda.html>`__.
# Test the installation
make test
The ``phyde`` module is also hosted on the Python Package Index (PyPI), and can be installed directly using
``pip``.

.. code:: py
# Install from PyPI with pip
pip install phyde
Running HyDe from the Command Line
----------------------------------

Expand All @@ -70,7 +78,7 @@ Running HyDe in Python
import phyde as hd
# Run a hyde analysis
hd.run_hyde(...)
res = hd.run_hyde("data.txt", "map.txt", "out", 16, 4, 50000, bootReps=100)
# import a data set for testing particular triples
data = hd.HydeData("data.txt", "map.txt", "out", 16, 4, 50000)
Expand Down
2 changes: 1 addition & 1 deletion phyde/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

__version__ = "0.1.1"
__version__ = "0.2.0"
__author__ = "Paul Blischak and Laura Kubatko"

from phyde.analyze.main import run_hyde
Expand Down
22 changes: 21 additions & 1 deletion phyde/core/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ class Bootstrap:
containing parameter values.
"""
def __init__(self, bootfile):
"""
Constructor.
"""
self.bootfile = bootfile
self.breps = {}
self.triples = []
self._read_bootstraps(bootfile)

def __call__(self, attr, p1, hyb, p2):
"""
A callable method to access attributes rom a bootstrapped
HyDe analysis. Returned as a list.
"""
return [t[attr] for t in self.breps[(p1, hyb, p2)]]

def _read_bootstraps(self, bootfile):
Expand Down Expand Up @@ -64,7 +71,7 @@ def _boot_info(self, b):

def summarize(self):
"""
Summarizes the results of a bootsrapped HyDe analysis.
"""
summaries = {}
for t in self.triples:
Expand All @@ -75,15 +82,28 @@ def summarize(self):
return summaries

def gamma(self, p1, hyb, p2):
"""
Return the values of gamma for the triple (p1, hyb, p2).
"""
return [t['Gamma'] for t in self.breps[(p1, hyb, p2)]]

def zscore(self, p1, hyb, p2):
"""
Return the values of the test statistic for the triple (p1, hyb, p2).
"""
return [t['Zscore'] for t in self.breps[(p1, hyb, p2)]]

def pvalue(self, p1, hyb, p2):
"""
Return the p-values for the triple (p1, hyb, p2).
"""
return [t['Pvalue'] for t in self.breps[(p1, hyb, p2)]]

def abba_baba(self, p1, hyb, p2):
"""
Calculate Patterson's D-Statistic for all bootstrap replicates
for the triple (p1, hyb, p2). Uses vectorization with numpy arrays.
"""
return ((np.array([t['ABBA'] for t in self.breps[(p1, hyb, p2)]]) - np.array([t['ABAB'] for t in self.breps[(p1, hyb, p2)]])) /
(np.array([t['ABBA'] for t in self.breps[(p1, hyb, p2)]]) + np.array([t['ABAB'] for t in self.breps[(p1, hyb, p2)]])))

Expand Down
12 changes: 9 additions & 3 deletions phyde/core/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ class HydeResult:
"""
def __init__(self, infile):
"""
Constructor.
"""
self.infile = infile
self.res = {}
self.triples = []
self._read_hyde_results(infile)

def __call__(self, attr, p1, hyb, p2):
"""
Callable method for accessing information in a HydeResult object.
"""
return self.res[(p1, hyb, p2)][attr]

def _read_hyde_results(self, file):
"""
Fxn for reading in results file from a hyde_cpp analysis.
"""
with open(file) as f:
results = f.read().splitlines()[1:-1]
Expand All @@ -40,7 +43,7 @@ def _read_hyde_results(self, file):

def _hyde_info(self, b):
"""
Store information for HyDe hypothesis test.
"""
if len(b) != 18:
raise ValueError("** Warning: length of hyde entry is incorrect. **")
Expand Down Expand Up @@ -69,5 +72,8 @@ def _hyde_info(self, b):
return hyde_info

def abba_baba(self, p1, hyb, p2):
"""
Calculate Patterson's D-Statistic for the triple (p1, hyb, p2).
"""
return ((np.array(self.res[(p1,hyb,p2)]['ABBA']) - np.array(self.res[(p1,hyb,p2)]['ABAB'])) /
(np.array(self.res[(p1,hyb,p2)]['ABBA']) + np.array(self.res[(p1,hyb,p2)]['ABAB'])))
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,23 @@
print(" Please see the documentation at http://hybridization-detection.rtfd.io/.\n")
sys.exit()
else:
setup(name="phyde",
version="0.1.1",
setup(
name="phyde",
version="0.2.0",
description="Hybridization detection using phylogenetic invariants",
long_description=open('README.rst').read(),
url="https://github.com/pblischak/HyDe",
author="Paul Blischak & Laura Kubatko",
author_email="[email protected]",
license="GPL",
packages=find_packages(),
ext_modules=cythonize("phyde/**/*.pyx", compiler_directives={'--cplus': True}),
include_dirs=[numpy.get_include()],
scripts=['scripts/run_hyde.py', 'src/hyde_cpp'],
license="GPL",
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
],
zip_safe=False
)

0 comments on commit fe3762e

Please sign in to comment.