#!/usr/bin/env python

import argparse
import sys
import logging
import os

sys.path = [os.path.join(os.path.dirname(os.path.realpath(__file__)),'..')] + sys.path

from mintyper import version
from mintyper import mintyperPipeline

__author__ = "Malte B. Hallgren"
__version__ = version.__version__

def main():
    description = 'mintyper: an outbreak-detection method for accurate \
     and rapid SNP typing of clonal clusters with noisy long reads.'

    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('--illumina', action="store", type=str, dest='illumina', nargs="+",
                        default=[], help='Illumina input files. Must be paired-end.')
    parser.add_argument('--nanopore', action="store", type=str, dest='nanopore', nargs="+",
                        default=[], help='Nanopore input files.')
    parser.add_argument('--iontorrent', action="store", type=str, dest='iontorrent', nargs="+",
                        default=[], help='IonTorrent input files.')
    parser.add_argument("--masking_scheme", type=str, action="store", dest="masking_scheme",
                        help="Give a fasta file containing a motif"
                                         ' that is to be masked in the aligned concensus files.')
    parser.add_argument("--prune_distance", type=int, action="store", dest="prune_distance",
                        default=10, help="X length that SNPs can be located between each other."
                                         " Default is 10."
                                         " If two SNPs are located within X length of each other,"
                                         " everything between them as well as X length on each side"
                                         " of the SNPs will not be used in the alignments"
                                         " to calculate the distance matrix.")
    parser.add_argument("--db", action="store", type=str, default="", dest="database",
                        help="Comeplete path to a KMA indexed reference database of whole genomes.")
    parser.add_argument("--reference", action="store", type=str, dest="reference",
                        help="To align your query sequences against a reference"
                             " of your own choice, use this argument.")
    parser.add_argument("--cluster_length", type=int, action="store", dest="cluster_length",
                        default=-1, help="Maximum distance within the same cluster."
                                         " Default is -1, thus not estimating any clusters."
                                         " Set to positive integer to generate a cluster file.")
    parser.add_argument("--output", action="store", dest="output",
                        help="Output directory name.")
    parser.add_argument("-insig_prune", action="store_true", dest="insig_prune", default=False,
                        help="By default insignificant bases are included in the pruning process."
                             " Use this flag, if you wish to NOT include them in the pruning.")
    parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
    parser.add_argument("-p", action="store_true", dest="pairwise", default=False,
                        help="Pairwise distances are used to calculated distance matrix. Can be used for non-closely related isolates.")

    args = parser.parse_args()

    mintyperPipeline.mintyper_pipeline(args)


if __name__ == '__main__':
    main()
