Skip to content
Snippets Groups Projects
Commit 5cf6da46 authored by pswain's avatar pswain
Browse files

minor doc changes

parent 90a06eec
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ from postprocessor.core.abc import PostProcessABC ...@@ -12,7 +12,7 @@ from postprocessor.core.abc import PostProcessABC
class LineageProcessParameters(ParametersABC): class LineageProcessParameters(ParametersABC):
"""Parameters.""" """Parameters - none are necessary."""
_defaults = {} _defaults = {}
...@@ -21,7 +21,7 @@ class LineageProcess(PostProcessABC): ...@@ -21,7 +21,7 @@ class LineageProcess(PostProcessABC):
""" """
To analyse lineage data. To analyse lineage data.
Currently bare bones, but extracts lineage information from a signal or a Cells object. Currently bare bones, but extracts lineage information from a Signal or Cells object.
""" """
def __init__(self, parameters: LineageProcessParameters): def __init__(self, parameters: LineageProcessParameters):
...@@ -35,7 +35,7 @@ class LineageProcess(PostProcessABC): ...@@ -35,7 +35,7 @@ class LineageProcess(PostProcessABC):
lineage: np.ndarray, lineage: np.ndarray,
*args, *args,
): ):
"""Implement method required by PostProcessABC.""" """Implement method required by PostProcessABC - undefined."""
pass pass
@classmethod @classmethod
...@@ -47,9 +47,9 @@ class LineageProcess(PostProcessABC): ...@@ -47,9 +47,9 @@ class LineageProcess(PostProcessABC):
**kwargs, **kwargs,
): ):
""" """
Override PostProcess.as_function classmethod. Override PostProcesABC.as_function method.
Lineage functions require lineage information to be passed if run as functions. Lineage functions require lineage information to be run as functions.
""" """
parameters = cls.default_parameters(**kwargs) parameters = cls.default_parameters(**kwargs)
return cls(parameters=parameters).run( return cls(parameters=parameters).run(
......
...@@ -13,16 +13,10 @@ from postprocessor.core.lineageprocess import ( ...@@ -13,16 +13,10 @@ from postprocessor.core.lineageprocess import (
class buddingsParameters(LineageProcessParameters): class buddingsParameters(LineageProcessParameters):
"""Parameter class to obtain budding events. """
Parameter class to obtain budding events.
Parameters
----------
LineageProcessParameters : lineage_location
Location of lineage matrix to be used for calculations.
Examples Define the location of lineage information in the h5 file.
--------
FIXME: Add docs.
""" """
...@@ -31,45 +25,44 @@ class buddingsParameters(LineageProcessParameters): ...@@ -31,45 +25,44 @@ class buddingsParameters(LineageProcessParameters):
class buddings(LineageProcess): class buddings(LineageProcess):
""" """
Calculate buddings in a trap assuming one mother per trap Calculate buddings in a trap assuming one mother per trap.
returns a pandas series with the buddings.
Return a pandas series with the buddings.
We define a budding event as the moment in which a bud was identified for We define a budding event as when a bud is first identified.
the first time, even if the bud is not considered one until later
in the experiment. This bud may not be considered a bud until later in the experiment.
""" """
def __init__(self, parameters: buddingsParameters): def __init__(self, parameters: buddingsParameters):
"""Initialise buddings."""
super().__init__(parameters) super().__init__(parameters)
def run( def run(
self, signal: pd.DataFrame, lineage: np.ndarray = None self, signal: pd.DataFrame, lineage: np.ndarray = None
) -> pd.DataFrame: ) -> pd.DataFrame:
"""TODO."""
lineage = lineage or self.lineage lineage = lineage or self.lineage
# select traps and mother cells in a given signal
# Get time of first appearance for all cells
fvi = signal.apply(lambda x: x.first_valid_index(), axis=1)
# Select mother cells in a given dataset
traps_mothers: t.Dict[tuple, list] = { traps_mothers: t.Dict[tuple, list] = {
tuple(mo): [] for mo in lineage[:, :2] if tuple(mo) in signal.index tuple(mo): [] for mo in lineage[:, :2] if tuple(mo) in signal.index
} }
for trap, mother, daughter in lineage: for trap, mother, daughter in lineage:
if (trap, mother) in traps_mothers.keys(): if (trap, mother) in traps_mothers.keys():
traps_mothers[(trap, mother)].append(daughter) traps_mothers[(trap, mother)].append(daughter)
mothers = signal.loc[ mothers = signal.loc[
set(signal.index).intersection(traps_mothers.keys()) set(signal.index).intersection(traps_mothers.keys())
] ]
# Create a new dataframe with dimensions (n_mother_cells * n_timepoints) # create a new dataframe with dimensions (n_mother_cells * n_timepoints)
buddings = pd.DataFrame( buddings = pd.DataFrame(
np.zeros((mothers.shape[0], signal.shape[1])).astype(bool), np.zeros((mothers.shape[0], signal.shape[1])).astype(bool),
index=mothers.index, index=mothers.index,
columns=signal.columns, columns=signal.columns,
) )
buddings.columns.names = ["timepoint"] buddings.columns.names = ["timepoint"]
# get time of first appearance for every cell using Pandas
# Fill the budding events fvi = signal.apply(lambda x: x.first_valid_index(), axis=1)
# fill the budding events
for mother_id, daughters in traps_mothers.items(): for mother_id, daughters in traps_mothers.items():
daughters_idx = set( daughters_idx = set(
fvi.loc[ fvi.loc[
...@@ -82,5 +75,4 @@ class buddings(LineageProcess): ...@@ -82,5 +75,4 @@ class buddings(LineageProcess):
mother_id, mother_id,
daughters_idx, daughters_idx,
] = True ] = True
return buddings return buddings
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