Changeset 286
- Timestamp:
- 01/30/08 02:09:41 (10 months ago)
- Files:
-
- trunk/cartwheel-server/data-model/website/motifs.sql (modified) (2 diffs)
- trunk/cartwheel-server/lib/cartwheel/website/PWMMotif.py (modified) (3 diffs)
- trunk/cartwheel-server/lib/cartwheel/website/RawPWMMotif.py (added)
- trunk/cartwheel-server/tests/functional-tests/test-with-user/test-web/test-folder-motifs.py (modified) (1 diff)
- trunk/cartwheel-server/website/canal/motif/__init__.py (modified) (10 diffs)
- trunk/cartwheel-server/website/canal/motif/analyze.ptl (modified) (3 diffs)
- trunk/cartwheel-server/website/canal/motif/pages.ptl (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cartwheel-server/data-model/website/motifs.sql
r283 r286 13 13 visible BOOLEAN DEFAULT 't', 14 14 motif_type TEXT CONSTRAINT valid_type 15 CHECK (motif_type IN ('IUPAC', 'PWM')),15 CHECK (motif_type IN ('IUPAC', 'PWM', 'RawPWM')), 16 16 folder_id INTEGER 17 17 ) INHERITS (cartwheel_objects); … … 38 38 class_id INTEGER REFERENCES classes DEFAULT :class_id, 39 39 source_motifs TEXT DEFAULT '', 40 default_threshold FLOAT40 threshold FLOAT 41 41 ) INHERITS (named_motifs); 42 43 \set class_id 2043 44 45 INSERT INTO classes (id, name, description) VALUES 46 (:class_id, 'cartwheel.website.RawPWMMotif', 47 'A raw PWM motif.'); 48 49 CREATE TABLE raw_pwm_motifs ( 50 class_id INTEGER REFERENCES classes DEFAULT :class_id, 51 matrix TEXT NOT NULL, 52 threshold FLOAT, 53 format TEXT NOT NULL 54 ) INHERITS (named_motifs); trunk/cartwheel-server/lib/cartwheel/website/PWMMotif.py
r277 r286 6 6 class PWMMotif(NamedMotif): 7 7 table = 'pwm_motifs' 8 mymembers = ('source_motifs', ' default_threshold')8 mymembers = ('source_motifs', 'threshold') 9 9 10 10 def make_pwm(self): … … 25 25 26 26 return pwm.find(sequence.seq[start:stop], 27 self. default_threshold, offset=start)27 self.threshold, offset=start) 28 28 29 29 def extra_information(self): … … 34 34 35 35 return "PWM consensus: %s; default threshold %g" % (consensus, 36 self. default_threshold)36 self.threshold) 37 37 def simple_key(self): 38 38 import motility trunk/cartwheel-server/tests/functional-tests/test-with-user/test-web/test-folder-motifs.py
r280 r286 253 253 254 254 follow('Return to folder menu') 255 256 def test_add_jaspar_motif(): 257 show() 258 follow("manage motifs") 259 follow("import_single_matrix") 260 261 fv('1', 'name', 'test_jaspar') 262 fv('1', 'format', 'JASPAR') 263 fv('1', 'matrix', 'AGATAG\nTGATAG\nTGATAA') 264 fv('1', 'notes', 'figgledybum') 265 266 submit() 267 code('200') 268 269 show() 270 271 find("Matrix motif 'test_jaspar' created.") 272 273 follow("Return to motif list") 274 275 ## simple test of edit 276 follow('edit-TGATAG') 277 submit('return') 278 279 ## end 280 follow('Return to folder menu') trunk/cartwheel-server/website/canal/motif/__init__.py
r283 r286 13 13 14 14 from pages import add_iupac, _q_index, build_pwm_from_list, \ 15 display_pwm_information 15 display_pwm_information, import_single_matrix 16 16 17 17 … … 19 19 from cartwheel.website.IUPACMotif import IUPACMotif 20 20 from cartwheel.website.PWMMotif import PWMMotif 21 from cartwheel.website.RawPWMMotif import RawPWMMotif 21 22 22 23 _q_exports = ['add_iupac', 'delete', 'edit', 'go_analyze', 23 'build_pwm_from_list', 'batch_export', 'batch_import'] 24 'build_pwm_from_list', 'batch_export', 'batch_import', 25 'import_single_matrix'] 24 26 25 27 def edit(request): … … 33 35 if isinstance(motif, IUPACMotif): 34 36 return edit_iupac_motif(request, motif) 37 elif isinstance(motif, PWMMotif): 38 return edit_pwm_motif(request, motif) 39 elif isinstance(motif, RawPWMMotif): 40 return edit_raw_pwm_motif(request, motif) 35 41 else: 36 r eturn edit_pwm_motif(request, motif)42 raise Exception("unknown motif type") 37 43 38 44 def delete(request): … … 138 144 name = motif.name 139 145 sequences = motif.source_motifs.split("\n") 140 threshold = motif. default_threshold146 threshold = motif.threshold 141 147 notes = motif.notes 142 148 … … 149 155 errors.append("you must enter a name!") 150 156 151 if ' default_threshold' in request.form:152 threshold = request.form[' default_threshold']157 if 'threshold' in request.form: 158 threshold = request.form['threshold'] 153 159 try: 154 160 threshold = float(threshold) … … 175 181 motif.name = name 176 182 motif.source_motifs = "\n".join(sequences) 177 motif. default_threshold = threshold183 motif.threshold = threshold 178 184 motif.notes = notes 179 185 … … 187 193 name=motif.name, 188 194 sequences=motif.source_motifs, 189 default_threshold=round(motif.default_threshold, 2),195 threshold=round(motif.threshold, 2), 190 196 notes=motif.notes) 191 197 … … 203 209 <textarea name='sequences' rows='5' cols='30'></textarea> 204 210 <p> 205 Threshold: <input type='text' name=' default_threshold' size='7'>211 Threshold: <input type='text' name='threshold' size='7'> 206 212 <p> 207 213 Notes:<br> … … 221 227 return wrap(htmlfill.render(formhtml, values), 222 228 display_pwm_information(pwm, sequences, threshold), 229 title="Edit PWM Motif '%s'" % (name,), 230 show_anything = False) 231 232 def edit_raw_pwm_motif(request, motif): 233 name = motif.name 234 matrix = motif.matrix 235 format = motif.format 236 threshold = motif.threshold 237 notes = motif.notes 238 239 errors = [] 240 241 if 'name' in request.form: 242 name = request.form['name'].strip() 243 244 if not name: 245 errors.append("you must enter a name!") 246 247 if 'threshold' in request.form: 248 threshold = request.form['threshold'] 249 try: 250 threshold = float(threshold) 251 except ValueError: 252 errors.append("threshold must be a number!") 253 254 if 'notes' in request.form: 255 notes = request.form['notes'] 256 257 if errors: 258 return "ERROR:<p><ul><li> %s</ul>" % ("<li>".join(errors,)) 259 260 motif.name = name 261 motif.matrix = matrix 262 motif.format = format 263 motif.threshold = threshold 264 motif.notes = notes 265 266 motif.manager.commit() 267 268 if 'return' in request.form: 269 return request.redirect(request.get_url(1)) 270 271 # fill 272 values = dict(motif_id=motif.id, 273 name=motif.name, 274 format=format, 275 matrix=matrix, 276 threshold=round(motif.threshold, 2), 277 notes=motif.notes) 278 279 formhtml = """\ 280 <h2>Edit imported matrix motif '%s'</h2> 281 <form method='POST' action=''> 282 283 <input type='hidden' name='motif_id'> 284 285 Name: <input type='text' name='name'> <p> 286 287 Matrix data type: 288 <select name='format'> 289 <option value='JASPAR'> JASPAR 290 </select> 291 <p> 292 293 Matrix data:<br> 294 <textarea name='matrix' rows='8' cols='40'></textarea> 295 <p> 296 Threshold: <input type='text' name='threshold' size='7'> 297 <p> 298 Notes:<br> 299 <blockquote> 300 <textarea name='notes' rows='5' cols='50'></textarea> 301 </blockquote> 302 <p> 303 <input type='submit' value='save & return to motif list' name='return'> 304 <input type='submit' value='save & update information'> 305 <input type='reset' value='reset form'> 306 </form> 307 <hr> 308 """ % (motif.name,) 309 310 formhtml = htmlfill.render(formhtml, values) 311 312 return wrap(htmlfill.render(formhtml, values), 313 # display_pwm_information(pwm, sequences, threshold), 223 314 title="Edit PWM Motif '%s'" % (name,), 224 315 show_anything = False) … … 246 337 elif motif.motif_type == 'PWM': 247 338 output.write('%% PWM from sites\n') 248 output.write('%% threshold=%g\n' % (motif. default_threshold,))339 output.write('%% threshold=%g\n' % (motif.threshold,)) 249 340 output.write('%s\n' % (motif.source_motifs,)) 250 341 else: trunk/cartwheel-server/website/canal/motif/analyze.ptl
r283 r286 1 1 """ 2 2 Web handler for dealing with sequence analysis by motifs. 3 4 CTB to test:5 - empty annotations6 3 """ 7 4 … … 388 385 <hr> 389 386 """ % (name, len(self.seq.seq), 390 motif.simple_key(), len(pwm), motif. default_threshold,)387 motif.simple_key(), len(pwm), motif.threshold,) 391 388 392 389 if not matches: … … 480 477 481 478 s = """# PWM motif %s: consensus %s/threshold %f\n# sequence: %s\n"""%\ 482 (motif.name, consensus, motif. default_threshold, self.seq.name,)479 (motif.name, consensus, motif.threshold, self.seq.name,) 483 480 484 481 # add in score. trunk/cartwheel-server/website/canal/motif/pages.ptl
r283 r286 1 1 import cartwheel.website 2 2 from canal.templates import header, footer, wrap, error 3 3 4 from cartwheel.website.IUPACMotif import IUPACMotif 4 5 from cartwheel.website.PWMMotif import PWMMotif 6 from cartwheel.website.RawPWMMotif import RawPWMMotif 7 5 8 from canal.group.utils import make_sequence_list_widget 6 9 from canal.motif import utils … … 10 13 11 14 nice_motif_types = dict(IUPAC='simple motif (IUPAC notation)', 12 PWM='matrix motif (PWM)') 15 PWM='matrix motif (PWM)', 16 RawPWM='imported matrix motif (PWM)') 13 17 14 18 template _q_index(request): … … 66 70 <li> <a href="build_pwm_from_list">build a matrix (PWM) 67 71 from a list of sites</a> 68 <li> <a href=" ">import matrix from JASPAR</a>72 <li> <a href="import_single_matrix">import a matrix from another program</a> 69 73 </ul> 70 74 … … 286 290 m = manager.create(PWMMotif, name=name, source_motifs="\n".join(sequences), 287 291 motif_type='PWM', 288 default_threshold=lowest_score,292 threshold=lowest_score, 289 293 notes=notes, 290 294 folder_id=folder_id) … … 383 387 ### 384 388 389 template display_pwm_from_sites(request, name, sequences, notes): 390 header("Motif '%s' created" % (name,)) 391 392 "<h2>Matrix motif '%s' created.</h2>" % (name,) 393 394 pwm = motility.make_pwm(sequences) 395 site_scores = [ (pwm.calc_score(s),s) for s in sequences ] 396 site_scores.sort() 397 site_scores.reverse() 398 399 lowest_score = site_scores[-1][0] 400 401 ### 402 403 display_pwm_information(pwm, sequences, lowest_score) 404 405 ### create 406 407 manager = cartwheel.website.get_object_manager() 408 409 folder_id = request.session.get_current_folder().id 410 411 m = manager.create(PWMMotif, name=name, source_motifs="\n".join(sequences), 412 motif_type='PWM', 413 threshold=lowest_score, 414 notes=notes, 415 folder_id=folder_id) 416 417 manager.commit() 418 419 """ 420 <p> 421 <a href='./edit?motif_id=%d'>Edit motif information and threshold</a> 422 <p> 423 <a href='./'>Return to motif list</a> 424 """ % (m.id,) 425 426 footer() 427 428 ### 429 430 def import_single_matrix[html](request): 431 if not request.form: 432 return wrap("""\ 433 <form method="POST"> 434 <h3>Import a matrix motif (PWM) from another program</h3> 435 436 <b>Instructions:</b> 437 <p> 438 ... 439 <p> 440 <hr> 441 Name: <input type='text' name='name'> 442 <p> 443 Matrix data type: 444 <select name='format'> 445 <option value='JASPAR'> JASPAR 446 </select> 447 <p> 448 Matrix data: 449 <br> 450 <textarea name='matrix' rows='8' cols='40'></textarea> 451 <p> 452 Notes:<br> 453 <blockquote> 454 <textarea name='notes' rows='5' cols='50'></textarea> 455 </blockquote> 456 <p> 457 <input type='submit' value='import'> 458 </form> 459 """, show_anything=False) 460 461 errors = [] 462 463 name = request.form['name'].strip() 464 matrix = request.form['matrix'] 465 format = request.form['format'] 466 notes = request.form.get('notes', '') 467 468 if not name: 469 errors.append("you must enter a name!") 470 471 if format not in ('JASPAR',): 472 errors.append("unknown data format: %s" % (format,)) 473 474 if errors: 475 return error("ERROR:<p><ul><li> %s</ul>" % ("<li>".join(errors,))) 476 477 header("Motif '%s' created" % (name,)) 478 479 "<h2>Matrix motif '%s' created.</h2>" % (name,) 480 481 ### create 482 483 manager = cartwheel.website.get_object_manager() 484 folder_id = request.session.get_current_folder().id 485 486 m = manager.create(RawPWMMotif, name=name, matrix=matrix, 487 motif_type=str('RawPWM'), 488 format=format, 489 threshold=0, 490 notes=notes, 491 folder_id=folder_id) 492 493 manager.commit() 494 495 """ 496 <p> 497 <a href='./edit?motif_id=%d'>Edit motif information and threshold</a> 498 <p> 499 <a href='./'>Return to motif list</a> 500 """ % (m.id,) 501 502 footer()
