diff --git a/limbo/old_data_analysis/align.py b/limbo/arin_data_analysis/align.py similarity index 100% rename from limbo/old_data_analysis/align.py rename to limbo/arin_data_analysis/align.py diff --git a/limbo/old_data_analysis/autoreg.py b/limbo/arin_data_analysis/autoreg.py similarity index 100% rename from limbo/old_data_analysis/autoreg.py rename to limbo/arin_data_analysis/autoreg.py diff --git a/limbo/old_data_analysis/crosscorr.py b/limbo/arin_data_analysis/crosscorr.py similarity index 100% rename from limbo/old_data_analysis/crosscorr.py rename to limbo/arin_data_analysis/crosscorr.py diff --git a/limbo/old_data_analysis/fft.py b/limbo/arin_data_analysis/fft.py similarity index 100% rename from limbo/old_data_analysis/fft.py rename to limbo/arin_data_analysis/fft.py diff --git a/limbo/old_data_analysis/fft_function.py b/limbo/arin_data_analysis/fft_function.py similarity index 100% rename from limbo/old_data_analysis/fft_function.py rename to limbo/arin_data_analysis/fft_function.py diff --git a/limbo/old_data_analysis/findpeaks.py b/limbo/arin_data_analysis/findpeaks.py similarity index 100% rename from limbo/old_data_analysis/findpeaks.py rename to limbo/arin_data_analysis/findpeaks.py diff --git a/limbo/old_data_analysis/standardscaler.py b/limbo/arin_data_analysis/standardscaler.py similarity index 100% rename from limbo/old_data_analysis/standardscaler.py rename to limbo/arin_data_analysis/standardscaler.py diff --git a/limbo/old_plotting/__init__.py b/limbo/arin_plotting/__init__.py similarity index 100% rename from limbo/old_plotting/__init__.py rename to limbo/arin_plotting/__init__.py diff --git a/limbo/old_plotting/boxplot.py b/limbo/arin_plotting/boxplot.py similarity index 100% rename from limbo/old_plotting/boxplot.py rename to limbo/arin_plotting/boxplot.py diff --git a/limbo/old_plotting/heatmap.py b/limbo/arin_plotting/heatmap.py similarity index 100% rename from limbo/old_plotting/heatmap.py rename to limbo/arin_plotting/heatmap.py diff --git a/limbo/old_plotting/histogram.py b/limbo/arin_plotting/histogram.py similarity index 100% rename from limbo/old_plotting/histogram.py rename to limbo/arin_plotting/histogram.py diff --git a/limbo/old_plotting/mean_plot.py b/limbo/arin_plotting/mean_plot.py similarity index 100% rename from limbo/old_plotting/mean_plot.py rename to limbo/arin_plotting/mean_plot.py diff --git a/limbo/old_plotting/median_plot.py b/limbo/arin_plotting/median_plot.py similarity index 100% rename from limbo/old_plotting/median_plot.py rename to limbo/arin_plotting/median_plot.py diff --git a/limbo/old_plotting/plot_utils.py b/limbo/arin_plotting/plot_utils.py similarity index 100% rename from limbo/old_plotting/plot_utils.py rename to limbo/arin_plotting/plot_utils.py diff --git a/limbo/old_plotting/plottingabc.py b/limbo/arin_plotting/plottingabc.py similarity index 100% rename from limbo/old_plotting/plottingabc.py rename to limbo/arin_plotting/plottingabc.py diff --git a/limbo/old_plotting/single_birth_plot.py b/limbo/arin_plotting/single_birth_plot.py similarity index 100% rename from limbo/old_plotting/single_birth_plot.py rename to limbo/arin_plotting/single_birth_plot.py diff --git a/limbo/old_plotting/single_plot.py b/limbo/arin_plotting/single_plot.py similarity index 100% rename from limbo/old_plotting/single_plot.py rename to limbo/arin_plotting/single_plot.py diff --git a/src/wela/dataloader.py b/src/wela/dataloader.py index 98a11a0c399b940f03dbb90266868c9ac18137fe..6ca43fc9f29b870854e2267aa673959c4b2cc773 100644 --- a/src/wela/dataloader.py +++ b/src/wela/dataloader.py @@ -10,7 +10,7 @@ try: from postprocessor.grouper import Grouper from wela.add_bud_fluorescence import add_bud_fluorescence except ModuleNotFoundError: - print("Can only load tsv files - cannot find postprocessor.") + print("Can only load tsv files - cannot find aliby's postprocessor.") class dataloader: diff --git a/src/wela/imageviewer.py b/src/wela/imageviewer.py index 3b7fd876d4e8533d27776862150c743e75e02f73..ff3c762309bcd6fb1f10923c577d60c65023ce18 100644 --- a/src/wela/imageviewer.py +++ b/src/wela/imageviewer.py @@ -9,6 +9,7 @@ from agora.io.cells import Cells from agora.io.metadata import parse_metadata from aliby.io.image import dispatch_image from aliby.tile.tiler import Tiler +from aliby.io.omero import UnsafeImage as OImage def colormap(channel): @@ -206,25 +207,18 @@ class LocalImageViewer(BaseImageViewer): class RemoteImageViewer(BaseImageViewer): """Fetching remote images with tiling and outline display.""" - credentials = ("host", "username", "password") - - def __init__(self, h5file: str, server_info: t.Dict[str, str]): + def __init__( + self, h5file: str, server_info: t.Dict[str, str], omero_id: int + ): """Initialise using a h5file and importing aliby.io.omero.""" - from aliby.io.omero import UnsafeImage as OImage - h5file_path = Path(h5file) super().__init__(h5file_path) - server_info = server_info or { - k: self.attrs["parameters"]["general"][k] for k in self.credentials - } - logfiles_meta = parse_metadata(h5file_path.parent) - image_id = logfiles_meta.get("image_id") - if image_id is None: - with h5py.File(h5file_path, "r") as f: - image_id = f.attrs.get("image_id") - if image_id is None: - raise ("No valid image_id found in metadata.") - image = OImage(image_id, **server_info) + with h5py.File(h5file_path, "r") as f: + breakpoint() + self.image_id = f.attrs.get("image_id") + + image = OImage(omero_id, **server_info) + breakpoint() self.tiler = Tiler.from_h5(image, h5file_path) self.cells = Cells.from_source(h5file_path) diff --git a/src/wela/plotting.py b/src/wela/plotting.py index 961ad11f913063d0ff9eadcbc3a2b6540d8c9101..025e51815e7d6d64dd8743148285646e6c277ae9 100644 --- a/src/wela/plotting.py +++ b/src/wela/plotting.py @@ -5,18 +5,28 @@ import matplotlib.pylab as plt import numpy as np import numpy.matlib +try: + from sklearn.preprocessing import StandardScaler +except ModuleNotFoundError: + pass + def kymograph( df, hue="median_GFP", x="time", y="id", + group=None, xtick_step_in_hours=5, vmax=None, vmin=None, cmap=None, + buddings=True, figsize=(6, 10), title=None, + filterfunc=None, + standardscale=False, + robust=False, returnfig=False, ): """ @@ -26,12 +36,47 @@ def kymograph( Time is assumed to be in hours. + Arguments + --------- + df: pd.DataFrame + Dataframe of data to plot. + hue: string + Variable to plot using colour. + x: string, optional + Variable for x-axis. + y: string, optional + Variable for y-axis: + group: string, optional + Group, or strain, to plot. + xtick_step_in_hours: int, optional + Set the interval between ticks on the x-axis. + vmax, vmin: float, optional + Define the data range covered by the colormap. + cmap: matplotlib.cm colormap, optional + The colourmap to use. + buddings: boolean, optional + If True, show budding events as black dots. + figsize: (int, int) + The size of the figure. + title: string, optional + Title ot use. + filterfunc: function, optional + Filter to apply to the data, assuming that the time series are + in rows. + standardscale: boolean, optional + If True, scale the mean of each single-cell time series to zero + and its standard deviation to one. + robust: boolean, optional + If True, change colourmap to show 2-98% of all the data's values. + returnfig: boolean, optional + If True, return fig and ax. + Examples -------- >>> from wela.plotting import kymograph >>> kymograph(dl.df, hue="median_GFP") >>> kymograph(dl.df, hue="bud_volume", title="2% Gal") - >>> kymograph(dl.df, hue="buddings") + >>> kymograph(dl.df, hue="buddings", group="Msn2") """ if cmap is None: if hue == "buddings": @@ -46,10 +91,25 @@ def kymograph( cmap = matplotlib.cm.Spectral else: cmap = matplotlib.cm.viridis + if group is not None: + df = df[df.group == group] wdf = df.pivot(index=y, columns=x, values=hue) dt = np.min(np.diff(np.sort(df.time.unique()))) - # from Arin data = wdf.to_numpy() + if filterfunc is not None: + data = filterfunc(data) + if standardscale: + scaler = StandardScaler().fit(data.transpose()) + data = scaler.transform(data.transpose()).transpose() + if robust: + vmin = np.nanpercentile(data, 2) + vmax = np.nanpercentile(data, 98) + # make axes even + if standardscale: + if np.abs(vmin) > np.abs(vmax): + vmax = -vmin + else: + vmin = -vmax # define horizontal axis ticks and labels xtick_min = 0 xtick_max = dt * data.shape[1] @@ -66,15 +126,19 @@ def kymograph( ax.set_xlabel(x) ax.set_ylabel(y) ax.set_title(title) - trace_heatmap = ax.imshow( + heatmap = ax.imshow( data, cmap=cmap, interpolation="none", vmax=vmax, vmin=vmin, ) + if buddings: + buddings = df.pivot(index=y, columns=x, values="buddings").to_numpy() + bud_mask = np.ma.masked_where(buddings == 0, buddings) + ax.imshow(bud_mask, interpolation="none") ax.figure.colorbar( - mappable=trace_heatmap, + mappable=heatmap, ax=ax, label=hue, aspect=50,