Changeset 283

Show
Ignore:
Timestamp:
01/28/08 01:14:05 (10 months ago)
Author:
t
Message:

added notes, color field (still unused), and 'combine' selectbox.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cartwheel-server/data-model/website/motifs.sql

    r261 r283  
    99 
    1010        name TEXT DEFAULT '', 
     11        notes TEXT DEFAULT '', 
     12        color TEXT DEFAULT '', 
    1113        visible BOOLEAN DEFAULT 't', 
    1214        motif_type TEXT CONSTRAINT valid_type 
  • trunk/cartwheel-server/lib/cartwheel/website/NamedMotif.py

    r276 r283  
    33class NamedMotif(CartwheelObject): 
    44    table = 'named_motifs' 
    5     mymembers = ('name', 'motif_type', 'folder_id', 'visible') 
     5    mymembers = ('name', 'motif_type', 'folder_id', 'visible', 'notes', 
     6                 'color') 
    67 
    78    def search(self, sequence, start, stop):         # actually runs the search 
  • trunk/cartwheel-server/website/canal/motif/__init__.py

    r281 r283  
    7979        else: 
    8080            motif.name = form['name'] 
     81             
    8182    if 'iupac' in form: 
    8283        iupac_str = form['iupac'].strip().upper() 
    8384        errors.extend(utils.validate_iupac(iupac_str)) 
    8485        motif.motif = form['iupac'] 
     86         
    8587    if 'mismatches' in form: 
    8688        try: 
     
    8991            errors.append('mismatches must be an integer') 
    9092 
     93    if 'notes' in form: 
     94        notes = form['notes'] 
     95        motif.notes = notes 
     96 
    9197    if errors: 
    9298        return "ERROR:<p><ul><li> %s</ul>" % ("<li>".join(errors)) 
     
    101107                  name=motif.name, 
    102108                  iupac=motif.motif, 
    103                   mismatches=motif.mismatches) 
     109                  mismatches=motif.mismatches, 
     110                  notes=motif.notes) 
    104111 
    105112    formhtml = """\ 
     
    114121 
    115122Mismatches to allow by default: <input type='text' name='mismatches' size='4'> 
     123<p> 
     124Notes:<br> 
     125 <blockquote> 
     126  <textarea name='notes' rows='5' cols='50'></textarea> 
     127 </blockquote> 
    116128<p> 
    117129<input type='submit' value='save & return to motif list' name='return'> 
     
    127139    sequences = motif.source_motifs.split("\n") 
    128140    threshold = motif.default_threshold 
     141    notes = motif.notes 
    129142 
    130143    errors = [] 
     
    154167            errors.extend(utils.validate_pwm_input(sequences, threshold)) 
    155168 
     169    if 'notes' in request.form: 
     170        notes = request.form['notes'] 
     171 
    156172    if errors: 
    157173        return "ERROR:<p><ul><li> %s</ul>" % ("<li>".join(errors,)) 
     
    160176    motif.source_motifs = "\n".join(sequences) 
    161177    motif.default_threshold = threshold 
     178    motif.notes = notes 
    162179     
    163180    motif.manager.commit() 
     
    170187                  name=motif.name, 
    171188                  sequences=motif.source_motifs, 
    172                   default_threshold=round(motif.default_threshold, 2)) 
     189                  default_threshold=round(motif.default_threshold, 2), 
     190                  notes=motif.notes) 
    173191 
    174192    pwm = motility.make_pwm(sequences) 
     
    186204<p> 
    187205Threshold: <input type='text' name='default_threshold' size='7'> 
    188  
     206<p> 
     207Notes:<br> 
     208 <blockquote> 
     209  <textarea name='notes' rows='5' cols='50'></textarea> 
     210 </blockquote> 
    189211<p> 
    190212<input type='submit' value='save & return to motif list' name='return'> 
     
    214236    for motif in motifs: 
    215237        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             
    217242        if motif.motif_type == 'IUPAC': 
    218243            output.write('%% IUPAC\n%% mismatches=%d\n' % (motif.mismatches,)) 
    219244            output.write('%s' % (motif.motif,)) 
     245 
    220246        elif motif.motif_type == 'PWM': 
    221247            output.write('%% PWM from sites\n') 
  • trunk/cartwheel-server/website/canal/motif/analyze.ptl

    r281 r283  
    2525 
    2626def draw_motifs_on_sequence(dna_seq, motifs, picture_class, 
    27                             seq_start, seq_stop): 
     27                            seq_start, seq_stop, combine=False): 
    2828    """ 
    2929    Do the motif search & use pygr_draw to actually draw a picture. 
     
    3939 
    4040    map_list = [] 
     41    d = {} 
     42     
    4143    for i, motif in enumerate(motifs): 
    4244        color_name = color_rotation[i % len(color_rotation)] 
    4345        color = getattr(colors, color_name) 
    4446 
    45         d = {} 
     47        if not combine: 
     48            d = {} 
     49         
    4650        matches = motif.search(dna_seq, seq_start, seq_stop) 
    4751         
    4852        for n, (start, stop, _, _) in enumerate(matches): 
    49             name = "match%d" % (n,) 
     53            name = "%d-match%d" % (i,n,) 
    5054            d[name] = Annotation(name, 'sequence', start, stop, 
    5155                                 color=color) 
     
    5458            continue 
    5559 
    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] 
    5969 
    6070    # 
     
    94104            stop = len(self.seq.seq) 
    95105 
     106        combine = int(request.form.get('combine', 1)) 
     107 
    96108        ### 
    97109         
     
    110122        <hr> 
    111123        <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
    116128 
    117129        """ 
     
    141153        "</table>" 
    142154 
     155        if combine: 
     156            combineNO = 'selected' 
     157            combineYES = '' 
     158        else: 
     159            combineNO = '' 
     160            combineYES = 'selected' 
     161             
    143162        """ 
    144163        <h4>Adjust parameters:</h4> 
     
    147166        to base <input type="text" name="stop" value="%d">. 
    148167        <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> 
    149173        <input type='submit' value='redraw'> 
    150174        <input type='submit' value='show entire sequence' name='reset_coords'> 
     
    152176        <p> 
    153177        <a href='../'>return to motif library page</a> 
    154         """ % (start, stop
     178        """ % (start, stop, combineNO, combineYES
    155179         
    156180        footer() 
     
    166190        seq_start, seq_stop = min(seq_start, seq_stop),max(seq_start, seq_stop) 
    167191 
     192        combine = int(request.form.get('combine', 1)) 
     193 
    168194        (folder, motifs) = get_folder_motifs(self.manager, request) 
    169195 
    170196        image = draw_motifs_on_sequence(self.seq, motifs, 
    171197                                        pygr_draw.BitmapSequencePicture, 
    172                                         seq_start, seq_stop
     198                                        seq_start, seq_stop, combine=combine
    173199 
    174200        request.response.set_content_type('image/png') 
     
    185211        seq_start, seq_stop = min(seq_start, seq_stop),max(seq_start, seq_stop) 
    186212 
     213        combine = int(request.form.get('combine', 1)) 
     214 
    187215        (folder, motifs) = get_folder_motifs(self.manager, request) 
    188216 
    189217        image = draw_motifs_on_sequence(self.seq, motifs, 
    190218                                        pygr_draw.PDFSequencePicture, 
    191                                         seq_start, seq_stop
     219                                        seq_start, seq_stop, combine=combine
    192220 
    193221        # force a download to a filename 
  • trunk/cartwheel-server/website/canal/motif/pages.ptl

    r281 r283  
    111111        Mismatches to allow: <input type='text' 
    112112              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'> 
    114119        </form> 
    115120<p> 
     
    140145    iupac_str = d['iupac'].parse(request) 
    141146    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): 
    144150        return error("ERROR: you have to enter name and motif!") 
    145151 
     
    166172    manager.create(IUPACMotif, name=name, motif=iupac_str, 
    167173                   motif_type='IUPAC', 
    168                    mismatches=int(mismatches), folder_id=folder_id) 
     174                   mismatches=int(mismatches), 
     175                   notes=notes, 
     176                   folder_id=folder_id) 
    169177 
    170178    manager.commit() 
     
    214222<textarea name='sequences' rows='5' cols='30'></textarea> 
    215223<p> 
     224Notes:<br> 
     225<blockquote> 
     226 <textarea name='notes' rows='5' cols='50'></textarea> 
     227</blockquote> 
     228<p> 
    216229<input type='submit' value='build PWM'> 
    217230</form> 
     
    227240 
    228241    name = request.form['name'].strip() 
     242    notes = request.form.get('notes', '') 
    229243 
    230244    if not name: 
     
    246260    ### ok, validation good so far.  build the PWM & display... 
    247261     
    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 
     264template display_pwm_from_sites(request, name, sequences, notes): 
    251265    header("Motif '%s' created" % (name,)) 
    252266     
     
    273287                       motif_type='PWM', 
    274288                       default_threshold=lowest_score, 
     289                       notes=notes, 
    275290                       folder_id=folder_id) 
    276291