Skip to Content
Bioinformatics with Python Cookbook - Second Edition
book

Bioinformatics with Python Cookbook - Second Edition

by Tiago Antao
November 2018
Intermediate to advanced
360 pages
9h 36m
English
Packt Publishing
Content preview from Bioinformatics with Python Cookbook - Second Edition

How to do it...

Take a look at the following steps:

  1. First, let's load the RAxML-generated tree for all Ebola viruses, as follows:
import dendropyebola_raxml = dendropy.Tree.get_from_path('my_ebola.nex', 'nexus')
  1. Then, we need to compute the level of each node (the distance to the root node):
def compute_level(node, level=0):    for child in node.child_nodes():        compute_level(child, level + 1)    if node.taxon is not None:        print("%s: %d %d" % (node.taxon, node.level(), level))compute_level(ebola_raxml.seed_node)

DendroPy's node representation has a level method (which is used for comparison), but the point here is to introduce a recursive algorithm, so we will implement it anyway.

Note how the function works; it's called with the seed_node (which ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Bioinformatics with Python Cookbook

Bioinformatics with Python Cookbook

Tiago Antao

Publisher Resources

ISBN: 9781789344691Supplemental Content