Changeset 276

Show
Ignore:
Timestamp:
01/20/08 22:38:34 (10 months ago)
Author:
t
Message:

added start/stop arguments to detail views

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cartwheel-server/lib/cartwheel/website/IUPACMotif.py

    r269 r276  
    55    mymembers = ('motif', 'mismatches') 
    66 
    7     def search(self, sequence): 
     7    def search(self, sequence, start, stop): 
    88        """ 
    99        sequence is FolderSequence. 
     
    1111        import motility 
    1212 
    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) 
    1416 
    1517    def extra_information(self): 
  • trunk/cartwheel-server/lib/cartwheel/website/NamedMotif.py

    r269 r276  
    55    mymembers = ('name', 'motif_type', 'folder_id', 'visible') 
    66 
    7     def search(self, sequence):         # actually runs the search 
     7    def search(self, sequence, start, stop):         # actually runs the search 
    88        raise NotImplementedError 
    99 
  • trunk/cartwheel-server/lib/cartwheel/website/PWMMotif.py

    r270 r276  
    1515        return pwm 
    1616 
    17     def search(self, sequence): 
     17    def search(self, sequence, start, stop): 
    1818        """ 
    1919        sequence is FolderSequence. 
     
    2424        pwm = motility.make_pwm(sites) 
    2525 
    26         return pwm.find(sequence.seq, self.default_threshold) 
     26        return pwm.find(sequence.seq[start:stop], 
     27                        self.default_threshold, offset=start) 
    2728 
    2829    def extra_information(self): 
  • trunk/cartwheel-server/website/canal/motif/__init__.py

    r269 r276  
    1111 
    1212def edit(request): 
     13    #motif_id = int(request.form['motif_id']) 
    1314    assert 0 
    1415 
  • trunk/cartwheel-server/website/canal/motif/analyze.ptl

    r275 r276  
    22Web handler for dealing with sequence analysis by motifs. 
    33""" 
     4 
     5import urllib 
    46 
    57import cartwheel.website 
     
    2123def draw_motifs_on_sequence(dna_seq, motifs, picture_class, 
    2224                            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 
    4963 
    5064class AnalyzeSequenceHandler: 
     
    91105        </tr> 
    92106        """ 
    93          
     107 
    94108        for i, motif in enumerate(motifs): 
    95109            color_name = color_rotation[i % len(color_rotation)] 
    96110            key = motif.simple_key() 
    97111             
     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             
    98117            """ 
    99118            <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> 
    101120              </td> 
    102121            </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) 
    105123 
    106124        "</table>" 
     
    167185             
    168186    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) 
    170195 
    171196        ### sort 
    172197 
    173         sort_by = request.form.get('sort_by') 
     198        sort_by = form.get('sort_by') 
    174199        sort_fn = lambda x,y: cmp(x[0], y[0]) 
    175200        sorted_text = 'position' 
     
    183208        matches = list(matches) 
    184209        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) 
    185217 
    186218        ### display 
     
    208240            """ 
    209241            <h3>Matches</h3> 
    210             %d matches, sorted by %s. 
     242            %(n_matches)d matches, sorted by %(sorted_text)s. 
    211243            <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> or 
    214              <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> 
    215247            <p> 
    216248            <table border="1"> 
     
    221253              <th>Match</th> 
    222254            </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) 
    225258 
    226259            for (start, stop, orientation, match_seq) in matches: 
     
    239272 
    240273    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 
    241283        pwm = motif.make_pwm() 
    242         matches = motif.search(self.seq
     284        matches = motif.search(self.seq, seq_start, seq_stop
    243285 
    244286        # add in score. 
     
    263305        matches.sort(sort_fn) 
    264306 
     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 
    265314        ### display 
    266315 
     
    287336            """ 
    288337            <h3>Matches</h3> 
    289             %d matches, sorted by %s. 
     338            %(n_matches)d matches, sorted by %(sorted_text)s. 
    290339            <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>, or 
    294              <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> 
    295344            <p> 
    296345            <table border="1"> 
     
    302351              <th>Score</th> 
    303352            </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             
    307357            for (start, stop, orientation, match_seq, score) in matches: 
    308358                o = 'forward' 
     
    320370 
    321371    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 
    322381        motif_id = int(request.form['motif_id']) 
    323382        motif = self.manager.load(motif_id) 
    324383 
    325         matches = motif.search(self.seq
     384        matches = motif.search(self.seq, seq_start, seq_stop
    326385 
    327386        s = """# motif: %s/%s/%d mismatches\n# sequence: %s\n""" % \ 
     
    337396 
    338397    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         
    339407        motif_id = int(request.form['motif_id']) 
    340408        motif = self.manager.load(motif_id) 
     
    342410        consensus = motif.simple_key() 
    343411        pwm = motif.make_pwm() 
    344         matches = motif.search(self.seq
     412        matches = motif.search(self.seq, seq_start, seq_stop
    345413 
    346414        s = """# PWM motif %s: consensus %s/threshold %f\n# sequence: %s\n"""%\