include: "rules/common.smk"
include: "rules/trimmomatic.smk"
include: "rules/subsample.smk"
include: "rules/quality.smk"
include: "rules/genome_preparation.smk"
include: "rules/alignment.smk"
include: "rules/methylation_extraction.smk"

# report template
report: "report/workflow.rst"
def all_input(wildcards):
	"""
	Function defining all requested inputs for the rule all (below).
	"""
	

	wanted_input = []
	# Quality report
	wanted_input.extend(
				expand(
					[
						
						outdir+"results/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}-multiqc_report.html"
					]
					,
					unit=get_merged(),

				)
			)
	wanted_input.extend(
				expand(
					[
						outdir+"results/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}-bismark_report.html"
					]
					,
					unit=get_unit(),

				)
			)

			
	# Bismark methylation extraction report 
	wanted_input.extend(
			expand(
				[
					outdir+"results/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}/methylation_extraction_bismark/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}.deduplicated.CX_report.txt.CGmap.gz"
				] ,
				unit=get_merged(),
			)
		)
	wanted_input.extend(
			expand(
				[
					outdir+"results/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}/methylation_extraction_bismark/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}.deduplicated.CX_report.txt"
				] ,
				unit=get_merged(),
			)
		)
	wanted_input.extend(
			expand(
				[
					outdir+"results/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}/methylation_extraction_bismark/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}.deduplicated.CX_report.txt.sorted.{context}.bw",
					outdir+"results/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}/methylation_extraction_bismark/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}.deduplicated.sorted.bedGraph.bw",
					outdir+"results/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}/alignment_bismark/{unit.sample}-TechRep_{unit.techrep}-BioRep_{unit.biorep}.deduplicated.bw"
				] ,
				unit=get_merged(),
				context= ["cg","chg","chh"]
			)
		)	
	return wanted_input
rule all:
	input: all_input
	output:
		outdir+"alignment.lock"
	resources:
		cpus= 1,
		mem_mb=2000,
		time_min=140
	shell:
		"touch {output}"
