示例#1
0
      #treeid = "ENSGT00390000013823"
      server = "http://beta.rest.ensembl.org"
      ext = "/genetree/id/" + treeid + "?"
      resp, content = http.request(server+ext, method="GET", headers={"Content-Type":"application/json"})
      
      if not resp.status == 200:
	print "Invalid response: ", resp.status
	continue	#evil continue


      decoded = json.loads(content)

      tree = decoded['tree']

      geneNodeMap = {}
      root = TreeNode()
      visit_json_elem(tree, root, geneNodeMap)
      
      orthologs = set()
      paralogs = set()
      paralogs_dubious = set()
      
      for g1 in geneNodeMap:
	for g2 in geneNodeMap:
	  if g1 != g2:
	    n1 = geneNodeMap[g1]
	    n2 = geneNodeMap[g2]
	    
	    lca = n1.get_common_ancestor(n2)
	    
	    if lca.name == 'duplication' or lca.name == 'gene_split':
##################################
ass_node2parent = {"1": "1"}
for nodeid in taxa:
    parentid = node2parent[nodeid]
    while nodeid != parentid:  #costruiamo un nuovo dizionario per i soli taxa che abbiamo identificato nel campione
        ass_node2parent[nodeid] = parentid
        nodeid = parentid
        parentid = node2parent[nodeid]

node2parentid = {}
for nodeid in ass_node2parent.keys():
    parentid = ass_node2parent[nodeid]
    # Stores node connections
    all_ids.update([nodeid, parentid])
    # Creates a new TreeNode instance for each new node in file
    n = TreeNode()
    # Sets some TreeNode attributes
    n.add_feature("name", node2name[nodeid])
    n.add_feature("taxid", nodeid)
    n.add_feature("Order", node2order[nodeid])

    # updates node list and connections
    node2parentid[n] = parentid
    id2node[nodeid] = n
print len(id2node)
# Reconstruct tree topology from previously stored tree connections
print 'Reconstructing tree topology...'
for node in id2node.itervalues():
    parentid = node2parentid[node]
    parent = id2node[parentid]
    # node with taxid=1 is the root of the tree