Skip to content

Commit

Permalink
ete3 and python3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajie.zhang committed Apr 4, 2019
1 parent 10d7e14 commit 05f3487
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions bin/bPTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import argparse
import os

from ete2 import Tree
from ete3 import Tree
from nexus import NexusReader
from summary import partitionparser
from ptp.ptpllh import lh_ratio_test, exp_distribution, species_setting, exponential_mixture
Expand Down Expand Up @@ -180,7 +180,7 @@ def __init__(self, filename, ftype="nexus", reroot=False, method="H1", seed=1234

self.taxa_order = taxa_order
if len(self.taxa_order) == 0:
self.taxa_order = Tree(self.trees[0]).get_leaf_names()
self.taxa_order = Tree(self.trees[0], format=1).get_leaf_names()
self.numtaxa = len(self.taxa_order)
self.numtrees = len(self.trees)
self.reroot = reroot
Expand Down Expand Up @@ -211,7 +211,7 @@ def remove_outgroups(self, ognames, remove = False, output = ""):
with open(output, "w") as fout:
for t in self.trees:
fout.write(t + "\n")
except ValueError, e:
except ValueError as e:
print(e)
print("")
print("")
Expand Down
5 changes: 4 additions & 1 deletion bin/summary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env python
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import sys
import argparse
Expand Down Expand Up @@ -242,7 +244,8 @@ def summary(self, fout = "", region = 1.0, bnmi = False, ML_par = None, ml_spe_s
pmap[par]= pmap.get(par, 0) + 1

"""Output partition summary"""
for key, value in sorted(pmap.iteritems(), reverse = True, key=lambda (k,v): (v,k)):
# kv: (-kv[1], kv[0])
for key, value in sorted(pmap.items(), reverse = True, key=lambda kv: (kv[1],kv[0])):
onespe = ""
for idx in key:
onespe = onespe + ", " + self.taxaorder[idx]
Expand Down
4 changes: 2 additions & 2 deletions nexus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
"""
__author__ = 'Simon Greenhill <simon@simon.net.nz>'

from reader import *
from writer import NexusWriter
from .reader import *
from .writer import NexusWriter

__version__ = "0.87"
PACKAGE_NAME = "python-nexus"
Expand Down
2 changes: 1 addition & 1 deletion nexus/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
;
END;
"""
from reader import NexusReader
from .reader import NexusReader

class NexusWriter:

Expand Down
13 changes: 7 additions & 6 deletions ptp/ptpllh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from scipy import stats

from ete2 import Tree, NodeStyle, TreeStyle, TextFace

from ete3 import Tree, NodeStyle, TreeStyle, TextFace
from ete3.treeview.main import _FaceAreas
#except ImportError:
#print("Please install the matplotlib and other dependent package first.")
#print("If your OS is ubuntu or has apt installed, you can try the following:")
Expand Down Expand Up @@ -212,7 +212,7 @@ def output_species(self, taxa_order = []):
print("#taxa_order != num_taxa!")
print(repr(num_taxa) + " " + repr(len(taxa_order)))
for sp in self.spe_list:
print sp
print(sp)
sys.exit()
return None, None
else:
Expand Down Expand Up @@ -650,11 +650,12 @@ def showTree(delimitation, scale = 500, render = False, fout = "", form = "svg",
style0["hz_line_type"] = 0
style0["size"] = 0

tree.clear_face()
#tree.clear_face()
for node in tree.get_descendants():
node.set_style(style0)
node.img_style["size"] = 0
node.clear_face()
node._faces = _FaceAreas()
#node.clear_face()

tree.set_style(style0)
tree.img_style["size"] = 0
Expand Down Expand Up @@ -692,7 +693,7 @@ def showTree(delimitation, scale = 500, render = False, fout = "", form = "svg",
node.add_face(TextFace("0", fsize = 8), column=0, position = "branch-top")
else:
node.add_face(TextFace("{0:.2f}".format(node.bs), fsize = 8), column=0, position = "branch-top")

ts = TreeStyle()
"""scale pixels per branch length unit"""
ts.scale = scale
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pytest
matplotlib
lxml
MySQL-python
PyQt5

0 comments on commit 05f3487

Please sign in to comment.