22
22
class GuideAdd :
23
23
def __init__ (self , ** kwargs ):
24
24
""" class for interfacing to the guide collection """
25
- # check required inputs set
25
+ # check required inputs set
26
26
for parameter in ['batchID' , 'guideID' , 'label' ]:
27
27
if parameter not in kwargs :
28
- self .sendErrorHTML ("'{parameter}' not set" .format (** locals ()))
28
+ self .sendErrorHTML ("'{parameter}' not set" .format (** locals ()))
29
29
self .dbConnection = Config ()
30
30
self .batchID = kwargs ['batchID' ]
31
31
self .guideID = kwargs ['guideID' ]
32
32
self .label = kwargs ['label' ]
33
33
self .notes = kwargs ['notes' ] if 'notes' in kwargs else ''
34
-
34
+
35
35
# fetch the stored guide info
36
36
self .metadata , self .guide = self .parseJSON ()
37
37
self .rgen = self .getRGEN (str (self .metadata ['rgenID' ]))
38
38
# redefine the connection to the database based on the genome
39
- self .dbConnection = Config (self .metadata ['genome' ])
39
+ self .dbConnection = Config (self .metadata ['genome' ])
40
40
# determine if the guide already exists
41
41
self .existingGuide = self .existingGuideInDatabase ()
42
42
@@ -46,12 +46,12 @@ def __init__(self, **kwargs):
46
46
self .rewriteGFF ()
47
47
print ("Successfully Updated Guide" )
48
48
else :
49
- # insert the guide into the database
49
+ # insert the guide into the database
50
50
self .insertGuide ()
51
51
self .rewriteGFF ()
52
52
print ("Successfully Inserted Guide" )
53
53
54
-
54
+
55
55
def rewriteGFF (self ):
56
56
""" rewrite the gff file """
57
57
# intialize the strings
@@ -65,7 +65,7 @@ def rewriteGFF(self):
65
65
sortedGuideCoordinates = sorted ([int (x ) for x in guideCoordinates .split ('-' )])
66
66
# calculate the pam coordinates
67
67
rgen = self .getRGEN (guideRecord ['rgenID' ])
68
- pamLocation = rgen ['PamLocation' ]
68
+ pamLocation = rgen ['PamLocation' ]
69
69
if (pamLocation == 'downstream' and strand == '+' ) or (pamLocation == 'upstream' and strand == '-' ):
70
70
pamStart = sortedGuideCoordinates [- 1 ]
71
71
pamEnd = int (pamStart ) + len (guideRecord ['pamSeq' ])
@@ -107,9 +107,9 @@ def rewriteGFF(self):
107
107
108
108
# increment the count
109
109
idCounter += 1
110
-
110
+
111
111
#try:
112
- guideGFF = os .path .join (self .dbConnection .ROOT_PATH , str ('jbrowse/data. ' + self .metadata ['genome' ]+ "/gRNA_CRISPR.gff" ))
112
+ guideGFF = os .path .join (self .dbConnection .ROOT_PATH , str ('jbrowse/data/ ' + self .metadata ['genome' ]+ "/gRNA_CRISPR.gff" ))
113
113
gffFile = open (guideGFF , 'wb' )
114
114
gffFile .write (featureStr .encode ('utf-8' ))
115
115
gffFile .write (pamStr .encode ('utf-8' ))
@@ -118,7 +118,7 @@ def rewriteGFF(self):
118
118
#except Exception as e:
119
119
# self.sendErrorHTML(str(e))
120
120
121
-
121
+
122
122
def getRGEN (self , rgenID ):
123
123
# fetch the correct rgen record using the rgenID attribute
124
124
rgenCollection = self .dbConnection .rgenCollection
@@ -133,16 +133,16 @@ def combineSequence(self, rgen, guideSeq, pamSeq):
133
133
if rgen ['PamLocation' ] == 'downstream' :
134
134
return guideSeq .upper () + ", " + pamSeq
135
135
elif rgen ['PamLocation' ] == 'upstream' :
136
- return pamSeq .upper () + ", " + guideSeq .upper ()
136
+ return pamSeq .upper () + ", " + guideSeq .upper ()
137
137
else :
138
138
sendErrorHMTL ("Unrecognized PAM Location for RGEN: " + str (self .rgen ['PamLocation' ]))
139
-
139
+
140
140
def insertGuide (self ):
141
141
""" create a new record in the database for the guide """
142
142
newGuideRecord = {
143
143
'batchName' : self .metadata ['gene' ],
144
144
'status' : 'Accepted' ,
145
- 'guideScore' : self .guide ['MIT' ] if 'MIT' in self .guide else '' ,
145
+ 'guideScore' : self .guide ['MIT' ] if 'MIT' in self .guide else '' ,
146
146
'guideSeq' : self .guide ['guide_seq' ],
147
147
'Notes' : self .notes ,
148
148
'inputSearchCoordinates' : self .metadata ['inputSearchCoordinates' ],
@@ -163,7 +163,7 @@ def insertGuide(self):
163
163
result = self .dbConnection .guideCollection .insert_one (newGuideRecord )
164
164
if not result :
165
165
self .sendErrorHTML ("Problem inserting record into Database" )
166
-
166
+
167
167
def updateGuide (self ):
168
168
""" find the existing guide and update its notes and label"""
169
169
existing_id = self .existingGuide ['_id' ]
@@ -176,7 +176,7 @@ def existingGuideInDatabase(self):
176
176
searchQuery = {
177
177
"guideSeq" : self .guide ['guide_seq' ],
178
178
"pamSeq" : self .guide ['pam_seq' ],
179
- "guideLocation" : self .guide ['guideLocation' ]
179
+ "guideLocation" : self .guide ['guideLocation' ]
180
180
}
181
181
if self .dbConnection .guideCollection .find (searchQuery ).count () > 0 :
182
182
existingGuide = self .dbConnection .guideCollection .find_one (searchQuery )
@@ -198,7 +198,7 @@ def parseJSON(self):
198
198
self .sendErrorHTML ("Batch JSON file is misconfigured; no metadata found" )
199
199
200
200
def sendErrorHTML (self , errorString ):
201
- """ write error and exit the program """
201
+ """ write error and exit the program """
202
202
print (errorString )
203
203
sys .exit ()
204
204
@@ -221,12 +221,12 @@ def main():
221
221
print (traceback .format_exc ())
222
222
else :
223
223
#parameters = {'guideID': '92+', 'label': 'TestLabel', 'batchID': 'dda41408f7b56fcb3b', 'notes': 'nospecialcharacters'}
224
- #parameters = {'notes': "Le'sfjkd%20fsj#%20s", 'batchID': 'bfd5911343bde9a7cd', 'label': 'Testing%20Update', 'guideID': '6-'}
224
+ #parameters = {'notes': "Le'sfjkd%20fsj#%20s", 'batchID': 'bfd5911343bde9a7cd', 'label': 'Testing%20Update', 'guideID': '6-'}
225
225
#{'label': 'testinglabel', 'guideID': '6-', 'notes': 'testing notes', 'batchID': '6aa1c0912c773384c7'}
226
226
try :
227
227
GuideAdd (** parameters )
228
228
except Exception as e :
229
229
print (str (e ))
230
230
231
231
if __name__ == "__main__" :
232
- main ()
232
+ main ()
0 commit comments