import "./tasks/fastqc.wdl" as fastqc
import "./tasks/fastqscreen.wdl" as fastqscreen
import "./tasks/bamqc.wdl" as bamqc
import "./tasks/benchmark.wdl" as benchmark
import "./tasks/multiqc.wdl" as multiqc
import "./tasks/vcfstat.wdl" as vcfstat
import "./tasks/mergeNum.wdl" as mergeNum
import "./tasks/jaccard_index.wdl" as JI
import "./tasks/mergeJI.wdl" as mergeJI


workflow {{ project_name }} {

	File inputSamplesFile
	Array[Array[File]] inputSamples = read_tsv(inputSamplesFile)
	File inputJIpiarsFile
	Array[Array[File]] inputJIpairs = read_tsv(inputJIpiarsFile)
	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 bamqc.bamqc as bamqc {
			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
		}	

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

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

	scatter (pair in inputJIpairs) {
		call JI.JI as JI {
			input:
			vcf_a=pair[0],
			vcf_b=pair[1],
			dir_name=pair[2],
			sdf=sdf
		}	
	}

	call mergeJI.mergeJI as mergeJI {
		input:
		JI_summary=JI.JI_summary,
		inputJIpiarsFile=inputJIpiarsFile
	}

}

