28
28
import argparse
29
29
import collections
30
30
import pyopentree
31
+ import dendropy
31
32
32
33
__prog__ = os .path .basename (__file__ )
33
34
__version__ = "1.0.0"
@@ -93,9 +94,7 @@ def yield_studies(
93
94
citation = citation )
94
95
yield s
95
96
96
- def get_trees (self ,
97
- doi ,
98
- schema = "nexus" ):
97
+ def get_trees (self , doi ):
99
98
study_query = self .studies_find_studies (
100
99
property_name = "ot:studyPublication" ,
101
100
property_value = doi ,
@@ -111,10 +110,11 @@ def get_trees(self,
111
110
tree_ids .extend (tree_group ["treeById" ].keys ())
112
111
tree_strings = []
113
112
for tree_id in tree_ids :
114
- s = self .get_study_tree (study_id = study_id , tree_id = tree_id , schema = schema )
115
- print (s )
113
+ s = self .get_study_tree (study_id = study_id , tree_id = tree_id , schema = "newick" )
116
114
tree_strings .append (s )
117
- return tree_strings
115
+ tree_str = "\n " .join (tree_strings )
116
+ trees = dendropy .TreeList .get_from_string (tree_str , "newick" )
117
+ return trees
118
118
119
119
def main ():
120
120
"""
@@ -179,10 +179,10 @@ def main():
179
179
study .citation ))
180
180
elif args .subparser_name == "get-trees" :
181
181
# http://dx.doi.org/10.1111/j.1365-294X.2012.05606.x
182
- trees_string = ots .get_trees (doi = args .doi , schema = args . schema )
183
- if trees_string is None :
182
+ trees = ots .get_trees (doi = args .doi )
183
+ if trees is None :
184
184
sys .exit ("No studies found with DOI: '{}'" .format (args .doi ))
185
- print (trees_string )
185
+ print (trees . as_string ( args . schema ) )
186
186
else :
187
187
parser .print_usage (sys .stderr )
188
188
sys .exit (1 )
0 commit comments