annotate cravat_submit/cravat_submit.py @ 0:399f41a4bad6 draft

Uploaded
author in_silico
date Tue, 12 Jun 2018 11:05:20 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
1 import requests
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
2 import json
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
3 import time
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
4 import urllib
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
5 import sys
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
6 import csv
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
7 import pdb
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
8
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
9 input_filename = sys.argv[1]
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
10 input_select_bar = sys.argv[2]
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
11 output_filename = sys.argv[3]
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
12
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
13 #in_file = open('input_call.txt', "r")
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
14 #out_file = open('output_call.txt', "w")
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
15
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
16 write_header = True
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
17
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
18 #plugs in params to given URL
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
19 submit = requests.post('http://staging.cravat.us/CRAVAT/rest/service/submit', files={'inputfile':open(input_filename)}, data={'email':'znylund@insilico.us.com', 'analyses': input_select_bar})
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
20 #,'analysis':input_select_bar,'functionalannotation': "on"})
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
21 #Makes the data a json dictionary, takes out only the job ID
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
22 jobid = json.loads(submit.text)['jobid']
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
23 #out_file.write(jobid)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
24 submitted = json.loads(submit.text)['status']
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
25 #out_file.write('\t' + submitted)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
26
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
27 #loops until we find a status equal to Success, then breaks
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
28 while True:
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
29 check = requests.get('http://staging.cravat.us/CRAVAT/rest/service/status', params={'jobid': jobid})
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
30 status = json.loads(check.text)['status']
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
31 resultfileurl = json.loads(check.text)['resultfileurl']
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
32 #out_file.write(str(status) + ', ')
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
33 pdb.set_trace()
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
34 if status == 'Success':
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
35 #out_file.write('\t' + resultfileurl)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
36 break
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
37 else:
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
38 time.sleep(2)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
39
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
40 #out_file.write('\n')
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
41
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
42 #creates three files
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
43 file_1 = time.strftime("%H:%M") + '_Z_Variant_Result.tsv'
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
44 file_2 = time.strftime("%H:%M") + '_Z_Additional_Details.tsv'
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
45 file_3 = time.strftime("%H:%M") + 'Combined_Variant_Results.tsv'
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
46
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
47
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
48 #Download the two results
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
49 urllib.urlretrieve("http://staging.cravat.us/CRAVAT/results/" + jobid + "/" + "Variant.Result.tsv", file_1)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
50 urllib.urlretrieve("http://staging.cravat.us/CRAVAT/results/" + jobid + "/" + "Variant_Additional_Details.Result.tsv", file_2)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
51
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
52 headers = []
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
53 duplicates = []
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
54
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
55 #opens the Variant Result file and the Variant Additional Details file as csv readers, then opens the output file (galaxy) as a writer
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
56 with open(file_1) as tsvin_1, open(file_2) as tsvin_2, open(output_filename, 'wb') as tsvout:
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
57 tsvreader_1 = csv.reader(tsvin_1, delimiter='\t')
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
58 tsvreader_2 = csv.reader(tsvin_2, delimiter='\t')
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
59 tsvout = csv.writer(tsvout, delimiter='\t')
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
60
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
61 #loops through each row in the Variant Additional Details file
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
62 for row in tsvreader_2:
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
63 #sets row_2 equal to the same row in Variant Result file
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
64 row_2 = tsvreader_1.next()
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
65 #checks if row is empty or if the first term contains '#'
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
66 if row == [] or row[0][0] == '#':
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
67 continue
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
68 #checks if the row begins with input line
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
69 if row[0] == 'Input line':
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
70 #Goes through each value in the headers list in VAD
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
71 for value in row:
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
72 #Adds each value into headers
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
73 headers.append(value)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
74 #Loops through the Keys in VR
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
75 for value in row_2:
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
76 #Checks if the value is already in headers
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
77 if value in headers:
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
78 continue
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
79 #else adds the header to headers
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
80 else:
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
81 headers.append(value)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
82
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
83 print headers
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
84 tsvout.writerow(headers)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
85
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
86
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
87 else:
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
88
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
89 cells = []
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
90 #Goes through each value in the next list
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
91 for value in row:
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
92 #adds it to cells
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
93 cells.append(value)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
94 #Goes through each value from the VR file after position 11 (After it is done repeating from VAD file)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
95 for value in row_2[11:]:
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
96 #adds in the rest of the values to cells
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
97 cells.append(value)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
98
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
99 print cells
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
100 tsvout.writerow(cells)
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
101
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
102
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
103
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
104
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
105
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
106
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
107
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
108
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
109
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
110
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
111
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
112
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
113
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
114
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
115
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
116
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
117
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
118
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
119
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
120
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
121
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
122
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
123
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
124 #a = 'col1\tcol2\tcol3'
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
125 #header_list = a.split('\t')
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
126
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
127 #loop through the two results, when you first hit header you print out the headers in tabular form
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
128 #Print out each header only once
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
129 #Combine both headers into one output file
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
130 #loop through the rest of the data and assign each value to its assigned header
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
131 #combine this all into one output file
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
132
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
133
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
134
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
135
399f41a4bad6 Uploaded
in_silico
parents:
diff changeset
136