4
4
Hillary Elrick, September 9th, 2019
5
5
6
6
Class for getting user input to perform a guide search. Given URL variables, returns appropriate HTML page results.
7
- Prints template for guide searching as well as AJAX calls to the GuideSearchAndScore.py program which is displayed the
7
+ Prints template for guide searching as well as AJAX calls to the GuideSearchAndScore.py program which is displayed the
8
8
results section of the HTML template.
9
9
10
10
Requires: initial searchLocation and genome
@@ -41,7 +41,7 @@ def __init__(self, **kwargs):
41
41
self .sendErrorHTML ("Invalid action string sent: " + str (kwargs ['action' ]))
42
42
else :
43
43
self .action = kwargs ['action' ]
44
-
44
+
45
45
if self .action in ['initialize' , 'update_input' ]:
46
46
# validate searchInput
47
47
if 'searchInput' not in kwargs :
@@ -84,8 +84,8 @@ def __init__(self, **kwargs):
84
84
def inputRowHTML (self ):
85
85
""" rebuild the form row for the input region and target gene and return it """
86
86
template_values = {
87
- 'search_location' : self .getInputHTML (),
88
- 'available_genes' : self .getOverlappingGenesHTML ()
87
+ 'search_location' : self .getInputHTML (),
88
+ 'available_genes' : self .getOverlappingGenesHTML ()
89
89
}
90
90
template_path = os .path .join (self .dbConnection .ROOT_PATH , "src/guide-finder/jinja2-templates/input_region.html" )
91
91
region_template = Template (open (template_path , 'rb' ).read ().decode ('utf-8' ))
@@ -107,25 +107,25 @@ def initialHTML(self):
107
107
return html_result
108
108
109
109
def sendErrorHTML (self , errorString ):
110
- """ format exceptions in HTML to prevent page from crashing """
110
+ """ format exceptions in HTML to prevent page from crashing """
111
111
if not hasattr (self , 'dbConnection' ):
112
112
self .dbConnection = Config ()
113
- template_path = os .path .join (self .dbConnection .ROOT_PATH , "GuideFinder/ templates/error.html" )
113
+ template_path = os .path .join (self .dbConnection .ROOT_PATH , "src/guide-finder/jinja2- templates/error.html" )
114
114
error_template = Template (open (template_path , 'rb' ).read ().decode ('utf-8' ))
115
115
html_result = error_template .render (errorString = errorString )
116
116
print (html_result )
117
117
sys .exit ()
118
-
118
+
119
119
def getOrganismHTML (self ):
120
120
""" convert underscored org database string to HTML with italicization """
121
121
org = self .dbConnection .organismName
122
122
org = org .replace ("_" ," " ).capitalize ()
123
- HTML = "<i>{org}</i> ({genome})" .format (org = org , genome = self .genome )
123
+ HTML = "<i>{org}</i> ({genome})" .format (org = org , genome = self .genome )
124
124
return HTML
125
-
125
+
126
126
def getOverlappingGenesHTML (self ):
127
127
""" Format the overlapped genes into a selection dropdown or text input if no overlap """
128
-
128
+
129
129
# prevent displaying all genes overlapped in case of large input sequence
130
130
if len (self .overlappedGenes ) < 20 and len (self .overlappedGenes ) > 0 :
131
131
HTML = "<select class='form-control' id='gene' required>"
@@ -135,20 +135,20 @@ def getOverlappingGenesHTML(self):
135
135
HTML += "<option value selected='selected'></option>"
136
136
for gene in self .overlappedGenes :
137
137
HTML += "<option value='{gene}'>{gene}</option>" .format (gene = gene )
138
-
139
- HTML += "</select>"
138
+
139
+ HTML += "</select>"
140
140
else :
141
141
HTML = "<input class='form-control' id='gene' type='text' required>"
142
142
143
143
return HTML
144
-
144
+
145
145
def getRgenHTML (self ):
146
146
""" returns the available rgens in a preformmatted HTML select tag """
147
147
HTML = '<select class="form-control" id="RGENS" onchange="getProtospacerLengths()">'
148
148
for rgen in self .dbConnection .rgenCollection .find ().sort ([("rgenID" ,1 )]):
149
149
HTML += '<option value="{rgenID}">{Shortform}</option>' .format_map (rgen )
150
150
HTML += "</select>"
151
-
151
+
152
152
return HTML
153
153
154
154
def getLengthsHTML (self ):
@@ -192,18 +192,18 @@ def getRegionLength(self):
192
192
length = abs (int (start )- int (end ))
193
193
except Exception as e :
194
194
return "N/A"
195
- return length
195
+ return length
196
196
197
197
def getOverlappingGenes (self ):
198
- """ using Teja's query to find genes in the mongodb that overlap the search input """
198
+ """ using Teja's query to find genes in the mongodb that overlap the search input """
199
199
try :
200
200
chm , start , end = re .search (r"(chr.+?):(\d+)\-(\d+)" , self .searchInput ).groups ()
201
201
except Exception as e :
202
202
return ["Invalid Input Sequence" ]
203
203
start = int (start )
204
204
end = int (end )
205
205
searchQuery = {
206
- '$or' : [
206
+ '$or' : [
207
207
{'$and' : [
208
208
{'start' :{'$gte' :start }},
209
209
{'start' :{'$lte' :end }},
@@ -213,7 +213,7 @@ def getOverlappingGenes(self):
213
213
{'start' :{'$lte' :start }},
214
214
{'end' :{'$gte' :end }},
215
215
{'chr' :chm }
216
- ]},
216
+ ]},
217
217
{'$and' : [
218
218
{'end' :{'$gte' :start }},
219
219
{'end' :{'$lte' :end }},
@@ -225,7 +225,7 @@ def getOverlappingGenes(self):
225
225
overlappedGenes .append (gene ['Name' ])
226
226
227
227
return overlappedGenes
228
-
228
+
229
229
def getRGEN (self ):
230
230
# fetch the correct rgen record using the rgenID attribute
231
231
rgenCollection = self .dbConnection .rgenCollection
@@ -235,7 +235,7 @@ def getRGEN(self):
235
235
else :
236
236
raise ValueError ("Incorrect number of records returned from RGEN database for rgenID: " + str (rgenID ))
237
237
return
238
-
238
+
239
239
def isValidInput (inputSeq ):
240
240
#TODO: code this. some validation done on front end but not for the chr number/letter
241
241
if len (inputSeq ) == 0 :
@@ -266,4 +266,4 @@ def main():
266
266
267
267
268
268
if __name__ == "__main__" :
269
- main ()
269
+ main ()
0 commit comments