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