Changeset 273

Show
Ignore:
Timestamp:
01/20/08 02:03:59 (10 months ago)
Author:
t
Message:

fixed get_motifs; added PDF download.

Files:

Legend:

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

    r265 r273  
    5656    def get_motifs(self): 
    5757        from cartwheel.website.NamedMotif import NamedMotif 
     58        from cucumber.DeepCatalog import DeepCatalog 
    5859         
    5960        m = self.manager 
     
    6162        limits = ['folder_id = %d' % (self.id,), 'visible'] 
    6263 
    63         c = m.createCatalog(NamedMotif, limits, 
    64                             "ORDER BY UPPER(named_motifs.name)") 
     64        c = DeepCatalog(m, NamedMotif, 
     65                        limits, 
     66                        "ORDER BY UPPER(named_motifs.name)") 
    6567 
    6668        return c 
  • trunk/cartwheel-server/website/canal/motif/analyze.ptl

    r272 r273  
    1919    return (folder, motifs) 
    2020 
     21def draw_motifs_on_sequence(dna_seq, motifs, picture_class, 
     22                            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 
     49 
    2150class AnalyzeSequenceHandler: 
    2251    _q_exports = ['_q_index', 
    23                   'draw_png', 
     52                  'draw_png', 'draw_pdf', 
    2453                  'matches_detail', 
    2554                  'export_matches_IUPAC', 
     
    5079        <p> 
    5180        <h4>Motif matches graphed against sequence:</h4> 
     81        <a href='draw_pdf??start=%d&stop=%d'>(download as PDF)</a><br> 
    5282        <img src='draw_png?start=%d&stop=%d'> 
    5383        <p> 
    54         """ % (start, stop
     84        """ % (start, stop, start, stop
    5585 
    5686        """ 
     
    6494        for i, motif in enumerate(motifs): 
    6595            color_name = color_rotation[i % len(color_rotation)] 
    66             motif = self.manager.load(motif.id) 
    6796            key = motif.simple_key() 
    6897             
     
    97126        seq_stop = min(len(self.seq.seq), seq_stop) 
    98127 
    99         picture_class = pygr_draw.BitmapSequencePicture 
    100         colors = pygr_draw.BitmapSequencePicture.colors 
    101  
    102         sequencedb = dict(sequence=pygr.sequence.Sequence(self.seq.seq, 
    103                                                           'sequence')) 
    104  
    105128        (folder, motifs) = get_folder_motifs(self.manager, request) 
    106129 
    107         map_list = [] 
    108         for i, motif in enumerate(motifs): 
    109             color_name = color_rotation[i % len(color_rotation)] 
    110             color = getattr(colors, color_name) 
    111              
    112             motif = self.manager.load(motif.id) 
    113              
    114             d = {} 
    115             matches = motif.search(self.seq) 
    116             for n, (start, stop, _, _) in enumerate(matches): 
    117                 name = "match%d" % (n,) 
    118                 d[name] = Annotation(name, 'sequence', start, stop, 
    119                                      color=color) 
    120  
    121             map = pygr_draw.create_annotation_map(d, sequencedb) 
    122  
    123             map_list.append(map) 
    124  
    125         sequence = sequencedb['sequence'][seq_start:seq_stop] 
    126         p = pygr_draw.draw_annotation_maps(sequence, map_list, 
    127                                            picture_class=picture_class) 
    128  
    129         image = p.finalize() 
     130        image = draw_motifs_on_sequence(self.seq, motifs, 
     131                                        pygr_draw.BitmapSequencePicture, 
     132                                        seq_start, seq_stop) 
     133                                         
    130134        request.response.set_content_type('image/png') 
    131  
     135        return image 
     136 
     137    def draw_pdf(self, request): 
     138        form = request.form 
     139        seq_start = int(form.get('start', 0)) 
     140        seq_start = max(seq_start, 0) 
     141         
     142        seq_stop = int(form.get('stop', len(self.seq.seq))) 
     143        seq_stop = min(len(self.seq.seq), seq_stop) 
     144 
     145        (folder, motifs) = get_folder_motifs(self.manager, request) 
     146 
     147        image = draw_motifs_on_sequence(self.seq, motifs, 
     148                                        pygr_draw.PDFSequencePicture, 
     149                                        seq_start, seq_stop) 
     150 
     151        # force a download to a filename 
     152        filename = 'motifs-seq%d.pdf' % (self.seq.id,) 
     153        request.response.set_header('Content-Disposition', 
     154                                    'attachment; filename=%s' % (filename,)) 
     155        request.response.set_header('Content-Length', len(image)) 
     156        request.response.set_header('Content-Type', 'binary/octet-stream') 
    132157        return image 
    133158 
  • trunk/cartwheel-server/website/canal/motif/pages.ptl

    r270 r273  
    3232 
    3333        for motif in motifs: 
    34             motif = manager.load(motif.id) 
    3534            """ 
    3635            <tr>