Advertisement
misingnoglic

Visual Python Evolutionary Tree

May 23rd, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. from visual import *
  2. import random
  3.  
  4. def treemaker(): #User interractive version of below
  5.     L=[]
  6.     n = int(input("How many animals do you want: "))
  7.     for g in range(n):
  8.         x=str(input("Name of Organism #"+str(g+1)+": "))
  9.         if g==0:
  10.             y=0
  11.         else: y=int(input("Evolutionary Distance from " + L[0][0]+": "))
  12.         if g==0:
  13.             z=0
  14.         else:
  15.             z=int(input("Paralogs with " + L[g-1][0]+": "))
  16.         L=L+[[x,y,z]]
  17.         print ("Current List: " +str(L))
  18.     return treeraw(L)
  19.  
  20. def treeraw(ListOfOrganismValues):
  21.     #List is a list of lists [x,y,z]: [name, evolutionary distance from first,paralogs with last animal]
  22.     L=ListOfOrganismValues #to make my life easier
  23.     for x in L:
  24.         if x[2]!=0:
  25.             g= (5/x[2])
  26.             x[2]=g        #for scaling
  27.     for x in range(len(L)): #number or organisms
  28.         if x>0:
  29.             (oldname,oldy,oldz) = L[x-1]
  30.         (name,y,z)=L[x] #extracting values
  31.         (a,b,c)=(random.random(),random.random(),random.random()) #Random color generator
  32.         organism = box(pos=(x,y,z), length=.5, height=.5, width=.5, color=(a,b,c), opacity=1) #creating the organism
  33.         text(text=name,align='center', depth=-0.3, color=color.green, pos=(x,y+.6,z), height=.5, width=.5) #Adding name
  34.         if x>0: #checking if it's the first
  35.             (oldname,oldy,oldz) = L[x-1]
  36.             curve(pos=[(x-1,oldy,oldz), (x,y,z)], radius=0.05) #making the lines between the animals
  37.  
  38.  
  39.  
  40. #tree([["Horse",0,0],["Donkey",1,8],["Chicken",11,10],["Penguin",13, 15],["Snake",21,16]]) #our example
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement