Skip to content

Commit

Permalink
Merge pull request #284 from NCI-CGR/213-create-header-only-files-for…
Browse files Browse the repository at this point in the history
…-sample_levelconcordancegraftsv-sample_levelconcordancekingkin0-when-no-relatives

fix empty relatedness files
  • Loading branch information
kliao12 authored May 6, 2024
2 parents 0591e84 + 3cc8d08 commit 1bc986b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/cgr_gwas_qc/workflow/scripts/sample_concordance.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- :mod:`cgr_gwas_qc.parsers.king`
- :mod:`cgr_gwas_qc.parsers.graf`
"""
import os
from itertools import combinations
from pathlib import Path
from typing import List, Tuple
Expand Down Expand Up @@ -102,9 +103,18 @@ def read(filename: PathLike):

@app.command()
def main(
sample_sheet_csv: Path, plink_file: Path, graf_file: Path, king_file: Path, outfile: Path,
sample_sheet_csv: Path,
plink_file: Path,
graf_file: Path,
king_file: Path,
outfile: Path,
):
ss = sample_sheet.read(sample_sheet_csv)

# Check if graf or king are empty (no related). If so add expected final headers to file
check_empty_add_headers(graf_file, ["GRAF_HGMR", "GRAF_AGMR", "GRAF_relationship"])
check_empty_add_headers(king_file, ["KING_Kinship", "KING_relationship"])

concordance = (
build(plink_file, graf_file, king_file)
.pipe(_add_expected_replicates, ss)
Expand All @@ -119,6 +129,13 @@ def main(
)


def check_empty_add_headers(file_path: Path, headers: list):
"""Check if the file is empty"""
if os.path.getsize(file_path) == 0:
with open(file_path, "w") as f:
f.write("\t".join(headers) + "\n")


def build(plink_file: PathLike, graf_file: PathLike, king_file: PathLike):
"""Build the main concordance table."""
return (
Expand Down Expand Up @@ -246,7 +263,8 @@ def _graf(filename: PathLike):
.set_index(["ID1", "ID2"])
.reindex(["HGMR", "AGMR", "relationship"], axis=1)
.rename(
{"HGMR": "GRAF_HGMR", "AGMR": "GRAF_AGMR", "relationship": "GRAF_relationship"}, axis=1,
{"HGMR": "GRAF_HGMR", "AGMR": "GRAF_AGMR", "relationship": "GRAF_relationship"},
axis=1,
)
)

Expand Down

0 comments on commit 1bc986b

Please sign in to comment.