Skip to content

Commit

Permalink
fix ranking to follow that variants after compound het are not penali…
Browse files Browse the repository at this point in the history
…sed in ranking
  • Loading branch information
yaseminbridges committed Dec 4, 2024
1 parent 5c70634 commit 51af8ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/pheval/post_processing/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,15 @@ def _rank_with_grouping_id(self, pheval_result_df: pd.DataFrame) -> pd.DataFrame
pheval_result_df["min_rank"] = (
pheval_result_df.groupby(["score", "grouping_id"])
.ngroup()
.rank(method="min", ascending=self.ascending)
)
.rank(method="dense", ascending=self.ascending)
).astype(int)
pheval_result_df["rank"] = pheval_result_df.groupby("score")["min_rank"].transform("max")
return pheval_result_df

def _rank_without_grouping_id(self, pheval_result_df: pd.DataFrame) -> pd.DataFrame:
"""Apply ranking without using grouping_id."""
pheval_result_df["rank"] = pheval_result_df["score"].rank(
method="max", ascending=self.ascending
pheval_result_df["rank"] = (
pheval_result_df["score"].rank(method="max", ascending=self.ascending).astype(int)
)
return pheval_result_df

Expand Down
20 changes: 10 additions & 10 deletions tests/test_post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ def test__rank_with_grouping_id(self):
{
"score": [0.9, 0.9, 0.8, 0.7, 0.7, 0.6, 0.5, 0.5, 0.4],
"grouping_id": ["A", "A", "B", "C", "D", "E", "F", "F", "G"],
"min_rank": [1.0, 1.0, 3.0, 5.0, 4.0, 6.0, 7.0, 7.0, 9.0],
"rank": [1.0, 1.0, 3.0, 5.0, 5.0, 6.0, 7.0, 7.0, 9.0],
"min_rank": [1, 1, 2, 4, 3, 5, 6, 6, 7],
"rank": [1, 1, 2, 4, 4, 5, 6, 6, 7],
}
)
)
Expand All @@ -347,7 +347,7 @@ def test__rank_without_grouping_id(self):
pd.DataFrame(
{
"score": [0.9, 0.9, 0.8, 0.7, 0.7, 0.6, 0.5, 0.5, 0.4],
"rank": [2.0, 2.0, 3.0, 5.0, 5.0, 6.0, 8.0, 8.0, 9.0],
"rank": [2, 2, 3, 5, 5, 6, 8, 8, 9],
}
)
)
Expand All @@ -366,7 +366,7 @@ def test_rank_pheval_results_gene(self):
"ENSG00000068985",
],
"score": [0.9234, 0.6529, 0.6529, 0.5235],
"rank": [1.0, 3.0, 3.0, 4.0],
"rank": [1, 3, 3, 4],
}
)
)
Expand All @@ -383,7 +383,7 @@ def test_rank_pheval_results_variant(self):
"ref": ["A", "A", "A", "T"],
"alt": ["G", "C", "C", "G"],
"score": [0.1245, 0.4578, 0.9999, 0.9999],
"rank": [1.0, 2.0, 4.0, 4.0],
"rank": [1, 2, 4, 4],
}
)
)
Expand All @@ -400,7 +400,7 @@ def test_rank_pheval_results_variant_grouping_id(self):
"ref": ["A", "A", "A", "T"],
"alt": ["G", "C", "C", "G"],
"score": [0.1245, 0.4578, 0.9999, 0.9999],
"rank": [4.0, 3.0, 1.0, 1.0],
"rank": [3, 2, 1, 1],
}
)
)
Expand All @@ -422,7 +422,7 @@ def test_rank_pheval_results_disease(self):
2: "OMIM:614483",
},
"score": {0: 4.284, 1: 4.284, 2: -1.871},
"rank": {0: 2.0, 1: 2.0, 2: 3.0},
"rank": {0: 2, 1: 2, 2: 3},
}
)
)
Expand All @@ -443,7 +443,7 @@ def test_create_pheval_result_gene(self):
"ENSG00000068985",
],
"score": [0.9234, 0.6529, 0.6529, 0.5235],
"rank": [1.0, 3.0, 3.0, 4.0],
"rank": [1, 3, 3, 4],
}
)
)
Expand All @@ -460,7 +460,7 @@ def test_create_pheval_result_variant(self):
"ref": ["A", "A", "A", "T"],
"alt": ["G", "C", "C", "G"],
"score": [0.1245, 0.4578, 0.9348, 0.9999],
"rank": [1.0, 2.0, 3.0, 4.0],
"rank": [1, 2, 3, 4],
}
)
)
Expand All @@ -482,7 +482,7 @@ def test_create_pheval_result_disease(self):
2: "OMIM:614483",
},
"score": {0: 4.284, 1: 4.284, 2: -1.871},
"rank": {0: 2.0, 1: 2.0, 2: 3.0},
"rank": {0: 2, 1: 2, 2: 3},
}
)
)
Expand Down

0 comments on commit 51af8ea

Please sign in to comment.