def draw_2nd_structure(srna): for i in range(3): name = srna.loc[i, "name"] sequence = srna.loc[i, "sequence"] folding = fold_rna(srna.loc[i, "sequence"])[0] print("##############", name, "###############") print(sequence) print(folding) print() fx_test = ">{0}\n{1}\n{2}\n".format(name, sequence, folding) textfile = open('./resources/' + srna.loc[i, "name"] + '.fx', "w") textfile.write(fx_test) textfile.close() for i in range(3): ##Print Structure plt.figure(figsize=(20, 20)) cg = forgi.load_rna('./resources/' + srna.loc[i, "name"] + '.fx', allow_many=False) fvm.plot_rna(cg, text_kwargs={"fontweight": "black"}, lighten=0.7, backbone_kwargs={"linewidth": 3}) plt.show() # plt.savefig(srna.loc[i, "name"]+'.png') return srna
def visualize(prim_str, pred_string, true_string, save_imgs = False, suffix_img = ''): corr_string = balance_op_tmp(pred_string) print(f'pred: {pred_string}') print(f"true: {true_string}") print(f'corr: {corr_string}') with open('tmp_vis_pred.txt', 'w') as f: f.write(prim_str+ os.linesep) f.write(corr_string+ os.linesep) f.close with open('tmp_vis_true.txt', 'w') as f: f.write(prim_str+ os.linesep) f.write(true_string+os.linesep) f.close plt.figure(figsize = (20, 20)) plt.title('predicted') cg = forgi.load_rna('tmp_vis_pred.txt', allow_many=False) fvm.plot_rna(cg, text_kwargs={"fontweight":"black"}, lighten=0.7,backbone_kwargs={"linewidth":3}) if save_imgs: plt.savefig(f'pred_{suffix_img}.jpg') plt.show() plt.figure(figsize = (20, 20)) plt.title('original') cg = forgi.load_rna('tmp_vis_true.txt', allow_many=False) fvm.plot_rna(cg, text_kwargs={"fontweight":"black"}, lighten=0.7,backbone_kwargs={"linewidth":3}) plt.savefig(f'true_{suffix_img}.jpg') plt.show()
def plot_sample(sample): """Source: https://www.kaggle.com/erelin6613/openvaccine-rna-visualization""" struct = sample['structure'] seq = sample['sequence'] bg = fgb.BulgeGraph.from_fasta_text(f'>rna1\n{struct}\n{seq}')[0] plt.figure(figsize=(20, 8)) fvm.plot_rna(bg) plt.title(f"RNA Structure (id: {sample.id})") plt.show()
def draw_structure( ): #Spits out a 2D image representing the structure of the RNA sequence for i in lines[1::3]: cg = str(i) fvm.plot_rna(cg, text_kwargs={"fontweight": "black"}, lighten=0.7, backbone_kwargs={"linewidth": 3}) plt.show()
def structure(sequence, dot_bracket, mirna_name, index): out_dir = index + "/mirna" with open(out_dir + "/" + mirna_name + ".db", "w") as temp_file: temp_file.write(sequence + '\n') temp_file.write(dot_bracket) cg = forgi.load_rna(out_dir + "/" + mirna_name + ".db", allow_many=False) fvm.plot_rna(cg, text_kwargs={"fontweight": "black"}, lighten=0.7, backbone_kwargs={"linewidth": 3}) plt.savefig("gui/src/assets/" + mirna_name + ".png")
def plot_sample(idx = 1, sequence=None, df=train): fig = plt.figure(figsize=(15,15)) fig.patch.set_facecolor((160/255, 177/255, 198/255)) if sequence is not None: samp = df[df.id == sequence] else: samp = df[df.index == idx] rna = [] seq = samp.loc[samp.index[0], 'sequence'] struct = samp.loc[samp.index[0], 'structure'] bg = fgb.BulgeGraph.from_fasta_text(f'>rna1\n{struct}\n{seq}')[0] fvm.plot_rna(bg, text_kwargs={"fontweight":"bold", }, lighten=0.8, backbone_kwargs={"linewidth":3}) plt.show()
Sequence = train_df[train_df['id'] == Select_id]["sequence"].values[0] structure = train_df[train_df['id'] == Select_id]["structure"].values[0] predicted_loop_type = train_df[train_df['id'] == Select_id]["predicted_loop_type"].values[0] bg, = bulge_graph.BulgeGraph.from_fasta_text('>seq\n' + Sequence + '\n' + structure) print("Sequence :", Sequence) print("Structure :", structure) print("Predicted Loop type :", predicted_loop_type) print("Generated Loop type :", bg.to_element_string()) # In[8]: plt.figure(figsize=(10, 10)) fvm.plot_rna(bg, text_kwargs={"fontweight": "black"}, lighten=0.7, backbone_kwargs={"linewidth": 3}) plt.show() # ## Generating Graph Matrices from the Structures # * [Referance](https://www.kaggle.com/theoviel/generating-graph-matrices-from-the-structures) # In[9]: def build_matrix(couples, size): mat = np.zeros((size, size)) for i in range(size): # neigbouring bases are linked as well if i < size - 1: mat[i, i + 1] = 1
predicted_loop_type = train_df[train_df['id'] == Select_id]["predicted_loop_type"].values[0] print("Sequence :", Sequence) print("structure :", structure) print("predicted_loop_type :", predicted_loop_type) # ## Visualize RNA-2D Structure # In[23]: bg, = bulge_graph.BulgeGraph.from_fasta_text('>seq\n' + Sequence + '\n' + structure) plt.figure(figsize=(10, 10)) fvm.plot_rna(bg, text_kwargs={"fontweight": "black"}, lighten=0.7, backbone_kwargs={"linewidth": 3}) plt.show() # ## Method for Graph Representation of RNA structure # * In 2D-Visualization it is difficult to picture which section is which part of RNA. To make it easier, we will generate a Graph Structure. The neato method can take that as input and create a nice visualization of the graph: # In[24]: def render_neato(s, format='png', dpi=100): p = subprocess.Popen( ['neato', '-T', format, '-o', '/dev/stdout', '-Gdpi={}'.format(dpi)], stdout=subprocess.PIPE, stdin=subprocess.PIPE)