#!/usr/bin/env python3
# Copyright (c) 2014-2016 Genome Research Ltd.
#
# This file is part of IVA.
#
# IVA is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.

import sys
import argparse
import iva

parser = argparse.ArgumentParser(
    usage = '%(prog)s [options] <output directory>',
)

parser.add_argument('outdir', help='Name of output directory', metavar='Directory_name')
parser.add_argument('--add_to_ref', action=iva.common.abspathAction, help='Filename of Genbank IDs or GI numbers to be added to database. Format is: whitespace separated list of GI numbers on each line. One line defines one genome (e.g. flu is 8 segments, so put 8 GI numbers on one line for one flu reference)', metavar='Filename')
parser.add_argument('--skip_viruses', action='store_true', help='Do not run kraken-build --download-library viruses when building the database. If this option used, then --add_to_ref must also be used')
parser.add_argument('--threads', type=int, help='Number of threads to use [%(default)s]', metavar='INT', default=1)
parser.add_argument('--minimizer_len', type=int, help='Number to pass to kraken-build minimizer_len option [%(default)s]', default=13, metavar='INT')
parser.add_argument('--max_db_size', type=int, help='Number to pass to kraken-build max_db_size option [%(default)s]', default=3, metavar='INT')
parser.add_argument('--verbose', action='store_true', help='Be verbose')
parser.add_argument('--version', action='version', version=iva.common.version)
options = parser.parse_args()

iva.external_progs.write_prog_info('iva_qc_make_db', '-')

db = iva.kraken.Database(
    options.outdir,
    extra_refs_file=options.add_to_ref,
    threads=options.threads,
    minimizer_len=options.minimizer_len,
    max_db_size=options.max_db_size,
    verbose=options.verbose,
    skip_virus_download=options.skip_viruses
)

db.build()
