task merge_family {
	Array[File] splited_vcf
	String project
	String docker
	String cluster_config
	String disk_size
	
	command <<<

		mkdir -p /cromwell_root/tmp/vcf

		cp ${sep=" " splited_vcf} /cromwell_root/tmp/vcf

		for a in /cromwell_root/tmp/vcf/*vcf
		do
			for b in /cromwell_root/tmp/vcf/*vcf
			do
				for c in /cromwell_root/tmp/vcf/*vcf
				do
					for d in /cromwell_root/tmp/vcf/*vcf
					do
						sample_a=$(echo $a | cut -f7 -d_)
						sample_b=$(echo $b | cut -f7 -d_)
						sample_c=$(echo $c | cut -f7 -d_)
						sample_d=$(echo $d | cut -f7 -d_)
						rep_a=$(echo $a | cut -f8 -d_)
						rep_b=$(echo $b | cut -f8 -d_)
						rep_c=$(echo $c | cut -f8 -d_)
						rep_d=$(echo $d | cut -f8 -d_)
						if [ $sample_a == "LCL5" ] && [ $sample_b == "LCL6" ] && [ $sample_c == "LCL7" ] && [ $sample_d == "LCL8" ] && [ $rep_a == $rep_b ] && [ $rep_c == $rep_d ] && [ $rep_b == $rep_c ];then
							cat $a | grep -v '#' > LCL5.body
							cat $b | grep -v '#' | cut -f 10 > LCL6.body
							cat $c | grep -v '#' | cut -f 10 > LCL7.body
							cat $d | grep -v '#' | cut -f 10 > LCL8.body
							echo -e "#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tLCL5\tLCL6\tLCL7\tLCL8" > header_name
							cat $a | grep '##' | cat - header_name > header
							paste LCL5.body LCL6.body LCL7.body LCL8.body > family.body
							cat header family.body > ${project}.$rep_a.family.vcf
						fi
					done
				done
			done
		done

	>>>

	runtime {
		docker:docker
		cluster: cluster_config
		systemDisk: "cloud_ssd 40"
		dataDisk: "cloud_ssd " + disk_size + " /cromwell_root/"
	}
	output {
		Array[File] family_vcf = glob("*.family.vcf")
	}
}
