Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor utility functions #55

Merged
merged 15 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cytominer_eval/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import List, Union

from cytominer_eval.transform import metric_melt
from cytominer_eval.transform.util import check_replicate_groups
from cytominer_eval.utils.transform_utils import check_replicate_groups
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, this line gives an error because utils are not imported here or in the init.py file. But I am unsure why the tests don't give that error?

This applies to all imports of util below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh interesting, what is the error?

Is it possible that your testing environment is out-of-date?

I also added a __init__.py file inside cytominer_eval/utils - so this might help. It should have been there in the first place, so thanks for making this note.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I know it works, for some reason pycharm is complaining about it. I think it's because if you run that file on its own, it won't find the util.
but all good

from cytominer_eval.operations import (
replicate_reproducibility,
precision_recall,
Expand All @@ -25,7 +25,7 @@ def evaluate(
replicate_groups: Union[List[str], dict],
operation: str = "replicate_reproducibility",
similarity_metric: str = "pearson",
replicate_reproducibility_quantile: np.float = 0.95,
replicate_reproducibility_quantile: float = 0.95,
replicate_reproducibility_return_median_cor: bool = False,
precision_recall_k: Union[int, List[int]] = 10,
grit_control_perts: List[str] = ["None"],
Expand Down
11 changes: 4 additions & 7 deletions cytominer_eval/operations/enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
from typing import List, Union
import scipy

from .util import assign_replicates, calculate_grit, check_grit_replicate_summary_method
from cytominer_eval.transform.util import (
set_pair_ids,
set_grit_column_info,
assert_melt,
)
from cytominer_eval.utils.operation_utils import assign_replicates
from cytominer_eval.utils.transform_utils import set_pair_ids, assert_melt


def enrichment(
similarity_melted_df: pd.DataFrame,
replicate_groups: List[str],
percentile: Union[float, List[float]],
) -> pd.DataFrame:
"""Calculate the enrichment score. This score is based on the fisher exact odds score. Similar to the other functions, the closest connections are determined and checked with the replicates.
"""Calculate the enrichment score. This score is based on the fisher exact odds score.
Similar to the other functions, the closest connections are determined and checked with the replicates.
This score effectively calculates how much better the distribution of correct connections is compared to random.

Parameters
Expand Down
9 changes: 5 additions & 4 deletions cytominer_eval/operations/grit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import pandas as pd
from typing import List

from .util import assign_replicates, calculate_grit, check_grit_replicate_summary_method
from cytominer_eval.transform.util import (
set_pair_ids,
from cytominer_eval.utils.operation_utils import assign_replicates
from cytominer_eval.utils.transform_utils import set_pair_ids, assert_melt
from cytominer_eval.utils.grit_utils import (
check_grit_replicate_summary_method,
set_grit_column_info,
assert_melt,
calculate_grit,
)


Expand Down
2 changes: 1 addition & 1 deletion cytominer_eval/operations/mp_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import pandas as pd
from typing import List

from .util import calculate_mp_value
from cytominer_eval.utils.mpvalue_utils import calculate_mp_value


def mp_value(
Expand Down
5 changes: 3 additions & 2 deletions cytominer_eval/operations/precision_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import pandas as pd
from typing import List, Union

from .util import assign_replicates, calculate_precision_recall
from cytominer_eval.transform.util import set_pair_ids, assert_melt
from cytominer_eval.utils.precisionrecall_utils import calculate_precision_recall
from cytominer_eval.utils.operation_utils import assign_replicates
from cytominer_eval.utils.transform_utils import set_pair_ids, assert_melt


def precision_recall(
Expand Down
8 changes: 4 additions & 4 deletions cytominer_eval/operations/replicate_reproducibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import pandas as pd
from typing import List

from .util import assign_replicates, set_pair_ids
from cytominer_eval.transform.util import assert_melt
from cytominer_eval.utils.operation_utils import assign_replicates, set_pair_ids
from cytominer_eval.utils.transform_utils import assert_melt


def replicate_reproducibility(
similarity_melted_df: pd.DataFrame,
replicate_groups: List[str],
quantile_over_null: np.float = 0.95,
quantile_over_null: float = 0.95,
return_median_correlations: bool = False,
) -> np.float:
) -> float:
r"""Summarize pairwise replicate correlations

For a given pairwise similarity matrix, replicate information, and specific options,
Expand Down
Loading