import os

configfile: srcdir('config.yaml')

include: config['snakelines_dir'] + '/rules/alignment/aligners/mafft.snake'
include: config['snakelines_dir'] + '/rules/alignment/phylogeny/iqtree.snake'
include: config['snakelines_dir'] + '/rules/alignment/visualisation/msaviewer.snake'
include: config['snakelines_dir'] + '/rules/alignment/visualisation/phylogenetic_tree.snake'

report_dir = 'report/{}'.format(config['report_dir'])

sequences = config['sequences']
seqdir = os.path.dirname(sequences)
seqname = os.path.basename(sequences)
seqname = seqname[:seqname.rfind('.')]


rule process:
    input:
        html       = '{seqdir}/alignment/mafft/{seqname}.html'.format(seqdir=seqdir, seqname=seqname),
        tree_svg   = '{seqdir}/alignment/mafft/{seqname}.aln.treefile.svg'.format(seqdir=seqdir, seqname=seqname),
        tree_ascii = '{seqdir}/alignment/mafft/{seqname}.aln.treefile.ascii'.format(seqdir=seqdir, seqname=seqname)

    output:
        html       = '{report_dir}/{seqname}.html'.format(report_dir=report_dir, seqname=seqname),
        tree_svg   = '{report_dir}/{seqname}.svg'.format(report_dir=report_dir, seqname=seqname),
        tree_ascii = '{report_dir}/{seqname}.txt'.format(report_dir=report_dir, seqname=seqname)

    run:
        shutil.copy(input.html, output.html)
        shutil.copy(input.tree_svg, output.tree_svg)
        shutil.copy(input.tree_ascii, output.tree_ascii)
