annotate saint_wrapper.py @ 26:bb1601260366 draft

Uploaded
author bornea
date Thu, 28 Jan 2016 16:31:19 -0500
parents
children b7e5a9bfa620
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
bb1601260366 Uploaded
bornea
parents:
diff changeset
1 #######################################################################################
bb1601260366 Uploaded
bornea
parents:
diff changeset
2 # Python-code: SAINT wrapper
bb1601260366 Uploaded
bornea
parents:
diff changeset
3 # Author: Adam L Borne
bb1601260366 Uploaded
bornea
parents:
diff changeset
4 # Contributers: Paul A Stewart, Brent Kuenzi
bb1601260366 Uploaded
bornea
parents:
diff changeset
5 #######################################################################################
bb1601260366 Uploaded
bornea
parents:
diff changeset
6 # This program takes a bait, prey and interactions file and uses SaintExpress to
bb1601260366 Uploaded
bornea
parents:
diff changeset
7 # generate resulting matrices. This allows the software to run within galaxy.
bb1601260366 Uploaded
bornea
parents:
diff changeset
8 #######################################################################################
bb1601260366 Uploaded
bornea
parents:
diff changeset
9 # Copyright (C) Adam Borne.
bb1601260366 Uploaded
bornea
parents:
diff changeset
10 # Permission is granted to copy, distribute and/or modify this document
bb1601260366 Uploaded
bornea
parents:
diff changeset
11 # under the terms of the GNU Free Documentation License, Version 1.3
bb1601260366 Uploaded
bornea
parents:
diff changeset
12 # or any later version published by the Free Software Foundation;
bb1601260366 Uploaded
bornea
parents:
diff changeset
13 # with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
bb1601260366 Uploaded
bornea
parents:
diff changeset
14 # A copy of the license is included in the section entitled "GNU
bb1601260366 Uploaded
bornea
parents:
diff changeset
15 # Free Documentation License".
bb1601260366 Uploaded
bornea
parents:
diff changeset
16 #######################################################################################
bb1601260366 Uploaded
bornea
parents:
diff changeset
17 ## REQUIRED INPUT ##
bb1601260366 Uploaded
bornea
parents:
diff changeset
18
bb1601260366 Uploaded
bornea
parents:
diff changeset
19 # 1) inter_file: Interaction file listing experiment bait, assignement, gene name and
bb1601260366 Uploaded
bornea
parents:
diff changeset
20 # spectrum count.
bb1601260366 Uploaded
bornea
parents:
diff changeset
21 # 2) prey_file: Prey file listing gene name, sequence legnth, and gene id.
bb1601260366 Uploaded
bornea
parents:
diff changeset
22 # 3) bait_file: Bait file listing bait experiment, assignment, and T or C.
bb1601260366 Uploaded
bornea
parents:
diff changeset
23 # 4) vc_bool: Boolean used to determine if virtual controls are being used.
bb1601260366 Uploaded
bornea
parents:
diff changeset
24 # 5) vc_num: Number of virtual controls to be used. (default = 1)
bb1601260366 Uploaded
bornea
parents:
diff changeset
25 # 6) go_bool: Boolean used to determine used of external data set.
bb1601260366 Uploaded
bornea
parents:
diff changeset
26 # 7) go_file: External data file if being used. (default = "None")
bb1601260366 Uploaded
bornea
parents:
diff changeset
27 #######################################################################################
bb1601260366 Uploaded
bornea
parents:
diff changeset
28 import os
bb1601260366 Uploaded
bornea
parents:
diff changeset
29 import sys
bb1601260366 Uploaded
bornea
parents:
diff changeset
30
bb1601260366 Uploaded
bornea
parents:
diff changeset
31 inter_file = sys.argv[1]
bb1601260366 Uploaded
bornea
parents:
diff changeset
32 prey_file = sys.argv[2]
bb1601260366 Uploaded
bornea
parents:
diff changeset
33 bait_file = sys.argv[3]
bb1601260366 Uploaded
bornea
parents:
diff changeset
34 num_of_rep = sys.argv[4]
bb1601260366 Uploaded
bornea
parents:
diff changeset
35 vc_bool = sys.argv[5]
bb1601260366 Uploaded
bornea
parents:
diff changeset
36 vc_num = sys.argv[6]
bb1601260366 Uploaded
bornea
parents:
diff changeset
37 go_bool = sys.argv[7]
bb1601260366 Uploaded
bornea
parents:
diff changeset
38 go_file = sys.argv[8]
bb1601260366 Uploaded
bornea
parents:
diff changeset
39 output_file = sys.argv[9]
bb1601260366 Uploaded
bornea
parents:
diff changeset
40 ins_path = sys.argv[10]
bb1601260366 Uploaded
bornea
parents:
diff changeset
41
bb1601260366 Uploaded
bornea
parents:
diff changeset
42 # Verifies the install of SaintExpress and installs if not found.
bb1601260366 Uploaded
bornea
parents:
diff changeset
43 def first_run_check():
bb1601260366 Uploaded
bornea
parents:
diff changeset
44 os.chdir(ins_path)
bb1601260366 Uploaded
bornea
parents:
diff changeset
45 dirs_list = []
bb1601260366 Uploaded
bornea
parents:
diff changeset
46 for (dirpath, dirnames, filename) in os.walk("./"):
bb1601260366 Uploaded
bornea
parents:
diff changeset
47 dirs_list.extend(dirnames)
bb1601260366 Uploaded
bornea
parents:
diff changeset
48 break
bb1601260366 Uploaded
bornea
parents:
diff changeset
49 if r"SAINTexpress_v3.6.1__2015-05-03" in dirs_list:
bb1601260366 Uploaded
bornea
parents:
diff changeset
50 pass
bb1601260366 Uploaded
bornea
parents:
diff changeset
51 else:
bb1601260366 Uploaded
bornea
parents:
diff changeset
52 cmd = r"unzip SAINTexpress_v3.6.1__2015-05-03.zip"
bb1601260366 Uploaded
bornea
parents:
diff changeset
53 os.system(cmd)
bb1601260366 Uploaded
bornea
parents:
diff changeset
54 os.chdir("./SAINTexpress_v3.6.1__2015-05-03")
bb1601260366 Uploaded
bornea
parents:
diff changeset
55 cmd1 = r"make -j"
bb1601260366 Uploaded
bornea
parents:
diff changeset
56 os.system(cmd1)
bb1601260366 Uploaded
bornea
parents:
diff changeset
57
bb1601260366 Uploaded
bornea
parents:
diff changeset
58 def default_run(inter_file1,prey_file1,bait_file1,output_file1,num_of_rep1):
bb1601260366 Uploaded
bornea
parents:
diff changeset
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)
bb1601260366 Uploaded
bornea
parents:
diff changeset
60 os.system(cmd)
bb1601260366 Uploaded
bornea
parents:
diff changeset
61 open('list.txt')
bb1601260366 Uploaded
bornea
parents:
diff changeset
62 os.rename('list.txt', str(output_file1))
bb1601260366 Uploaded
bornea
parents:
diff changeset
63
bb1601260366 Uploaded
bornea
parents:
diff changeset
64 def with_L(inter_file1,prey_file1,bait_file1,output_file1,vc_num1,num_of_rep1):
bb1601260366 Uploaded
bornea
parents:
diff changeset
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)
bb1601260366 Uploaded
bornea
parents:
diff changeset
66 os.system(cmd)
bb1601260366 Uploaded
bornea
parents:
diff changeset
67 open('list.txt')
bb1601260366 Uploaded
bornea
parents:
diff changeset
68 os.rename('list.txt', str(output_file1))
bb1601260366 Uploaded
bornea
parents:
diff changeset
69
bb1601260366 Uploaded
bornea
parents:
diff changeset
70 def external_data_no_L(inter_file1,prey_file1,bait_file1,output_file1,go_file1,num_of_rep1):
bb1601260366 Uploaded
bornea
parents:
diff changeset
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)
bb1601260366 Uploaded
bornea
parents:
diff changeset
72 os.system(cmd)
bb1601260366 Uploaded
bornea
parents:
diff changeset
73 open('list.txt')
bb1601260366 Uploaded
bornea
parents:
diff changeset
74 os.rename('list.txt', str(output_file1))
bb1601260366 Uploaded
bornea
parents:
diff changeset
75
bb1601260366 Uploaded
bornea
parents:
diff changeset
76 def external_data_with_L(inter_file1,prey_file1,bait_file1,output_file1,go_file1,num_of_rep1,vc_num1):
bb1601260366 Uploaded
bornea
parents:
diff changeset
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)
bb1601260366 Uploaded
bornea
parents:
diff changeset
78 os.system(cmd)
bb1601260366 Uploaded
bornea
parents:
diff changeset
79 open('list.txt')
bb1601260366 Uploaded
bornea
parents:
diff changeset
80 os.rename('list.txt', str(output_file1))
bb1601260366 Uploaded
bornea
parents:
diff changeset
81
bb1601260366 Uploaded
bornea
parents:
diff changeset
82 first_run_check()
bb1601260366 Uploaded
bornea
parents:
diff changeset
83 if (vc_bool == "true"):
bb1601260366 Uploaded
bornea
parents:
diff changeset
84 if (go_bool == "false"):
bb1601260366 Uploaded
bornea
parents:
diff changeset
85 with_L(inter_file, prey_file, bait_file, output_file, vc_num, num_of_rep)
bb1601260366 Uploaded
bornea
parents:
diff changeset
86 elif (go_bool == "true"):
bb1601260366 Uploaded
bornea
parents:
diff changeset
87 external_data_with_L(inter_file, prey_file, bait_file, output_file, go_file, num_of_rep, vc_num)
bb1601260366 Uploaded
bornea
parents:
diff changeset
88 elif (vc_bool == "false"):
bb1601260366 Uploaded
bornea
parents:
diff changeset
89 if (go_bool == "false"):
bb1601260366 Uploaded
bornea
parents:
diff changeset
90 default_run(inter_file, prey_file, bait_file, output_file, num_of_rep)
bb1601260366 Uploaded
bornea
parents:
diff changeset
91 elif (go_bool == "true"):
bb1601260366 Uploaded
bornea
parents:
diff changeset
92 external_data_no_L(inter_file, prey_file, bait_file, output_file, go_file, num_of_rep)