Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dendropy #103

Merged
merged 6 commits into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ addons:
- liblapack-dev
- libgfortran3
- libncurses5-dev
- r-base
- r-base-dev
- r-base-core
cache:
directories:
- "build"
Expand Down
5 changes: 1 addition & 4 deletions ariba/external_progs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Error (Exception): pass
'samtools': 'samtools',
'spades': 'spades.py',
'sspace': 'SSPACE_Basic_v2.0.pl',
'r': 'Rscript',
}


Expand All @@ -38,7 +37,6 @@ class Error (Exception): pass
'samtools': ('', re.compile('^Version: ([0-9\.]+)')),
'spades': ('', re.compile('^SPAdes genome assembler v\.?([0-9\.]+)')),
'sspace': ('', re.compile('^Usage: .*pl \[SSPACE_(.*)\]')),
'r': ('--version', re.compile('^R .*version ([0-9\.]+)')),
}


Expand All @@ -47,11 +45,10 @@ class Error (Exception): pass
'bowtie2': '2.1.0',
'cdhit': '4.6',
'cdhit2d': '4.6',
'mash': '1.1',
'mash': '1.0.2',
'nucmer': '3.1',
'samtools': '1.2',
'spades': '3.5.0',
'r': '2.14.0'
}


Expand Down
22 changes: 8 additions & 14 deletions ariba/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import openpyxl
import pyfastaq
import dendropy
from ariba import flag, common, report, summary_cluster, summary_sample

class Error (Exception): pass
Expand Down Expand Up @@ -328,26 +329,19 @@ def _write_distance_matrix(cls, lines, outfile):
scores[j][i] = scores[i][j]

with open(outfile, 'w') as f:
sample_names = [x[0] for x in lines]
sample_names = [''] + [x[0] for x in lines]
print(*sample_names, sep='\t', file=f)
for i in range(len(scores)):
print(lines[i][0], *scores[i][1:], sep='\t', file=f)
print(lines[i][0], *scores[i], sep='\t', file=f)


@classmethod
def _newick_from_dist_matrix(cls, distance_file, outfile):
r_script = outfile + '.tmp.R'

with open(r_script, 'w') as f:
print('library(ape)', file=f)
print('a=read.table("', distance_file, '", header=TRUE, row.names=1, comment.char="")', sep='', file=f)
print('h=hclust(dist(a))', file=f)
print('write.tree(as.phylo(h), file="', outfile, '")', sep='', file=f)

common.syscall('Rscript --no-save ' + r_script)
if os.path.exists(r_script + 'out'):
os.unlink(r_script + 'out')
os.unlink(r_script)
with open(distance_file) as f:
pdm = dendropy.PhylogeneticDistanceMatrix.from_csv(src=f, delimiter='\t')
upgma_tree = pdm.upgma_tree()
with open(outfile, 'w') as f:
print(upgma_tree.as_string("newick"), end='', file=f)


def run(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file1 file2 file3
file1 3 2
file2 0 1
file3 1 0
file1 file2 file3
file1 0 3 2
file2 3 0 1
file3 2 1 0
1 change: 0 additions & 1 deletion ariba/tests/data/summary_test_newick_from_dist_matrix.tre

This file was deleted.

8 changes: 4 additions & 4 deletions ariba/tests/data/summary_test_write_distance_matrix.distances
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file1 file2 file3
file1 3 2
file2 0 1
file3 1 0
file1 file2 file3
file1 0 3 2
file2 3 0 1
file3 2 1 0
5 changes: 3 additions & 2 deletions ariba/tests/summary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ def test_newick_from_dist_matrix(self):
tmp_tree = 'tmp.test.newick_from_dist_matrix.tre'
dist_file = os.path.join(data_dir, 'summary_test_newick_from_dist_matrix.distances')
summary.Summary._newick_from_dist_matrix(dist_file, tmp_tree)
expected = os.path.join(data_dir, 'summary_test_newick_from_dist_matrix.tre')
self.assertTrue(filecmp.cmp(expected, tmp_tree, shallow=False))
# the exact ordering of the nodes is not predictable, so we'll trust dendropy
# and just check that an output file got written
self.assertTrue(os.path.exists(tmp_tree))
os.unlink(tmp_tree)

7 changes: 0 additions & 7 deletions install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,3 @@ update_path ${mummer_dir}
update_path ${samtools_dir}
update_path ${spades_dir}


# -------------- R packages ---------------
mkdir -p ~/R/libs
echo "R_LIBS=~/R/libs" > ~/.Renviron
wget https://cran.r-project.org/src/contrib/Archive/ape/ape_3.1.tar.gz
R CMD INSTALL ape_3.1.tar.gz

1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
test_suite='nose.collector',
tests_require=['nose >= 1.3'],
install_requires=[
'dendropy >= 4.1.0',
'openpyxl >= 1.6.2',
'pyfastaq >= 3.12.0',
'pysam >= 0.8.1',
Expand Down