#!/usb/bin/env python

# ----------------------------------------------------------------------------
# Copyright (c) 2017-, Jose Antonio Navas Molina.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

import click

from biom import load_table

from cmirr.export_taxonomy import taxonomy_exporter


@click.group()
def cmirr():
    pass


@cmirr.command(name='export-taxonomy')
@click.option('--input-biom', required=True,
              type=click.Path(exists=True, dir_okay=False, readable=True,
                              resolve_path=True),
              help='Input biom table to export the taxonomy from')
@click.option('--output-taxa', required=True,
              type=click.Path(exists=False, dir_okay=False, writable=True,
                              resolve_path=True),
              help='Output taxonomy file')
def export_taxonomy(input_biom, output_taxa):
    biom_table = load_table(input_biom)
    with open(output_taxa, 'w') as f:
        f.write("Feature ID\tTaxon\n")
        for line in taxonomy_exporter(biom_table):
            f.write(line)


if __name__ == '__main__':
    cmirr()
