"""
    This is a basic framework for processing of of viral genomes, currently
    tailored for EBOV. Some generalization work needed to expand this
    to generic viral genomes with an arbitrary number of segments/chromosomes.
    
    Make copies of this Snakefile and config.yaml to your analysis directory and
    customize as needed.
"""

__author__ = 'Daniel Park <dpark@broadinstitute.org>'

import os

configfile: "config.yaml"
pipesDir = os.path.join(os.path.expanduser(config['bin_dir']), 'pipes', 'rules')

include: os.path.join(pipesDir, 'common.rules')
set_env_vars()

include: os.path.join(pipesDir, 'demux.rules')
include: os.path.join(pipesDir, 'hs_deplete.rules')
include: os.path.join(pipesDir, 'assembly.rules')
include: os.path.join(pipesDir, 'interhost.rules')
include: os.path.join(pipesDir, 'ncbi.rules')
include: os.path.join(pipesDir, 'intrahost.rules')
include: os.path.join(pipesDir, 'reports.rules')

rule all:
    input:
        # create final assemblies for all samples
        expand("{data_dir}/{subdir}/{sample}.fasta",
            data_dir=config["data_dir"], subdir=config["subdirs"]["assembly"],
            sample=read_samples_file(config["samples_assembly"])),
        # create BAMs of aligned reads to own consensus and to common ref
        expand("{data_dir}/{subdir}/{sample}.bam",
            data_dir=config["data_dir"], subdir=config["subdirs"]["align_self"],
            sample=read_samples_file(config["samples_assembly"])),
        # intrahost variant calling
        config["data_dir"]+'/'+config["subdirs"]["intrahost"] +'/isnvs.vcf.gz',
        # create summary reports
        config["reports_dir"]+'/summary.fastqc.txt',
        config["reports_dir"]+'/summary.spike_count.txt'
    params: LSF="-N"
    run:
            if "job_profiler" in config:
                print("running report on all job runs")
                shell("{config[job_profiler]} {config[log_dir]} {config[reports_dir]}/summary.job_stats.txt")
            print("echo all done!")

rule clean:
    params: LSF="-N"
    shell: "rm -rf {config[tmp_dir]}/* .snakemake/tmp.*"
