if (flag==0):#### this means that the leaf has not neighbors at one node of dist
if (flag==0):#### this means that the leaf has no neighbors at one node of dist
parent=parent.up#### therefore I climb the tree down towards the root of one more step and look for leaves
multi_flag=0
ifarguments.verbose==3:
...
...
@@ -78,7 +78,7 @@ def find_N(t,leaf):
print"gran parent"
printparent
temp_dlist={}
forninrange(0,len(parent.get_children())):#this for loop start from grean parent and climb up max one nodes, if it finds leaves calculate the distances,
forninrange(0,len(parent.get_children())):#this for loop start from gran parent and climb up max one nodes, if it finds leaves calculate the distances,
ifparent.is_root():
break
if (parent.children[n].is_leaf()):
...
...
@@ -108,7 +108,7 @@ def find_leaf_to_prune(dlist): #parse the list with all neighbor pairs and d
parser.add_argument('-RTL','--stop_at_RTL',metavar='0-1',default='0',help='stop pruning when the relative tree length falls below RTL',type=restricted_float,nargs='?')
parser.add_argument('-r','--resolution',metavar='INT',default=1,help='number of leaves to prune at each iteration (default: 1)',type=int,nargs='?')
parser.add_argument('-p','--solve_polytomies',help='resolve polytomies at random (default: FALSE)',action='store_true',default=False)
parser.add_argument('-pr','--random',help='prune random leaves (default: FALSE)',action='store_true',default=False)
parser.add_argument('-lp','--leaves_pair',metavar='0,1,2',default=2,help='After the pair of leaves with the smallest distance is dentified Treemmer prunes: 0: the longest leaf\n1: the shortest leaf\n2: random choice (default)',type=int,nargs='?')
parser.add_argument('-pr','--prune_random',help='prune random leaves (default: FALSE)',action='store_true',default=False)
parser.add_argument('-lp','--leaves_pair',metavar='0,1,2',default=2,help='After the pair of leaves with the smallest distance is dentified Treemmer prunes: 0: the longest leaf\n1: the shortest leaf\n2: random choice (default: 2)',type=int,nargs='?')
parser.add_argument('-np','--no_plot',help='do not load matplotlib and plot (default: FALSE)',action='store_true',default=False)
parser.add_argument('-fp','--fine_plot',help='when --resolution > 1, plot RTL vs n leaves every time a leaf is pruned (default: FALSE => plot every X leaves (X = -r))',action='store_true',default=False)
parser.add_argument('-c','--cpu',metavar='INT',default=1,help='number of cpu to use (default: 1)',type=int,nargs='?')
parser.add_argument('-v','--verbose',metavar='0,1,2',default='0',help='0: silent, 1: show progress, 2: print tree at each iteration, 3: only for testing (findN), 4: only for testing (prune_t) (default: 1)',type=int,nargs='?',choices=[0,1,2,3,4])
parser.add_argument('-v','--verbose',metavar='0,1,2',default='1',help='0: silent, 1: show progress, 2: print tree at each iteration, 3: only for testing (findN), 4: only for testing (prune_t) (default: 1)',type=int,nargs='?',choices=[0,1,2,3,4])
arguments=parser.parse_args()
if ((arguments.stop_at_RTL>0)and(arguments.stop_at_X_leaves>0)):
raiseargparse.ArgumentTypeError("-X and -RTL are mutually exclusive arguments")
raiseargparse.ArgumentTypeError("-X and -RTL are mutually exclusive options")
...
...
@@ -262,14 +256,15 @@ ori_length = len(t)
ifarguments.solve_polytomies:
t.resolve_polytomy()
ifarguments.verbose>0:
ifarguments.verbose>0:# print progress on standard output
print"N of taxa in tree is : "+str(len(t))
ifarguments.solve_polytomies:
print"\nPolytomies will be solved at random"
else:
print"\nPolytomies will be kept"
ifarguments.prune_random:
print"\nA random leaf is pruned at each iteration, you don't really need Treemmer to do this"
ifarguments.stop_at_X_leaves:
print"\nTreemmer will reduce the tree to"+str(arguments.stop_at_X_leaves)+" leaves"
else:
...
...
@@ -283,7 +278,16 @@ if arguments.verbose > 0:
x=[]
y=[]
while (len(t)>3):
output.append ('1 '+str(len(t)))#append first point to the output with RTL = 1 (before starting pruning)################################
length=len(t)
x.append(length)
y.append(1)
while (len(t)>3):#################### Main loop ################################