def makeStarting(tips,RF_norm_start,name,RF_norm_cloud,cloud_size): #Choose starting trees print(name) print("Making starting trees...") # Create random tree. Average branch length of 1. No variation in branch length. Don't print out tree structure t1 = readTree.rand_tree(tips=tips,brl_avg=1,brl_std=None,verbose='F') # Calculate number of NNI moves based on desired normalized RF distance. RF_max = 2*(tips-2) NNI_moves_start = int((RF_max * RF_norm_start)/2) if NNI_moves_start == 0: NNI_moves_start = 1 NNI_moves_cloud = int((RF_max * RF_norm_cloud)/2) # Create second starting tree t2 = readTree.NNI_mult_moves(in_tree=t1,num_moves=NNI_moves_start,node_choice='random',no_dup_start_tree='F', req_min_RF=RF_norm_start) # Write out tree files readTree.write_single_tree(t1,'%s_starting_tree_1.tree' % name) readTree.write_single_tree(t2,'%s_starting_tree_2.tree' % name) # Write out log file # Calculate emperical distance between two start trees as a gut check RF_emp = readTree.rf_unweighted(t1,t2,normalized='T')[1] # write to log file with open('%s.log' % name, "w") as log_file: line1 = "File name: "+str(name) line1b = "Tips: "+str(tips)+", Trees per cloud: "+str(cloud_size) line2 = "Starting trees - RF_input: "+str(RF_norm_start)+", RF_calc: "+str(RF_emp)+", NNI_moves: "+str(NNI_moves_start) line3 = "Cloud of trees - RF_input: "+str(RF_norm_cloud)+", NNI_moves: "+str(NNI_moves_cloud) log_file.write("%s\n%s\n%s" % (line1, line2, line3)) # Pass tree files to next function return t1,t2
def makeStarting(tips,RF_norm_start,name,RF_norm_cloud,cloud_size): #Choose starting trees print(name) print("Making starting trees...") # Create random tree. Average branch length of 1. No variation in branch length. Don't print out tree structure t1 = readTree.rand_tree(tips=tips,brl_avg=1,brl_std=None,verbose='F') # Calculate number of NNI moves based on desired normalized RF distance. RF_max = 2*(tips-2) NNI_moves_start = int((RF_max * RF_norm_start)/2) if NNI_moves_start == 0: NNI_moves_start = 1 # Calc cloud for log file NNI_moves_cloud = int((RF_max * RF_norm_cloud)/2) # Create second starting tree t2 = readTree.NNI_mult_moves(in_tree=t1,num_moves=NNI_moves_start,node_choice='random',no_dup_start_tree='F', req_min_RF=RF_norm_start) readTree.rf_unweighted(t1,t2,"T") t3 = readTree.NNI_mult_moves(in_tree=t2,num_moves=NNI_moves_start,node_choice='random',no_dup_start_tree='F', req_min_RF=RF_norm_start) d12=readTree.rf_unweighted(t1,t2,"T")[1] d23=readTree.rf_unweighted(t2,t3,"T")[1] d13=readTree.rf_unweighted(t1,t3,"T")[1] print("first t2 to t3 RF"+str(d23)) #t1 and t2 are guarenteed to be RF start apart, same with t2 and t3. So we only need to check t1 and t3. while d23 != RF_norm_start: print("redoing third start tree") t3 = readTree.NNI_mult_moves(in_tree=t1,num_moves=NNI_moves_start,node_choice='random',no_dup_start_tree='F', req_min_RF=RF_norm_start) d23=readTree.rf_unweighted(t2,t3,"T")[1] print(d23) # do it all again with another starting tree t4 = readTree.NNI_mult_moves(in_tree=t1,num_moves=NNI_moves_start,node_choice='random',no_dup_start_tree='F', req_min_RF=RF_norm_start) # now we need to check d24 and d34 d14=readTree.rf_unweighted(t1,t4,"T")[1] d24=readTree.rf_unweighted(t2,t4,"T")[1] d34=readTree.rf_unweighted(t3,t4,"T")[1] while d24 != RF_norm_start or d34 != RF_norm_start: print("redoing fourth start tree") t4 = readTree.NNI_mult_moves(in_tree=t1,num_moves=NNI_moves_start,node_choice='random',no_dup_start_tree='F', req_min_RF=RF_norm_start) d24=readTree.rf_unweighted(t2,t4,"T")[1] d34=readTree.rf_unweighted(t3,t4,"T")[1] print(str(d24)+", "+str(d34)) # Write out tree files readTree.write_single_tree(t1,'%s_starting_tree_1.tree' % name) readTree.write_single_tree(t2,'%s_starting_tree_2.tree' % name) readTree.write_single_tree(t3,'%s_starting_tree_3.tree' % name) readTree.write_single_tree(t4,'%s_starting_tree_4.tree' % name) # Write out log file rfs=str(d12)+", "+str(d13)+", "+str(d23)+", "+str(d14)+", "+str(d24)+", "+str(d34) with open('%s.log' % name, "w") as log_file: line1 = "File name: "+str(name) line1b = "Tips: "+str(tips)+", Trees per cloud: "+str(cloud_size) line2 = "Starting trees - RF_input: "+str(RF_norm_start)+", RF_calc: "+str(rfs)+", NNI_moves: "+str(NNI_moves_start) line3 = "Cloud of trees - RF_input: "+str(RF_norm_cloud)+", NNI_moves: "+str(NNI_moves_cloud) log_file.write("%s\n%s\n%s" % (line1, line2, line3)) # Pass tree files to next function return t1,t2,t3,t4
def makeStarting(tips, RF_norm_start_far, RF_norm_start, name, RF_norm_cloud, cloud_size): #Choose starting trees print(name) print("Making starting trees...") # Round the things RF_norm_start_far = round(RF_norm_start_far, 2) RF_norm_start = round(RF_norm_start, 2) # Calculate number of NNI moves based on desired normalized RF distance. RF_max = 2 * (tips - 2) NNI_moves_start = int((RF_max * RF_norm_start) / 2) if NNI_moves_start == 0: NNI_moves_start = 1 NNI_moves_start_far = int((RF_max * RF_norm_start_far) / 2) print("NNI: " + str(NNI_moves_start) + "NNI far: " + str(NNI_moves_start_far)) # Calc cloud for log file NNI_moves_cloud = int((RF_max * RF_norm_cloud) / 2) # Create random tree. Average branch length of 1. No variation in branch length. Don't print out tree structure t1 = readTree.rand_tree(tips=tips, brl_avg=1, brl_std=None, verbose='F') # Create second starting tree t2 = readTree.NNI_mult_moves(in_tree=t1, num_moves=NNI_moves_start, node_choice='random', no_dup_start_tree='F', req_min_RF=RF_norm_start) # Make third tree that is farther away t3 = readTree.NNI_mult_moves(in_tree=t1, num_moves=NNI_moves_start_far, node_choice='random', no_dup_start_tree='F', req_min_RF=RF_norm_start_far) d12 = readTree.rf_unweighted(t1, t2, "T")[1] d23 = readTree.rf_unweighted(t2, t3, "T")[1] d13 = readTree.rf_unweighted(t1, t3, "T")[1] print("first t1 to t2 RF - " + str(round(d12, 2))) print("first t1 to t3 RF - " + str(round(d13, 2))) print("first t2 to t3 RF - " + str(round(d23, 2))) #t1 and t2 are guarenteed to be RF start apart, same with t2 and t3. So we only need to check t1 and t3. while round(d23, 2) != RF_norm_start_far: print("redoing third start tree - " + name) print(round(d23, 2), RF_norm_start_far) t3 = readTree.NNI_mult_moves(in_tree=t1, num_moves=NNI_moves_start_far, node_choice='random', no_dup_start_tree='F', req_min_RF=RF_norm_start_far) d23 = readTree.rf_unweighted(t2, t3, "T")[1] print("t1 to t2 RF - " + str(round(d12, 2))) print("t1 to t3 RF - " + str(round(d13, 2))) print("t2 to t3 RF - " + str(round(d23, 2))) # Write out tree files readTree.write_single_tree(t1, '%s_starting_tree_1.tree' % name) readTree.write_single_tree(t2, '%s_starting_tree_2.tree' % name) readTree.write_single_tree(t3, '%s_starting_tree_3.tree' % name) # Write out log file rfs = str(d12) + ", " + str(d13) + ", " + str(d23) with open('%s.log' % name, "w") as log_file: line1 = "File name: " + str(name) line1b = "Tips: " + str(tips) + ", Trees per cloud: " + str(cloud_size) line2 = "Starting trees - RF_input: " + str( RF_norm_start) + "RF_input_far: " + str( RF_norm_start_far) + ", RF_calc: " + str( rfs) + ", NNI_moves: " + str( NNI_moves_start) + ", NNI_moves_far: " + str( NNI_moves_start_far) line3 = "Cloud of trees - RF_input: " + str( RF_norm_cloud) + ", NNI_moves: " + str(NNI_moves_cloud) log_file.write("%s\n%s\n%s" % (line1, line2, line3)) # Pass tree files to next function return t1, t2, t3
t1 = readTree.rand_tree(tips=tips, brl_avg=1, brl_std=None, verbose='F') # Calculate number of NNI moves based on desired normalized RF distance. RF_max = 2 * (tips - 2) NNI_moves_start = int((RF_max * RF_norm_start) / 2) if NNI_moves_start == 0: NNI_moves_start = 1 # Create second starting tree t2 = readTree.NNI_mult_moves(in_tree=t1, num_moves=NNI_moves_start, node_choice='random', no_dup_start_tree='F', req_min_RF=RF_norm_start) # Write out tree files readTree.write_single_tree(t1, '%s_starting_tree_1.tree' % name) readTree.write_single_tree(t2, '%s_starting_tree_2.tree' % name) ############################################################ # Make cluster of trees around each starting tree ############################################################ # Calculate number of NNI moves based on desired normalized RF distance. NNI_moves_cloud = int((RF_max * RF_norm_cloud) / 2) if NNI_moves_cloud == 0: NNI_moves_cloud = 1 # Make a cloud for each starting tree c_size = int(cloud_size) - 1 print("Making clouds...") # Make clouds