#!/usr/bin/python3
"""Update existing gnomonicus tables with a new catalogue."""

import argparse
import piezo
import pandas
import grumpy

from gnomonicus import populateEffects


def main():
    # Argparser setup
    parser = argparse.ArgumentParser(
        description="Parse an existing mutations.csv and a catalogue to produce effects.csv and predictions.csv"
    )
    parser.add_argument(
        "--mutations", required=True, help="Path to the existing mutations table"
    )
    parser.add_argument(
        "--genome_object",
        required=True,
        help="Path to a genbank file",
    )
    parser.add_argument(
        "--catalogue_file",
        default=None,
        required=False,
        help="Path to the resistance catalogue",
    )
    parser.add_argument("--output", default=".", help="Output path")
    parser.add_argument(
        "--progress", action="store_true", default=False, help="Show progress bar"
    )
    options = parser.parse_args()

    mutations = pandas.read_csv(options.mutations)
    resistanceCatalogue = piezo.ResistanceCatalogue(options.catalogue_file)

    # Pull out original VCF stem from mutations filename
    vcf_stem = options.mutations.split("/")[-1].replace(".mutations.csv", "")

    populateEffects(
        options.output,
        resistanceCatalogue,
        mutations,
        vcf_stem,
        True,
        True,
        grumpy.Genome(options.genome_object),
        append=True,
    )


if __name__ == "__main__":
    main()
