"""
.. module:: annotation
   :platform: Unix, OSX
   :synopsis: A module of methods and utilities for annotating files, post-processing annotated VCFs, and transforming
   into additional formats.

.. moduleauthor:: Daniel Gaston <daniel.gaston@dal.ca>


"""

import pipeline


def snpeff(job, config, sample, input_vcf):
    """Annotate the specified VCF using snpEff
    :param config: The configuration dictionary.
    :type config: dict.
    :param sample: sample name.
    :type sample: str.
    :param input_vcf: The input_vcf file name to process.
    :type input_vcf: str.
    :returns:  str -- The output vcf file name.
    """

    output_vcf = "{}.snpEff.{}.vcf".format(sample, config['snpeff']['reference'])
    logfile = "{}.snpeff.log".format(sample)

    snpeff_command = ("java",
                      "-Xmx{}g".format(config['snpeff']['max_mem']),
                      "-jar",
                      "{}".format(config['snpeff']['bin']),
                      "-v",
                      "{}".format(config['snpeff']['reference']),
                      "{}".format(input_vcf),
                      ">"
                      "{}".format(output_vcf))

    job.fileStore.logToMaster("snpEff Command: {}\n".format(snpeff_command))
    pipeline.run_and_log_command(" ".join(snpeff_command), logfile)

    return output_vcf


def gemini(job, config, sample, input_vcf):
    """Take the specified VCF and use GEMINI to add additional annotations and convert to database format
    :param config: The configuration dictionary.
    :type config: dict.
    :param sample: sample name.
    :type sample: str.
    :param input_vcf: The input_vcf file name to process.
    :type input_vcf: str.
    :returns:  str -- The output GEMINI database name.
    """

    db = "{}.snpEff.{}.db".format(sample, config['snpeff']['reference'])
    logfile = "{}.gemini.log".format(sample)

    command = ("{}".format(config['gemini']['bin']),
               "load",
               "--cores",
               "{}".format(config['gemini']['num_cores']),
               "--save-info-string",
               "-v",
               "{}".format(input_vcf),
               "-t",
               "snpEff",
               "{}".format(db))

    job.fileStore.logToMaster("GEMINI Command: {}\n".format(command))
    pipeline.run_and_log_command(" ".join(command), logfile)

    return db

@@ -2361,8 +2361,1059 @@
 turn db%0A
+%0A%0Adef vcfanno(job, config, sample, input_vcf):%0A    %22%22%22Take the specified VCF and use vcfanno to add additional annotations%0A    :param config: The configuration dictionary.%0A    :type config: dict.%0A    :param sample: sample name.%0A    :type sample: str.%0A    :param input_vcf: The input_vcf file name to process.%0A    :type input_vcf: str.%0A    :returns:  str -- The output vcf file name.%0A    %22%22%22%0A%0A    output_vcf = %22%7B%7D.vcfanno.snpEff.%7B%7D.vcf%22.format(sample, config%5B'snpeff'%5D%5B'reference'%5D)%0A    logfile = %22%7B%7D.vcfanno.log%22.format(sample)%0A%0A    command = (%22%7B%7D%22.format(config%5B'vcfanno'%5D%5B'bin'%5D),%0A               %22-p%22,%0A               %22%7B%7D%22.format(config%5B'vcfanno'%5D%5B'num_cores'%5D),%0A               %22--lua%22,%0A               %22%7B%7D%22.format(config%5B'vcfanno'%5D%5B'lua'%5D),%0A               %22%7B%7D%22.format(config%5B'vcfanno'%5D%5B'conf'%5D),%0A               %22%7B%7D%22.format(input_vcf),%0A               %22%3E%22,%0A               %22%7B%7D%22.format(output_vcf))%0A%0A    job.fileStore.logToMaster(%22GEMINI Command: %7B%7D%5Cn%22.format(command))%0A    pipeline.run_and_log_command(%22 %22.join(command), logfile)%0A%0A    return output_vcf%0A

add vcfanno wrapper module