"""
Author: Thomas Cokelaer
Affiliation: Institut Pasteur
Aim: Find Fix contaminant in the fastq
Data: paired end to be placed inside ./fastq_raw
Run: snakemake -s Snakefile
Changelog:
"""
import sequana
from sequana import snakemake as sm

# Change parameters inside config.yaml
import glob

configfile: "config.yaml"


include: sm.rules['dag']
include: sm.rules['cleanup']
include: sm.rules["fastq_sampling"]
include: '/home/cokelaer/Work/github/sequana/sequana/rules/bwa_fix/Snakefile'
include: '/home/cokelaer/Work/github/sequana/sequana/rules/fastqc/Snakefile'
include: '/home/cokelaer/Work/github/sequana/sequana/rules/bwa_bam_to_fastq/Snakefile'

sm.message(str(config))

workdir: "."

############# NOTHING to change here below
fastq_sampling = expand(fastq_sampling_wc[0], dataset=fastq_sampling_wc[1])
#fastqc_input = expand(fastqc_wc[0], dataset=fastqc_wc[1])



expand("fastqc_results/{dataset}_fastqc.html", dataset=data_tags)


rule all:
    input:
        "bwa_fix/contaminant_R1.mapped.fastq",
        "bwa_fix/contaminant_R2.mapped.fastq",
        "report/index.html", 
        "report/bwa_fix.html",
    version: sequana.version


rule report:
    input:
        dag = "dag.svg", 
        other = ["bwa_fix/fix_stats.json", "fastqc/fastqc.done"]
    output: "report/index.html", "report/bwa_fix.html"
    run:
        from sequana import report_main
        from sequana import report_fix
        from sequana import report_fastqc

        # Main page
        s = report_main.SequanaReport()
        s.create_report()

        # Fix page
        s = report_fix.FixReport(output_filename="bwa_fix.html")
        s.input_filename = "bwa_fix/fix_stats.json"
        s.create_report()

        s = report_fastqc.FastQCReport()
        s.create_report()

        shell("cp Snakefile report/")
        shell("cp dag.svg report/")


rule general_cleanup:
    params: cleanup=["report.html"]

