Skip to content

Commit

Permalink
reconnect to the overall workflow [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi18av committed Jun 23, 2024
1 parent c9b516a commit 39b28af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 41 deletions.
67 changes: 26 additions & 41 deletions bin/fastq_cohort_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,48 @@
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Summarize the input FASTQ validation report')

parser.add_argument('joint_vcf_name', metavar='joint_vcf_name', default="joint", type=str,
help='The prefix name of joint analysis used for used in the pipeline')
parser.add_argument('magma_samplesheet', metavar='magma_samplesheet', type=str, help='')

parser.add_argument('merged_fastq_reports', metavar='merged_fastq_reports', type=str, help='')

parser.add_argument('magma_analysis', metavar='magma_analysis', type=str, help='')

args = vars(parser.parse_args())

vcf_name = args['joint_vcf_name']
args = vars(parser.parse_args())

# ============================================
# Parse the validation reports for exact sample names which passed/failed
# ============================================

# Load the JSON file into a dictionary
with open('merged_fastq_reports.json', 'r') as f:
with open(args['merged_fastq_reports'], 'r') as f:
fastq_report_dict = json.load(f)

with open('samplesheet.json', 'r') as f:
magma_analysis_dict = json.load(f)
with open(args['magma_samplesheet'], 'r') as f:
magma_samplesheet_json = json.load(f)

fastq_report_keys_list = list(fastq_report_dict.keys())

for k in magma_analysis_dict.keys():
magma_analysis_dict[k]["fastq_report"] = {}

if magma_analysis_dict[k]['R1'] is not None:
fastq_1_name = magma_analysis_dict[k]['R1'].split("/")[-1]
magma_analysis_dict[k]["fastqs_approved"] = True
for elem in magma_samplesheet_json:
elem["fastq_report"] = {}

if elem['R1'] is not None:
fastq_1_name = elem['R1'].split("/")[-1]
elem["fastqs_approved"] = True
if fastq_1_name in fastq_report_keys_list:
magma_analysis_dict[k]["fastq_report"][fastq_1_name] = {"file": fastq_report_dict[fastq_1_name]}
elem["fastq_report"][fastq_1_name] = {"file": fastq_report_dict[fastq_1_name]}
else:
magma_analysis_dict[k]["fastq_report"][fastq_1_name] = {"fastq_utils_check": "failed"}
magma_analysis_dict[k]["fastqs_approved"] = False
elem["fastq_report"][fastq_1_name] = {"fastq_utils_check": "failed"}
elem["fastqs_approved"] = False

if magma_analysis_dict[k]['R2'] is not None:
fastq_2_name = magma_analysis_dict[k]['R2'].split("/")[-1]
if elem['R2'] != "" :
fastq_2_name = elem['R2'].split("/")[-1]
if fastq_2_name in fastq_report_keys_list:
magma_analysis_dict[k]["fastq_report"][fastq_2_name] = {"file": fastq_report_dict[fastq_2_name]}
elem["fastq_report"][fastq_2_name] = {"file": fastq_report_dict[fastq_2_name]}
else:
magma_analysis_dict[k]["fastq_report"][fastq_2_name] = {"fastq_utils_check": "failed"}
magma_analysis_dict[k]["fastqs_approved"] = False

with open('magma_analysis.json', 'w') as f:
json.dump(magma_analysis_dict, f, indent=4, ensure_ascii= False)

# ============================================
# Parse the validation reports for exact sample names which passed/failed
# ============================================

# Filter the dictionary for samples with fastqs_approved == True and False
approved_samples = {k for k, v in magma_analysis_dict.items() if v["fastqs_approved"] == True}
# Write approved_samples to a txt file with newline
with open("approved_samples.txt", "w") as f:
for sample in approved_samples:
f.write(sample + "\n")

rejected_samples = {k for k, v in magma_analysis_dict.items() if v["fastqs_approved"] == False}
# Write approved_samples to a txt file with newline
if rejected_samples:
with open("rejected_samples.txt", "w") as f:
for sample in rejected_samples:
f.write(sample + "\n")
elem["fastq_report"][fastq_2_name] = {"fastq_utils_check": "failed"}
elem["fastqs_approved"] = False

with open(args['magma_analysis'], 'w') as f:
json.dump(magma_samplesheet_json, f, indent=4, ensure_ascii= False)
1 change: 1 addition & 0 deletions modules/utils/.#fastq_cohort_validation.nf

0 comments on commit 39b28af

Please sign in to comment.