def test_cropping(): features = [ GraphicFeature(start=5, end=20, strand=+1, color="#ffd700", label="Small feature"), GraphicFeature( start=20, end=500, strand=+1, color="#ffcccc", label="Gene 1 with a very long name", ), GraphicFeature(start=400, end=700, strand=-1, color="#cffccc", label="Gene 2"), GraphicFeature(start=600, end=900, strand=+1, color="#ccccff", label="Gene 3"), ] # PLOT AND EXPORT A LINEAR VIEW OF THE CONSTRUCT record = GraphicRecord(sequence_length=1000, features=features) cropped_record = record.crop((425, 650)) assert len(cropped_record.features) == 3
def test_cropping_on_the_edge(): repeated_sequence = "ATGCATGCAT" graphic_record = GraphicRecord( sequence_length=1000, sequence=100 * repeated_sequence ) small_gr = graphic_record.crop((990, 1000)) assert small_gr.sequence == repeated_sequence
def create_dna_structure(file_name): results = request.get_json() features = [] for i, spacerRepeat in enumerate(results['spacerRepeats']): features.append(GraphicFeature(start=spacerRepeat['position'], end=spacerRepeat['position']+len(spacerRepeat['repeat']), strand=+1, color="#cffccc", label="Repeat_"+str(i+1))) if 'spacer' in spacerRepeat: features.append(GraphicFeature(start=spacerRepeat['position']+len(spacerRepeat['repeat'])+1, end=spacerRepeat['position']+len(spacerRepeat['repeat'])+spacerRepeat['lengths'][1], strand=+1, color="#ccccff", label="Spacer_"+str(i+1))) record = GraphicRecord(sequence_length=results['length'], features=features) record = record.crop((results['spacerRepeats'][0]['position']-50, results['spacerRepeats'][len(results['spacerRepeats'])-1]['position']+ len(results['spacerRepeats'][len(results['spacerRepeats'])-1]['repeat'])+50)) ax, _ = record.plot(figure_width=10) ax.figure.savefig('static/logos/'+str(file_name)+'.png', bbox_inches='tight') return jsonify('{"success":1}')
strand=+1, color="#ffcccc", label="Gene 1 with a very long name"), GraphicFeature(start=400, end=700, strand=-1, color="#cffccc", label="Gene 2"), GraphicFeature(start=600, end=900, strand=+1, color="#ccccff", label="Gene 3") ]) zoom_start, zoom_end = 398, 428 # coordinates of the "detail" cropped_record = record.crop((zoom_start, zoom_end)) fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 3)) # PLOT THE WHOLE SEQUENCE ax1.set_title("Whole sequence", loc='left', weight='bold') record.plot(ax=ax1) ax1.fill_between((zoom_start, zoom_end), +1000, -1000, alpha=0.15) # PLOT THE SEQUENCE DETAILS cropped_record.plot(ax=ax2) cropped_record.plot_sequence(ax=ax2) cropped_record.plot_translation(ax=ax2, location=(408, 423),
def show_crispr_grna_results( sequence: str, guides: List[dict], indexes: Optional[List[int]] = None, scoreField: str = "onTargetScore", ): """Shows guide rnas results for CRISPR. Args: sequence (str): A string containing the complete organism sequence guides (dict): A table on 'records' format that contains guides info.\ The required fields are `start` (int), `end` (ind), indicating the limits of the guide in sequence's index. indexes(list): Indexes (start and end) of the targeted sequence within the complete sequence. \ If not set, the targeting sequence is not shown. scoreField (str): Select which score from GRNA tool show in the chart. \ Available scores are "onTargetScore" (default) and "offTargetScore" """ targeting_seq_feat = [] # Show main targeted sequence if index are set. If not, we calculate indexes to limit plot range at the `crop` # instruction. if indexes is not None: targeting_seq_feat = [ GraphicFeature( start=indexes[0], end=indexes[1], color="#cffccc", label="Sequence", strand=+1, ), ] else: # TODO(diegovalenzuelaiturra): Check behavior is the same when using generators instead of lists. # indexes = [min([x['start'] for x in guides]), max([x['end'] for x in guides])] indexes = [ min(x['start'] for x in guides), max(x['end'] for x in guides) ] # Plot records record = GraphicRecord( sequence=sequence, features=targeting_seq_feat + [ GraphicFeature( start=x['start'], end=x['end'] + 1, color="#ffcccc", label=f"{scoreField}: {x[scoreField]}", strand=+1 if x['forward'] else -1, ) for x in guides ], ) # Limit plot range record = record.crop((indexes[0] - 10, indexes[1] + 11)) # crop # Plot and set to show sequence ax, _ = record.plot(figure_width=20) record.plot_sequence(ax)