comparison saint_wrapper.py @ 28:b7e5a9bfa620 draft

Uploaded
author bornea
date Thu, 28 Jan 2016 16:32:34 -0500
parents bb1601260366
children bec1c735fe96
comparison
equal deleted inserted replaced
27:8f6b0b0b242c 28:b7e5a9bfa620
1 ####################################################################################### 1 #######################################################################################
2 # Python-code: SAINT wrapper 2 # Python-code: Dotplot Runner
3 # Author: Adam L Borne 3 # Author: Adam L Borne
4 # Contributers: Paul A Stewart, Brent Kuenzi 4 # Contributers: Paul A Stewart, Brent Kuenzi
5 ####################################################################################### 5 #######################################################################################
6 # This program takes a bait, prey and interactions file and uses SaintExpress to 6 # This runs SAINTexpress found at http://saint-apms.sourceforge.net/Main.html in
7 # generate resulting matrices. This allows the software to run within galaxy. 7 # galaxy.
8 ####################################################################################### 8 #######################################################################################
9 # Copyright (C) Adam Borne. 9 # Copyright (C) Adam Borne.
10 # Permission is granted to copy, distribute and/or modify this document 10 # Permission is granted to copy, distribute and/or modify this document
11 # under the terms of the GNU Free Documentation License, Version 1.3 11 # under the terms of the GNU Free Documentation License, Version 1.3
12 # or any later version published by the Free Software Foundation; 12 # or any later version published by the Free Software Foundation;
14 # A copy of the license is included in the section entitled "GNU 14 # A copy of the license is included in the section entitled "GNU
15 # Free Documentation License". 15 # Free Documentation License".
16 ####################################################################################### 16 #######################################################################################
17 ## REQUIRED INPUT ## 17 ## REQUIRED INPUT ##
18 18
19 # 1) inter_file: Interaction file listing experiment bait, assignement, gene name and 19 # 1) list_file: SaintExpress output file.
20 # spectrum count. 20 # 2) FDR1: Primary false discovery rate. (default = 0.01)
21 # 2) prey_file: Prey file listing gene name, sequence legnth, and gene id. 21 # 3) FDR2: Secondary false discovery rate. (default = 0.025)
22 # 3) bait_file: Bait file listing bait experiment, assignment, and T or C. 22 # 4) spec_max: Maximum spectral count. (default = 50)
23 # 4) vc_bool: Boolean used to determine if virtual controls are being used.
24 # 5) vc_num: Number of virtual controls to be used. (default = 1)
25 # 6) go_bool: Boolean used to determine used of external data set.
26 # 7) go_file: External data file if being used. (default = "None")
27 ####################################################################################### 23 #######################################################################################
24
25
28 import os 26 import os
29 import sys 27 import sys
28
30 29
31 inter_file = sys.argv[1] 30 inter_file = sys.argv[1]
32 prey_file = sys.argv[2] 31 prey_file = sys.argv[2]
33 bait_file = sys.argv[3] 32 bait_file = sys.argv[3]
34 num_of_rep = sys.argv[4] 33 num_of_rep = sys.argv[4]
37 go_bool = sys.argv[7] 36 go_bool = sys.argv[7]
38 go_file = sys.argv[8] 37 go_file = sys.argv[8]
39 output_file = sys.argv[9] 38 output_file = sys.argv[9]
40 ins_path = sys.argv[10] 39 ins_path = sys.argv[10]
41 40
42 # Verifies the install of SaintExpress and installs if not found.
43 def first_run_check():
44 os.chdir(ins_path)
45 dirs_list = []
46 for (dirpath, dirnames, filename) in os.walk("./"):
47 dirs_list.extend(dirnames)
48 break
49 if r"SAINTexpress_v3.6.1__2015-05-03" in dirs_list:
50 pass
51 else:
52 cmd = r"unzip SAINTexpress_v3.6.1__2015-05-03.zip"
53 os.system(cmd)
54 os.chdir("./SAINTexpress_v3.6.1__2015-05-03")
55 cmd1 = r"make -j"
56 os.system(cmd1)
57 41
58 def default_run(inter_file1,prey_file1,bait_file1,output_file1,num_of_rep1): 42 def first_run_check():
59 cmd = str(ins_path) + r"/SAINTexpress_v3.6.1__2015-05-03/bin/SAINTexpress-spc " + r"-R" + str(num_of_rep1) + " " + str(inter_file1) + " " + str(prey_file1) + " " + str(bait_file1) 43 dirs_list = []
60 os.system(cmd) 44 for (dirpath, dirnames, filename) in os.walk("./"):
61 open('list.txt') 45 dirs_list.extend(dirnames)
62 os.rename('list.txt', str(output_file1)) 46 break
47 if r"SAINTexpress_v3.6.1__2015-05-03" in dirs_list:
48 pass
49 else:
50 cmd = r"unzip SAINTexpress_v3.6.1__2015-05-03.zip"
51 os.system(cmd)
52 os.chdir("./SAINTexpress_v3.6.1__2015-05-03")
53 cmd1 = r"make -j"
54 os.system(cmd1)
63 55
64 def with_L(inter_file1,prey_file1,bait_file1,output_file1,vc_num1,num_of_rep1):
65 cmd = str(ins_path) + r"/SAINTexpress_v3.6.1__2015-05-03/bin/SAINTexpress-spc "+ r"-R" + str(num_of_rep1) + " " + r"-L" + str(vc_num1) + " " + str(inter_file1) + " " + str(prey_file1) + " " + str(bait_file1)
66 os.system(cmd)
67 open('list.txt')
68 os.rename('list.txt', str(output_file1))
69 56
70 def external_data_no_L(inter_file1,prey_file1,bait_file1,output_file1,go_file1,num_of_rep1): 57 def default_run(inter_file1, prey_file1, bait_file1, output_file1, num_of_rep1):
71 cmd = str(ins_path) + r"/SAINTexpress_v3.6.1__2015-05-03/bin/SAINTexpress-spc "+ r"-R" + str(num_of_rep1) + " " + str(inter_file1) + " " + str(prey_file1) + " " + str(bait_file1) + " " + str(go_file1) 58 # Default is no virtual controls through purification and set replicates number.
72 os.system(cmd) 59 cmd = (str(ins_path) + r"/SAINTexpress_v3.6.1__2015-05-03/bin/SAINTexpress-spc " + r"-R"
73 open('list.txt') 60 + str(num_of_rep1) + " " + str(inter_file1) + " " + str(prey_file1) +
74 os.rename('list.txt', str(output_file1)) 61 " " + str(bait_file1))
62 os.system(cmd)
63 open('list.txt')
64 os.rename('list.txt', str(output_file1))
75 65
76 def external_data_with_L(inter_file1,prey_file1,bait_file1,output_file1,go_file1,num_of_rep1,vc_num1):
77 cmd = str(ins_path) + r"/SAINTexpress_v3.6.1__2015-05-03/bin/SAINTexpress-spc "+ r"-R" + str(num_of_rep1) + " " + r"-L" + str(vc_num1) + " " + str(inter_file1) + " " + str(prey_file1) + " " + str(bait_file1) + " " + str(go_file1)
78 os.system(cmd)
79 open('list.txt')
80 os.rename('list.txt', str(output_file1))
81 66
82 first_run_check() 67 def with_L(inter_file1, prey_file1, bait_file1, output_file1, vc_num1, num_of_rep1):
83 if (vc_bool == "true"): 68 # L is the flag for Virtual Controls through Purification.
84 if (go_bool == "false"): 69 cmd = (str(ins_path) + r"/SAINTexpress_v3.6.1__2015-05-03/bin/SAINTexpress-spc "+ r"-R"
85 with_L(inter_file, prey_file, bait_file, output_file, vc_num, num_of_rep) 70 + str(num_of_rep1) + " " + r"-L" + str(vc_num1) + " " + str(inter_file1) + " " +
86 elif (go_bool == "true"): 71 str(prey_file1) + " " + str(bait_file1))
87 external_data_with_L(inter_file, prey_file, bait_file, output_file, go_file, num_of_rep, vc_num) 72 os.system(cmd)
88 elif (vc_bool == "false"): 73 open('list.txt')
89 if (go_bool == "false"): 74 os.rename('list.txt', str(output_file1))
90 default_run(inter_file, prey_file, bait_file, output_file, num_of_rep) 75
91 elif (go_bool == "true"): 76
92 external_data_no_L(inter_file, prey_file, bait_file, output_file, go_file, num_of_rep) 77 def external_data_no_L(inter_file1, prey_file1, bait_file1, output_file1, go_file1, num_of_rep1):
78 # Uses external data in the GO file format and no Virtual Controls.
79 cmd = (str(ins_path) + r"/SAINTexpress_v3.6.1__2015-05-03/bin/SAINTexpress-spc "+ r"-R"
80 + str(num_of_rep1) + " " + str(inter_file1) + " " + str(prey_file1) + " " +
81 str(bait_file1) + " " + str(go_file1))
82 os.system(cmd)
83 open('list.txt')
84 os.rename('list.txt', str(output_file1))
85
86
87 def external_data_with_L(inter_file1, prey_file1, bait_file1, output_file1, go_file1, num_of_rep1, vc_num1):
88 # Uses external data in the GO file format and Virtual Controls.
89 cmd = (str(ins_path) + r"/SAINTexpress_v3.6.1__2015-05-03/bin/SAINTexpress-spc "+ r"-R"
90 + str(num_of_rep1) + " " + r"-L" + str(vc_num1) + " " + str(inter_file1) + " " +
91 str(prey_file1) + " " + str(bait_file1) + " " + str(go_file1))
92 os.system(cmd)
93 open('list.txt')
94 os.rename('list.txt', str(output_file1))
95
96
97 first_run_check()
98 if vc_bool == "true":
99 if go_bool == "false":
100 with_L(inter_file, prey_file, bait_file, output_file, vc_num, num_of_rep)
101 elif go_bool == "true":
102 external_data_with_L(inter_file, prey_file, bait_file, output_file, go_file, num_of_rep, vc_num)
103 elif vc_bool == "false":
104 if go_bool == "false":
105 default_run(inter_file, prey_file, bait_file, output_file, num_of_rep)
106 elif go_bool == "true":
107 external_data_no_L(inter_file, prey_file, bait_file, output_file, go_file, num_of_rep)