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)
# "cr_max":10000, # "cg_min":2000, # "cg_max":(2**14), }] # height = 260 * 20 # width = 700 * 20 # i = files[0] # spimg_ax = subfig_spore_image.plot_big_image(spimg_ax, # sp_image_basedir + i["Path"], # this_dir, # cache path. # ((i["y"], i["y"] + height), # (i["x"], i["x"] + width)), # (height, width), # i, vertical=False, scalebar=True) # letter_lab = (-0.10, 0.98) # for l, a in zip(figure_util.letters, [spimg_ax, spcount_ax, cellcount_ax]): # a.text(letter_lab[0], letter_lab[1], l, transform=a.transAxes, fontsize=figure_util.letter_font_size) filename = "spore_grad_density_compare" width, height = figure_util.get_figsize(figure_util.fig_width_small_pt, wf=1.0, hf=1.1) fig.subplots_adjust(left=0.1, right=0.95, top=0.98, bottom=0.09, hspace=0.35) #, wspace=0.25) fig.set_size_inches(width, height) figure_util.save_figures(fig, filename, ["pdf", "png"], os.path.dirname(__file__)) # print("request size : ", figure_util.inch2cm((width, height))) # fig.savefig(filename + ".png", dpi=dpi) # fig.savefig(filename + ".pdf", dpi=dpi) # figure_util.print_pdf_size(filename + ".pdf")
letter_settings = { "horizontalalignment": "center", "verticalalignment": "top", "fontsize": figure_util.letter_font_size, "color": "black", } x1 = 0.02 aximg.text(x1, 0.995, "B", transform=figall.transFigure, **letter_settings) aximg.text(x1, 0.64, "C", transform=figall.transFigure, **letter_settings) aximg.text(x1, 0.50, "D", transform=figall.transFigure, **letter_settings) aximg.text(x1, 0.36, "E", transform=figall.transFigure, **letter_settings) aximg.text(x1, 0.22, "F", transform=figall.transFigure, **letter_settings) x2 = 0.53 aximg.text(x2, 0.64, "G", transform=figall.transFigure, **letter_settings) aximg.text(x2, 0.50, "H", transform=figall.transFigure, **letter_settings) aximg.text(x2, 0.36, "I", transform=figall.transFigure, **letter_settings) aximg.text(x2, 0.22, "J", transform=figall.transFigure, **letter_settings) filename = "pad_movie_tracemain" width, height = figure_util.get_figsize(figure_util.fig_width_small_pt, wf=1.0, hf=1.0) figall.set_size_inches(width, height) figall.subplots_adjust(left=0.15, right=0.99, top=1.0, bottom=0.1) # hspace=0.05) print("request size : ", figure_util.inch2cm((width, height))) figure_util.save_figures(figall, filename, ["png", "pdf"], this_dir)
################## im = skimage.io.imread(os.path.join(this_dir, "delru_bf10_col2_strip.png")) ax_fstrip.imshow(im, interpolation="bicubic") ax_fstrip.grid(False) ax_fstrip.axis("off") axes = [ax_exprmt, ax_gradnt, ax_fstrip, ax_pulses] letter_style = { "verticalalignment": "top", "horizontalalignment": "right", "fontsize": figure_util.letter_font_size, # "color": "red" } letter_x = 0.03 axes[0].text(letter_x, 0.995, "A", transform=fig.transFigure, **letter_style) axes[1].text(0.47, 0.995, "B", transform=fig.transFigure, **letter_style) axes[2].text(letter_x, 0.63, "C", transform=fig.transFigure, **letter_style) axes[3].text(letter_x, 0.26, "D", transform=fig.transFigure, **letter_style) filename = "bf_movie_main" # width, height = figure_util.get_figsize(figure_util.fig_width_big_pt, wf=1.0, hf=0.5 ) width, height = figure_util.get_figsize(figure_util.fig_width_small_pt, wf=1.0, hf=1.3) fig.subplots_adjust(left=0.095, right=0.97, top=0.97, bottom=0.06) # , hspace=0.25, wspace=0.25) fig.set_size_inches(width, height) # common.cm2inch(width, height)) figure_util.save_figures(fig, filename, ["png", "pdf"], base_dir=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)