Skip to content
Snippets Groups Projects
Commit 20d85934 authored by pswain's avatar pswain
Browse files

change(indexing): validate_lineage always warns if lineage misassigned

parent b97331da
No related branches found
No related tags found
No related merge requests found
...@@ -249,7 +249,7 @@ class Signal(BridgeH5): ...@@ -249,7 +249,7 @@ class Signal(BridgeH5):
dataset: str or t.List[str], dataset: str or t.List[str],
in_minutes: bool = True, in_minutes: bool = True,
lineage: bool = False, lineage: bool = False,
run_lineage_check: bool = True, stop_on_lineage_check: bool = True,
**kwargs, **kwargs,
) -> pd.DataFrame or t.List[pd.DataFrame]: ) -> pd.DataFrame or t.List[pd.DataFrame]:
""" """
...@@ -282,7 +282,7 @@ class Signal(BridgeH5): ...@@ -282,7 +282,7 @@ class Signal(BridgeH5):
lineage, lineage,
indices=np.array(df.index.to_list()), indices=np.array(df.index.to_list()),
how="daughters", how="daughters",
run_lineage_check=run_lineage_check, stop_on_lineage_check=stop_on_lineage_check,
) )
mother_label[valid_indices] = lineage[ mother_label[valid_indices] = lineage[
valid_lineage, 1 valid_lineage, 1
......
...@@ -8,7 +8,7 @@ def validate_lineage( ...@@ -8,7 +8,7 @@ def validate_lineage(
lineage: np.ndarray, lineage: np.ndarray,
indices: np.ndarray, indices: np.ndarray,
how: str = "families", how: str = "families",
run_lineage_check: bool = True, stop_on_lineage_check: bool = True,
): ):
""" """
Identify mother-bud pairs both in lineage and a Signal's indices. Identify mother-bud pairs both in lineage and a Signal's indices.
...@@ -31,9 +31,9 @@ def validate_lineage( ...@@ -31,9 +31,9 @@ def validate_lineage(
If "mothers", matches indicate mothers from mother-bud pairs; If "mothers", matches indicate mothers from mother-bud pairs;
If "daughters", matches indicate daughters from mother-bud pairs; If "daughters", matches indicate daughters from mother-bud pairs;
If "families", matches indicate mothers and daughters in mother-bud pairs. If "families", matches indicate mothers and daughters in mother-bud pairs.
run_lineage_check: bool stop_on_lineage_check: bool
If True, check for errors in the lineage assignment such as a daughter If True, raise an Exception for any errors in the lineage assignment such
being assigned two mothers. as a daughter being assigned two mothers.
Returns Returns
------- -------
...@@ -91,25 +91,27 @@ def validate_lineage( ...@@ -91,25 +91,27 @@ def validate_lineage(
valid_indices = index_isin(indices, selected_lineages[:, c_index, :]) valid_indices = index_isin(indices, selected_lineages[:, c_index, :])
flat_valid_indices = valid_indices.flatten() flat_valid_indices = valid_indices.flatten()
# test for mismatch # test for mismatch
if run_lineage_check: if how == "families":
if how == "families": test_mismatch = (
test_mismatch = ( indices[flat_valid_indices, :].size
indices[flat_valid_indices, :].size != np.unique(
!= np.unique( lineage[flat_valid_lineage, :].reshape(-1, 2), axis=0
lineage[flat_valid_lineage, :].reshape(-1, 2), axis=0 ).size
).size )
) else:
else: test_mismatch = (
test_mismatch = ( indices[flat_valid_indices, :].size
indices[flat_valid_indices, :].size != lineage[flat_valid_lineage, c_index, :].size
!= lineage[flat_valid_lineage, c_index, :].size )
) if test_mismatch:
if test_mismatch: # all unique indices in valid_lineages should be in valid_indices
# all unique indices in valid_lineages should be in valid_indices if stop_on_lineage_check:
raise Exception( raise Exception(
"Error in validate_lineage: " "Error in validate_lineage: "
"lineage information is likely not unique." "lineage information is likely not unique."
) )
else:
print("Warning: error in validate_lineage.")
return flat_valid_lineage, flat_valid_indices return flat_valid_lineage, flat_valid_indices
......
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