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

bugfix: retrieve additional missing data from QC_Report.xlsx #307

Merged
merged 4 commits into from
Jul 11, 2024
Merged
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
25 changes: 20 additions & 5 deletions src/cgr_gwas_qc/workflow/scripts/qc_report_table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import List

import pandas as pd
import typer
Expand Down Expand Up @@ -28,7 +29,6 @@ def main(
graf: Path,
outfile: Path,
):

with pd.ExcelWriter(outfile) as writer:
_sample_qc(sample_sheet_csv, sample_qc_csv).to_excel(
writer, sheet_name="SAMPLE_QC", index=False
Expand Down Expand Up @@ -56,7 +56,6 @@ def main(
"Number Samples Per Subject",
"Replicate IDs",
"Sample Excluded from QC",
"IdatsInProjectDir",
"Sample Used in Subject Analysis",
"Subject Removed",
# QC Results
Expand All @@ -70,7 +69,6 @@ def main(
"Contaminated",
"Contamination_Rate",
"IdatIntensity",
"Expected Replicate",
"Expected Replicate Discordance",
"Unexpected Replicate",
"Sex Discordant",
Expand All @@ -85,14 +83,31 @@ def main(
]


_PASS_FAIL_QC_COLUMNS: List[str] = [
"is_call_rate_filtered",
"is_contaminated",
"Expected Replicate Discordance",
"Unexpected Replicate",
"is_sex_discordant",
]


def _count_issues(sample_qc_csv: PathLike, qc_columns: List[str]) -> pd.DataFrame:
df = sample_qc_table.read(sample_qc_csv)
df["Count_of_QC_Issue"] = df[qc_columns].sum(axis=1)
df["Sample Pass QC"] = df["Count_of_QC_Issue"] == 0 # TRUE iif all pass_fail columns are true
return df


def _sample_qc(sample_sheet_csv: PathLike, sample_qc_csv: PathLike) -> pd.DataFrame:
ss = sample_sheet.read(sample_sheet_csv, remove_exclusions=False).rename(
REPORT_NAME_MAPPER, axis=1
)
_additional_columns = [x for x in ss.columns if x not in _SAMPLE_QC_COLUMNS]

df = _count_issues(sample_qc_csv, _PASS_FAIL_QC_COLUMNS)
return (
sample_qc_table.read(sample_qc_csv)
.rename(REPORT_NAME_MAPPER, axis=1)
df.rename(REPORT_NAME_MAPPER, axis=1)
.merge(ss, on="Sample_ID", suffixes=["", "_DROP"], how="outer")
.filter(regex="^(?!.*_DROP)")
.reindex(_SAMPLE_QC_COLUMNS + _additional_columns, axis=1)
Expand Down
Loading