alpha=0.4) leg = ax.legend(loc="upper right") leg.get_frame().set_alpha(1.0) ax, leg = figure_util.shift_legend(ax, leg, yshift=0.06) ax.set_ylim(0, 0.29) ax.set_xlim(left=0, right=150) ax.set_xlabel("Distance from top of biofilm (μm)") ax.set_ylabel("YFP/RFP ratio") ax.text(-0.03, letter_lab[1], letters[3], ha="right", va="top", transform=ax.transAxes, fontsize=figure_util.letter_font_size) filename = os.path.join(this_dir, "fig_10x_grad") width, height = figure_util.get_figsize(figure_util.fig_width_small_pt, wf=1.0, hf=1.0) fig.set_size_inches(width, height) #fig.tight_layout() print("request size : ", figure_util.inch2cm((width, height))) fig.savefig(filename + ".png") fig.savefig(filename + ".pdf") fig.clear() plt.close(fig) figure_util.print_pdf_size(filename + ".pdf")
def main(): basedir = os.path.join(this_dir, "../../datasets/LSM700_63x_sigb") if not USE_CACHE_PLOTS: cell_df = pd.read_hdf(os.path.join(basedir, "single_cell_data.h5"), "cells") file_df = filedb.get_filedb(os.path.join(basedir, "file_list.tsv")) else: file_df = None cell_df = None time = 48 location = "center" slice_srt, slice_end = 5, 7 #10, 15 #slice_srt, slice_end = 5, 6 #10, 15 # # There is no major difference between 5-6 and 7-8, just the QP skew is bigger in 5-6 #slice_srt, slice_end = 7, 8 #10, 15 # Moving to 2um because it makes the plots look nicer. # fig, ax = plt.subplots(4, 2) # axhisto = ax[:, 1] # aximage = ax[:, 0] fig, ax = plt.subplots(2, 4) axhisto = ax[1, :] aximage = ax[0, :] for i, (name, path, roi, chans) in enumerate(image_list): impath = os.path.join(image_base_dir, path) aximage[i] = subfig_draw_bin.get_figure(aximage[i], name, impath, roi, chans, FP_max_min, (slice_srt, slice_end), add_scale_bar=i == 0) aximage[i].set_title("") aximage[i].text(imgletter_lab[0], imgletter_lab[1], topletters[i], transform=aximage[i].transAxes, **letter_settings, color="white") text_x = 0.40 text_top = 0.85 line_sep = 0.15 title_loc, cv_loc, samp_loc, cell_loc = [ (text_x, text_top - (line_sep * i)) for i in range(4) ] strain_map, des_strain_map = strainmap.load() gchan = "green_raw_bg_meannorm" rchan = "red_raw_bg_meannorm" if not USE_CACHE_PLOTS: cell_df = cell_df[cell_df[rchan] > 0].copy() #max_val = 30000 #max_val = 1.0 #6.0 #20000 #gmax_val = 1.0 #7.5 max_val = 6.5 #2.5 gmax_val = 6.5 #0.75 nbins = 150 rbins = (0, max_val, nbins) gbins = (0, gmax_val, nbins) percentile = 0 #99 list_of_histos = [("wt_sigar_sigby", rchan, "WT P$_{sigA}$-RFP", figure_util.strain_color["JLB021"]), ("wt_sigar_sigby", gchan, "WT P$_{sigB}$-YFP", figure_util.strain_color["JLB021"]), ("delqp_sigar_sigby", gchan, "ΔrsbQP P$_{sigB}$-YFP", figure_util.strain_color["JLB039"]), ("delru_sigar_sigby", gchan, "ΔrsbRU P$_{sigB}$-YFP", figure_util.strain_color["JLB088"])] print("-----------") for i, (strain, chan, label, color) in enumerate(list_of_histos): print(label) strain_df = None if not USE_CACHE_PLOTS: fids = file_df[(file_df["time"] == time) & (file_df["location"] == location) & (file_df["strain"] == des_strain_map[strain])].index strain_df = cell_df[cell_df["global_file_id"].isin(fids)] dset = time, location, strain plot_args = {"color": color, "max_min": "std", "mode_mean": False} tbins = gbins if "red" in chan: tbins = rbins args = (axhisto[i], strain_df, chan, tbins, (slice_srt, slice_end), dset, percentile, USE_CACHE_PLOTS, this_dir, plot_args) axhisto[i], _, meandmed = subfig_indivfile_histo.get_figure(*args) axhisto[i].text(1.0, hisletter_lab[1], label, horizontalalignment='right', verticalalignment='top', color="black", fontsize=plt.rcParams["axes.titlesize"], transform=axhisto[i].transAxes) axhisto[i].text(hisletter_lab[0], hisletter_lab[1], letters[i], transform=axhisto[i].transAxes, **letter_settings) #leg = axhisto[0].legend(loc="center right") #axhisto[-1].set_xlabel("Mean normalised cell fluorecence") axhisto[0].set_ylabel("Percentage of cells") axhisto[0].set_xlim(0, max_val) for a in np.ravel(axhisto): #a.set_ylabel("Percentage of cells") a.set_xlabel("Mean normalised cell fluorecence") a.set_ylim(0, 5) a.set_xlim(0, gmax_val) a.tick_params(axis='x', which='both', direction='out') #, length=2, pad=0) a.tick_params(axis='y', which='both', direction='out') #, length=2, pad=0) # for a in axhisto[:-1]: # a.set_xticklabels([]) for a in axhisto[1:]: a.set_yticklabels([]) filename = "demo_longtail" #fig.subplots_adjust(left=000, ri0ht=0.98, top = 1.0, bottom=0.06, hspace=0.08, wspace=0.2) #width, height = figure_util.get_figsize(figure_util.fig_width_small_pt, wf=1.0, hf=1.7) fig.subplots_adjust(left=0.05, right=0.99, top=1.0, bottom=0.10, hspace=0.08, wspace=0.15) width, height = figure_util.get_figsize(figure_util.fig_width_big_pt, wf=1.0, hf=0.5) fig.set_size_inches(width, height) figure_util.save_figures(fig, filename, ["png", "pdf"], this_dir)
# failed attempts to get axis coords converted to figure coords. #print(ax[-1,-1].xaxis.get_label_coords()) #print(ax[-1,-1].xaxis.label.get_position()) # transform(fig.transFigure)) #print(txt.get_[0].inverse_transformed(fig.transFigure)) # a[-1,0].set_ylabel("Distance from air interface (μm)") # label_space = rcParams["axes.labelpad"] # a[-1,0].yaxis.set_label_coords(tick_label_left - 0.01, (left + right)/2, transform=fig.transFigure) #label_position = fig.transFigure.inverted().transform(ax[-1,-1].xaxis.label.get_position()) #print(fig.transFigure.inverted().transform(ax[-1,-1].xaxis.label.get_position())) fig.text(0.5, 0.009, "Distance from air interface (μm)", horizontalalignment='center', color=rcParams["axes.labelcolor"], fontsize=rcParams["xtick.labelsize"]) ax[2, 0].set_ylabel("YFP/RFP ratio") filename = "fig_10x_grad_all" width, height = figure_util.get_figsize(figure_util.fig_width_medium_pt, wf=1.0, hf=1.0) fig.set_size_inches(width, height) # common.cm2inch(width, height)) fig.tight_layout() print("request size : ", figure_util.inch2cm((width, height))) figure_util.save_figures(fig, filename, ["pdf", "png"], this_dir)
def main(): curve_score_methods = { "std": ("Standard deviation", (0.0, 1.0), lambda d, h, b: np.std(d)), # 1.5, "mean": ("Mean", (0.0, 4.0), lambda d, h, b: np.mean(d)), "cv": ( "Coefficient of variation", (0.3, 0.8), lambda d, h, b: scipy.stats.variation(d), ), # "skew": ("modern skew", # 0.0, 3.0, # lambda d, h, b: scipy.stats.skew(d)), "skew_normed": ( "Skew", (0.0, 2.9), lambda d, h, b: scipy.stats.skew(d, bias=False), ), # "mode": ("Mode", # 0.0, 3.5, # lambda d, h, b: b[h.argmax()]), # "num": ("# cells", # 0.0, 2000, # lambda d, h, b: len(d)), # "pearson_mode_mean": ("pearson Mode mean", # 0.0, 1.2, # joy_plots_of_gradients.pearson_mode_mean_skew), # "non_parameteric_skew": ("Non parameteric", # 0.0, 0.4, # joy_plots_of_gradients.non_parametric_skew), "kurtosis": ("Kurtosis", (0.0, 8.0), lambda d, h, b: scipy.stats.kurtosis(d)), } plot_colors = [ # "mean", # "std", "cv", # "skew", # "num", # "skew_normed", "skew_normed", # same as pandas # "pearson_mode_mean", # "non_parameteric_skew", # "kurtosis", ] # basedir = "../../data/bio_film_data/63xdatasets" #this_dir = os.path.dirname(__file__) this_dir = "/media/nmurphy/BF_Data_Orange/" #basedir = os.path.join(this_dir, "../../datasets/LSM700_63x_sigb") basedir = os.path.join(this_dir, "datasets/LSM700_63x_sigb") # cell_df = pd.read_hdf(os.path.join(basedir, "edge_redo_lh1segment_data_bg_back_bleed.h5"), "cells") # cell_df = pd.read_hdf(os.path.join(basedir, "new_edge_bgsubv2_maxnorm_lh1segment.h5"), "cells") cell_df = pd.read_hdf(os.path.join(basedir, "single_cell_data.h5"), "cells") # cell_df = pd.read_hdf(os.path.join(basedir, "edge_redo_lh1segment_data.h5"), "cells") # cell_df = pd.read_hdf(os.path.join(basedir, "lh1segment_bgsub_data.h5"), "cells") # cell_df = cell_df[cell_df["area"] > 140] cell_df = cell_df[cell_df["distance"] > 2] time = 48 # .0 location = "center" file_df = filedb.get_filedb(os.path.join(basedir, "file_list.tsv")) strain_map, des_strain_map = strainmap.load() # cbar_mins = {0: 0.5, 1:0.0} percentile = 0 # 99# # green_chan = "meannorm_green" # red_chan = "meannorm_red" rmax = 6.5 gmax = 6.5 # 0.4 green_chan = "green_raw_bg_mean" red_chan = "red_raw_bg_mean" rmax = 50000 gmax = 10000 strains = [ ("wt_sigar_sigby", red_chan, rmax, "WT\n P$_{sigA}$-RFP"), ("wt_sigar_sigby", green_chan, gmax, "WT\n P$_{\mathit{sigB}}$-YFP"), ( "delru_sigar_sigby", green_chan, gmax, "Δ$\mathit{rsbRU}$\n P$_{\mathit{sigB}}$-YFP", ), ( "delqp_sigar_sigby", green_chan, gmax, "Δ$\mathit{rsbQP}$\n P$_{\mathit{sigB}}$-YFP", ), ] # ("2xqp_sigar_sigby", green_chan, gmax, "2$\\times$rsbQP\n P$_{sigB}$-YFP")] fig, ax = plt.subplots(len(plot_colors), len(strains), sharey=True) for c, (strain, chan, max_val, name) in enumerate(strains): strain_num = des_strain_map[strain] distances, sbins, histograms, stats = joy_plots_of_gradients.get_strain_result( file_df, cell_df, time, location, strain_num, chan, max_val, percentile, curve_score_methods, ) for r, k in enumerate(plot_colors): color = figure_util.strain_color[strain_num.upper()] ax[r, c], mv, leglist = joy_plots_of_gradients.plot_curves( ax[r, c], color, distances, sbins, histograms, stats, k) if c == len(strains) - 1: posn = ax[r, c].get_position() cbax = fig.add_axes([ posn.x0 + posn.width + 0.0005, posn.y0, 0.015, posn.height ]) label = curve_score_methods[k][0] min_zval = curve_score_methods[k][1][0] max_zval = curve_score_methods[k][1][1] sm = plt.cm.ScalarMappable( cmap=plt.get_cmap("viridis"), norm=plt.Normalize(vmin=min_zval, vmax=max_zval), ) sm._A = [] _ = plt.colorbar(sm, cax=cbax) # , fig=fig) cbax.set_ylabel(label, rotation=-90, labelpad=8) cbax.tick_params(direction="out") if r == 0: ax[r, c].set_title(name, fontsize=6) ax[r, c].get_xaxis().set_ticklabels([]) ax[r, c].set_xlim(0, max_val) # this didnt return the right mode for some reason # leg = ax[0, -1].legend(leglist) leg = ax[0, -1].legend(leglist, ["Mode", "Mean"], loc="lower left", bbox_to_anchor=(0.84, 0.97)) leg.set_zorder(400) for a in ax.flatten(): a.tick_params(direction="out") ax[0, 0].annotate( "Distance from top of biofilm (μm)", xy=(0, 0), xytext=(0.02, 0.5), textcoords="figure fraction", # arrowprops=dict(facecolor='black', shrink=0.05), horizontalalignment="center", verticalalignment="center", fontsize="medium", color=mpl.rcParams["axes.labelcolor"], rotation=90, ) ax[1, 2].annotate( "Normalized fluoresence", xy=(0, 0), xytext=(0.5, 0.04), textcoords="figure fraction", # arrowprops=dict(facecolor='black', shrink=0.05), horizontalalignment="center", verticalalignment="center", fontsize="medium", color=mpl.rcParams["axes.labelcolor"], ) # for a in ax[:, 0].flatten(): # ticklabs = a.yaxis.get_ticklabels() # ticklabs = a.get_yticks()#.tolist() # ticklabs[-1] = '' letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] # letter_lab = (-0.13, 0.98) for a, l in zip(ax.flatten(), letters): a.annotate( l, xy=(0, 0), xytext=(-0.13, 0.95), textcoords="axes fraction", # arrowprops=dict(facecolor='black', shrink=0.05), horizontalalignment="center", verticalalignment="center", fontsize=figure_util.letter_font_size, color="black", ) # a.text(letter_lab[0], letter_lab[1], l, transform=a.transAxes, fontsize=8) filename = "sup_meta_histo" width, height = figure_util.get_figsize(figure_util.fig_width_medium_pt, wf=1.0, hf=0.6) fig.subplots_adjust(left=0.085, right=0.89, top=0.89, bottom=0.13, hspace=0.20, wspace=0.25) fig.set_size_inches(width, height) # common.cm2inch(width, height)) figure_util.save_figures(fig, filename, ["png", "pdf"], this_dir)
def main(): basedir = os.path.join(this_dir, "../../datasets/LSM700_63x_sigb") time = 48 location = "center" # slice_srt, slice_end = 5, 7 #10, 15 slice_srt_end = (5, 7) fig, ax = plt.subplots(2, 2) axhisto = ax[1, 1] aximage = [ax[0, 0], ax[0, 1], ax[1, 0]] for i, (name, path, roi, chans) in enumerate(image_list): impath = os.path.join(image_base_dir, path) aximage[i] = subfig_draw_bin.get_figure( aximage[i], name, impath, roi, chans, FP_max_min, slice_srt_end, add_scale_bar=i == 0, ) aximage[i].set_title("") aximage[i].text(imgletter_lab[0], imgletter_lab[1], topletters[i], transform=aximage[i].transAxes, **letter_settings) # , color="white") aximage[i].text(0.05, 0.05, name, transform=aximage[i].transAxes, **label_settings, color="white") ##################### ## Histograms generate_data_subset = False strain_map, des_strain_map = strainmap.load() file_df = filedb.get_filedb(os.path.join(basedir, "file_list.tsv")) cachedpath = os.path.join(basedir, "histo_tops_normed.h5") gchan = "green_raw_bg_mean" rchan = "red_raw_bg_mean" nbins = 150 gmax = 1 gbins = np.linspace(0, gmax, nbins) list_of_histos = [ # ("2xqp_sigar_sigby", gchan, rchan, gbins, slice_srt_end, "2xQP", strain_color["JLB095"]), ( "wt_sigar_sigby", gchan, rchan, gbins, slice_srt_end, r"WT P$_{\mathit{sigB}}$-YFP", strain_color["JLB021"], ), ( "delru_sigar_sigby", gchan, rchan, gbins, slice_srt_end, r"Δ$\mathit{rsbRU}$ P$_{\mathit{sigB}}$-YFP", strain_color["JLB088"], ), ( "delqp_sigar_sigby", gchan, rchan, gbins, slice_srt_end, r"Δ$\mathit{rsbQP}$ P$_{\mathit{sigB}}$-YFP", strain_color["JLB039"], ), ] axes = [axhisto] * len(list_of_histos) if generate_data_subset: df = pd.read_hdf(os.path.join(basedir, "single_cell_data.h5"), "cells") cellsdf = subfig_normalised_histos.get_data_subset( df, file_df, list_of_histos, time, location, cachedpath) else: cellsdf = pd.read_hdf(cachedpath, "cells") axes = subfig_normalised_histos.get_figure(cellsdf, file_df, axes, time, location, list_of_histos) axes[0].legend() axhisto.text(hisletter_lab[0], hisletter_lab[1], letters[0], transform=axhisto.transAxes, **letter_settings) axhisto.set_ylabel("Percentage of cells") axhisto.set_xlim(0, gmax) axhisto.set_ylim(0, 8.5) axhisto.tick_params(axis="x", which="both", direction="out") # , length=2, pad=0) axhisto.tick_params(axis="y", which="both", direction="out") # , length=2, pad=0) axhisto.yaxis.set_major_locator(mticker.MaxNLocator(nbins=3, integer=True)) axhisto.set_xlabel("Normalised cell fluorecence") filename = "demo_longtail" fig.subplots_adjust(left=0.05, right=0.95, top=0.99, bottom=0.1, hspace=0.08, wspace=0.20) width, height = figure_util.get_figsize(figure_util.fig_width_small_pt, wf=1.0, hf=0.9) fig.set_size_inches(width, height) figure_util.save_figures(fig, filename, ["png", "pdf"], this_dir)
def main(): this_dir = os.path.dirname(__file__) basedir = os.path.join(this_dir, "../../datasets/LSM700_63x_sigb") #cell_df = pd.read_hdf(os.path.join(basedir, "edge_redo_lh1segment_data_bg_back_bleed.h5"), "cells") cell_df = pd.read_hdf(os.path.join(basedir, "single_cell_data.h5"), "cells") print(cell_df.columns) file_df = filedb.get_filedb(os.path.join(basedir, "file_list.tsv")) file_df.loc[file_df["time"] == 26.0, ['time']] = 24.0 file_df.loc[file_df["time"] == 38.0, ['time']] = 36.0 USE_CACHE_PLOTS = False time = 48 location = "center" slice_srt, slice_end = 5, 7 fig, axhisto = plt.subplots(1, 1) strain_map, des_strain_map = strainmap.load() gchan = "green_raw_bg_autofluor_bleedthrough_meannorm" gmax_val = 20 nbins=150 gbins = (0, gmax_val, nbins) percentile = 0 list_of_histos = [ ("wt_sigar_sigby", gchan, "WT P$_{sigB}$-YFP", strain_color["JLB021"]), ("delqp_sigar_sigby", gchan, "ΔrsbQP P$_{sigB}$-YFP", strain_color["JLB039"]), ("delru_sigar_sigby", gchan, "ΔrsbRU P$_{sigB}$-YFP", strain_color["JLB088"]), ("2xqp_sigar_sigby", gchan, "2$\\times$rsbQP P$_{sigB}$-YFP", strain_color["JLB095"]), ] print("-----------") lelines = [] lelabs = [] for i, (strain, chan, label, color) in enumerate(list_of_histos): print(label) fids = file_df[(file_df["time"] == time) & (file_df["location"] == location) & (file_df["strain"] == des_strain_map[strain])].index strain_df = cell_df[cell_df["global_file_id"].isin(fids)] #strain_df = get_strain(file_df, cell_df, strain) plot_args = {"color":color, "max_min":"none", "mode_mean":False} tbins = gbins dset = time, location, strain args = (axhisto, strain_df, chan, tbins, (slice_srt, slice_end), dset, percentile, USE_CACHE_PLOTS, this_dir, plot_args) axhisto, line, _ = subfig_indivfile_histo.get_figure(*args) lelines += [line] lelabs += [label] axhisto.legend(lelines, lelabs) axhisto.set_xlabel("Normalised cell fluorecence (bleed through subtracted)") axhisto.set_ylabel("Percentage of cells") axhisto.set_ylim(0, 7) axhisto.set_xlim(0, gmax_val) filename = "sup_bleed_histo" fig.subplots_adjust(left=0.1, right=0.9, top = 0.98, bottom=0.2)#, hspace=0.35, wspace=0.2) width, height = figure_util.get_figsize(figure_util.fig_width_small_pt, wf=1.0, hf=0.5) fig.set_size_inches(width, height)# common.cm2inch(width, height)) figure_util.save_figures(fig, filename, ["png", "pdf"], this_dir)