Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
akotlar committed Nov 11, 2024
1 parent daa1399 commit eae1d66
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 39 deletions.
46 changes: 26 additions & 20 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,21 @@ process MERGE_ALL_PHASED_VCF {
process COPY_SKIPPED_VCFS {
label 'copy_skipped_vcfs'

publishDir "${params.output}/final_vcf", mode: 'copy'
publishDir params.output, mode: 'copy'

input:
file(skipped_files)
path(skipped_files)

output:
path('final_vcf/*'), emit: skipped_files

script:
"""
mkdir final_vcf
for f in ${skipped_files}; do
mv \$f final_vcf/
done
echo "Copying skipped VCF file: ${skipped_files}"
"""
}
Expand All @@ -214,18 +222,17 @@ workflow {
println "Welcome to ${params.service.name} (${workflow.manifest.version})"

if (params.imputation.enabled) {
INPUT_VALIDATION()

// Copy skipped VCFs to the final output directory's subdirectory 'final_vcfs'
// COPY_SKIPPED_VCFS(
// INPUT_VALIDATION.out.skipped_files
// )
def input_validation = INPUT_VALIDATION()

// Proceed with quality control on validated files
// Pass outputs to QUALITY_CONTROL
QUALITY_CONTROL(
INPUT_VALIDATION.out.validated_files,
INPUT_VALIDATION.out.validation_report,
site_files_ch
input_validation.validated_files,
input_validation.validation_report,
site_files_ch.collect()
)

COPY_SKIPPED_VCFS(
input_validation.skipped_files.collect()
)

// Check if QC chunks exist in case QC failed
Expand All @@ -235,7 +242,6 @@ workflow {

if (params.mode == 'imputation') {
def phased_ch = QUALITY_CONTROL.out.qc_metafiles

if (phasing_engine != 'no_phasing') {
PHASING(
QUALITY_CONTROL.out.qc_metafiles
Expand All @@ -249,16 +255,16 @@ workflow {
phased_ch
)

if (params.merge_results == true) {
if (params.merge_results) {
ENCRYPTION(
IMPUTATION.out.groupTuple()
)
IMPUTATION.out.groupTuple()
)
}
} else {
if (params.merge_results == true) {
} else {
if (params.merge_results) {
MERGE_ALL_PHASED_VCF(
phased_ch.groupTuple()
)
phased_ch.groupTuple()
)
}
}
}
Expand Down
35 changes: 23 additions & 12 deletions modules/local/input_validation/input_validation_vcf.nf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ process INPUT_VALIDATION_VCF {
path vcf_files

output:
path("split_vcfs/*.vcf.gz"), emit: validated_files
path("skipped_vcfs/*.vcf.gz"), emit: skipped_files, optional: true
path("validated_vcfs/*.vcf.gz"), emit: validated_files
path("skipped_vcfs/*.vcf.gz"), emit: skipped_files
path("validation_report.txt"), emit: validation_report

script:
Expand Down Expand Up @@ -42,7 +42,7 @@ EOF
skipped_vcfs=()
# Create the directories for split VCF files
mkdir -p split_vcfs skipped_vcfs
mkdir -p split_vcfs skipped_vcfs validated_vcfs
# Process each VCF file
for vcf in ${vcf_files}; do
Expand Down Expand Up @@ -159,23 +159,34 @@ EOF
base=\$(basename "\$f")
if [[ "\$base" =~ _([1-9]|1[0-9]|2[0-2]|X|chr([1-9]|1[0-9]|2[0-2]|X))\\.vcf\\.gz\$ ]]; then
vcf_files_to_validate+=("\$f")
mv "\$f" validated_vcfs/
if [ -f "\$f.csi" ] || [ -f "\$f.tbi" ]; then
mv "\$f".csi validated_vcfs/
mv "\$f".tbi validated_vcfs/
fi
else
skipped_vcfs+=("\$f")
mv "\$f" skipped_vcfs/
if [ -f "\$f.csi" ] || [ -f "\$f.tbi" ]; then
mv "\$f".csi skipped_vcfs/
mv "\$f".tbi skipped_vcfs/
fi
fi
done
for f in "\${skipped_vcfs[@]}"; do
mv "\$f.*" skipped_vcfs/
done
final_skip_files=(skipped_vcfs/*.vcf.gz)
# get the final_vcf_files_to_validate by globbing
echo "VCF files to validate:"
printf '%s\\n' "\${vcf_files_to_validate[@]}"
final_vcf_files_to_validate=(validated_vcfs/*.vcf.gz)
echo "Skipped VCF files:"
printf '%s\\n' "\${skipped_vcfs[@]}"
echo "skipped_vcfs: \${final_skip_files[@]}"
echo "validated_vcfs: \${final_vcf_files_to_validate[@]}"
# Run the validation program only if there are files to validate
if [ \${#vcf_files_to_validate[@]} -gt 0 ]; then
if [ \${#final_vcf_files_to_validate[@]} -gt 0 ]; then
java -Xmx${avail_mem}M -jar /opt/imputationserver-utils/imputationserver-utils.jar \\
validate \\
--population ${params.population} \\
Expand All @@ -189,7 +200,7 @@ EOF
--no-index \\
--contactName "${contactName}" \\
--contactEmail "${contactEmail}" \\
"\${vcf_files_to_validate[@]}"
"\${final_vcf_files_to_validate[@]}"
exit_code_a=\$?
else
echo "No VCF files to validate."
Expand Down
5 changes: 2 additions & 3 deletions modules/local/quality_control/quality_control_report.nf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
process QUALITY_CONTROL_REPORT {

label 'preprocessing'
publishDir params.output, mode: 'copy'

Expand All @@ -10,10 +9,11 @@ process QUALITY_CONTROL_REPORT {
path(qc_report_file)

output:
path("*.html")
path('*.html')

script:
"""
echo "maf_file: ${maf_file}"
Rscript -e "require( 'rmarkdown' ); render('${qc_report_file}',
params = list(
maf_file = '${maf_file}',
Expand All @@ -30,5 +30,4 @@ process QUALITY_CONTROL_REPORT {
output_file='\$PWD/quality-control.html'
)"
"""

}
6 changes: 2 additions & 4 deletions workflows/input_validation.nf
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ include { INPUT_VALIDATION_VCF } from '../modules/local/input_validation/input_v

Channel
.fromPath(params.files)
.set {files}
.set { files }

workflow INPUT_VALIDATION {

main:
INPUT_VALIDATION_VCF(files.collect())

emit:
validated_files = INPUT_VALIDATION_VCF.out.validated_files.collect()
skipped_files = INPUT_VALIDATION_VCF.out.skipped_files.collect()
validation_report = INPUT_VALIDATION_VCF.out.validation_report
}


0 comments on commit eae1d66

Please sign in to comment.