Changeset 276
- Timestamp:
- 01/20/08 22:38:34 (10 months ago)
- Files:
-
- trunk/cartwheel-server/lib/cartwheel/website/IUPACMotif.py (modified) (2 diffs)
- trunk/cartwheel-server/lib/cartwheel/website/NamedMotif.py (modified) (1 diff)
- trunk/cartwheel-server/lib/cartwheel/website/PWMMotif.py (modified) (2 diffs)
- trunk/cartwheel-server/website/canal/motif/__init__.py (modified) (1 diff)
- trunk/cartwheel-server/website/canal/motif/analyze.ptl (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cartwheel-server/lib/cartwheel/website/IUPACMotif.py
r269 r276 5 5 mymembers = ('motif', 'mismatches') 6 6 7 def search(self, sequence ):7 def search(self, sequence, start, stop): 8 8 """ 9 9 sequence is FolderSequence. … … 11 11 import motility 12 12 13 return motility.find_iupac(sequence.seq, self.motif, self.mismatches) 13 return motility.find_iupac(sequence.seq[start:stop], 14 self.motif, self.mismatches, 15 offset=start) 14 16 15 17 def extra_information(self): trunk/cartwheel-server/lib/cartwheel/website/NamedMotif.py
r269 r276 5 5 mymembers = ('name', 'motif_type', 'folder_id', 'visible') 6 6 7 def search(self, sequence ): # actually runs the search7 def search(self, sequence, start, stop): # actually runs the search 8 8 raise NotImplementedError 9 9 trunk/cartwheel-server/lib/cartwheel/website/PWMMotif.py
r270 r276 15 15 return pwm 16 16 17 def search(self, sequence ):17 def search(self, sequence, start, stop): 18 18 """ 19 19 sequence is FolderSequence. … … 24 24 pwm = motility.make_pwm(sites) 25 25 26 return pwm.find(sequence.seq, self.default_threshold) 26 return pwm.find(sequence.seq[start:stop], 27 self.default_threshold, offset=start) 27 28 28 29 def extra_information(self): trunk/cartwheel-server/website/canal/motif/__init__.py
r269 r276 11 11 12 12 def edit(request): 13 #motif_id = int(request.form['motif_id']) 13 14 assert 0 14 15 trunk/cartwheel-server/website/canal/motif/analyze.ptl
r275 r276 2 2 Web handler for dealing with sequence analysis by motifs. 3 3 """ 4 5 import urllib 4 6 5 7 import cartwheel.website … … 21 23 def draw_motifs_on_sequence(dna_seq, motifs, picture_class, 22 24 seq_start, seq_stop): 23 sequencedb = dict(sequence=pygr.sequence.Sequence(dna_seq.seq, 24 'sequence')) 25 colors = picture_class.colors 26 27 map_list = [] 28 for i, motif in enumerate(motifs): 29 color_name = color_rotation[i % len(color_rotation)] 30 color = getattr(colors, color_name) 31 32 d = {} 33 matches = motif.search(dna_seq) 34 for n, (start, stop, _, _) in enumerate(matches): 35 name = "match%d" % (n,) 36 d[name] = Annotation(name, 'sequence', start, stop, 37 color=color) 38 39 map = pygr_draw.create_annotation_map(d, sequencedb) 40 41 map_list.append(map) 42 43 sequence = sequencedb['sequence'][seq_start:seq_stop] 44 p = pygr_draw.draw_annotation_maps(sequence, map_list, 45 picture_class=picture_class) 46 47 image = p.finalize() 48 return image 25 """ 26 Do the motif search & use pygr_draw to actually draw a picture. 27 """ 28 29 sequencedb = dict(sequence=pygr.sequence.Sequence(dna_seq.seq,'sequence')) 30 colors = picture_class.colors 31 32 # 33 # for each motif, build a separate annotation map 34 # 35 36 map_list = [] 37 for i, motif in enumerate(motifs): 38 color_name = color_rotation[i % len(color_rotation)] 39 color = getattr(colors, color_name) 40 41 d = {} 42 matches = motif.search(dna_seq, seq_start, seq_stop) 43 44 for n, (start, stop, _, _) in enumerate(matches): 45 name = "match%d" % (n,) 46 d[name] = Annotation(name, 'sequence', start, stop, 47 color=color) 48 49 map = pygr_draw.create_annotation_map(d, sequencedb) 50 51 map_list.append(map) 52 53 # 54 # draw! 55 # 56 57 sequence = sequencedb['sequence'][seq_start:seq_stop] 58 p = pygr_draw.draw_annotation_maps(sequence, map_list, 59 picture_class=picture_class) 60 61 image = p.finalize() 62 return image 49 63 50 64 class AnalyzeSequenceHandler: … … 91 105 </tr> 92 106 """ 93 107 94 108 for i, motif in enumerate(motifs): 95 109 color_name = color_rotation[i % len(color_rotation)] 96 110 key = motif.simple_key() 97 111 112 search_results = motif.search(self.seq, start, stop) 113 114 param_dict = dict(motif_id=motif.id, start=start, stop=stop) 115 param_s = urllib.urlencode(param_dict) 116 98 117 """ 99 118 <tr><td>%s</td><td>%d matches</td><td>%s</td> 100 <td><a href='matches_detail? motif_id=%d'id='detail-%s'>detail</a>119 <td><a href='matches_detail?%s' id='detail-%s'>detail</a> 101 120 </td> 102 121 </tr> 103 """ % (motif.name, len(motif.search(self.seq)), color_name, 104 motif.id, key) 122 """ % (motif.name, len(search_results), color_name, param_s, key) 105 123 106 124 "</table>" … … 167 185 168 186 template matches_detail_IUPAC(self, request, motif): 169 matches = motif.search(self.seq) 187 form = request.form 188 seq_start = int(form.get('start', 0)) 189 seq_start = max(seq_start, 0) 190 191 seq_stop = int(form.get('stop', len(self.seq.seq))) 192 seq_stop = min(len(self.seq.seq), seq_stop) 193 194 matches = motif.search(self.seq, seq_start, seq_stop) 170 195 171 196 ### sort 172 197 173 sort_by = request.form.get('sort_by')198 sort_by = form.get('sort_by') 174 199 sort_fn = lambda x,y: cmp(x[0], y[0]) 175 200 sorted_text = 'position' … … 183 208 matches = list(matches) 184 209 matches.sort(sort_fn) 210 211 ### 212 213 param_dict = dict(start=seq_start, 214 stop=seq_stop, 215 motif_id=motif.id) 216 param_s = urllib.urlencode(param_dict) 185 217 186 218 ### display … … 208 240 """ 209 241 <h3>Matches</h3> 210 % d matches, sorted by %s.242 %(n_matches)d matches, sorted by %(sorted_text)s. 211 243 <p> 212 <a href="export_matches_IUPAC? motif_id=%d">export matches in text format</a> |213 sort by <a href="matches_detail? motif_id=%d&sort_by=p">position</a> or214 <a href="matches_detail? motif_id=%d&sort_by=o">orientation</a>244 <a href="export_matches_IUPAC?%(param_s)s">export matches in text format</a> | 245 sort by <a href="matches_detail?%(param_s)s&sort_by=p">position</a> or 246 <a href="matches_detail?%(param_s)s&&sort_by=o">orientation</a> 215 247 <p> 216 248 <table border="1"> … … 221 253 <th>Match</th> 222 254 </tr> 223 """ % (len(matches), sorted_text, 224 motif.id, motif.id, motif.id) 255 """ % dict(n_matches=len(matches), 256 sorted_text=sorted_text, 257 param_s=param_s) 225 258 226 259 for (start, stop, orientation, match_seq) in matches: … … 239 272 240 273 template matches_detail_PWM(self, request, motif): 274 form = request.form 275 seq_start = int(form.get('start', 0)) 276 seq_start = max(seq_start, 0) 277 278 seq_stop = int(form.get('stop', len(self.seq.seq))) 279 seq_stop = min(len(self.seq.seq), seq_stop) 280 281 ## 282 241 283 pwm = motif.make_pwm() 242 matches = motif.search(self.seq )284 matches = motif.search(self.seq, seq_start, seq_stop) 243 285 244 286 # add in score. … … 263 305 matches.sort(sort_fn) 264 306 307 ### 308 309 param_dict = dict(start=seq_start, 310 stop=seq_stop, 311 motif_id=motif.id) 312 param_s = urllib.urlencode(param_dict) 313 265 314 ### display 266 315 … … 287 336 """ 288 337 <h3>Matches</h3> 289 % d matches, sorted by %s.338 %(n_matches)d matches, sorted by %(sorted_text)s. 290 339 <p> 291 <a href="export_matches_PWM? motif_id=%d">export matches in text format</a> |292 sort by <a href="matches_detail? motif_id=%d&sort_by=p">position</a>,293 <a href="matches_detail? motif_id=%d&sort_by=o">orientation</a>, or294 <a href="matches_detail? motif_id=%d&sort_by=s">score</a>340 <a href="export_matches_PWM?%(param_s)s">export matches in text format</a> | 341 sort by <a href="matches_detail?%(param_s)s&sort_by=p">position</a>, 342 <a href="matches_detail?%(param_s)s&sort_by=o">orientation</a>, or 343 <a href="matches_detail?%(param_s)s&sort_by=s">score</a> 295 344 <p> 296 345 <table border="1"> … … 302 351 <th>Score</th> 303 352 </tr> 304 """ % (len(matches), sorted_text, 305 motif.id, motif.id, motif.id, motif.id) 306 353 """ % dict(n_matches=len(matches), 354 sorted_text=sorted_text, 355 param_s=param_s) 356 307 357 for (start, stop, orientation, match_seq, score) in matches: 308 358 o = 'forward' … … 320 370 321 371 def export_matches_IUPAC(self, request): 372 form = request.form 373 seq_start = int(form.get('start', 0)) 374 seq_start = max(seq_start, 0) 375 376 seq_stop = int(form.get('stop', len(self.seq.seq))) 377 seq_stop = min(len(self.seq.seq), seq_stop) 378 379 ### 380 322 381 motif_id = int(request.form['motif_id']) 323 382 motif = self.manager.load(motif_id) 324 383 325 matches = motif.search(self.seq )384 matches = motif.search(self.seq, seq_start, seq_stop) 326 385 327 386 s = """# motif: %s/%s/%d mismatches\n# sequence: %s\n""" % \ … … 337 396 338 397 def export_matches_PWM(self, request): 398 form = request.form 399 seq_start = int(form.get('start', 0)) 400 seq_start = max(seq_start, 0) 401 402 seq_stop = int(form.get('stop', len(self.seq.seq))) 403 seq_stop = min(len(self.seq.seq), seq_stop) 404 405 ### 406 339 407 motif_id = int(request.form['motif_id']) 340 408 motif = self.manager.load(motif_id) … … 342 410 consensus = motif.simple_key() 343 411 pwm = motif.make_pwm() 344 matches = motif.search(self.seq )412 matches = motif.search(self.seq, seq_start, seq_stop) 345 413 346 414 s = """# PWM motif %s: consensus %s/threshold %f\n# sequence: %s\n"""%\
