Exemple #1
0
        for newCognateID in range(1,numCognates + 1):
            multi = MSA("cognates/" + phylName + "/" + familyName + "/" + str(conceptID - 3) + "." + str(newCognateID) + ".msq",merge_vowels=False,unique_seqs=False)
            cognateLangs = [nameToID[taxon] - langs[0] for taxon in multi.taxa]
            #cognateLangs = [int(lexdict[IDList[0]][0]) - langs[0] for IDList in etym_dict[cognateID] if IDList != 0]
            #print "cognate set " + str(cognateID) + " - cognate langs: " + str(cognateLangs)
            if len(cognateLangs) > 1:  #cognate sets of size 1 are useless
                cognateGuideTree = subGuideTree(familyGuideTree,cognateLangs)       
                #print("\nAligning cognate " + str(cognateID) + ":")
                #print "  cognate langs = " + str(cognateLangs)
                #printTree(cognateGuideTree,0,names=[germanicNameTable[lang] for lang in cognateLangs])
                cognateNameTable = [nameTable[lang] for lang in cognateLangs]
                tree_mtx = convert.newick.nwk2guidetree(str(cognateGuideTree))
                multi.prog_align(model=internal_asjp,gop=-4,scale=0.9,guide_tree=tree_mtx)
                #print(multi)
                
                cons = get_consensus(multi, cognateGuideTree, recon_alg="sankoff_parsimony", gaps=True, classes=False, rep_weights = rep_weights, local = "gap")

                cognateParsimony = 0.0
                
                #aggregate the parsimony value
                for i in range(len(cognateGuideTree.reconstructed)):
                    cognateParsimony += min(cognateGuideTree.sankoffTable[i].values())
                    
                familyParsimony += cognateParsimony
                    
                print("Reconstructed proto-" + familyName + " word for concept " + str(conceptID - 3) + ":\t" + cons + "\twith average parsimony " + str(cognateParsimony / len(cognateLangs)))
                 
                #PRINT OUT RECONSTRUCTION STEPS IN A TREE VISUALIZATION
                if graphicalOutput:
                    outputTree = Tree()
                    outputTree.add_face(TextFace(str("".join(cognateGuideTree.reconstructed))), column=0, position = "branch-right")
     if (IDList != 0):
         [langID, word, entry, langName] = lexdict[IDList[0]][:4]
         entry_msq_file.write(langName + "\t" + entry + "\n")
 entry_msq_file.close()
 cognateLangs = [int(lexdict[IDList[0]][0]) - langs[0] for IDList in etym_dict[cognateID] if IDList != 0]
 if len(cognateLangs) > 1:  #cognate sets of size 1 are useless
     cognateGuideTree = subGuideTree(germanicGuideTree,cognateLangs)       
     print("\nAligning cognate " + str(cognateID) + ":")
     print "  cognate langs = " + str(cognateLangs)
     printTree(cognateGuideTree,0,names=[germanicNameTable[lang] for lang in cognateLangs])
     multi = MSA("./cognate" + str(cognateID) + ".msq",merge_vowels=True,unique_seqs=False)
     tree_mtx = convert.newick.nwk2guidetree(str(cognateGuideTree))
     multi.prog_align(model=sca,gop=-4,scale=0.9,guide_tree=tree_mtx)
     print(multi)
     #old version of call had taxa=[str(i) for i in range(len(langs))]
     cons = get_consensus(multi, cognateGuideTree, gaps=True, classes=False)
     print("Reconstructed proto word for concept " + str(conceptID - 3) + ":\t" + cons)   
     #print("\nDetermining and counting sound changes at the edges of the guide tree, and cascading them to the supertrees:")
     for node in cognateGuideTree.postorder():
         if not hasattr(node, "recon_changes"):
             node.recon_changes = {}
         if not node.isRoot():
             for i in range (0,len(node.reconstructed)):
                 #if node.reconstructed[i] != node.Parent.reconstructed[i]:
                     change = (node.Parent.reconstructed[i], node.reconstructed[i])
                     origNode = node
                     while origNode != None:
                         if not hasattr(origNode, "recon_changes"):
                             origNode.recon_changes = {}
                         if change not in origNode.recon_changes.keys():
                             origNode.recon_changes[change] = 1
Exemple #3
0
 if len(cognateLangs) > 1:  #cognate sets of size 1 are useless
     cognateGuideTree = subGuideTree(germanicGuideTree, cognateLangs)
     print("\nAligning cognate " + str(cognateID) + ":")
     print "  cognate langs = " + str(cognateLangs)
     printTree(cognateGuideTree,
               0,
               names=[germanicNameTable[lang] for lang in cognateLangs])
     multi = MSA("./cognate" + str(cognateID) + ".msq",
                 merge_vowels=True,
                 unique_seqs=False)
     tree_mtx = convert.newick.nwk2guidetree(str(cognateGuideTree))
     multi.prog_align(model=sca, gop=-4, scale=0.9, guide_tree=tree_mtx)
     print(multi)
     #old version of call had taxa=[str(i) for i in range(len(langs))]
     cons = get_consensus(multi,
                          cognateGuideTree,
                          gaps=True,
                          classes=False)
     print("Reconstructed proto word for concept " +
           str(conceptID - 3) + ":\t" + cons)
     #print("\nDetermining and counting sound changes at the edges of the guide tree, and cascading them to the supertrees:")
     for node in cognateGuideTree.postorder():
         if not hasattr(node, "recon_changes"):
             node.recon_changes = {}
         if not node.isRoot():
             for i in range(0, len(node.reconstructed)):
                 #if node.reconstructed[i] != node.Parent.reconstructed[i]:
                 change = (node.Parent.reconstructed[i],
                           node.reconstructed[i])
                 origNode = node
                 while origNode != None:
                     if not hasattr(origNode, "recon_changes"):