-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRunTribeMCL.py
88 lines (60 loc) · 3.05 KB
/
RunTribeMCL.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#Created on 1/31/2015
__author__ = 'Juan A. Ugalde'
import os
import argparse
program_description = "This script will run a TribeMCL analysis, using MCL and iterating over a series of different" \
"inflation values (if requested)"
parser = argparse.ArgumentParser(description=program_description)
parser.add_argument("-o", "--output_directory", type=str, required=True)
parser.add_argument("-b", "--input_blast", type=str, required=True, help="Input BLAST file, tabular format")
parser.add_argument("-i", "--iteration", action="store_true", help="If this flag is used, the FastOrtho will be run"
"with several inflation values for testing. "
"The output will also be a table and a plot showing"
"the number of clusters found at different inflation"
"values")
parser.add_argument("-t", "--threads", type=int, help="Number of threads to use for MCL")
args = parser.parse_args()
#Create the output directory
if not os.path.exists(args.output_directory):
os.makedirs(args.output_directory)
#Create an option file. If the iteration flag is not set, we will use the default value of 1.5
#After creation, run FastOrtho
#Move to the output directory
#os.chdir(args.output_directory)
threads = 1
if args.threads:
threads = args.threads
#Run FastOrtho
#Run TribeMCL
abc_file = args.output_directory + "/seq.abc"
tab_file = args.output_directory + "/seq.tab"
mci_file = args.output_directory + "/seq.mci"
make_abc_file = "cut -f 1,2,11 " + args.input_blast + " > " + abc_file
run_mcxload = "mcxload -abc " + abc_file + " --stream-mirror --stream-neg-log10 -stream-tf 'ceil(200)' -o " \
+ mci_file + " -write-tab " + tab_file
os.system(make_abc_file)
os.system(run_mcxload)
if not args.iteration:
output_file = args.output_directory + "/out.seq.mci.I.1.4"
run_mcl = "mcl " + mci_file + " -I 1.4 -te " + str(threads) + " -o " + output_file + " -use-tab " + tab_file
os.system(run_mcl)
#Create an option file with iteration. The range will go from 1 to 10, in 0.5 intervals. This could
#change, depending on some results.
else:
i = 1.1
cluster_inflation = []
while i < 5.1:
output_file = args.output_directory + "/out.seq.mci.I" + str(i)
run_mcl = "mcl " + mci_file + " -I " + str(i) + " -te " + str(threads) + \
" -o " + output_file + " -use-tab " + tab_file
os.system(run_mcl)
#Count number of clusters
number_cluster = 0
with open(output_file) as f:
number_cluster = sum(1 for _ in f)
cluster_inflation.append([i, number_cluster])
i += 0.1
cluster_data = open(args.output_directory + "/Inflation_ClusterSize.txt", 'w')
for value in cluster_inflation:
cluster_data.write(str(value[0]) + "\t" + str(value[1]) + "\n")
cluster_data.close()