-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimsq.py
200 lines (182 loc) · 7.74 KB
/
limsq.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env python2
import argparse
import os
import commands
""" Var definition """
options_to_url = {"project" : "project__name=",
"subproject" : "subprojects__subproject_name=",
"pedigree" : "pedigree=",
"cohort" : "cohort__name=",
"sample" : "barcode=",
"SampleName" : "name=",
"aliquot" : "library__aliquot__aliquot_barcode=",
"library" : "library__name=",
"material" : "subprojects__sample_type__name=",
"flowcell" : "library__loadedwith__lane__flowcell__name=",
"lane" : "library__loadedwith__lane__lane=",
"index" : "library__multiplex_index__multiplex_index_name=",
"GenomeRef" : "library__loadedwith__mapping__reference_filename=",
"subprojectApplication" : "subprojects__application__name=",
"motherId" : "mother_id=",
"fatherId" : "father_id=",
"libraryGBS" : "library__gbs_index__multiplex_index_name=",
"mappingVersion" : "library__loadedwith__mapping__version=",
"mapperName" : "mapper=",
"mapperVersion" : "mapperversion="
}
options_to_url_QC={"libraryPassFail" : "library__passfail__status=",
"LanePassFail" : "library__loadedwith__passfail__status="}
lims_header = "project;subproject;id;SampleName;sample;library;SubprojectId;material;aliquot;flowcell;lane;index;libraryPassFail;LanePassFail;libApplication;Kit;Organism;Sex;pedigree;cohort;GenomeRef;SplitIndexcohort;SubprojectCov;motherId;fatherId;library__gbs_index__multiplex_index_name;readLength;sampleStatus;mappingVersion;mapperName;mapperVersion"
def main():
lims_url = "https://lims.cnag.cat/lims/lims_q_2/?"
options = get_options()
lims_url = generate_lims_query(lims_url,options,options_to_url)
lims_output = commands.getstatusoutput("wget -q -O- \""+ lims_url + "\" |sort|uniq|grep -v \"^#\"")[1].split("\n")
#For some reason lims doesn't allow me to query everything at once, with the filters so they have to be added one by one
lims_filtering_list = generate_filtering_list(lims_url, options)
print(lims_header)
for lims_out_line in lims_output:
if lims_out_line not in lims_filtering_list:
print(lims_out_line)
#Some strange characters are permitted which causes conflicts in the html ("#" for instance)
#Convert them to hex so all the options are now codified as hex ASCII
def text_fixer(character):
return("%"+str(hex(ord(character))).split("x")[1])
def generate_lims_query(lims_url, options, options_to_url):
for url_key in options_to_url.keys():
url_to_query = options_to_url[url_key]
value = getattr(options, url_key)
if value != None:
for query_value in value.split(","):
query_value = "".join(map(str,map(text_fixer,query_value)))
lims_url = add_to_lims_query(lims_url, url_to_query, query_value)
return(lims_url)
def generate_filtering_list(lims_url,options):
lims_filtering_list = list()
for url_key in options_to_url_QC.keys():
lims_url_QC = lims_url
url_to_query = options_to_url_QC[url_key]
value = getattr(options, url_key)
if value != None:
for query_value in value.split(","):
lims_url_QC = add_to_lims_query(lims_url_QC, url_to_query, query_value)
lims_filtering_list = lims_filtering_list + commands.getstatusoutput("wget -q -O- \""+ lims_url_QC + "\"")[1].split("\n")
return(lims_filtering_list)
def add_to_lims_query(lims_url, url_to_query, query_value):
lims_url = lims_url+"&"+url_to_query+query_value
return(lims_url)
def get_options():
parser = argparse.ArgumentParser()
parser.add_argument('-project',
'-p',
dest="project",
help="OPT CSV",
)
parser.add_argument('-subproject',
'-sp',
help="OPT CSV",
dest="subproject",
)
parser.add_argument('-pedigree',
'-ped',
help="OPT CSV",
dest="pedigree",
)
parser.add_argument('-cohort',
help="OPT CSV",
dest="cohort",
)
parser.add_argument('-sample',
'-s',
help="OPT CSV",
dest="sample",
)
parser.add_argument('-sampleName',
'-sn',
help="OPT CSV",
dest="SampleName",
)
parser.add_argument('-aliquot',
'-a',
help="OPT CSV",
dest="aliquot",
)
parser.add_argument('-library',
'-lib',
help="OPT CSV",
dest="library",
)
parser.add_argument('-material',
'-m',
help="OPT CSV",
dest="material",
)
parser.add_argument('-flowcell',
'-f',
help="OPT CSV",
dest="flowcell",
)
parser.add_argument('-lane',
'-l',
help="OPT CSV",
dest="lane",
)
parser.add_argument('-index',
'-i',
help="OPT CSV",
dest="index",
)
parser.add_argument('-genome',
'-g',
help="OPT CSV",
dest="GenomeRef",
)
parser.add_argument('-subprojectapplication',
'-spap',
help="OPT CSV",
dest="subprojectApplication",
)
parser.add_argument('-libpf',
'-libraryPassFail',
help="OPT CSV of library PassFail status to EXCLUDE",
dest="libraryPassFail",
)
parser.add_argument('-lanepf',
'-lanePassFail',
help="OPT CSV of lane PassFail status to EXCLUDE",
dest="LanePassFail",
)
parser.add_argument('-mother_id',
'-mid',
help="OPT CSV",
dest="motherId",
)
parser.add_argument('-father_id',
'-fid',
help="OPT CSV",
dest="fatherId",
)
parser.add_argument('-gbs_index',
'-gbs',
help="OPT CSV",
dest="libraryGBS",
)
parser.add_argument('-mappingVersion',
'-mV',
help="OPT CSV",
dest="mappingVersion",
)
parser.add_argument('-mapperName',
'-MN',
help="OPT CSV",
dest="mapperName",
)
parser.add_argument('-mapperVersion',
'-MV',
help="OPT CSV",
dest="mapperVersion",
)
options = parser.parse_args()
return options
if __name__ == "__main__":
exit(main())