diff --git a/cytominer_eval/operations/percent_strong.py b/cytominer_eval/operations/percent_strong.py index c8902cd..6b7a20e 100644 --- a/cytominer_eval/operations/percent_strong.py +++ b/cytominer_eval/operations/percent_strong.py @@ -29,6 +29,7 @@ def percent_strong( A metric describing the proportion of replicates that correlate above the given quantile of non-replicate correlation distribution """ + assert 0 < quantile and 1 >= quantile, "quantile must be between 0 and 1" similarity_melted_df = assign_replicates( @@ -38,13 +39,18 @@ def percent_strong( # Check to make sure that the melted dataframe is upper triangle assert_melt(similarity_melted_df, eval_metric="percent_strong") + # check that there are group_replicates (non-unique rows) + replicate_df = similarity_melted_df.query("group_replicate") + denom = replicate_df.shape[0] + + assert denom != 0, "no replicate groups identified in {rep} columns!".format( + rep=replicate_groups + ) + non_replicate_quantile = similarity_melted_df.query( "not group_replicate" ).similarity_metric.quantile(quantile) - replicate_df = similarity_melted_df.query("group_replicate") - denom = replicate_df.shape[0] - percent_strong = ( replicate_df.similarity_metric > non_replicate_quantile ).sum() / denom diff --git a/cytominer_eval/tests/test_operations/test_percent_strong.py b/cytominer_eval/tests/test_operations/test_percent_strong.py index 892b889..5084b7c 100644 --- a/cytominer_eval/tests/test_operations/test_percent_strong.py +++ b/cytominer_eval/tests/test_operations/test_percent_strong.py @@ -53,3 +53,16 @@ def test_percent_strong(): expected_result = 0.3074 assert np.round(output, 4) == expected_result + + +def test_percent_strong_uniquerows(): + with pytest.raises(AssertionError) as err: + replicate_groups = ["Metadata_pert_well"] + output = percent_strong( + similarity_melted_df=similarity_melted_df, + replicate_groups=replicate_groups, + quantile=0.95, + ) + assert "no replicate groups identified in {rep} columns!".format( + rep=replicate_groups + ) in str(err.value)