Skip to content

Commit eab6005

Browse files
committed
Instantiate into tree and back
1 parent 1c48b80 commit eab6005

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

examples/opentree-doi-search/opentree-doi-search.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import argparse
2929
import collections
3030
import pyopentree
31+
import dendropy
3132

3233
__prog__ = os.path.basename(__file__)
3334
__version__ = "1.0.0"
@@ -93,9 +94,7 @@ def yield_studies(
9394
citation=citation)
9495
yield s
9596

96-
def get_trees(self,
97-
doi,
98-
schema="nexus"):
97+
def get_trees(self, doi):
9998
study_query = self.studies_find_studies(
10099
property_name="ot:studyPublication",
101100
property_value=doi,
@@ -111,10 +110,11 @@ def get_trees(self,
111110
tree_ids.extend(tree_group["treeById"].keys())
112111
tree_strings = []
113112
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")
116114
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
118118

119119
def main():
120120
"""
@@ -179,10 +179,10 @@ def main():
179179
study.citation))
180180
elif args.subparser_name == "get-trees":
181181
# 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:
184184
sys.exit("No studies found with DOI: '{}'".format(args.doi))
185-
print(trees_string)
185+
print(trees.as_string(args.schema))
186186
else:
187187
parser.print_usage(sys.stderr)
188188
sys.exit(1)

0 commit comments

Comments
 (0)