def plot_asymmetry_comp(inputs, paths_in, paths_out, settings): #sns.boxplot(data=iris, orient="h", palette="Set2") files = inputs['files'] path_figure = paths_out['path_figures'] + 'Comparison/' minlength = settings['minlength'] maxlength = settings['maxlength'] minlength_1 = str(minlength) + '_' maxlength_1 = str(maxlength) + '_' name_settings = minlength_1 + maxlength_1 data = {} score_list = [] fname_list = [] plot_count = 0 fnames = '' for fname in files: fnames += fname plot_count += 1 path_analysis = paths_out['path_analysis'] + fname + '/' asymmetry_dict = ribo_util.unPickle(path_analysis + 'asymmetry') df = pd.DataFrame(asymmetry_dict) #display(df) score = df['Score'].values.tolist() for value in score: fname_list.append(fname) score_list.append(value) data['file'] = fname_list data['score'] = score_list data = pd.DataFrame(data) sns.set_style("white") plot = plt.figure(figsize=(20, 10)) plot = sns.boxplot(x="score", y='file', data=data, orient="h", color="grey", fliersize=0) plot.axvline(linewidth=3, color='r') plot.set(xlim=(-5, 5)) plot.tick_params(labelsize=18) sns.despine(offset=5) plt.savefig(path_figure + 'asymmetry/' + fnames + name_settings + '.pdf', dpi=600, bbox_inches="tight") plt.show()
def plot_pausescore(inputs, paths_in, paths_out, settings, settings_plot): files = inputs['files'] aa_codon = settings_plot['aa_or_codon'] aminoacids = settings_plot['amino_acid'] codons = settings_plot['codon'] ymax_dot = settings_plot['ymax_dot'] ymax_line = settings_plot['ymax_line'] vmax_HM = settings_plot['vmax_HM'] path_figure = paths_out['path_figures'] aa_plots = len(aminoacids) codon_plots = len(codons) aa_code, codon_code = ribo_util.get_genetic_code() for fname in files: minlength = settings['minlength'] maxlength = settings['maxlength'] plot_upstream = settings[ 'plot_upstream'] / 3 * 3 #change window to interval of 3 plot_downstream = settings['plot_downstream'] / 3 * 3 start_trim = settings['start_trim'] / 3 * 3 stop_trim = settings['stop_trim'] / 3 * 3 frameshift = settings['frameshift'] A_site = settings['A_site shift'] minlength_1 = str(minlength) + '_' maxlength_1 = str(maxlength) + '_' plot_upstream_1 = str(plot_upstream) + '_' plot_downstream_1 = str(plot_downstream) + '_' start_trim_1 = str(start_trim) + '_' stop_trim_1 = str(stop_trim) + '_' frameshift_1 = str(frameshift) + '_' a_site_1 = str(A_site) + '_' name_settings = minlength_1 + maxlength_1 + plot_upstream_1 + plot_downstream_1 name_settings += start_trim_1 + stop_trim_1 + frameshift_1 path_pausescore = paths_out['path_analysis'] + fname + '/pause_score/' ### For aa_analysis ### if aa_codon == 'aa': aa_score = ribo_util.unPickle(path_pausescore + 'aa_scores' + name_settings) aa_HM = ribo_util.unPickle(path_pausescore + 'aa_HM_data' + name_settings) aa_plot = ribo_util.unPickle(path_pausescore + 'aa_plot_data' + name_settings) aa_df = pd.DataFrame(aa_score) aa_df = aa_df.sort_values(by=['Amino Acid']) sns.set_style("white") sns.set_context("talk") plt.figure(figsize=(8 + 4 * aa_plots, 5)) plt.subplot2grid((2, 2 + aa_plots), (0, 0), rowspan=2, colspan=2) plot = sns.stripplot(x="Amino Acid", y="A_site", data=aa_df, size=12) plot = sns.stripplot(x="Amino Acid", y="P_site", data=aa_df, size=6, color='black') plot = sns.stripplot(x="Amino Acid", y="E_site", data=aa_df, size=6, color='grey') #sns.despine(offset=5, trim = True ) plt.ylim(0, ymax_dot) plot.axhline(y=1, xmin=0, xmax=1, dashes=[2, 2, 2, 2], color='grey') plt.title(fname + ' Amino Acid Pause Scores') plt.xlabel("Amino Acid") plt.ylabel("Pause Score") aa_HM_dict = {} aa_plot_dict = {} for aa in aminoacids: df_HM = pd.DataFrame(aa_HM[aa]) df_plot = pd.DataFrame(aa_plot[aa]) aa_HM_dict[aa] = df_HM aa_plot_dict[aa] = df_plot xlim_lower = aa_plot_dict[aa].index[0] xlim_upper = aa_plot_dict[aa].index[-1] sns.set_style("white") sns.set_style("ticks") plotnum = 0 for aa in aminoacids: plt.subplot2grid((2, 2 + aa_plots), (0, 2 + plotnum), rowspan=1, colspan=1) plot_2 = plt.plot(aa_plot_dict[aa], sns.xkcd_rgb["dark grey"]) plt.title(aa + ' Average Plot') plt.ylabel("Pause Score") plt.ylim(0, ymax_line) plt.xlim(xlim_lower, xlim_upper) sns.despine(offset=5) plt.subplot2grid((2, 2 + aa_plots), (1, 2 + plotnum), rowspan=1, colspan=1) plot_3 = sns.heatmap(aa_HM_dict[aa], cmap="ocean_r", vmin=0, vmax=vmax_HM, cbar=False, xticklabels=15, yticklabels=6) sns.despine(offset=5) plotnum += 1 plt.tight_layout() plt.savefig(path_figure + fname + '/aa_pausescore' + name_settings + '_aa_pause_scores.png', dpi=400) plt.show() aa_plot_csv = pd.DataFrame(aa_plot) aa_plot_csv.to_csv(path_pausescore + 'aa_plot_values.csv') ### For codon_analysis ### if aa_codon == 'codon': codon_score = ribo_util.unPickle(path_pausescore + 'codon_scores' + name_settings) codon_HM = ribo_util.unPickle(path_pausescore + 'codon_HM_data' + name_settings) codon_plot = ribo_util.unPickle(path_pausescore + 'codon_plot_data' + name_settings) aa_list = [] for codon in codon_score['Codon']: aa = codon_code[codon] aa_list.append(aa) codon_score['Amino_Acid'] = aa_list codon_df = pd.DataFrame(codon_score) codon_df = codon_df.sort_values(by=['Amino_Acid', 'Codon']) sns.set_style("white") sns.set_context("talk") plt.figure(figsize=(28 + 4 * codon_plots, 5)) plt.subplot2grid((2, 7 + codon_plots), (0, 0), rowspan=2, colspan=7) plot = sns.stripplot(x="Codon", y="A_site", data=codon_df, size=12) plot = sns.stripplot(x="Codon", y="P_site", data=codon_df, size=6, color='black') plot = sns.stripplot(x="Codon", y="E_site", data=codon_df, size=6, color='grey') #sns.despine(offset=5, trim = True ) plt.ylim(0, ymax_dot) plot.axhline(y=1, xmin=0, xmax=1, dashes=[2, 2, 2, 2], color='grey') plot.axvline(x=3.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(1, 4, 'A', fontsize=30) #add text plot.axvline(x=5.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(4, 4, 'C', fontsize=30) #add text plot.axvline(x=7.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(6, 4, 'D', fontsize=30) #add text plot.axvline(x=9.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(8, 4, 'E', fontsize=30) #add text plot.axvline(x=11.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(10, 4, 'F', fontsize=30) #add text plot.axvline(x=15.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(13, 4, 'G', fontsize=30) #add text plot.axvline(x=17.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(16, 4, 'H', fontsize=30) #add text plot.axvline(x=20.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(18.8, 4, 'I', fontsize=30) #add text plot.axvline(x=22.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(21, 4, 'K', fontsize=30) #add text plot.axvline(x=28.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(25, 4, 'L', fontsize=30) #add text plot.axvline(x=29.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(28.6, 4, 'M', fontsize=30) #add text plot.axvline(x=31.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(30, 4, 'N', fontsize=30) #add text plot.axvline(x=35.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(33, 4, 'P', fontsize=30) #add text plot.axvline(x=37.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(36, 4, 'Q', fontsize=30) #add text plot.axvline(x=43.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(40, 4, 'R', fontsize=30) #add text plot.axvline(x=49.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(46, 4, 'S', fontsize=30) #add text plot.axvline(x=53.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(51, 4, 'T', fontsize=30) #add text plot.axvline(x=57.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(55, 4, 'V', fontsize=30) #add text plot.axvline(x=60.5, ymin=0, ymax=ymax_dot, color='grey', lw=.8) plt.text(58.4, 4, 'W', fontsize=30) #add text plt.text(61.5, 4, '_', fontsize=30) #add text''' plt.title(fname + ' Codon Pause Scores') plt.xlabel("Codon") plt.ylabel("Pause Score") codon_HM_dict = {} codon_plot_dict = {} for codon in codons: df_HM = pd.DataFrame(codon_HM[codon]) df_plot = pd.DataFrame(codon_plot[codon]) codon_HM_dict[codon] = df_HM codon_plot_dict[codon] = df_plot xlim_lower = codon_plot_dict[codon].index[0] xlim_upper = codon_plot_dict[codon].index[-1] sns.set_style("white") sns.set_style("ticks") plotnum = 0 for codon in codons: plt.subplot2grid((2, 7 + codon_plots), (0, 7 + plotnum), rowspan=1, colspan=1) plot_2 = plt.plot(codon_plot_dict[codon], sns.xkcd_rgb["dark grey"]) plt.title(codon + ' Average Plot') plt.ylabel("Pause Score") plt.ylim(0, ymax_line) plt.xlim(xlim_lower, xlim_upper) sns.despine(offset=5) plt.subplot2grid((2, 7 + codon_plots), (1, 7 + plotnum), rowspan=1, colspan=1) plot_3 = sns.heatmap(codon_HM_dict[codon], cmap="ocean_r", vmin=0, vmax=vmax_HM, cbar=False, xticklabels=15, yticklabels=6) sns.despine(offset=5) plotnum += 1 plt.tight_layout() plt.savefig(path_figure + fname + '/codon_pausescore' + name_settings + '.pdf', dpi=400) plt.show()