[med-svn] [Git][med-team/graphlan][master] 7 commits: New upstream version 1.1.3
Andreas Tille
gitlab at salsa.debian.org
Wed Sep 26 13:12:43 BST 2018
Andreas Tille pushed to branch master at Debian Med / graphlan
Commits:
44895364 by Andreas Tille at 2018-09-26T11:35:01Z
New upstream version 1.1.3
- - - - -
acbfc839 by Andreas Tille at 2018-09-26T11:35:27Z
Update upstream source from tag 'upstream/1.1.3'
Update to upstream version '1.1.3'
with Debian dir 01a232141bbd9e03b83ce4a03757be53b9f08a6d
- - - - -
70db3e12 by Andreas Tille at 2018-09-26T11:35:27Z
New upstream version
- - - - -
e629be31 by Andreas Tille at 2018-09-26T11:35:27Z
debhelper 11
- - - - -
de48d5d6 by Andreas Tille at 2018-09-26T11:35:32Z
Point Vcs fields to salsa.debian.org
- - - - -
42e4c864 by Andreas Tille at 2018-09-26T11:35:32Z
Standards-Version: 4.2.1
- - - - -
ed2e94fe by Andreas Tille at 2018-09-26T11:46:26Z
Upload to unstable
- - - - -
13 changed files:
- .hg_archival.txt
- .hgignore
- .hgsubstate
- .hgtags
- debian/changelog
- debian/compat
- debian/control
- examples/guide/annot_3.txt
- examples/metaref_fams/mr1.a.txt
- graphlan.py
- graphlan_annotate.py
- src/graphlan_lib.py
- src/pyphlan.py
Changes:
=====================================
.hg_archival.txt
=====================================
@@ -1,4 +1,4 @@
repo: 0fdb21ec3cf53e710d679fbd7768f91510570ae7
-node: edea23ce7c21765cbd9ff601e1f91614241eae81
+node: c1fa530b9bcac13bbccacf8bfafd500536d17b7c
branch: default
-tag: 1.1
+tag: 1.1.3
=====================================
.hgignore
=====================================
@@ -3,4 +3,10 @@ syntax: glob
*.pyc
*.DS_Store
*.log
+examples/ade_pcopri
+examples/neisseriaceae/
+examples/caritro_fig6/
+examples/andrew_crc_cutc/
+examples/nic_erectale/
+examples/rand/
examples/test/
=====================================
.hgsubstate
=====================================
@@ -1,2 +1,2 @@
-b2e0ba66718673ea28cb217c8e5dcd8e578fd033 export2graphlan
+c168a100f37e23e2c110849a8d91fac8da49f5bd export2graphlan
eae40ebc0030c7179baed999c74de412ba696598 pyphlan
=====================================
.hgtags
=====================================
@@ -5,3 +5,6 @@ ba9c6f680022333b5b1bf0652748ab2db29e888a 0.9
eaa3d2e05d74912da0f013bbfbb199764b180f05 0.9.5
64570f7d4ae33f46ddd360101c13555396a0cab1 0.9.6
7d483b7d34ccadb30f5c56f82b7aab19a820d1d6 1.0
+edea23ce7c21765cbd9ff601e1f91614241eae81 1.1
+17f32c8d85849d397884564680c145e5b8d28923 1.1.1
+3820c323e3c68d3d9e02bae2aefbc7d179df80bf 1.1.2
=====================================
debian/changelog
=====================================
@@ -1,3 +1,12 @@
+graphlan (1.1.3-1) unstable; urgency=medium
+
+ * New upstream version
+ * debhelper 11
+ * Point Vcs fields to salsa.debian.org
+ * Standards-Version: 4.2.1
+
+ -- Andreas Tille <tille at debian.org> Wed, 26 Sep 2018 13:35:33 +0200
+
graphlan (1.1-3) unstable; urgency=medium
* Moved packaging from SVN to Git
=====================================
debian/compat
=====================================
@@ -1 +1 @@
-10
+11
=====================================
debian/control
=====================================
@@ -3,12 +3,12 @@ Maintainer: Debian Med Packaging Team <debian-med-packaging at lists.alioth.debian.
Uploaders: Andreas Tille <tille at debian.org>
Section: science
Priority: optional
-Build-Depends: debhelper (>= 10),
+Build-Depends: debhelper (>= 11~),
python-all,
dh-python
-Standards-Version: 4.1.1
-Vcs-Browser: https://anonscm.debian.org/cgit/debian-med/graphlan.git
-Vcs-Git: https://anonscm.debian.org/git/debian-med/graphlan.git
+Standards-Version: 4.2.1
+Vcs-Browser: https://salsa.debian.org/med-team/graphlan
+Vcs-Git: https://salsa.debian.org/med-team/graphlan.git
Homepage: https://bitbucket.org/nsegata/graphlan/wiki/Home
Package: graphlan
=====================================
examples/guide/annot_3.txt
=====================================
@@ -418,7 +418,7 @@ Staphylococcaceae.Staphylococcus.Swarneri ring_height 5 2.39465498028
Bacillaceae.Bacillus.Bsubtilis clade_marker_label 65
Staphylococcaceae.Staphylococcus.Saureus clade_marker_label 17
-Bacillaceae.Bacillus.Banthracis clade_marker_label x
+Bacillaceae.Bacillus.Banthracis clade_marker_label x
Bacillaceae.Bacillus.Banthracis clade_marker_font_color w
Bacillaceae.Bacillus.Banthracis clade_marker_edge_color b
Bacillaceae.Lysinibacillus.Lfusiformis clade_marker_label 156
=====================================
examples/metaref_fams/mr1.a.txt
=====================================
@@ -15,9 +15,9 @@ c2 clade_marker_color #0000FF
c2 clade_marker_size 35
c3 clade_marker_color #00FF00
c3 clade_marker_size 35
-#class2 annotation_background_color #0000FF
+#class2 annotation_background_color #0000FF
#class2 class_label Clades in which X is a core gene
-clade_marker_size 10
+clade_marker_size 10
branch_thickness 0.5
Bacill.Bacillale class c3
Bacill.Bacillale.Staphylococcaceae.Gemella class c1
@@ -48,7 +48,7 @@ Clostridia.Thermoanaerobacterales.Thermoanaerobacteraceae.Thermoanaerobacterium
#Bacill.Bacillale class class2
Bacill.Bacillale annotation Y
Bacill.Bacillale.Staphylococcaceae annotation Y1
-Bacill.Bacillale.Thermoactinomycetaceae annotation Y2
+Bacill.Bacillale.Thermoactinomycetaceae annotation Y2
Bacill.Bacillale.unclassified annotation Y3
Bacilli.Lactobacillales.Aerococcaceae class c2
Bacilli.Lactobacillales.Aerococcaceae.Aerococcus class c2
@@ -69,8 +69,6 @@ Bacill.Bacillale.Thermoactinomycetaceae.unclassified ring_shape 1 v
Bacilli.Lactobacillales.Aerococcaceae.Eremococcus ring_shape 1 v
Bacilli.Lactobacillales.Carnobacteriaceae.Carnobacterium ring_shape 1 v
Bacilli.Lactobacillales.Carnobacteriaceae.Desemzia ring_shape 1 v
-Bacilli.Lactobacillales.Lactobacillaceae.Lactobacillus ring_shape 1 v
-Bacilli.Lactobacillales.Lactobacillaceae.Pediococcus ring_shape 1 v
Clostridia.Clostridiales.Incertae_Sedis_XI.Finegoldia ring_shape 1 v
Clostridia.Clostridiales.Incertae_Sedis_XI.Gallicola ring_shape 1 v
Clostridia.Clostridiales.Incertae_Sedis_XI.Helcococcus ring_shape 1 v
@@ -78,7 +76,7 @@ Clostridia.Clostridiales.Incertae_Sedis_XI.Peptoniphilus ring_shape 1 v
Clostridi.Clostridiales.Ruminococcaceae.Papillibacter ring_shape 1 v
Clostridi.Clostridiale.Veillonellaceae.Selenomonas ring_shape 1 v
Clostridia.Thermoanaerobacterales.Thermoanaerobacteraceae.Thermoanaerobacterium ring_shape 1 v
-Bacilli.Lactobacillales.Aerococcaceae.Aerococcus ring_shape 1 v
+Bacilli.Lactobacillales.Aerococcaceae.Aerococcus ring_shape 1 v
Bacilli.Lactobacillales.Aerococcaceae.Eremococcus ring_shape 1 v
Bacilli.Lactobacillales.Aerococcaceae.unclassified ring_shape 1 v
Bacilli.Lactobacillales.Aerococcaceae.Abiotrophia ring_shape 1 v
@@ -96,8 +94,6 @@ Bacill.Bacillale.Thermoactinomycetaceae.unclassified ring_width 1 0.6
Bacilli.Lactobacillales.Aerococcaceae.Eremococcus ring_width 1 0.6
Bacilli.Lactobacillales.Carnobacteriaceae.Carnobacterium ring_width 1 0.6
Bacilli.Lactobacillales.Carnobacteriaceae.Desemzia ring_width 1 0.6
-Bacilli.Lactobacillales.Lactobacillaceae.Lactobacillus ring_width 1 0.6
-Bacilli.Lactobacillales.Lactobacillaceae.Pediococcus ring_width 1 0.6
Clostridia.Clostridiales.Incertae_Sedis_XI.Finegoldia ring_width 1 0.6
Clostridia.Clostridiales.Incertae_Sedis_XI.Gallicola ring_width 1 0.6
Clostridia.Clostridiales.Incertae_Sedis_XI.Helcococcus ring_width 1 0.6
@@ -105,7 +101,7 @@ Clostridia.Clostridiales.Incertae_Sedis_XI.Peptoniphilus ring_width 1 0.6
Clostridi.Clostridiales.Ruminococcaceae.Papillibacter ring_width 1 0.6
Clostridi.Clostridiale.Veillonellaceae.Selenomonas ring_width 1 0.6
Clostridia.Thermoanaerobacterales.Thermoanaerobacteraceae.Thermoanaerobacterium ring_width 1 0.6
-Bacilli.Lactobacillales.Aerococcaceae.Aerococcus ring_width 1 0.6
+Bacilli.Lactobacillales.Aerococcaceae.Aerococcus ring_width 1 0.6
Bacilli.Lactobacillales.Aerococcaceae.Eremococcus ring_width 1 0.6
Bacilli.Lactobacillales.Aerococcaceae.unclassified ring_width 1 0.6
Bacilli.Lactobacillales.Aerococcaceae.Abiotrophia ring_width 1 0.6
@@ -123,8 +119,6 @@ Bacill.Bacillale.Thermoactinomycetaceae.unclassified ring_height 1 0.6
Bacilli.Lactobacillales.Aerococcaceae.Eremococcus ring_height 1 0.6
Bacilli.Lactobacillales.Carnobacteriaceae.Carnobacterium ring_height 1 0.6
Bacilli.Lactobacillales.Carnobacteriaceae.Desemzia ring_height 1 0.6
-Bacilli.Lactobacillales.Lactobacillaceae.Lactobacillus ring_height 1 0.6
-Bacilli.Lactobacillales.Lactobacillaceae.Pediococcus ring_height 1 0.6
Clostridia.Clostridiales.Incertae_Sedis_XI.Finegoldia ring_height 1 0.6
Clostridia.Clostridiales.Incertae_Sedis_XI.Gallicola ring_height 1 0.6
Clostridia.Clostridiales.Incertae_Sedis_XI.Helcococcus ring_height 1 0.6
=====================================
graphlan.py
=====================================
@@ -2,9 +2,9 @@
#------------------------------------------------------------------------------
# NAME: graphlan.py
-# DESCRIPTION: GraPhlAn is a python program for creating images of circular
-# cladogram starting from a tree given in PhyloXML format. The
-# PhyloXML input tree can be formatted and annotated using the
+# DESCRIPTION: GraPhlAn is a python program for creating images of circular
+# cladogram starting from a tree given in PhyloXML format. The
+# PhyloXML input tree can be formatted and annotated using the
# graphlan_annotate.py script.
#
# Author: Nicola Segata
@@ -14,10 +14,16 @@
#------------------------------------------------------------------------------
__author__ = 'Nicola Segata (nsegata at hsph.harvard.edu)'
-__version__ = '0.9.7'
-__date__ = '21 July 2014'
+__version__ = '1.1.3'
+__date__ = '5 June 2018'
+import sys
+
+if sys.version_info[0] > 2:
+ raise Exception("GraPhlAn requires Python 2, your current Python version is {}.{}.{}"
+ .format(sys.version_info[0], sys.version_info[1], sys.version_info[2]))
+
from sys import argv
from argparse import ArgumentParser
from src.graphlan_lib import CircTree as CTree
@@ -34,7 +40,7 @@ def read_params(args):
help = "the output image, the format is guessed from the extension "
"unless --format is given. Available file formats are: png, "
"pdf, ps, eps, svg" )
- arg('--format', choices=['png','pdf','ps','eps','svg'], default=None,
+ arg('--format', choices=['png','pdf','ps','eps','svg'], default=None,
type = str, metavar=['output_image_format'],
help = "set the format of the output image (default none meaning that "
"the format is guessed from the output file extension)")
@@ -53,7 +59,9 @@ def read_params(args):
arg('--external_legends', default=False, action='store_true',
help = "specify whether the two external legends should be put in separate file or keep them "
"along with the image (default behavior)")
- arg( '-v','--version', action='version', version="GraPhlAn version "+__version__+" ("+__date__+")",
+ arg('--avoid_reordering', default=True, action='store_false',
+ help = "specify whether the tree will be reorder or not (default the tree will be reordered)")
+ arg( '-v','--version', action='version', version="GraPhlAn version "+__version__+" ("+__date__+")",
help="Prints the current GraPhlAn version and exit" )
return vars(parser.parse_args())
@@ -62,9 +70,10 @@ if __name__ == "__main__":
args = read_params( argv )
ctree = CTree( args['intree'], args['warnings'] )
ctree.positions = args['positions']
- ctree.draw( args['outimg'],
- out_format = args['format'],
- out_dpi = args['dpi'],
- out_size = args['size'],
- out_pad = args['pad'],
- external_legends = args['external_legends'])
+ ctree.draw(args['outimg'],
+ out_format=args['format'],
+ out_dpi=args['dpi'],
+ out_size=args['size'],
+ out_pad=args['pad'],
+ external_legends=args['external_legends'],
+ reorder_tree=args['avoid_reordering'])
=====================================
graphlan_annotate.py
=====================================
@@ -11,10 +11,16 @@
#------------------------------------------------------------------------------
__author__ = 'Nicola Segata (nsegata at hsph.harvard.edu)'
-__version__ = '0.9'
-__date__ = '22 August 2012'
+__version__ = '1.1.3'
+__date__ = '5 June 2018'
+import sys
+
+if sys.version_info[0] > 2:
+ raise Exception("GraPhlAn requires Python 2, your current Python version is {}.{}.{}"
+ .format(sys.version_info[0], sys.version_info[1], sys.version_info[2]))
+
from sys import argv
from argparse import ArgumentParser
from src.graphlan_lib import CircTree as CTree
=====================================
src/graphlan_lib.py
=====================================
@@ -1,3 +1,9 @@
+import sys
+
+if sys.version_info[0] > 2:
+ raise Exception("GraPhlAn requires Python 2, your current Python version is {}.{}.{}"
+ .format(sys.version_info[0], sys.version_info[1], sys.version_info[2]))
+
from Bio import Phylo
from Bio.Phylo import PhyloXML
from Bio.Phylo import PhyloXMLIO
@@ -17,87 +23,79 @@ import matplotlib.patches as mpatches
import matplotlib.lines as lines
import matplotlib
matplotlib.use('Agg')
+matplotlib.rcParams['svg.fonttype'] = 'none'
from pylab import *
from pyphlan import PpaTree
-clade_attr = ( ( 'clade_marker_size', float, 20.0 ),
- ( 'clade_marker_color', str, '#FFFFFF' ),
- ( 'clade_marker_edge_width', float, 0.5 ),
- ( 'clade_marker_shape', str, 'o' ),
- ( 'clade_marker_edge_color', str, '#000000' ),
- ( 'clade_marker_label', str, '' ),
- ( 'clade_marker_font_size', str, '7' ),
- ( 'clade_marker_font_color', str, 'k' ),
- ( 'class_label', str, "" ), # to rem
- ( 'annotation_font_size', int, 7 ),
- ( 'annotation_font_stretch', int, 0 ),
- ( 'annotation_background_color', str, '#FF0000' ),
- ( 'annotation_background_edge_color',str, '#FF0000' ), # not implemented yet
- ( 'annotation', str, '' ),
- ( 'annotation_rotation', int, 0 ),
- )
+clade_attr = ( ( 'clade_marker_size', float, 20.0 ),
+ ( 'clade_marker_color', str, '#FFFFFF' ),
+ ( 'clade_marker_edge_width', float, 0.5 ),
+ ( 'clade_marker_shape', str, 'o' ),
+ ( 'clade_marker_edge_color', str, '#000000' ),
+ ( 'clade_marker_label', str, '' ),
+ ( 'clade_marker_font_size', str, '7' ),
+ ( 'clade_marker_font_color', str, 'k' ),
+ ( 'class_label', str, "" ), # to rem
+ ( 'annotation_font_size', int, 7 ),
+ ( 'annotation_font_stretch', int, 0 ),
+ ( 'annotation_background_color', str, '#FF0000' ),
+ ( 'annotation_background_edge_color', str, '#FF0000' ), # not implemented yet
+ ( 'annotation', str, '' ),
+ ( 'annotation_rotation', int, 0 ) )
clade_attr_d = dict([(p,(t,d)) for p,t,d in clade_attr])
-ext_attr = ( ( 'ring_color', str, '#000000' ),
- ( 'ring_width', float, 1.0 ),
- ( 'ring_height', float, -1.0 ),
- ( 'ring_alpha', float, 1.0 ),
- ( 'ring_shape', str, "R" ),
- ( 'ring_label', str, None ),
- ( 'ring_label_font_size', int, 11 ),
- ( 'ring_label_color', str, 'k' ),
- ( 'ring_edge_width', float, 0.1 ),
- ( 'ring_edge_color', str, None ),
- ( 'ring_internal_separator_thickness', float, 0.0 ),
- ( 'ring_separator_color', str, 'k' ),
- ( 'ring_external_separator_thickness', float, 0.0 ),
- )
+ext_attr = ( ( 'ring_color', str, '#000000' ),
+ ( 'ring_width', float, 1.0 ),
+ ( 'ring_height', float, -1.0 ),
+ ( 'ring_alpha', float, 1.0 ),
+ ( 'ring_shape', str, "R" ),
+ ( 'ring_label', str, None ),
+ ( 'ring_label_font_size', int, 11 ),
+ ( 'ring_label_color', str, 'k' ),
+ ( 'ring_edge_width', float, 0.1 ),
+ ( 'ring_edge_color', str, None ),
+ ( 'ring_internal_separator_thickness', float, 0.0 ),
+ ( 'ring_separator_color', str, 'k' ),
+ ( 'ring_external_separator_thickness', float, 0.0 ) )
ext_attr_d = dict([(p,(t,d)) for p,t,d in ext_attr])
-int_attr = (
- ( 'internal_label', str, None ),
- ( 'internal_label_font_size', int, 8 ),
- )
+int_attr = ( ( 'internal_label', str, None ),
+ ( 'internal_label_font_size', int, 8 ) )
int_attr_d = dict([(p,(t,d)) for p,t,d in int_attr])
-structural_attr = ( ( 'ignore_branch_len', int, 0 ),
- ( 'total_plotted_degrees', float, 360.0 ),
- ( 'start_rotation', float, 180.0 ),
- ( 'clade_separation', float, 0.0 ),
- ( 'branch_bracket_width', float, 0.25 ),
- ( 'branch_bracket_depth', float, 1.0 ),
- )
-
-global_graphical_attr = ( ( 'annotation_background_width', float, 0.1 ),
- ( 'annotation_background_alpha', float, 0.2 ),
- ( 'annotation_background_separation', float, 0.02 ),
- ( 'annotation_background_offset', float, 0.02 ),
- ( 'class_legend_font_size', int, 7 ),
- ( 'title', str, "" ),
- ( 'title_font_size', int, 15 ),
- ( 'class_legend_marker_size', float, 1.0 ),
- ( 'annotation_legend_font_size', int, 7 ),
- ( 'internal_labels_rotation', float, None ),
- )
-
-branch_attr = ( ( 'branch_thickness', float, 0.75 ),
- ( 'branch_color', str, '#000000' ),
- ( 'branch_color_from_ancestor', int, 1 ),
- )
-
+structural_attr = ( ( 'ignore_branch_len', int, 0 ),
+ ( 'total_plotted_degrees', float, 360.0 ),
+ ( 'start_rotation', float, 180.0 ),
+ ( 'clade_separation', float, 0.0 ),
+ ( 'branch_bracket_width', float, 0.25 ),
+ ( 'branch_bracket_depth', float, 1.0 ) )
+
+global_graphical_attr = ( ( 'annotation_background_width', float, 0.1 ),
+ ( 'annotation_background_alpha', float, 0.2 ),
+ ( 'annotation_background_separation', float, 0.02 ),
+ ( 'annotation_background_offset', float, 0.02 ),
+ ( 'class_legend_font_size', int, 7 ),
+ ( 'title', str, "" ),
+ ( 'title_font_size', int, 15 ),
+ ( 'class_legend_marker_size', float, 1.0 ),
+ ( 'annotation_legend_font_size', int, 7 ),
+ ( 'internal_labels_rotation', float, None ) )
+
+branch_attr = ( ( 'branch_thickness', float, 0.75 ),
+ ( 'branch_color', str, '#000000' ),
+ ( 'branch_color_from_ancestor', int, 1 ) )
leg_sep = '_._._'
-leg_attr = ( ( 'annotation_background_color', str, "w" ),
- ( 'annotation_background_edge_color', str, "k" ),
- ( 'clade_marker_color', str, "w" ),
- ( 'clade_marker_edge_width', float, 0.5 ),
- ( 'clade_marker_size', float, 20.0 ),
- ( 'keys', str, "?" ),
- )
+leg_attr = ( ( 'annotation_background_color', str, "w" ),
+ ( 'annotation_background_edge_color', str, "k" ),
+ ( 'clade_marker_color', str, "w" ),
+ ( 'clade_marker_edge_width', float, 0.5 ),
+ ( 'clade_marker_size', float, 20.0 ),
+ ( 'clade_marker_shape', str, 'o' ),
+ ( 'keys', str, "?" ) )
lev_sep = '.'
-
legal_options = set(zip(*clade_attr+ext_attr+int_attr+structural_attr+global_graphical_attr+branch_attr+leg_attr)[0]) | set(['class'])
def random_keys(used_keys):
@@ -115,8 +113,8 @@ class CircTree(PpaTree):
def annotate( self, inp_file, out_file = None,
c = None, p = None, v = None ):
- term_names = set([t.name for t in self.tree.get_terminals()])
- nterm_names = set([t.name for t in self.tree.get_nonterminals()])
+ term_names = set([t.name for t in self.tree.get_terminals() if t.name])
+ nterm_names = set([t.name for t in self.tree.get_nonterminals() if t.name])
clade_names = term_names | nterm_names
props, gprops, classes = ddict(dict), {}, ddict(dict)
@@ -147,8 +145,14 @@ class CircTree(PpaTree):
self._tmp_levs = set()
for line in (l.strip().split('\t') for l in lines if l[0] != '#'):
+ if not ''.join(line): # skip empty lines
+ continue
ll = len(line)
- if ll == 2:
+ if (ll < 2) or (ll > 4):
+ sys.stderr.write('Unrecognized annotation "{}", maybe spaces '
+ 'instead of tabs?\n'.format(line))
+ exit(1)
+ elif ll == 2:
legal( line[0] ) # in legal_options, "%s is not a valid option" % line[1]
gprops[line[0]] = line[1]
elif ll == 3:
@@ -159,7 +163,12 @@ class CircTree(PpaTree):
elif clade in ext_attr_d:
prop,lev = clade,prop
legal( prop )
- ilev = int(lev)
+ try:
+ ilev = int(lev)
+ except:
+ print(line)
+ asdasdasd
+
if prop not in gprops:
gprops[prop] = {}
if ilev not in gprops[prop]:
@@ -203,9 +212,21 @@ class CircTree(PpaTree):
else:
gprops[prop] = {ilev:val}
elif clade.split(lev_sep)[-1] in clade_names:
- ilev = int(lev)
+ try:
+ ilev = int(lev)
+ except:
+ print(line)
+ asdasdasd
+
self._tmp_levs.add( ilev )
if prop in props[clade]:
+ # print "clade", clade
+ # print "prop", prop
+ # print "props[clade]", props[clade]
+ # print "val", val
+ # print "ilev", ilev
+ # print
+
props[clade][prop][ilev] = val
else:
props[clade][prop] = {ilev:val}
@@ -214,12 +235,11 @@ class CircTree(PpaTree):
if ilev not in gprops[prop]:
gprops[prop][ilev] = ext_attr_d[prop][1]
else:
- print ll
- print clade.split(lev_sep)[-1]
- print clade_names
- print line
- sys.stderr.write( "Classes not implemented for external "
- "annotations\n" )
+ # print ll
+ # print clade.split(lev_sep)[-1]
+ # print clade_names
+ # print line
+ sys.stderr.write( "Classes not implemented for external annotations\n" )
exit(1)
@@ -249,7 +269,13 @@ class CircTree(PpaTree):
value = v
if k == 'annotation':
if v.count(":"):
- kkk,vvv = v.split(":")
+
+ try:
+ kkk,vvv = v.split(":")
+ except:
+ print(v)
+ asdasdasd
+
if kkk == '*':
if fn is None:
kkk = rkeys_gen.next()
@@ -258,7 +284,7 @@ class CircTree(PpaTree):
fn = kkk
if vvv == '*':
vvv = clade.name
- value = kkk + ":" + vvv
+ value = kkk + ": " + vvv
elif v == '*':
value = clade.name
cp.append( Prop( value=value, ref='A:1', id_ref=k,
@@ -333,6 +359,8 @@ class CircTree(PpaTree):
# visual separation between subtrees.
# This is executed if the user sets clade_separatio > 0.0
self._ord_leaves = []
+
+
def compute_tot_add( clade ):
if clade.is_terminal():
self._ord_leaves.append( clade )
@@ -349,8 +377,8 @@ class CircTree(PpaTree):
last = t
coffset = self.start_rotation + (rpi2 - self.total_plotted_degrees) * 0.5
- circ_step = self.total_plotted_degrees*(1.0-self.clade_separation) / self._n_terminals
- self.circ_pos = coffset+circ_step/2
+ circ_step = self.total_plotted_degrees * (1.0 - self.clade_separation) / self._n_terminals
+ self.circ_pos = coffset - circ_step
self._last_leaf = self.tree.root
self._varf = circ_step
@@ -359,6 +387,7 @@ class CircTree(PpaTree):
self._ext_levs = set()
#self._ext_max_height = {}
+
def set_clade_data_rec( clade ):
if self.ignore_branch_len:
clade.branch_length = 1.0
@@ -464,6 +493,7 @@ class CircTree(PpaTree):
self._ext_levs[l] = default
self._all_ext_attr = [v[0] for v in ext_attr]
+
def rec_set_exts( clade ):
if hasattr( clade, "ext" ):
ext = clade.ext
@@ -570,7 +600,6 @@ class CircTree(PpaTree):
gprops = dict([(p.id_ref,p.value)
for p in self.tree.properties if not p.id_ref.startswith("ext__") ])
-
eggrops = [( int(p.id_ref.split('__')[1]),p.id_ref.split('__')[2], p.value)
for p in self.tree.properties if p.id_ref.startswith("ext__")]
iggrops = [( float(p.id_ref.split('__')[1]),p.id_ref.split('__')[2], p.value)
@@ -622,7 +651,6 @@ class CircTree(PpaTree):
if attr == 'ring_height':
self._ext_max_height[int(lev)] = float(val) if float(val) >= 0.0 else 0.0
-
self._n_terminals = self.tree.count_terminals()
# with few leaves, the total rotation is lowered (unless the user set it)
if self._n_terminals < 16 and 'total_plotted_degrees' not in gprops:
@@ -630,6 +658,7 @@ class CircTree(PpaTree):
self.total_plotted_degrees = self.total_plotted_degrees * rpi / 180.0
self.start_rotation = self.start_rotation * rpi / 180.0
+
def set_branches( self ):
def set_branches_rec( clade, fcol ):
if clade == self.tree.root:
@@ -674,82 +703,146 @@ class CircTree(PpaTree):
set_branches_rec( self.tree.root, self.branch_color )
+
def set_wings( self ):
if not self._wing_levs:
+ # print "not self._wing_levs", not self._wing_levs
+
self._wing_tot_offset = 1.0 # self._max_depth
self._tot_offset = 1.0
return
+
if self.ignore_branch_len:
+ # print "self.ignore_branch_len", self.ignore_branch_len
+
self._wing_levs.sort(reverse=True)
- nlevs = len( self._wing_levs )
- minl, maxl = min(self._wing_levs),max(self._wing_levs)
+ nlevs = len(self._wing_levs)
+ minl, maxl = min(self._wing_levs), max(self._wing_levs)
+
+ # print "nlevs", nlevs
+ # print "minl", minl
+ # print "maxl", maxl
+
lthetas = [l.theta for l in self.tree.get_terminals()]
rad_offset = self.annotation_background_separation
lev_width = self.annotation_background_width
+ # print "lthetas", lthetas
+ # print "rad_offset", rad_offset
+ # print "lev_width", lev_width
+
def set_wings_rec( clade ):
- if hasattr( clade, 'annotation') and not hasattr( clade, 'annotation_background_color'):
+ if hasattr(clade, 'annotation') and not hasattr(clade, 'annotation_background_color'):
if self.warnings:
- sys.stderr.write("Warning: label "
- "\""+clade.annotation+"\" has "
- "a default gray background because no color is found for "
- "the corresponding \"annotation\"\n")
- clade.annotation_background_color = [0.3,0.3,0.3]
- if hasattr( clade, 'annotation_background_color'):
+ sys.stderr.write('Warning: label "{}" has a default gray background because no color is found for the corresponding "annotation"\n'.format(clade.annotation))
+
+ clade.annotation_background_color = [0.3, 0.3, 0.3]
+
+ if hasattr(clade, 'annotation_background_color'):
if clade.is_terminal(): # same as non-terminal ??
+ # print "clade.theta", clade.theta
+ # print ''
+ # print "clade.pc", clade.pc
+ # print "clade.nc", clade.nc
+ # print ''
+ # print "clade.pc.theta", clade.pc.theta
+ # print "clade.nc.theta", clade.nc.theta
+
cpc = clade.theta + (clade.theta-clade.nc.theta) if clade.pc is None else clade.pc.theta
cnc = clade.theta - (clade.pc.theta-clade.theta) if clade.nc is None else clade.nc.theta
+
if cpc > clade.theta:
cpc -= rpi2
+
if cnc < clade.theta:
cnc += rpi2
- lsm = ( clade.theta + cpc ) * 0.5
- lgr = ( clade.theta + cnc ) * 0.5
+ lsm = (clade.theta + cpc) * 0.5
+ lgr = (clade.theta + cnc) * 0.5
else:
- f,t = clade.fc.theta, clade.fc.pc.theta if clade.fc.pc else clade.fc.nc.theta
- cpc = min(abs(f-t),abs(f+rpi2-t),abs(t+rpi2-f))
- f,t = clade.lc.theta, clade.lc.nc.theta if clade.lc.nc else clade.lc.pc.theta
- cnc = min(abs(f-t),abs(f+rpi2-t),abs(t+rpi2-f))
+ # print "clade.fc.pc", clade.fc.pc
+ # print "clade.lc.nc", clade.lc.nc
+ # print ''
+ # print "clade.fc.theta", clade.fc.theta
+ # print "clade.lc.theta", clade.lc.theta
+ # print ''
+ # print "clade.fc.pc.theta", clade.fc.pc.theta
+ # print "clade.fc.nc.theta", clade.fc.nc.theta
+ # print ''
+ # print "clade.lc.pc.theta", clade.lc.pc.theta
+ # print "clade.lc.nc.theta", clade.lc.nc.theta
+
+ f, t = clade.fc.theta, clade.fc.pc.theta if clade.fc.pc else clade.fc.nc.theta
+ cpc = min(abs(f-t), abs(f+rpi2-t), abs(t+rpi2-f))
+ f, t = clade.lc.theta, clade.lc.nc.theta if clade.lc.nc else clade.lc.pc.theta
+ cnc = min(abs(f-t), abs(f+rpi2-t), abs(t+rpi2-f))
lsm = clade.fc.theta - cpc * 0.5
lgr = clade.lc.theta + cnc * 0.5
- self._wing_thetas.append( lsm )
+ # print ''
+ # print "cpc", cpc
+ # print "cnc", cnc
+ # print "lsm", lsm
+ # print "lgr", lgr
+
+ self._wing_thetas.append(lsm)
+
if self.ignore_branch_len:
- rad = 1.0 + lev_width * ( 1 + self._wing_levs.index(int(self._depths[clade.name])) ) - clade.r
+ rad = 1.0 + lev_width * ( 1 + self._wing_levs.index(int(self._depths[clade.name])) ) - clade.r
else:
rad = (1.0 - clade.r) + lev_width
- self._wing_radii.append( rad + rad_offset )
- width = abs( lgr - lsm)
- self._wing_widths.append( width )
- self._wing_bottoms.append( clade.r )
- self._wing_colors.append( clade.annotation_background_color )
+
+ # print "rad", rad
+
+ self._wing_radii.append(rad + rad_offset)
+ width = abs(lgr - lsm)
+
+ # print "width", width
+
+ self._wing_widths.append(width)
+ self._wing_bottoms.append(clade.r)
+ self._wing_colors.append(clade.annotation_background_color)
+
if clade.r + rad + rad_offset > self._wing_tot_offset:
self._wing_tot_offset = clade.r + rad + rad_offset
self._tot_offset = self._wing_tot_offset
+ # print ''
+ # print "self._wing_tot_offset", self._wing_tot_offset
+ # print "self._tot_offset", self._tot_offset
+
if hasattr( clade, 'annotation') and clade.annotation:
lab, ext_key = clade.annotation, None
+
if lab.count(":"):
ext_key, lab = lab, lab.split(":")[0]
- self._label.append( lab )
+
+ self._label.append(lab)
+
if ext_key:
self._ext_key.append( ext_key )
+
avgtheta = (lgr + lsm)*0.5
self._label_theta.append( avgtheta )
- rot90 = hasattr( clade, 'annotation_rotation') and clade.annotation_rotation
+ rot90 = hasattr(clade, 'annotation_rotation') and clade.annotation_rotation
fract = 0.05 if rot90 else 0.5
+
if self.ignore_branch_len:
rad = 1.0 + lev_width * ( 1 + self._wing_levs.index(int(self._depths[clade.name])) ) - lev_width * fract
else:
rad = 1.0 + lev_width * fract
+ # print "rad", rad
+
self._label_r.append( rad + rad_offset )
rot = avgtheta * 180.0 / rpi + 90.0 if rpi < clade.theta%rpi2 < rpi2 else avgtheta * 180.0 / rpi - 90.0
rot = (rot + 360.0) % 360.0 + 1e-10
rot = -rot if rot90 else rot
+
+ # print "rot", rot
+
self._label_rot.append( rot )
lfs = clade.annotation_font_size if hasattr(clade,"annotation_font_size") else self.default_annotation_font_size
self._annotation_font_size.append( lfs )
@@ -761,6 +854,7 @@ class CircTree(PpaTree):
set_wings_rec( self.tree.root )
+
def disambiguate_names(self):
def disambiguate_names_rec( clade, cnames = set() ):
if not hasattr(clade,'name'):
@@ -771,34 +865,41 @@ class CircTree(PpaTree):
for c in clade.clades:
disambiguate_names_rec( c, cnames )
+
disambiguate_names_rec( self.tree.root )
def get_legend( self ):
ax1 = plt.subplot(111, visible=False)
+ keys = getattr(self, "leg_keys")
- keys = getattr( self, "leg_keys")
-
- clade_marker_color = getattr( self, "leg_clade_marker_color")
+ clade_marker_color = getattr(self, "leg_clade_marker_color")
if not clade_marker_color:
clade_marker_color = [self.default_clade_marker_color] * len(keys)
- clade_marker_size = getattr( self, "leg_clade_marker_size")
+
+ clade_marker_size = getattr(self, "leg_clade_marker_size")
if not clade_marker_size:
clade_marker_size = [self.default_clade_marker_size] * len(keys)
- clade_marker_edge_width = getattr( self, "leg_clade_marker_edge_width")
+
+ clade_marker_edge_width = getattr(self, "leg_clade_marker_edge_width")
if not clade_marker_edge_width:
clade_marker_edge_width = [self.default_clade_marker_edge_width] * len(keys)
+ clade_marker_shape = getattr(self, "leg_clade_marker_shape")
+ if not clade_marker_shape:
+ clade_marker_shape = [self.default_clade_marker_shape] * len(keys)
+
ll = []
- for s,c,lw in zip(clade_marker_size,clade_marker_color,clade_marker_edge_width):
- l = ax1.scatter( 0.0, 0.0, s = s, c = c,
- linewidths = lw )
+ for s,c,lw,m in zip(clade_marker_size, clade_marker_color, clade_marker_edge_width, clade_marker_shape):
+ l = ax1.scatter( 0.0, 0.0, s=s, c=c, linewidths=lw, marker=m )
ll.append(l)
+
ax1.set_xlim((0,1))
ax1.set_ylim((0,1))
return ll , keys, 'upper right'
+
def _init_attr( self ):
self._depths = dict([(c.name,dist) for c,dist in
self.tree.depths(self.ignore_branch_len).items()])
@@ -834,17 +935,13 @@ class CircTree(PpaTree):
self._ext_patches = []
self._ext_lines = []
- def draw( self, out_img, out_format = None, out_dpi = 72, out_size = 7.0, out_pad = 0.5, external_legends = False ):
- self.reorder_tree()
+ def draw(self, out_img, out_format=None, out_dpi=72, out_size=7.0, out_pad=0.5, external_legends=False, reorder_tree=True):
+ self.reorder_tree(reorder_tree)
#self.tree.ladderize()
-
self.load_set_attr()
-
self.disambiguate_names()
-
self._init_attr()
-
self.set_clade_data()
self.set_branches()
self.set_wings()
@@ -859,7 +956,6 @@ class CircTree(PpaTree):
xticks([])
yticks([])
-
if len(self._t) > 0 and len(self._r) > 0:
ax.scatter( self._t, self._r,
marker = self.default_clade_marker_shape,
@@ -889,19 +985,13 @@ class CircTree(PpaTree):
color=self._br_colors,
linewidth= self.branch_thickness )
-
if len( self._wing_thetas ) < 2:
self._wing_thetas.append(0)
self._wing_radii.append(0)
self._wing_widths.append(0)
self._wing_bottoms.append(0)
- wbar = ax.bar( self._wing_thetas, self._wing_radii,
- width = self._wing_widths,
- bottom = self._wing_bottoms,
- alpha = self.annotation_background_alpha,
- color = self._wing_colors,
- edgecolor = self._wing_colors,
- )
+
+ wbar = ax.bar(self._wing_thetas, self._wing_radii, width=self._wing_widths, bottom=self._wing_bottoms, alpha=self.annotation_background_alpha, color=self._wing_colors, edgecolor=self._wing_colors, align='edge')
for lev,d in self.int_levs.items():
if 'internal_label' in d:
@@ -970,6 +1060,10 @@ class CircTree(PpaTree):
for l,v in self.ext_levs.items():
for p in ['ring_internal_separator_thickness','ring_external_separator_thickness']:
if p in v and float(v[p]) > 0.0:
+ if l not in self._ext_bottoms.keys():
+ print('[e] External ring #'+str(l), 'defined, but not used. Please check your annotations file')
+ continue
+
bot = offset + self._ext_bottoms[l]
if p == 'ring_external_separator_thickness':
bot += self._ext_max_height[l]*0.1 if l in self._ext_max_height else 0.1
@@ -981,12 +1075,12 @@ class CircTree(PpaTree):
if 'ring_label' in v and v['ring_label']:
bot = offset + self._ext_bottoms[l]
bot1 = offset + ( self._ext_bottoms[l+1] if l+1 in self._ext_bottoms else self._ext_bottoms[l] +
- (self._ext_max_height[l]*0.1 if l in self._ext_max_height else 0.1) )
- off = (rpi2-self.total_plotted_degrees)*0.5
+ (self._ext_max_height[l]*0.1 if l in self._ext_max_height else 0.1) )
+
+ off = self.start_rotation + (rpi2 - self.total_plotted_degrees) * 0.5
b = (bot+bot1)*0.5
- s = -90 if 0.5*rpi < self.start_rotation < 1.5*rpi else 90
- #rot = (self.start_rotation*360.0/rpi2 + s + off*360.0/rpi2 )%360.0
- rot = (self.start_rotation*360.0/rpi2 + s )%360.0
+ s = 180.0 if self.start_rotation == rpi else 0.0
+ rot = (self.start_rotation*360.0/rpi2)%180.0 - 90 + s
fs = v['ring_label_font_size']
lcol = v['ring_label_color']
ax.text( self.start_rotation, b, v['ring_label'], rotation = rot,
@@ -1004,31 +1098,19 @@ class CircTree(PpaTree):
#ax.text( 0, 1, t )
if self._ext_key:
- #a = ax.legend( bbox_to_anchor=(.0, 1), loc = 'upper left', shadow=False, frameon = False,
- # scatterpoints = 1, borderpad = 0, handlelength = 0,
- # handletextpad = 0, markerscale = 0.0, ncol = 1,
- # labelspacing = 0.05,
- # prop = {'size':self.annotation_legend_font_size}
- # )
-
if external_legends:
- if self._ext_key:
- lengths = [len(s) for s in self._ext_key]
- charsize = self.annotation_legend_font_size * 0.0138889
- width = round(max(lengths) * charsize * 10.) / 10.
- height = round(self._tot_offset * len(self._ext_key) * charsize * 10.) / 10.
- fig_annot = plt.figure(figsize=(width, height))
- ax = fig_annot.add_subplot(111, frame_on=False, xticks=[], yticks=[])
- else:
- print '[W] External annotation not created, no annotated labels!'
+ lengths = [len(s) for s in self._ext_key]
+ charsize = self.annotation_legend_font_size * 0.0138889
+ width = round(max(lengths) * charsize * 10.) / 10.
+ height = round(self._tot_offset * len(self._ext_key) * charsize * 10.) / 10.
+ fig_annot = plt.figure(figsize=(width, height))
+ ax = fig_annot.add_subplot(111, frame_on=False, xticks=[], yticks=[])
ll = [ax.scatter(0.0, 0.0, s=0.0)] * len(self._ext_key)
-
- if self._ext_key:
- plt.figlegend(ll, sorted(self._ext_key), 'upper left', frameon=False,
- shadow=False, scatterpoints=1, handlelength=0, markerscale=0.0,
- handletextpad=0.2, ncol=1, labelspacing=0.1,
- prop={'size': self.annotation_legend_font_size})
+ plt.figlegend(ll, sorted(self._ext_key), 'upper left', frameon=False,
+ shadow=False, scatterpoints=1, handlelength=0, markerscale=0.0,
+ handletextpad=0.2, ncol=1, labelspacing=0.1,
+ prop={'size': self.annotation_legend_font_size})
if external_legends: # add '_annot' to the filename
if out_format:
@@ -1036,10 +1118,11 @@ class CircTree(PpaTree):
else:
img_name = out_img[:out_img.rfind('.')] + "_annot" + out_img[out_img.rfind('.'):]
- if self._ext_key:
- plt.savefig(img_name, dpi=out_dpi, bbox_inches='tight',
- bbox_extra_artists=handles, pad_inches=out_pad, format=out_format)
- plt.close()
+ plt.savefig(img_name, dpi=out_dpi, bbox_inches='tight',
+ bbox_extra_artists=handles, pad_inches=out_pad, format=out_format)
+ plt.close()
+ # else:
+ # print '[w] External annotation not created, no annotated labels!'
if external_legends:
if labels: # need to check if there are annotated labels!
@@ -1048,7 +1131,7 @@ class CircTree(PpaTree):
height = round(self._tot_offset * len(labels) * charsize * self.class_legend_marker_size * 10.) / 10.
plt.figure(figsize=(width, height))
else:
- print '[W] External legend not created, no annotated labels!'
+ print('[w] External legend not created, no annotated labels!')
if labels:
plt.figlegend(handles, labels, loc, labelspacing=0.1, frameon=False,
@@ -1073,7 +1156,6 @@ class CircTree(PpaTree):
pad_inches=out_pad, format=out_format,
# edgecolor=fc
)
-
plt.close()
else:
plt.show()
=====================================
src/pyphlan.py
=====================================
@@ -9,7 +9,7 @@ from Bio.Phylo.BaseTree import Clade as BClade
import string
from numpy import pi as rpi
rpi2 = 2.0*rpi
-import numpy as np
+import numpy as np
import array as arr
import collections as colls
import sys
@@ -115,7 +115,7 @@ def reroot_mid_fat_edge( tree, node ):
def clades2terms( tree, startswith = None ):
c2t = {}
def clades2terms_rec( c ):
- if startswith:
+ if startswith:
if c.name and c.name.startswith( startswith ):
c2t[c] = c.get_terminals()
else:
@@ -127,11 +127,11 @@ def clades2terms( tree, startswith = None ):
def dist_matrix( tree ):
terminals = list(tree.get_terminals())
- term_names = [t.name for t in terminals]
+ term_names = [t.name for t in terminals]
# can be made faster with recursion
for n in tree.get_nonterminals():
n.ids = set( [nn.name for nn in n.get_terminals()] )
-
+
dists = dict([(n,dict([(nn,0.0) for nn in term_names])) for n in term_names])
def dist_matrix_rec( clade ):
@@ -160,18 +160,21 @@ class PpaTree:
def __load_tree_txt__( self, fn ):
tree = Phylo.BaseTree.Tree()
try:
- rows = [l.decode('utf-8').rstrip().split("\t")[0] for l in
+ rows = [l.decode('utf-8').rstrip().split("\t")[0] for l in
open(fn, 'rb')]
except IOError:
raise IOError()
-
+
clades = [r.split(lev_sep) for r in rows]
tree = BTree()
tree.root = BClade()
-
+
def add_clade_rec( father, txt_tree ):
- fl = set([t[0] for t in txt_tree])
+ fl = []
+ for c in [t[0] for t in txt_tree]:
+ if c in fl: continue
+ else: fl.append(c)
father.clades = []
for c in fl:
nclade = BClade( branch_length = 1.0,
@@ -184,7 +187,7 @@ class PpaTree:
add_clade_rec( tree.root, clades )
self.ignore_branch_len = 1
return tree.as_phyloxml()
-
+
def __read_tree__( self, fn ):
for ff in ['phyloxml','newick','nexus',"txt"]:
@@ -199,25 +202,25 @@ class PpaTree:
continue
except IOError:
sys.stderr.write("Error: No tree file found: "+fn+"\n")
- raise IOError
+ raise IOError
except Exception:
continue
else:
return tree.as_phyloxml()
sys.stderr.write("Error: unrecognized input format "+fn+"\n")
- raise ValueError
+ raise ValueError
def __init__( self, filename, warnings = False ):
self.warnings = warnings
if filename is None:
self.tree = None
- return
+ return
try:
- self.tree = self.__read_tree__(filename)
+ self.tree = self.__read_tree__(filename)
self.add_full_paths()
except:
- sys.exit(0)
+ sys.exit(0)
def core_test( self, ok, tot, pr ):
@@ -242,7 +245,7 @@ class PpaTree:
add = 0
for subclade in clade.clades:
if "?" in subclade.name:
- out = subclade.imgids - intersection # targs
+ out = subclade.imgids - intersection # targs
add += len(out)
if add and len_intersection >= add:
len_intersection += int(round(add/1.99))
@@ -259,10 +262,10 @@ class PpaTree:
if len(subclade.imgids & targs) == 0:
nsubclades_absent += 1
continue
-
+
sc_intersection = subclade.imgids & targs
sc_len_intersection = len(sc_intersection)
-
+
sc_add = 0
for sc_subclade in subclade.clades:
if "?" in sc_subclade.name:
@@ -271,7 +274,7 @@ class PpaTree:
if add and sc_len_intersection >= sc_add:
sc_len_intersection += int(round(sc_add/1.99))
- subcore = self.core_test( sc_len_intersection, subclade.nterminals, er )
+ subcore = self.core_test( sc_len_intersection, subclade.nterminals, er )
if subcore < 0.05:
return False, core, None
if nsubclades > 0 and nsubclades == nsubclades_absent:
@@ -295,7 +298,7 @@ class PpaTree:
1.0)]
return []
if skip_qm and clade.name and "?" in clade.name:
- return []
+ return []
if len(clade.imgids) == 1:
cimg = list(clade.imgids)[0]
if cimg in terminals:
@@ -320,7 +323,7 @@ class PpaTree:
def add_full_paths( self ):
-
+
def _add_full_paths_( clade, path ):
lpath = path + ([clade.name] if clade.name else [])
clade.full_name = ".".join( lpath )
@@ -330,7 +333,7 @@ class PpaTree:
def find_cores( self, cl_taxa_file, min_core_size = 1, error_rate = 0.95, subtree = None, skip_qm = True ):
if subtree:
- self.subtree( 'name', subtree )
+ self.subtree( 'name', subtree )
self.ctc = {}
imgids2terminals = {}
for t in self.tree.get_terminals():
@@ -343,7 +346,7 @@ class PpaTree:
n.imgids = set( [nn.imgid for nn in n.get_terminals()] )
n.nterminals = len( n.imgids )
- self.add_full_paths() # unnecessary
+ self.add_full_paths() # unnecessary
ret = {}
for vec in (l.strip().split('\t') for l in open(cl_taxa_file)):
@@ -357,7 +360,7 @@ class PpaTree:
ret[sid] = self._find_core( tgts, er = error_rate, root_name = subtree, skip_qm = skip_qm )
#print sid #, ret[sid]
return ret
-
+
def markerness( self, coreness, uniqueness, cn_min, cn_max, cn_avg ):
return coreness * uniqueness * (1.0 / float(cn_max-cn_min+1)) * 1.0 / cn_avg
@@ -376,9 +379,9 @@ class PpaTree:
n.imgids = set( [nn.imgid for nn in n.get_terminals()] )
n.nterminals = len( n.imgids )
- self.add_full_paths() # unnecessary
-
- cus = dict([(int(l[0]),[int(ll) for ll in l[1:]]) for l in
+ self.add_full_paths() # unnecessary
+
+ cus = dict([(int(l[0]),[int(ll) for ll in l[1:]]) for l in
(line.strip().split('\t') for line in open(cu_file))])
cinfo = dict([(int(v[0]),[v[1]] + [int(vv) for vv in v[2:6]] + [float(vv) for vv in v[6:]])
for v in (line.strip().split('\t') for line in open(core_file))])
@@ -390,7 +393,7 @@ class PpaTree:
lca = self.lca( cus[sid], ids2clades )
if lca.is_terminal():
tin = set([lca.imgid])
- tout = tgts_l - tin
+ tout = tgts_l - tin
else:
tout = tgts_l - lca.imgids
tin = lca.imgids & tgts_l
@@ -403,15 +406,15 @@ class PpaTree:
gtax = ci[0]
cobs, ctot = int(ci[1]), int(ci[2])
markerness = self.markerness( coreness, uniqueness, cn_min, cp_max, cn_avg )
-
+
res_lin = [ gtax, markerness, coreness, uniqueness, cobs, ctot, cn_min, cp_max, cn_avg,
ltin, ltout, "|".join([str(s) for s in tin]), "|".join([str(s) for s in tout]) ]
- ret[sid] = res_lin
+ ret[sid] = res_lin
return ret
-
+
def select_markers( self, marker_file, markerness_th = 0.0, max_markers = 200 ):
- cl2markers = colls.defaultdict( list )
+ cl2markers = colls.defaultdict( list )
for line in (l.strip().split('\t') for l in open( marker_file )):
gid = line[1]
markerness = float(line[2])
@@ -433,7 +436,7 @@ class PpaTree:
for c in clade.clades:
_get_c2t_( c )
_get_c2t_( self.tree.root )
- return tc2t
+ return tc2t
def ltcs( self, terminals, tc2t = None, terminals2clades = None, lca_precomputed = None ):
set_terminals = set( terminals )
@@ -444,7 +447,7 @@ class PpaTree:
terms = tc2t[clade] if tc2t else set([cc.name for cc in clade.get_terminals()])
if len(terms) < cur_max:
return None,0
- if terms <= set_terminals:
+ if terms <= set_terminals:
return clade,len(terms)
rets = []
for c in clade.clades:
@@ -456,7 +459,7 @@ class PpaTree:
if rets:
return sorted(rets,key=lambda x:x[1])[-1][0],cur_max
else:
- return None,None
+ return None,None
return _ltcs_rec_( lca, cur_max = 0 )[0]
def lca( self, terminals, terminals2clades = None ):
@@ -476,7 +479,7 @@ class PpaTree:
lca = self.tree.common_ancestor( clade_targets )
return lca
-
+
def lcca( self, t, t2c ):
node_path = list(self.tree.get_path(t))
if not node_path or len(node_path) < 2:
@@ -520,7 +523,7 @@ class PpaTree:
outs = [c]
if len(out_terms):
diam = sum(sorted(ltcs.depths().values())[-2:])
- outs += [":".join([t.name,str( self.tree.distance(ltcs,t)/diam )])
+ outs += [":".join([t.name,str( self.tree.distance(ltcs,t)/diam )])
for t in out_terms]
res.append( outs )
return res
@@ -528,7 +531,7 @@ class PpaTree:
def tax_resolution( self, terminals ):
pass
-
+
def prune( self, strategy = 'lca', n = None, fn = None, name = None, newname = None ):
prune = None
if strategy == 'root_name':
@@ -557,7 +560,7 @@ class PpaTree:
toprune = node_path[-n]
fat = node_path[-n-1]
fat.clades = [cc for cc in fat.clades if cc != toprune]
- prune = None
+ prune = None
else:
sys.stderr.write( strategy + " not supported yet." )
sys.exit(-1)
@@ -620,8 +623,8 @@ class PpaTree:
def reroot( self, strategy = 'lca', tf = None, n = None ):
if strategy in [ 'lca', 'ltcs' ]:
- targets = self.read_targets( tf )
-
+ targets = self.read_targets( tf )
+
lca = self.lca( targets ) if strategy == 'lca' else self.ltcs( targets )
reroot_mid_fat_edge( self.tree, lca)
@@ -641,46 +644,55 @@ class PpaTree:
#self.tree.reroot_at_midpoint(update_splits=True)
elif strategy == 'longest_edge':
nodes = list(self.tree.get_nonterminals()) + list(self.tree.get_terminals())
- longest = max( nodes, key=lambda x:x.branch_length )
+ longest = max( nodes, key=lambda x:x.branch_length )
reroot_mid_fat_edge( self.tree, longest )
#longest_edge = max( self.ntree.get_edge_set(),
# key=lambda x:x.length)
#self.tree.reroot_at_edge(longest_edge, update_splits=True)
elif strategy == 'longest_internal_edge':
nodes = list(self.tree.get_nonterminals())
- longest = max( nodes, key=lambda x:x.branch_length )
+ longest = max( nodes, key=lambda x:x.branch_length )
if self.tree.root != longest:
reroot_mid_fat_edge( self.tree, longest )
#longest = get_lensorted_int_edges( self.tree )
#self.tree.reroot_at_edge( list(longest)[-1], update_splits=True )
elif strategy == 'longest_internal_edge_n':
nodes = list(self.tree.get_nonterminals())
- longest = max( nodes, key=lambda x:x.branch_length
- if len(x.get_terminals()) >= n else -1.0)
+ longest = max( nodes, key=lambda x:x.branch_length
+ if len(x.get_terminals()) >= n else -1.0)
reroot_mid_fat_edge( self.tree, longest )
#longest = get_lensorted_int_edges( self.tree, n )
#self.tree.reroot_at_edge( list(longest)[-1], update_splits=True )
- def reorder_tree( self ):
+ def reorder_tree( self, reorder_tree ):
self._ord_terms = []
- def reorder_tree_rec( clade ):
+
+
+ def reorder_tree_rec( clade, reorder_tree ):
if clade.is_terminal():
self._ord_terms.append( clade )
return clade,clade
- clade.clades.sort( key=lambda x:len(x.get_terminals()), reverse = True)
+
+ if reorder_tree:
+ clade.clades.sort(key=lambda x:len(x.get_terminals()), reverse = True)
+
for c in clade.clades:
- c.fc,c.lc = reorder_tree_rec( c )
- return clade.clades[0].fc,clade.clades[-1].lc
+ c.fc,c.lc = reorder_tree_rec( c, reorder_tree )
+
+ return clade.clades[0].fc,clade.clades[-1].lc
#clade.fc, clade.lc = clade.clades[0], clade.clades[-1]
-
- reorder_tree_rec( self.tree.root )
+
+
+ reorder_tree_rec( self.tree.root, reorder_tree )
last = None # self._ord_terms[-1]
+
for c in self._ord_terms:
c.pc = last
if last:
last.nc = c
last = c
+
c.nc = None
#self._ord_terms[-1].nc = None # self._ord_terms[0]
@@ -696,7 +708,7 @@ class PpaTree:
leaves += rec_subtree_leaves( c )
leaves = [l for l in leaves if l]
subtrees.append( (clade.name if clade.name else "",leaves) )
- return leaves
+ return leaves
rec_subtree_leaves( self.tree.root )
return subtrees
@@ -713,14 +725,14 @@ class PpaTree:
if not nam and not clade.name:
lnam = ""
elif not nam:
- lnam = clade.name
+ lnam = clade.name
elif not clade.name:
lnam = nam
else:
- lnam = lev_sep.join( [nam, clade.name if clade.name else ""] )
- ret += [lnam] if lnam else []
+ lnam = lev_sep.join( [nam, clade.name if clade.name else ""] )
+ ret += [lnam] if lnam else []
for c in clade.clades:
- ret += rec_name(c,lnam)
+ ret += rec_name(c,lnam)
return ret
names = set(rec_name(self.tree.root))
else:
View it on GitLab: https://salsa.debian.org/med-team/graphlan/compare/7e3e813f69b7af460ed049567354f1b68ce143a0...ed2e94feb06db5c7f53f23234ce6d7613aae58ad
--
View it on GitLab: https://salsa.debian.org/med-team/graphlan/compare/7e3e813f69b7af460ed049567354f1b68ce143a0...ed2e94feb06db5c7f53f23234ce6d7613aae58ad
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20180926/f3048468/attachment-0001.html>
More information about the debian-med-commit
mailing list