def json(self): """ Return coordinates for blobs in JSON format. """ picture_class = pygr_draw.PythonList pic = pygr_draw.draw_annotation_maps(self.interval, self.nlmsa_list, picture_class=picture_class, wrappers=self.wrappers) l = pic.finalize() return json.dumps(l)
def png(self): """ Draw & return a png for the given interval / NLMSAs. """ from pygr_draw.BitmapSequencePicture import BitmapSequencePicture picture_class = BitmapSequencePicture pic = pygr_draw.draw_annotation_maps(self.interval, self.nlmsa_list, picture_class=picture_class, wrappers=self.wrappers) image = pic.finalize() response = quixote.get_response() response.set_content_type('image/png') return image
from pygr import seqdb genome = seqdb.BlastDB('example.fa') sequence_name = 'chrI' import pygr_draw from pygr_draw import AnnotationGroup, Annotation picture_class = pygr_draw.BitmapSequencePicture colors = picture_class.colors annotations2 = {} annotations2['blip'] = Annotation('blip', sequence_name, 25, 75, color=colors.green) annotations2['gene1'] = AnnotationGroup('gene1', sequence_name, ((50, 100), (200, 300), (500, 1500)),color=colors.red) annotations2['gene2'] = AnnotationGroup('gene2', sequence_name, ((100, 300), (1500, 2000), (3000, 3750)),color=colors.blue) annotations2['gene3'] = AnnotationGroup('gene3', sequence_name, ((3800, 4000), ( 4500, 5000)),color=colors.blue) annotations_map = pygr_draw.create_annotation_map(annotations2, genome) p = pygr_draw.draw_annotation_maps(genome[sequence_name][:4000],(annotations_map,),picture_class=picture_class) image = p.finalize() filename = 'group-example.png' open(filename, 'w').write(image) print 'Output in', filename
def json(self): """ Return coordinates for blobs in JSON format. """ #use request.form instead?? request = quixote.get_request().get_fields() #request should contain: # rel: relation - "view", "left", "right", "zin", "zout" # sequence # start # stop try: start=int(request['start']) stop=int(request['stop']) sequence=request['sequence'] except KeyError: assert False, "Incomplete AJAX request." # we may want to raise a 501 server error here that the ajax can catch assert start!=stop, "Sequence start and stop are invalid." #Calculate the old interval interval = '%s:%d-%d' % (sequence, start, stop) ival = parse_interval_string(self.genome_db, interval) parent_len = len(ival.pathForward) if request['rel']=='view': start = max(start, 0) stop = min(stop, parent_len) elif request['rel']=='left': start = max(ival.start - len(ival)/2, 0) stop = min(start + len(ival), parent_len) elif request['rel']=='zin': start = ival.start + len(ival) / 4 stop = ival.stop - len(ival) / 4 elif request['rel']=='zout': start = max(ival.start - len(ival)/2, 0) stop = min(ival.stop + len(ival)/2, parent_len) elif request['rel']=='right': start = max(ival.start + len(ival)/2, 0) stop = min(start + len(ival), parent_len) #Calculate the new interval interval = '%s:%d-%d' % (request['sequence'], start, stop) ival = parse_interval_string(self.genome_db, interval) #get the data for the canvas drawing jsonObj="" if(USE_PYTHONLIST): from pygr_draw.PythonList import PythonList picture_class = PythonList pic = pygr_draw.draw_annotation_maps(ival, self.nlmsa_list, picture_class=picture_class, wrappers=self.wrappers) jsonObj = pic.finalize() return json.dumps({"start":start,"stop":stop,"sequence":sequence,"data":jsonObj}) else: from pygr_draw.JSONSequencePicture import JSONSequencePicture picture_class = JSONSequencePicture pic = pygr_draw.draw_annotation_maps(ival, self.nlmsa_list, picture_class=picture_class, wrappers=self.wrappers) jsonObj = pic.finalize() return json.dumps({"start":start,"stop":stop,"sequence":sequence,"data":jsonObj})
est_map = '/u/t/dev/lamprey-est-map/data/52/aln-52' al1 = cnestedlist.NLMSA(est_map) # plot the ESTs with names == sequence.id, color == 'red' wrapper_est = SequenceWrapperFactory(color='red') reads_filename = '/u/t/dev/lamprey-est-map/data/brain-rnaseq/lamprey30M2H/s_1_al-trim3-20' al2 = cnestedlist.NLMSA(reads_filename) wrapper_read = SequenceWrapperFactory(name='') # because we're not using pygr.Data, the NLMSAs have different seqdbs # for the supercontigs. We have to munge them to make them the same # so that we can do a single draw. EVIL. Ignore Me. sc = al1.seqDict.prefixDict['supercontigs'] al2.seqDict.prefixDict['supercontigs'] = al1.seqDict.prefixDict['supercontigs'] al2.seqDict.dicts[sc] = 'supercontigs' # choose the sequence to plot contig1 = al1.seqDict['supercontigs.Contig0'][:5000] # build a png picture_class = pygr_draw.BitmapSequencePicture p = pygr_draw.draw_annotation_maps(contig1, (al1, al2), picture_class=picture_class, wrappers=(wrapper_est, wrapper_read)) # write out image = p.finalize() filename = 'draw.png' open(filename, 'w').write(image)