@@ -102,7 +102,7 @@ def collapse_tnrs_match_names_results(results, method='first_hit_only'):
102
102
return results
103
103
104
104
def write_tree_to_path (tree , path , schema = 'nexml' ):
105
- tree .write_to_path (dest = path , schema = 'nexml' )
105
+ tree .write_to_path (dest = path , schema = schema )
106
106
107
107
def get_internal_nodes (tree , only_named_nodes = False , exclude_seed_node = False ):
108
108
node_iterator = tree .preorder_internal_node_iter (
@@ -187,7 +187,8 @@ def get_tol_induced_tree(ott_ids, keep_taxon_name=True, keep_ott_id=True):
187
187
src = raw_api_data ['subtree' ],
188
188
schema = 'newick' ,
189
189
preserve_underscores = True ,
190
- suppress_internal_node_taxa = False )
190
+ suppress_internal_node_taxa = False ,
191
+ terminating_semicolon_required = False )
191
192
192
193
induced_tree = parse_opentree_taxon_labels_in_dendropy_tree (
193
194
tree = induced_tree ,
@@ -204,7 +205,8 @@ def get_tol_subtree(ott_id, keep_taxon_name=True, keep_ott_id=True):
204
205
src = raw_api_data ['newick' ],
205
206
schema = 'newick' ,
206
207
preserve_underscores = True ,
207
- suppress_internal_node_taxa = False )
208
+ suppress_internal_node_taxa = False ,
209
+ terminating_semicolon_required = False )
208
210
209
211
subtree = parse_opentree_taxon_labels_in_dendropy_tree (
210
212
tree = subtree ,
@@ -221,7 +223,8 @@ def get_taxonomy_subtree(ott_id, keep_taxon_name=True, keep_ott_id=True):
221
223
src = raw_api_data ['subtree' ],
222
224
schema = 'newick' ,
223
225
preserve_underscores = True ,
224
- suppress_internal_node_taxa = False )
226
+ suppress_internal_node_taxa = False ,
227
+ terminating_semicolon_required = False )
225
228
226
229
subtree = parse_opentree_taxon_labels_in_dendropy_tree (
227
230
tree = subtree ,
@@ -230,77 +233,108 @@ def get_taxonomy_subtree(ott_id, keep_taxon_name=True, keep_ott_id=True):
230
233
231
234
return subtree
232
235
236
+ def tol_mrca (ott_ids ):
237
+ raw_api_data = pyopentree .tol_mrca (ott_ids = ott_ids .values (), node_ids = None )
238
+
239
+ return {raw_api_data ['mrca_name' ]: raw_api_data ['ott_id' ]}
240
+
233
241
if __name__ == "__main__" :
234
242
243
+ # ott_ids = get_ott_ids(
244
+ # names=['dog', 'cat', 'canada goose', 'african elephant', 'monarch butterfly', 'Solanum chilense', 'Prunus dulcis'],
245
+ # context_name=None,
246
+ # do_approximate_matching=False,
247
+ # include_deprecated=False,
248
+ # include_dubious=False)
249
+ # print(ott_ids)
250
+
251
+ # ott_ids_collapsed = collapse_tnrs_match_names_results(
252
+ # results=ott_ids,
253
+ # method='first_hit_only')
254
+ # print(ott_ids)
255
+
256
+ # induced_tree = get_tol_induced_tree(
257
+ # ott_ids=ott_ids,
258
+ # keep_taxon_name=True,
259
+ # keep_ott_id=False)
260
+ # print(induced_tree)
261
+
262
+ # internal_nodes = get_internal_nodes(
263
+ # tree=induced_tree, only_named_nodes=True, exclude_seed_node=False)
264
+ # for internal_node in internal_nodes:
265
+ # print(internal_node)
266
+ # print()
267
+
268
+ # leaf_nodes = get_leaf_nodes(
269
+ # tree=induced_tree)
270
+ # for leaf_node in leaf_nodes:
271
+ # print(leaf_node)
272
+ # print()
273
+
274
+ # colors = ['red', 'green', 'blue', 'orange', 'pink']
275
+ # nexss = NEXSS()
276
+ # internal_node_count = len(internal_nodes)
277
+ # j = 0
278
+ # for i, node in enumerate(internal_nodes):
279
+ # if i % len(colors) == 0:
280
+ # j = 0
281
+ # else:
282
+ # j = j + 1
283
+ # style = {'color': colors[j]}
284
+ # nexss.annotate_node(
285
+ # node=node,
286
+ # tag='clade',
287
+ # content=node.taxon.label,
288
+ # style=style)
289
+
290
+ # nexss.write_to_path('/Users/karolis/Desktop/induced_tree.nexss')
291
+
292
+ # induced_tree = normalize_branch_lengths(
293
+ # tree=induced_tree,
294
+ # branch_length=1.0)
295
+
296
+ # write_tree_to_path(
297
+ # tree=induced_tree,
298
+ # path='/Users/karolis/Desktop/induced_tree.nexml',
299
+ # schema='nexml')
300
+
301
+ # Clade
302
+ clade = 'Hominoidea'
235
303
ott_ids = get_ott_ids (
236
- names = ['dog' , 'cat' , 'canada goose' , 'african elephant' , 'monarch butterfly' , 'Solanum chilense' , 'Prunus dulcis' ],
304
+ names = [clade ],
237
305
context_name = None ,
238
306
do_approximate_matching = False ,
239
307
include_deprecated = False ,
240
308
include_dubious = False )
241
309
print (ott_ids )
242
310
243
- ott_ids_collapsed = collapse_tnrs_match_names_results (
244
- results = ott_ids ,
245
- method = 'first_hit_only' )
246
- print (ott_ids )
247
-
248
- induced_tree = get_tol_induced_tree (
249
- ott_ids = ott_ids ,
250
- keep_taxon_name = True ,
251
- keep_ott_id = False )
252
- print (induced_tree )
253
-
254
- internal_nodes = get_internal_nodes (
255
- tree = induced_tree , only_named_nodes = True , exclude_seed_node = False )
256
- for internal_node in internal_nodes :
257
- print (internal_node )
258
- print ()
259
-
260
- leaf_nodes = get_leaf_nodes (
261
- tree = induced_tree )
262
- for leaf_node in leaf_nodes :
263
- print (leaf_node )
264
- print ()
265
-
266
- colors = ['red' , 'green' , 'blue' , 'orange' , 'pink' ]
267
- nexss = NEXSS ()
268
- internal_node_count = len (internal_nodes )
269
- j = 0
270
- for i , node in enumerate (internal_nodes ):
271
- if i % len (colors ) == 0 :
272
- j = 0
273
- else :
274
- j = j + 1
275
- style = {'color' : colors [j ]}
276
- nexss .annotate_node (
277
- node = node ,
278
- tag = 'clade' ,
279
- content = node .taxon .label ,
280
- style = style )
281
-
282
- nexss .write_to_path ('/Users/karolis/Desktop/induced_tree.nexss' )
311
+ # ott_ids = get_ott_ids(
312
+ # names=['Geospiza', 'Iridophanes'],
313
+ # context_name=None,
314
+ # do_approximate_matching=False,
315
+ # include_deprecated=False,
316
+ # include_dubious=False)
317
+ # print(ott_ids)
283
318
284
- induced_tree = normalize_branch_lengths (
285
- tree = induced_tree ,
286
- branch_length = 1.0 )
319
+ # ott_ids_collapsed = collapse_tnrs_match_names_results(
320
+ # results=ott_ids,
321
+ # method='first_hit_only')
322
+ # print(ott_ids)
287
323
288
- write_tree_to_path (
289
- tree = induced_tree ,
290
- path = '/Users/karolis/Desktop/induced_tree.nexml' ,
291
- schema = 'nexml' )
324
+ # mrca = tol_mrca(ott_ids)
292
325
326
+ # clade = mrca.keys()[0]
293
327
294
- ott_ids = get_ott_ids (
295
- names = ['Solanaceae' ],
296
- context_name = None ,
297
- do_approximate_matching = False ,
298
- include_deprecated = False ,
299
- include_dubious = False )
300
- print (ott_ids )
328
+ # ott_ids = get_ott_ids(
329
+ # names=[clade ],
330
+ # context_name=None,
331
+ # do_approximate_matching=False,
332
+ # include_deprecated=False,
333
+ # include_dubious=False)
334
+ # print(ott_ids)
301
335
302
336
tol_subtree = get_tol_subtree (
303
- ott_id = ott_ids ['Solanaceae' ][0 ],
337
+ ott_id = ott_ids [clade ][0 ],
304
338
keep_taxon_name = True ,
305
339
keep_ott_id = False )
306
340
# print(tol_subtree)
@@ -317,7 +351,7 @@ def get_taxonomy_subtree(ott_id, keep_taxon_name=True, keep_ott_id=True):
317
351
# print(leaf_node)
318
352
# print()
319
353
320
- colors = ['red' , 'green' , 'blue' , 'orange' , 'pink' ]
354
+ colors = ['red' , 'green' , 'blue' , 'orange' ]
321
355
nexss = NEXSS ()
322
356
internal_node_count = len (internal_nodes )
323
357
j = 0
@@ -333,20 +367,42 @@ def get_taxonomy_subtree(ott_id, keep_taxon_name=True, keep_ott_id=True):
333
367
content = node .taxon .label ,
334
368
style = style )
335
369
336
- nexss .write_to_path ('/Users/karolis/Desktop/Solanaceae.nexss' )
370
+ tol_subtree .ladderize (ascending = True )
371
+
372
+ nexss .write_to_path ('/Users/karolis/Desktop/' + clade + '.nexss' )
337
373
338
374
tol_subtree = normalize_branch_lengths (
339
375
tree = tol_subtree ,
340
376
branch_length = 1.0 )
341
377
342
378
write_tree_to_path (
343
379
tree = tol_subtree ,
344
- path = '/Users/karolis/Desktop/Solanaceae .nexml' ,
380
+ path = '/Users/karolis/Desktop/' + clade + ' .nexml' ,
345
381
schema = 'nexml' )
346
382
347
-
348
- # taxonomy_subtree = get_taxonomy_subtree(
349
- # ott_id='541933',
350
- # keep_taxon_name=True,
351
- # keep_ott_id=False)
352
- # print(taxonomy_subtree)
383
+ write_tree_to_path (
384
+ tree = tol_subtree ,
385
+ path = '/Users/karolis/Desktop/' + clade + '.newick' ,
386
+ schema = 'newick' )
387
+
388
+ import subprocess
389
+ # command = 'pstastic.py ~/Desktop/' + clade + '.nexml ~/Desktop/' + clade + '.nexss --output ~/Desktop/' + clade + '.pdf -ow 3000 -oh 8000 --dpi 300'
390
+ command = 'pstastic.py ~/Desktop/' + clade + '.nexml ~/Desktop/' + clade + '.nexss --output ~/Desktop/' + clade + '.pdf'
391
+ subprocess .call (
392
+ command ,
393
+ # stdout=subprocess.PIPE,
394
+ # stderr=subprocess.PIPE,
395
+ shell = True )
396
+
397
+ subprocess .call (
398
+ 'open ~/Desktop/' + clade + '.pdf' ,
399
+ # stdout=subprocess.PIPE,
400
+ # stderr=subprocess.PIPE,
401
+ shell = True )
402
+
403
+
404
+ taxonomy_subtree = get_taxonomy_subtree (
405
+ ott_id = '541933' ,
406
+ keep_taxon_name = True ,
407
+ keep_ott_id = False )
408
+ print (taxonomy_subtree )
0 commit comments