pgx-main from prod added

This commit is contained in:
2025-08-18 12:06:58 +02:00
parent fcb0e9aa4c
commit fe48df8676
984 changed files with 878657 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
# Generate a PharmCAT outside call file from a StellarPGx allele file
from argparse import ArgumentParser
from pathlib import Path
import pandas as pd
import shutil
def parse_file(infile):
"""
Generate a PharmCAT outside call file from a StellarPGx allele file
(also save input file to data/)
Args:
infile (str): StellarPGx allele file
"""
assert infile.endswith(".alleles")
gene = infile.split("_")[-1][:-8].upper()
infile = Path(infile)
assert infile.exists()
stem = infile.stem.replace(".deduped", "")
shutil.copy(infile, "data/" + stem + ".alleles")
outfile = "data/" + stem + ".tsv"
with open(infile, "r") as f:
lines = f.read().split("\n")
result = ""
likely = ""
for i, line in enumerate(lines):
if line.strip() == "Result:":
result = lines[i+1]
elif line.strip() == "Likely background alleles:":
likely = lines[i+1]
if result.startswith("Possible"):
diplotype = likely
else:
diplotype = result
pd.DataFrame([[gene, diplotype]]).to_csv(outfile, sep="\t", index=False, header=False)
def main():
parser = ArgumentParser(description="StellarPGx Output Parser")
parser.add_argument('input_file', type=str, help="StellarPGx allele file")
args = parser.parse_args()
parse_file(args.input_file)
if __name__ == '__main__':
main()