Skip to content
Snippets Groups Projects
Commit 61baa5e5 authored by Alán Muñoz's avatar Alán Muñoz
Browse files

refactor(births): rename births to buddings

parent 5ce29fb2
No related branches found
No related tags found
No related merge requests found
......@@ -179,20 +179,20 @@ class ExperimentCompiler(Compiler):
names_signals = {
"dvol": "postprocessing/dsignal/postprocessing_savgol_extraction_general_None_volume",
"bud_dvol": "postprocessing/bud_metric/postprocessing_dsignal_postprocessing_savgol_extraction_general_None_volume",
"births": "postprocessing/births/extraction_general_None_volume",
"buddings": "postprocessing/buddings/extraction_general_None_volume",
}
operations = {
"dvol": ("dvol", "max"),
"bud_dvol": ("bud_dvol", "max"),
"births": ("births", "sum"),
"births_mean": ("births", "mean"),
"buddings": ("buddings", "sum"),
"buddings_mean": ("buddings", "mean"),
}
input_signals = {
k: self.grouper.concat_signal(v) for k, v in names_signals.items()
}
ids = input_signals["births"].index
ids = input_signals["buddings"].index
for v in input_signals.values():
ids = ids.intersection(v.index)
......@@ -271,31 +271,31 @@ class ExperimentCompiler(Compiler):
def compile_growth_metrics(
self,
min_nbirths: int = 2,
min_nbuddings: int = 2,
):
"""Filter mothers with n number of births and get their metrics.
"""Filter mothers with n number of buddings and get their metrics.
Select cells with at least two recorded births
Select cells with at least two recorded buddings
"""
names_signals = {
"dvol": "postprocessing/dsignal/postprocessing_savgol_extraction_general_None_volume",
"bud_dvol": "postprocessing/bud_metric/postprocessing_dsignal_postprocessing_savgol_extraction_general_None_volume",
"births": "postprocessing/births/extraction_general_None_volume",
"buddings": "postprocessing/buddings/extraction_general_None_volume",
}
operations = {
"dvol": ("dvol", "max"),
"bud_dvol": ("bud_dvol", "max"),
"births": ("births", "sum"),
"buddings": ("buddings", "sum"),
"cycle_length_mean": (
"births",
"buddings",
lambda x: np.diff(np.where(x)[0]).mean(),
),
"cycle_length_min": (
"births",
"buddings",
lambda x: np.diff(np.where(x)[0]).min(),
),
"cycle_length_median": (
"births",
"buddings",
lambda x: np.median(np.diff(np.where(x)[0])),
),
}
......@@ -303,7 +303,7 @@ class ExperimentCompiler(Compiler):
input_signals = {
k: self.grouper.concat_signal(v) for k, v in names_signals.items()
}
ids = self.get_shared_ids(input_signals, min_nbirths=min_nbirths)
ids = self.get_shared_ids(input_signals, min_nbuddings=min_nbuddings)
compiled_df = pd.DataFrame(
{
......@@ -316,18 +316,18 @@ class ExperimentCompiler(Compiler):
return compiled_df
def get_shared_ids(
self, input_signals: Dict[str, pd.DataFrame], min_nbirths: int = None
self, input_signals: Dict[str, pd.DataFrame], min_nbuddings: int = None
):
"""Get the intersection id of multiple signals.
"births" must be one the keys in input_signals to use the
argument min_nbirths.
"buddings" must be one the keys in input_signals to use the
argument min_nbuddings.
"""
ids = list(input_signals.values())[0].index
if min_nbirths is not None:
if min_nbuddings is not None:
ids = (
input_signals["births"]
.loc[input_signals["births"].sum(axis=1) >= min_nbirths]
input_signals["buddings"]
.loc[input_signals["buddings"].sum(axis=1) >= min_nbuddings]
.index
)
for v in input_signals.values():
......
......@@ -48,7 +48,7 @@ class alignParameters(ParametersABC):
Specifies the number of events required for each cell. For example, if
events_at_least is 2, then it will discard time series (from the DataFrame)
that have less than 2 events. As a more pratical example: discarding
flavin time series that derive from cells with less than 2 births
flavin time series that derive from cells with less than 2 buddings
identified.
"""
......
......@@ -12,7 +12,7 @@ from postprocessor.core.processes.lineageprocess import (
)
class birthsParameters(LineageProcessParameters):
class buddingsParameters(LineageProcessParameters):
"""Parameter class to obtain birth events.
Parameters
......@@ -29,14 +29,14 @@ class birthsParameters(LineageProcessParameters):
_defaults = {"lineage_location": "postprocessing/lineage_merged"}
class births(LineageProcess):
class buddings(LineageProcess):
"""
Calculate births in a trap assuming one mother per trap
Calculate buddings in a trap assuming one mother per trap
returns a pandas series with the births
returns a pandas series with the buddings
"""
def __init__(self, parameters: birthsParameters):
def __init__(self, parameters: buddingsParameters):
super().__init__(parameters)
def load_lineage(self, lineage):
......@@ -60,12 +60,12 @@ class births(LineageProcess):
mothers = signal.loc[
set(signal.index).intersection(traps_mothers.keys())
]
births = pd.DataFrame(
buddings = pd.DataFrame(
np.zeros((mothers.shape[0], signal.shape[1])).astype(bool),
index=mothers.index,
columns=signal.columns,
)
births.columns.names = ["timepoint"]
buddings.columns.names = ["timepoint"]
for mother_id, daughters in traps_mothers.items():
daughters_idx = set(
fvi.loc[
......@@ -74,9 +74,9 @@ class births(LineageProcess):
)
].values
).difference({0})
births.loc[
buddings.loc[
mother_id,
daughters_idx,
] = True
return births
return buddings
......@@ -55,7 +55,7 @@ class PostProcessorParameters(ParametersABC):
},
"processes": [
[
"births",
"buddings",
[
"/extraction/general/None/volume",
],
......
......@@ -15,7 +15,7 @@ class _HeatmapPlotter(BasePlotter):
self,
trace_df,
trace_name,
births_df,
buddings_df,
cmap,
unit_scaling,
xtick_step,
......@@ -27,7 +27,7 @@ class _HeatmapPlotter(BasePlotter):
super().__init__(trace_name, unit_scaling, xlabel, plot_title)
# Define attributes from arguments
self.trace_df = trace_df
self.births_df = births_df
self.buddings_df = buddings_df
self.cmap = cmap
self.xtick_step = xtick_step
self.scale = scale
......@@ -83,16 +83,16 @@ class _HeatmapPlotter(BasePlotter):
ax.xaxis.set_major_locator(
ticker.MultipleLocator(self.xtick_step / self.unit_scaling)
)
# Overlay births, if present
if self.births_df is not None:
# Overlay buddings, if present
if self.buddings_df is not None:
# Must be masked array for transparency
births_array = self.births_df.to_numpy()
births_heatmap_mask = np.ma.masked_where(
births_array == 0, births_array
buddings_array = self.buddings_df.to_numpy()
buddings_heatmap_mask = np.ma.masked_where(
buddings_array == 0, buddings_array
)
# Overlay
ax.imshow(
births_heatmap_mask,
buddings_heatmap_mask,
interpolation="none",
)
# Draw colour bar
......@@ -104,7 +104,7 @@ class _HeatmapPlotter(BasePlotter):
def heatmap(
trace_df,
trace_name,
births_df=None,
buddings_df=None,
cmap=cm.RdBu,
unit_scaling=1,
xtick_step=60,
......@@ -123,7 +123,7 @@ def heatmap(
Time series of traces (rows = cells, columns = time points).
trace_name : string
Name of trace being plotted, e.g. 'flavin'.
births_df : pandas.DataFrame
buddings_df : pandas.DataFrame
Birth mask (rows = cells, columns = time points). Elements should be
0 or 1.
cmap : matplotlib ColorMap
......@@ -160,7 +160,7 @@ def heatmap(
plotter = _HeatmapPlotter(
trace_df,
trace_name,
births_df,
buddings_df,
cmap,
unit_scaling,
xtick_step,
......
......@@ -6,7 +6,7 @@ from postprocessor.routines.single_plot import _SinglePlotter
class _SingleBirthPlotter(_SinglePlotter):
"""Draw a line plot of a single time series, but with births overlaid"""
"""Draw a line plot of a single time series, but with buddings overlaid"""
def __init__(
self,
......@@ -33,7 +33,7 @@ class _SingleBirthPlotter(_SinglePlotter):
xlabel,
plot_title,
)
# Add some more attributes useful for births
# Add some more attributes useful for buddings
self.birth_mask = birth_mask
self.birth_color = birth_color
self.birth_linestyle = birth_linestyle
......@@ -71,7 +71,7 @@ def single_birth_plot(
plot_title="",
ax=None,
):
"""Plot time series of trace, overlaid with births
"""Plot time series of trace, overlaid with buddings
Parameters
----------
......@@ -82,18 +82,18 @@ def single_birth_plot(
trace_name : string
Name of trace being plotted, e.g. 'flavin'.
birth_mask : array_like
Mask to indicate where births are. Expect values of '0' and '1' or
Mask to indicate where buddings are. Expect values of '0' and '1' or
'False' and 'True' in the elements.
unit_scaling : int or float
Unit scaling factor, e.g. 1/60 to convert minutes to hours.
trace_color : string
matplotlib colour string for the trace
birth_color : string
matplotlib colour string for the vertical lines indicating births
matplotlib colour string for the vertical lines indicating buddings
trace_linestyle : string
matplotlib linestyle argument for the trace
birth_linestyle : string
matplotlib linestyle argument for the vertical lines indicating births
matplotlib linestyle argument for the vertical lines indicating buddings
xlabel : string
x axis label.
plot_title : string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment