pgx-main from prod added
This commit is contained in:
51
pgx-main/stellar_parser.py
Normal file
51
pgx-main/stellar_parser.py
Normal 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()
|
||||
Reference in New Issue
Block a user