Skip to content

Commit

Permalink
refactor: Refactor meta comparison (#114)
Browse files Browse the repository at this point in the history
This PR does some minor refactoring in the meta comparison code as they
were still some comments from @dlaehnemann in #113 that havent been
addressed.
  • Loading branch information
fxwiegand authored Sep 11, 2024
1 parent 3f8f126 commit 5bf9ea0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions workflow/scripts/compare_diffexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

diffexp_x = pl.from_pandas(pyreadr.read_r(snakemake.input[0])[None]).lazy()
diffexp_y = pl.from_pandas(pyreadr.read_r(snakemake.input[1])[None]).lazy()
label_x = list(snakemake.params.labels.keys())[0]
label_y = list(snakemake.params.labels.keys())[1]
label_x = list(snakemake.params.labels)[0]
label_y = list(snakemake.params.labels)[1]

effect_x = f"effect {label_x} (beta score)"
effect_y = f"effect {label_y} (beta score)"
Expand Down
11 changes: 5 additions & 6 deletions workflow/scripts/compare_enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

diffexp_x = pl.read_csv(snakemake.input[0], separator="\t").lazy()
diffexp_y = pl.read_csv(snakemake.input[1], separator="\t").lazy()
label_x = list(snakemake.params.labels.keys())[0]
label_y = list(snakemake.params.labels.keys())[1]
label_x = list(snakemake.params.labels)[0]
label_y = list(snakemake.params.labels)[1]

effect_x_pos = f"positive effect {label_x}"
effect_y_pos = f"positive effect {label_y}"
Expand Down Expand Up @@ -37,10 +37,9 @@ def prepare(df):
# Select necessary columns
df = (
df.select(
[cs.by_name("GO", "term", "p_uncorrected", "p_fdr_bh", "study_items")]
cs.by_name("GO", "term", "p_uncorrected", "p_fdr_bh", "study_items")
)
.with_columns(
[
pl.col("study_items")
.map_elements(
extract_study_items,
Expand All @@ -51,7 +50,6 @@ def prepare(df):
),
)
.alias("parsed_terms")
]
)
.with_columns(
[
Expand Down Expand Up @@ -102,7 +100,8 @@ def plot(df, effect_x, effect_y, title, xlabel, ylabel):
line = (
alt.Chart(
pl.DataFrame(
{effect_x: [min_value, max_value], effect_y: [min_value, max_value]}
{effect_x: [min_value, max_value], effect_y: [min_value, max_value]},
schema={effect_x: pl.Float64, effect_y: pl.Float64},
)
)
.mark_line(color="lightgrey")
Expand Down
8 changes: 4 additions & 4 deletions workflow/scripts/compare_pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

diffexp_x = pl.read_csv(snakemake.input[0], separator="\t").lazy()
diffexp_y = pl.read_csv(snakemake.input[1], separator="\t").lazy()
label_x = list(snakemake.params.labels.keys())[0]
label_y = list(snakemake.params.labels.keys())[1]
label_x = list(snakemake.params.labels)[0]
label_y = list(snakemake.params.labels)[1]


effect_x = f"effect {label_x}"
Expand Down Expand Up @@ -106,8 +106,8 @@ def prepare(df):
)
)

min_value = combined.select(pl.min(effect_x, effect_y)).min_horizontal()[0]
max_value = combined.select(pl.max(effect_x, effect_y)).max_horizontal()[0]
min_value = min(df[effect_x].min(), df[effect_y].min())
max_value = max(df[effect_x].max(), df[effect_y].max())

line = (
alt.Chart(
Expand Down

0 comments on commit 5bf9ea0

Please sign in to comment.