def simData_XExtraMutations(N,L,k,mutationsMustBeVisible =True): simTree = simulator_KingmanFiniteSites(N,10*L/2.0,L,False) result = simTree.untillFirstXInconsistencies(X = k) if not mutationsMustBeVisible: # assure that we have k more mutations on the underlying tree than # we have segregating sites while result["Inconsistencies"] < k: result = simTree.untillFirstXInconsistencies(X = k) else: # Assure that we have k visible inconsistencies with the infinite sites # model while result["typeCount"][0] + result["typeCount"][2] < k: result = simTree.untillFirstXInconsistencies(X = k) S_redundantRowsAndColumns = simTree.getS() #remove null-rows S1 = withoutNullColumns(S_redundantRowsAndColumns) #remove redundant rows, and associate each row with a count-vector n instead S,n = S_and_n(S1) return S,n
def simData_k_mutations_total(N,L,k,mutation_must_be_visible = True): simTree = simulator_KingmanFiniteSites(N,10.0*k,L,False) if mutation_must_be_visible: result = simTree.until_k_visible_mutations(k) else: result = simTree.until_k_mutations(k) #re-run simulations if we didn't get enough mutations. while k > len(result['coalescent'].mutations): simTree = simulator_KingmanFiniteSites(N,10.0*k,L,False) if mutation_must_be_visible: result = simTree.until_k_visible_mutations(k) else: result = simTree.until_k_mutations(k) S_redundant_rows_and_columns = result['S'] S_redundant_columns, Nr = S_and_n( S_redundant_rows_and_columns ) S_transpose, Nc = S_and_n( np.transpose(S_redundant_columns) ) S = np.transpose(S_transpose) return S,Nr,Nc
def simData(N,theta,L): simTree = simulator_KingmanFiniteSites(N,theta/2,L) S_redundantRowsAndColumns = simTree.getS() #remove null-rows S1 = withoutNullColumns(S_redundantRowsAndColumns) #remove redundant rows, and associate each row with a count-vector n instead S,n = S_and_n(S1) return S,n
def test(n = 10, theta = 1.0, L = 10): sim = fsmi.simulator_KingmanFiniteSites(n,theta,L) myTree = sim_to_tree(sim) # str_newick_test = '(A,(B,C)D);' # dpTree_test = dp.Tree.get(data = str_newick_test, schema = 'newick') # dpTree_test.print_plot() str_newick_sim = myTree.str_newick(True) print str_newick_sim dpTree_sim = dp.Tree.get(data = str_newick_sim, schema = 'newick') dpTree_sim.print_plot() phyloTree = Phylo.read(StringIO(str_newick_sim),'newick') print phyloTree plt.figure() Phylo.draw(phyloTree) phyloTree.rooted = True plt.figure() Phylo.draw_graphviz(phyloTree, prog = 'dot') plt.draw()