import "./tasks/fastqc.wdl" as fastqc
import "./tasks/fastqscreen.wdl" as fastqscreen
import "./tasks/qualimap.wdl" as qualimap
import "./tasks/benchmark.wdl" as benchmark
import "./tasks/vcfstat.wdl" as vcfstat
import "./tasks/sentieon.wdl" as sentieon
import "./tasks/multiqc.wdl" as multiqc
import "./tasks/mergeNum.wdl" as mergeNum
import "./tasks/mergeSentieon.wdl" as mergeSentieon


workflow project_name {

	File inputSamplesFile
	Array[Array[File]] inputSamples = read_tsv(inputSamplesFile)
	File screen_ref_dir
	File fastq_screen_conf
	File benchmarking_dir
	File ref_dir
	String fasta
	File sdf

	scatter (sample in inputSamples) {
		call fastqc.fastqc as fastqc {
			input:
			read1=sample[0],
			read2=sample[1]
		}

		call fastqscreen.fastq_screen as fastqscreen {
			input:
			read1=sample[0],
			read2=sample[1],
			screen_ref_dir=screen_ref_dir,
			fastq_screen_conf=fastq_screen_conf
		}

		call qualimap.qualimap as qualimap {
			input:
			bam=sample[2],
			bai=sample[3]
		}

		call benchmark.benchmark as benchmark {
			input:
			vcf=sample[4],
			benchmarking_dir=benchmarking_dir,
			ref_dir=ref_dir,
			sample_mark=sample[5],
			fasta=fasta
		}

		call vcfstat.vcfstat as vcfstat {
			input:
			rtg_vcf=benchmark.rtg_vcf,
			rtg_vcf_index=benchmark.rtg_vcf_index,
			sample_name=sample[6]
		}

		call sentieon.sentieon as sentieon {
			input:
			aln_metrics=sample[7],
			dedup_metrics=sample[8],
			is_metrics=sample[9],
			deduped_coverage=sample[10],
			sample_name=sample[6]
		}

	}
	call multiqc.multiqc as multiqc {
		input:
		read1_zip=fastqc.read1_zip,
		read2_zip=fastqc.read2_zip,
		txt1=fastqscreen.txt1,
		txt2=fastqscreen.txt2,
		zip=qualimap.zip,
		summary=benchmark.summary
	}

	call mergeNum.mergeNum as mergeNum {
		input:
		vcfnumber=vcfstat.vcfnumber
	}

	call mergeSentieon.mergeSentieon as mergeSentieon {
		input:
		aln_metrics_header=sentieon.aln_metrics_header,
		aln_metrics_data=sentieon.aln_metrics_data,
		dedup_metrics_header=sentieon.dedup_metrics_header,
		dedup_metrics_data=sentieon.dedup_metrics_data,
		is_metrics_header=sentieon.is_metrics_header,
		is_metrics_data=sentieon.is_metrics_data,
		deduped_coverage_header=sentieon.deduped_coverage_header,
		deduped_coverage_data=sentieon.deduped_coverage_data
	}
}

