Skip to content

Commit

Permalink
Merge pull request #18 from hillsbury/issues/15
Browse files Browse the repository at this point in the history
added assertion error for missing replicates
  • Loading branch information
hillsbury authored Nov 9, 2020
2 parents 56bd9e5 + df05b4d commit 6f9d350
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cytominer_eval/operations/percent_strong.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions cytominer_eval/tests/test_operations/test_percent_strong.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 6f9d350

Please sign in to comment.