Changeset 283
- Timestamp:
- 01/28/08 01:14:05 (10 months ago)
- Files:
-
- trunk/cartwheel-server/data-model/website/motifs.sql (modified) (1 diff)
- trunk/cartwheel-server/lib/cartwheel/website/NamedMotif.py (modified) (1 diff)
- trunk/cartwheel-server/website/canal/motif/__init__.py (modified) (10 diffs)
- trunk/cartwheel-server/website/canal/motif/analyze.ptl (modified) (10 diffs)
- trunk/cartwheel-server/website/canal/motif/pages.ptl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cartwheel-server/data-model/website/motifs.sql
r261 r283 9 9 10 10 name TEXT DEFAULT '', 11 notes TEXT DEFAULT '', 12 color TEXT DEFAULT '', 11 13 visible BOOLEAN DEFAULT 't', 12 14 motif_type TEXT CONSTRAINT valid_type trunk/cartwheel-server/lib/cartwheel/website/NamedMotif.py
r276 r283 3 3 class NamedMotif(CartwheelObject): 4 4 table = 'named_motifs' 5 mymembers = ('name', 'motif_type', 'folder_id', 'visible') 5 mymembers = ('name', 'motif_type', 'folder_id', 'visible', 'notes', 6 'color') 6 7 7 8 def search(self, sequence, start, stop): # actually runs the search trunk/cartwheel-server/website/canal/motif/__init__.py
r281 r283 79 79 else: 80 80 motif.name = form['name'] 81 81 82 if 'iupac' in form: 82 83 iupac_str = form['iupac'].strip().upper() 83 84 errors.extend(utils.validate_iupac(iupac_str)) 84 85 motif.motif = form['iupac'] 86 85 87 if 'mismatches' in form: 86 88 try: … … 89 91 errors.append('mismatches must be an integer') 90 92 93 if 'notes' in form: 94 notes = form['notes'] 95 motif.notes = notes 96 91 97 if errors: 92 98 return "ERROR:<p><ul><li> %s</ul>" % ("<li>".join(errors)) … … 101 107 name=motif.name, 102 108 iupac=motif.motif, 103 mismatches=motif.mismatches) 109 mismatches=motif.mismatches, 110 notes=motif.notes) 104 111 105 112 formhtml = """\ … … 114 121 115 122 Mismatches to allow by default: <input type='text' name='mismatches' size='4'> 123 <p> 124 Notes:<br> 125 <blockquote> 126 <textarea name='notes' rows='5' cols='50'></textarea> 127 </blockquote> 116 128 <p> 117 129 <input type='submit' value='save & return to motif list' name='return'> … … 127 139 sequences = motif.source_motifs.split("\n") 128 140 threshold = motif.default_threshold 141 notes = motif.notes 129 142 130 143 errors = [] … … 154 167 errors.extend(utils.validate_pwm_input(sequences, threshold)) 155 168 169 if 'notes' in request.form: 170 notes = request.form['notes'] 171 156 172 if errors: 157 173 return "ERROR:<p><ul><li> %s</ul>" % ("<li>".join(errors,)) … … 160 176 motif.source_motifs = "\n".join(sequences) 161 177 motif.default_threshold = threshold 178 motif.notes = notes 162 179 163 180 motif.manager.commit() … … 170 187 name=motif.name, 171 188 sequences=motif.source_motifs, 172 default_threshold=round(motif.default_threshold, 2)) 189 default_threshold=round(motif.default_threshold, 2), 190 notes=motif.notes) 173 191 174 192 pwm = motility.make_pwm(sequences) … … 186 204 <p> 187 205 Threshold: <input type='text' name='default_threshold' size='7'> 188 206 <p> 207 Notes:<br> 208 <blockquote> 209 <textarea name='notes' rows='5' cols='50'></textarea> 210 </blockquote> 189 211 <p> 190 212 <input type='submit' value='save & return to motif list' name='return'> … … 214 236 for motif in motifs: 215 237 output.write('>%s\n' % (motif.name,)) 216 238 notes = motif.notes.split("\n") 239 for n in notes: 240 output.write('%% notes=%s' % (n,)) 241 217 242 if motif.motif_type == 'IUPAC': 218 243 output.write('%% IUPAC\n%% mismatches=%d\n' % (motif.mismatches,)) 219 244 output.write('%s' % (motif.motif,)) 245 220 246 elif motif.motif_type == 'PWM': 221 247 output.write('%% PWM from sites\n') trunk/cartwheel-server/website/canal/motif/analyze.ptl
r281 r283 25 25 26 26 def draw_motifs_on_sequence(dna_seq, motifs, picture_class, 27 seq_start, seq_stop ):27 seq_start, seq_stop, combine=False): 28 28 """ 29 29 Do the motif search & use pygr_draw to actually draw a picture. … … 39 39 40 40 map_list = [] 41 d = {} 42 41 43 for i, motif in enumerate(motifs): 42 44 color_name = color_rotation[i % len(color_rotation)] 43 45 color = getattr(colors, color_name) 44 46 45 d = {} 47 if not combine: 48 d = {} 49 46 50 matches = motif.search(dna_seq, seq_start, seq_stop) 47 51 48 52 for n, (start, stop, _, _) in enumerate(matches): 49 name = " match%d" % (n,)53 name = "%d-match%d" % (i,n,) 50 54 d[name] = Annotation(name, 'sequence', start, stop, 51 55 color=color) … … 54 58 continue 55 59 56 map = pygr_draw.create_annotation_map(d, sequencedb) 57 58 map_list.append(map) 60 if not combine: 61 map = pygr_draw.create_annotation_map(d, sequencedb) 62 map_list.append(map) 63 64 if combine: 65 assert not map_list 66 if d: 67 map = pygr_draw.create_annotation_map(d, sequencedb) 68 map_list = [map] 59 69 60 70 # … … 94 104 stop = len(self.seq.seq) 95 105 106 combine = int(request.form.get('combine', 1)) 107 96 108 ### 97 109 … … 110 122 <hr> 111 123 <h4>Motif matches graphed against sequence:</h4> 112 <a href='draw_pdf?start=%d&stop=%d '>(download as PDF)</a><br>113 <img src='draw_png?start=%d&stop=%d ' width='100%%'>114 <p> 115 """ % (start, stop, start, stop)124 <a href='draw_pdf?start=%d&stop=%d&combine=%d'>(download as PDF)</a><br> 125 <img src='draw_png?start=%d&stop=%d&combine=%d' width='100%%'> 126 <p> 127 """ % (start, stop, combine, start, stop, combine) 116 128 117 129 """ … … 141 153 "</table>" 142 154 155 if combine: 156 combineNO = 'selected' 157 combineYES = '' 158 else: 159 combineNO = '' 160 combineYES = 'selected' 161 143 162 """ 144 163 <h4>Adjust parameters:</h4> … … 147 166 to base <input type="text" name="stop" value="%d">. 148 167 <p> 168 Show different motifs on different rows? <select name='combine'> 169 <option value='1' %s> no 170 <option value='0' %s> yes 171 </select> 172 <p> 149 173 <input type='submit' value='redraw'> 150 174 <input type='submit' value='show entire sequence' name='reset_coords'> … … 152 176 <p> 153 177 <a href='../'>return to motif library page</a> 154 """ % (start, stop )178 """ % (start, stop, combineNO, combineYES) 155 179 156 180 footer() … … 166 190 seq_start, seq_stop = min(seq_start, seq_stop),max(seq_start, seq_stop) 167 191 192 combine = int(request.form.get('combine', 1)) 193 168 194 (folder, motifs) = get_folder_motifs(self.manager, request) 169 195 170 196 image = draw_motifs_on_sequence(self.seq, motifs, 171 197 pygr_draw.BitmapSequencePicture, 172 seq_start, seq_stop )198 seq_start, seq_stop, combine=combine) 173 199 174 200 request.response.set_content_type('image/png') … … 185 211 seq_start, seq_stop = min(seq_start, seq_stop),max(seq_start, seq_stop) 186 212 213 combine = int(request.form.get('combine', 1)) 214 187 215 (folder, motifs) = get_folder_motifs(self.manager, request) 188 216 189 217 image = draw_motifs_on_sequence(self.seq, motifs, 190 218 pygr_draw.PDFSequencePicture, 191 seq_start, seq_stop )219 seq_start, seq_stop, combine=combine) 192 220 193 221 # force a download to a filename trunk/cartwheel-server/website/canal/motif/pages.ptl
r281 r283 111 111 Mismatches to allow: <input type='text' 112 112 name='mismatches' size='4' value='0'><p> 113 <input type='submit' value='add IUPAC motif'> 113 Notes:<br> 114 <blockquote> 115 <textarea name='notes' rows='5' cols='50'></textarea> 116 </blockquote> 117 <p> 118 <input type='submit' value='add IUPAC motif'> 114 119 </form> 115 120 <p> … … 140 145 iupac_str = d['iupac'].parse(request) 141 146 mismatches = d['mismatches'].parse(request) 142 143 if not (request.form and name and iupac_str and mismatches): 147 notes = request.form.get('notes', '') 148 149 if not (request.form and name and iupac_str): 144 150 return error("ERROR: you have to enter name and motif!") 145 151 … … 166 172 manager.create(IUPACMotif, name=name, motif=iupac_str, 167 173 motif_type='IUPAC', 168 mismatches=int(mismatches), folder_id=folder_id) 174 mismatches=int(mismatches), 175 notes=notes, 176 folder_id=folder_id) 169 177 170 178 manager.commit() … … 214 222 <textarea name='sequences' rows='5' cols='30'></textarea> 215 223 <p> 224 Notes:<br> 225 <blockquote> 226 <textarea name='notes' rows='5' cols='50'></textarea> 227 </blockquote> 228 <p> 216 229 <input type='submit' value='build PWM'> 217 230 </form> … … 227 240 228 241 name = request.form['name'].strip() 242 notes = request.form.get('notes', '') 229 243 230 244 if not name: … … 246 260 ### ok, validation good so far. build the PWM & display... 247 261 248 return display_pwm_from_sites(request, name, sequences )249 250 template display_pwm_from_sites(request, name, sequences ):262 return display_pwm_from_sites(request, name, sequences, notes) 263 264 template display_pwm_from_sites(request, name, sequences, notes): 251 265 header("Motif '%s' created" % (name,)) 252 266 … … 273 287 motif_type='PWM', 274 288 default_threshold=lowest_score, 289 notes=notes, 275 290 folder_id=folder_id) 276 291
