Skip to content
Snippets Groups Projects
Commit a0e90ff6 authored by Menardo Fabrizio's avatar Menardo Fabrizio
Browse files

implemented_plot

parent 6a334ff0
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,6 @@ import argparse
############################################################ define arg type float 0 < X > 1 ###############################################################
......@@ -214,6 +213,11 @@ def write_stop(t,output1,output2):
F=open(output2,"w")
F.write("\n".join(list_names))
F.close()
########################################## PLOT tree length decay #######################
......@@ -230,7 +234,7 @@ parser.add_argument('-r','--resolution', metavar='INT', default=1,help='number o
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('-p','--solve_polytomies',help='resolve polytmies at random (default: FALSE)',action='store_true',default =False)
### yet to implemen
parser.add_argument('-np','--no_plot',help='do not load matplotlib and plot (default: FALSE)',action='store_true',default =False)
parser.add_argument('-X','--stop_at_X_leaves', metavar='0-n_leaves', default='0', help='stop pruning when the number of leaves fall below X (integer)', type =int, nargs='?')
parser.add_argument('-RTL','--stop_at_RTL', metavar='0-1', default='0', help='stop pruning when the relative tree length falls below RTL (decimal number between 0 and 1)', type =restricted_float,nargs='?')
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='?')
......@@ -252,7 +256,7 @@ stop=0
TOT_TL=calculate_TL(t)
TL=TOT_TL
ori_length = len(t)
if arguments.solve_polytomies:
t.resolve_polytomy()
......@@ -274,7 +278,8 @@ if arguments.verbose > 0:
print "\nTreemmer will prune " + str(arguments.resolution) + " leaves at each iteration"
print "\nTreemmer will use " + str(arguments.cpu) + " cpu(s)"
x=[]
y=[]
while (len(t) > 3):
counter = counter +1
......@@ -340,6 +345,10 @@ while (len(t) > 3):
break
output.append (str(rel_TL) + ' ' + str(len(t)))
length=len(t)
x.append(length)
y.append(rel_TL)
if arguments.verbose==1:
print "\nRTL : " + str(rel_TL) + " N_seq: " +str(len(t))
......@@ -349,7 +358,22 @@ while (len(t) > 3):
if stop == 0:
F=open(arguments.INFILE+"_res_"+ str(arguments.resolution) + "_LD","w")
F.write("\n".join(output))
if not arguments.no_plot:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
ax = plt.figure().gca()
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
plt.scatter(x, y, s= 2, c= 'black')
plt.xlim(ori_length, 3)
plt.ylim(0,1.1)
plt.xlabel('Number of leaves')
plt.ylabel('Relative tree length')
plt.savefig(arguments.INFILE+'_TLD.png')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment