Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3320554
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:57:25+00:00 2026-05-17T22:57:25+00:00

I trying to build a tree with BioPython, Phylo module. What I’ve done so

  • 0

I trying to build a tree with BioPython, Phylo module.
What I’ve done so far is this image: alt text

each name has a four digit number followed by – and a number: this number refer to the number of times that sequence is represented. That means 1578 – 22, that node should represent 22sequences.

the file with the sequences aligned: file
the file with the distance to build a tree: file

So now I known how to change each size of the node. Each node has a different size, this is easy doing an array of the different values:

    fh = open(MEDIA_ROOT + "groupsnp.txt")    
    list_size = {}
    for line in fh:
        if '>' in line:
            labels = line.split('>')
            label = labels[-1]
            label = label.split()
            num = line.split('-')
            size = num[-1]
            size = size.split()
            for lab in label:
                for number in size:
                    list_size[lab] = int(number)

    a = array(list_size.values())

But the array is arbitrary, I would like to put the correct node size into the right node, I tried this:

         for elem in list_size.keys():
             if labels == elem:
                 Phylo.draw_graphviz(tree_xml, prog="neato", node_size=a)

but nothing appears when I use the if statement.

Anyway of doing this?

I would really appreciate!

Thanks everybody

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:57:26+00:00Added an answer on May 17, 2026 at 10:57 pm

    I finally got this working. The basic premise is that you’re going to use the labels/nodelist to build your node_sizes. This way they correlate properly. I’m sure I’m missing some important options to make the tree look 100% but it appears the node sizes are showing up properly.

    #basically a stripped down rewrite of Phylo.draw_graphviz
    import networkx, pylab
    from Bio import Phylo
    
    
    #taken from draw_graphviz
    def get_label_mapping(G, selection): 
        for node in G.nodes(): 
            if (selection is None) or (node in selection): 
                try: 
                    label = str(node) 
                    if label not in (None, node.__class__.__name__): 
                        yield (node, label) 
                except (LookupError, AttributeError, ValueError): 
                    pass
    
    
    kwargs={}
    tree = Phylo.read('tree.dnd', 'newick')
    G = Phylo.to_networkx(tree)
    Gi = networkx.convert_node_labels_to_integers(G, discard_old_labels=False)
    
    node_sizes = []
    labels = dict(get_label_mapping(G, None))
    kwargs['nodelist'] = labels.keys()
    
    #create our node sizes based on our labels because the labels are used for the node_list
    #this way they should be correct
    for label in labels.keys():
        if str(label) != "Clade":
            num = label.name.split('-')
            #the times 50 is just a guess on what would look best
            size = int(num[-1]) * 50
            node_sizes.append(size)
    
    kwargs['node_size'] = node_sizes
    posi = networkx.pygraphviz_layout(Gi, 'neato', args='') 
    posn = dict((n, posi[Gi.node_labels[n]]) for n in G) 
    
    networkx.draw(G, posn, labels=labels, node_color='#c0deff', **kwargs)
    
    pylab.show()
    

    Resulting Tree
    alt text

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a directory tree such as how xml trees are
Im trying to build a kd-tree for searching through a set of points, but
I'm trying to build an expression tree ( still ) but getting further! I
I am trying to build a navigation tree via recursion in JSF. I have
I am trying to build a dynamic Expression Tree like below : Func<IEnumerable<int>, int,
Trying to build a GUI application in Java/Swing. I'm mainly used to painting GUIs
I trying to build and compile my xcodeproj in command line and it is
I'm trying to build a grammar with the following: NUMERIC: INTEGER | FLOAT |
I'm currently trying to build a personal website to create a presence on the
I am trying to build a function in C/C++ to sort an array and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.