# do onstart/onexit things
SAMPLE_SCHEMAS = ['sample', 'assembly', 'technical_replicates', 'biological_replicates', 'strandedness']
CONFIG_SCHEMAS = ['general', 'download', 'alignment_general', 'peakcalling', 'deseq2', 'trackhub']
include: "../../rules/configuration.smk"


# load all the relevant rules
include: f"{config['rule_dir']}/get_fastq.smk"
include: f"{config['rule_dir']}/trimming.smk"
include: f"{config['rule_dir']}/merge_replicates.smk"
include: f"{config['rule_dir']}/get_genome.smk"
include: f"{config['rule_dir']}/blacklist.smk"
include: f"{config['rule_dir']}/alignment.smk"
include: f"{config['rule_dir']}/bam_cleaning.smk"
include: f"{config['rule_dir']}/peak_calling.smk"
include: f"{config['rule_dir']}/peak_counts.smk"
include: f"{config['rule_dir']}/motif_scan.smk"
include: f"{config['rule_dir']}/bigfiles.smk"
include: f"{config['rule_dir']}/trackhub.smk"
include: f"{config['rule_dir']}/deseq2.smk"
include: f"{config['rule_dir']}/qc.smk"
include: f"{config['rule_dir']}/qc_peaks.smk"


# set the quality_control functions
QUALITY_CONTROL = [get_trimming_qc, get_alignment_qc, get_peak_calling_qc]


rule seq2science:
    """
    call peaks for each sample (or condition if applies)
    """
    input:
        expand(
            ([f"{{final_bam_dir}}/{CUSTOM_ASSEMBLIES[treps.loc[trep, 'assembly']]}-{trep}.samtools-coordinate.{{b}}am" for trep in treps.index]) +
            ([f"{{final_bam_dir}}/{CUSTOM_ASSEMBLIES[treps.loc[trep, 'assembly']]}-{trep}.samtools-coordinate.{{b}}am.{{b}}ai" for trep in treps.index]) +
            (["{trackhub_dir}"]                     if config['create_trackhub'] else []) +
            (["{qc_dir}/multiqc_{assemblies}.html"] if config["create_qc_report"] else []),
            assemblies=ALL_ASSEMBLIES, b="cr" if config.get('store_as_cram') else "b", **config) +
         count_table_output() + DE_CONTRASTS
