Ömer An
02/26/2025, 2:17 AM#!/usr/bin/env nextflow
params.vcf_file = "sample.vcf" // Input VCF file
params.upload_url = "https://yourserver.com/uploads/" // VCF upload location
params.api_url = "https://vendor-api.com/submit" // Vendor API URL
params.submission_id = "12345"
params.submitter = "LabXYZ"
params.max_retries = 3 // Number of retries on failure
process generate_xml {
input:
path vcf_file
output:
path "submission.xml"
script:
def vcf_filename = vcf_file.getName()
"""
cat <<EOF > submission.xml
<Request>
<Metadata>
<SubmissionID>${params.submission_id}</SubmissionID>
<Submitter>${params.submitter}</Submitter>
</Metadata>
<VCFFile>
<FileName>${vcf_filename}</FileName>
<FileURL>${params.upload_url}${vcf_filename}</FileURL>
</VCFFile>
</Request>
EOF
"""
}
process upload_vcf {
input:
path vcf_file
output:
path "upload_status.txt"
script:
"""
LOG_FILE="vcf_upload.log"
RETRIES=0
SUCCESS=0
while [ \$RETRIES -lt ${params.max_retries} ]; do
echo "Attempt \$((RETRIES+1)) to upload VCF file..." | tee -a \$LOG_FILE
curl -X PUT --upload-file ${vcf_file} ${params.upload_url}${vcf_file.getName()} -o upload_response.txt -s -w "%{http_code}" > status_code.txt
STATUS_CODE=\$(cat status_code.txt)
if [ "\$STATUS_CODE" == "200" ]; then
echo "VCF file uploaded successfully." | tee -a \$LOG_FILE
echo "success" > upload_status.txt
SUCCESS=1
break
else
echo "Upload failed with status: \$STATUS_CODE" | tee -a \$LOG_FILE
cat upload_response.txt | tee -a \$LOG_FILE
fi
RETRIES=\$((RETRIES+1))
sleep 5 # Wait before retrying
done
if [ \$SUCCESS -eq 0 ]; then
echo "VCF upload failed after ${params.max_retries} attempts." | tee -a \$LOG_FILE
exit 1
fi
"""
}
process submit_xml {
input:
path xml_file
path "upload_status.txt"
script:
"""
if [ "\$(cat upload_status.txt)" != "success" ]; then
echo "Skipping XML submission because VCF upload failed." | tee -a xml_submission.log
exit 1
fi
LOG_FILE="xml_submission.log"
RETRIES=0
SUCCESS=0
while [ \$RETRIES -lt ${params.max_retries} ]; do
echo "Attempt \$((RETRIES+1)) to submit XML..." | tee -a \$LOG_FILE
curl -X POST -H "Content-Type: application/xml" --data @${xml_file} ${params.api_url} -o xml_response.txt -s -w "%{http_code}" > status_code.txt
STATUS_CODE=\$(cat status_code.txt)
if [ "\$STATUS_CODE" == "200" ]; then
echo "XML submitted successfully." | tee -a \$LOG_FILE
SUCCESS=1
break
else
echo "XML submission failed with status: \$STATUS_CODE" | tee -a \$LOG_FILE
cat xml_response.txt | tee -a \$LOG_FILE
fi
RETRIES=\$((RETRIES+1))
sleep 5
done
if [ \$SUCCESS -eq 0 ]; then
echo "XML submission failed after ${params.max_retries} attempts." | tee -a \$LOG_FILE
exit 1
fi
"""
}
workflow {
vcf_file = file(params.vcf_file)
xml_file = generate_xml(vcf_file)
upload_result = upload_vcf(vcf_file)
submit_xml(xml_file, upload_result)
}Mahesh Binzer-Panchal
02/26/2025, 7:52 AM