def vis_pegRNA2(df,genome_fasta=None,**kwargs): """Given one instance of easy-prime prediction (rawX format), generate DNA visualization Input -------- the data frame contains 4 rows: RTT, PBS, sgRNA, ngRNA """ pegRNA_id = df.index.tolist()[0] variant_id = pegRNA_id.split("_")[0] chr = df['CHROM'][0] start = df['start'].min() start -= start%10 start -= 1 end = df['end'].max() end -= end%10 end += 10 variant_pos = df.POS.min() ref = df.REF[0] alt = df.ALT[0] predicted_efficiency = df.predicted_efficiency[0]*100 pos = variant_pos-start sequence = get_fasta_single(chr,start,end,genome_fasta).upper() fig,ax = plt.subplots() feature_list = [] for s,r in df.iterrows(): r_start = r.start-start r_end = r_start+(r.end-r.start) r_strand = get_strand(r.strand) gf = GraphicFeature(start=r_start, end=r_end, strand=r_strand, color=my_colors[r.type],label=r.type) feature_list.append(gf) record = GraphicRecord(sequence=sequence, features=feature_list) # ax, _ = record.plot(figure_width=int(len(sequence)/5)) record.plot(ax=ax,figure_width=int(len(sequence)/5)) return 0 record.plot_sequence(ax) ax.fill_between((pos-1.5, pos-0.5), +1000, -1000, alpha=0.5,color=my_colors['variant']) locs, labels = plt.xticks() new_labels = [] flag = True for i in locs: if flag: new_labels.append("%s %s"%(chr,int(start+i+1))) flag=False else: new_labels.append(int(start+i+1)) plt.xticks(locs,new_labels) plt.title("ID: %s, CHR: %s, POS: %s, REF: %s, ALT: %s \n Predicted efficiency: %.1f"%(variant_id,chr,variant_pos,ref,alt,predicted_efficiency)+"%") my_stringIObytes = io.BytesIO() ax.figure.savefig(my_stringIObytes, format='png',bbox_inches='tight') my_stringIObytes.seek(0) img_string = base64.b64encode(my_stringIObytes.read()) return "data:image/png;base64,%s"%(img_string.decode("utf-8"))
def Visualiser_sekvens(gen): import warnings from Bio import BiopythonParserWarning warnings.simplefilter('ignore', BiopythonParserWarning) if gen == 'alle': fil = 'Artemisia%20annua.gb' graphic_record = ChangeFeatures().translate_record(fil) ax, _ = graphic_record.plot(figure_width=20) ax.figure.tight_layout() elif gen == "aldh1": sequence = "CTGTGTCTAGATTTACGGTTTTGTTGAGTATGGAGTATTTATCCCTGTGTCTAGATTTACGGTTTGAAGACTCAGGAAACTCTCATTAAGCGATCAACGTAGCATGATCATCAAAAGCATGGTTTTGTAAACTCGACATGTCAATGTACCAGCCGATCCAAGTATCCAAGCAATTGGTTCACCACACCAAAAGAGTTTTACACTTAAAAACAACAATTAATTCTAAATAGTCTATGTAATGAAATATGTTTTGTGTGGGTTAGTTTAGTTCATAGTTGCGCCATAAGTATTTACAGCAA" record = GraphicRecord(sequence=sequence, features=[ GraphicFeature(start=0, end=28, strand=+1, color='#ffd700', label="Promotor"), GraphicFeature(start=29, end=299, strand=+1, color="#ffcccc", label="aldh1") ]) ax, _ = record.plot(figure_width=50) record.plot_sequence(ax) record.plot_translation(ax, (29, 299), fontdict={'weight': 'bold'}) elif gen == 'CYP71AV1': sequence = "ATTTTTGGGGGCCCCCCCCCATTTTTTGGGGGGCGCGCGATGAAGTTGGTCATTCGAAATATACTTCCAAAATATGAAGTTGGTCATTCGAAATATACTTCCAAACAACCGAGCTGGTCAGGTAGATTTTGTTTCAGATGAAGATGCAATCCACCGTTGGGGGAGTTTCATGAATAACAATCGCAAATAAGATATATTGTTGATTCTTGATGATGTTTGGTCTGATACCATCATCACCGACCTCCAATTCAGGTCACGTGGATACAAGATCCTCGTGACCTCTGAAACAACCTTTAAGAGATTCGATACATATAAAGTGAGACCTCTCAGTGTTCAAGATGCCATCAATCTGTTATGCTATTCAACACTTTCGGAGCGTGCAAGTCAAGCCACAAATGACATACAGACCTTGTTGACAAGGTGAAATTTCAAATTATTCCAAGATTCATGTTTCATACCTTTATAAGAAAGTAATATCTAAACCATATTAACAAATACTAACAATTAACTTTCAAATGTTTTTGTAGTTAACCAAATGTTGCAAGAAGAATCCGCTCGCCTTAAGTGTCATTGGTGGTCGCCTAAAGGGGACACAAATGGAAAGTTGGCATCATACACTGAAAAAGCTATCTCAAGCCACACACCCTCTTATCGACCTTCCTTTGGATGAGGCAAACAGATTTCATCTCGCAAGAGCTCTCGGTTTACTCAAAGATGATGAACGCAACAGCCCCAGAAGTTCAACCTCGAAATTGACCCGATCTTACCAAGTCA" record = GraphicRecord(sequence=sequence, features=[ GraphicFeature(start=1, end=38, strand=+1, color='#cffccc', label="Promotor"), GraphicFeature(start=39, end=774, strand=+1, color="#cff77d", label="CYP71AV1") ]) ax, _ = record.plot(figure_width=100) record.plot_sequence(ax) record.plot_translation(ax, (39, 774), fontdict={'weight': 'bold'}) return
def haplotype_blocks_fig(model, ref_seq): s1, s2 = model.align_alleles() record = GraphicRecord(sequence=ref_seq, sequence_length=len(ref_seq), features=[ GraphicFeature(start=0, end=len(s1), strand=+1, color='#ffcccc'), GraphicFeature(start=0, end=len(s2), strand=+1, color='#cffccc') ]) ax, _ = record.plot(figure_width=5) record.plot_sequence(ax) record.plot_translation(ax, (8, 23), fontdict={'weight': 'bold'}) ax.figure.savefig('haplotypes.png', bbox_inches='tight')
def test_sequence_and_translation_plotting(): from dna_features_viewer import ( GraphicFeature, GraphicRecord, CircularGraphicRecord, ) features = [ GraphicFeature( start=5, end=10, strand=+1, color="#ffd700", label="bbS-1" ), GraphicFeature( start=8, end=15, strand=+1, color="#ffcccc", label="CrC" ), ] record = GraphicRecord(sequence=7 * "ATGC", features=features) ax, _ = record.plot(figure_width=5) record.plot_sequence(ax) record.plot_translation(ax, (8, 23), fontdict={"weight": "bold"})
from dna_features_viewer import GraphicFeature, GraphicRecord record = GraphicRecord(sequence="ATGCATGCATGCATGCATGCATGCATGC", features=[ GraphicFeature(start=5, end=10, strand=+1, color='#ffcccc'), GraphicFeature(start=8, end=15, strand=+1, color='#ccccff') ]) ax, _ = record.plot(figure_width=5) record.plot_sequence(ax) record.plot_translation(ax, (8, 23), fontdict={'weight': 'bold'}) ax.figure.savefig('sequence_and_translation.png', bbox_inches='tight')
def probe_graph(file_name, path): #file_name = "results_riftl_test.txt" #file_name = sys.argv[1] f = open(file_name, "r") probes = [] for line in f: print(line) line_info = line.split(':') #print(line) #print(line_info) if (line_info[0] == "Sequence"): sequence = line_info[1] elif (line_info[0] == "Initiator"): initiator1 = line_info[1].upper() initiator2 = line_info[2].upper() elif (line_info[0] == "Probes"): probes.append(line_info[1].upper()) probes.append(line_info[3].upper()) probes.append(line_info[2]) probes.append(line_info[4]) elif (line_info[0] == "Name"): name = line_info[1].rstrip() file_write = path + "/" + name + "_Probe_Set" ".txt" w = open(file_write, "w+") """print(sequence) print(initiator1) print(initiator2) print(probe1) print(probe2) print(start)""" x = 1 print(probes) print(name) for a in range(0, len(probes), 4): gstart = 28 gend = 3 probe1 = probes[a] probe2 = probes[a + 1] probe1 = Seq(probe1) probe1 = probe1.complement() probe2 = Seq(probe2) probe2 = probe2.complement() probe1 = str(probe1) probe2 = str(probe2) start = probes[a + 2] end = probes[a + 3] start = int(start) start -= 4 if start <= 0: gend = 0 - start - 1 gstart = gend + 25 start = 0 end = int(end) subseq = sequence[start:end] subseq = subseq.upper() record = GraphicRecord( sequence=subseq, features=[ GraphicFeature(start=gstart, end=gend, strand=+1, color='#ffcccc', label=probe1), GraphicFeature(start=gstart + 28, end=gstart + 2, strand=+1, color='#ccccff', label=probe2), GraphicFeature(start=gstart, end=gstart, strand=-1, color='m', label="space"), GraphicFeature(start=gstart + 1, end=gstart + 1, strand=-1, color='m', label="space"), GraphicFeature(start=gstart, end=(gstart - len(initiator1)), strand=-1, color='y', label=initiator1), GraphicFeature(start=gstart + 2, end=(gstart + 2 + len(initiator1)), strand=+1, color='y', label=initiator2) ]) ax, _ = record.plot(figure_width=10) record.plot_sequence(ax) total1 = initiator1 + "TT" + probe1[::-1] total2 = probe2[::-1] + "TT" + initiator2 w.write("PROBE SET" + str(x) + "\n") w.write("Probe1:" + total1 + "\n") w.write("Probe2:" + total2 + "\n") #print(total2) tosave = path + "/" + name + "Plots for Probes" + str(x) x += 1 ax.figure.savefig(tosave, bbox_inches='tight') #break w.close()
from dna_features_viewer import GraphicFeature, GraphicRecord record = GraphicRecord(sequence="ATGCATGCATGCATGCATGCATGCATGC", features=[ GraphicFeature(start=5, end=10, strand=+1, color='#ffcccc'), GraphicFeature(start=8, end=15, strand=+1, color='#ccccff') ]) ax, _ = record.plot(figure_width=6) record.plot_sequence(ax, guides_intensity=0.2) fontdict = {'weight': 'bold'} record.plot_translation(ax, (8, 23), fontdict=fontdict, guides_intensity=0.8) ax.figure.savefig('sequence_and_translation.png', bbox_inches='tight')
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)