Ejemplo n.º 1
0
def cli(genome, database, **kwargs):
    """Add a strain GENOME to the wgMLST DATABASE."""

    try:

        with pymlst.open_wg(os.path.abspath(database)) as mlst:
            mlst.add_strain(genome, **utils.clean_kwargs(kwargs))

    except exceptions.PyMLSTError as err:
        raise click.ClickException(str(err))
Ejemplo n.º 2
0
def cli(fastqs, database, **kwargs):
    """Add a strain from FASTQS(.gz) reads to the wgMLST DATABASE."""

    try:

        with pymlst.open_wg(os.path.abspath(database)) as mlst:
            mlst.add_reads(fastqs, **utils.clean_kwargs(kwargs))

    except exceptions.PyMLSTError as err:
        raise click.ClickException(str(err))
Ejemplo n.º 3
0
def cli(database, **kwargs):
    """Extract an strains list from a wgMLST DATABASE."""

    tab_kwargs,out_kwargs = utils.get_output(utils.clean_kwargs(kwargs))

    try:

        with pymlst.open_wg(os.path.abspath(database)) as mlst:
            mlst.extract(StrainExtractor(**tab_kwargs), **out_kwargs)

    except exceptions.PyMLSTError as err:
        raise click.ClickException(str(err))
Ejemplo n.º 4
0
def cli(database, **kwargs):
    """Compute Multiple Sequence Alignment from a wgMLST DATABASE."""

    seq_kwargs, out_kwargs = utils.get_output(utils.clean_kwargs(kwargs))

    try:

        with pymlst.open_wg(os.path.abspath(database)) as mlst:
            mlst.extract(MsaExtractor(**seq_kwargs), **out_kwargs)

    except exceptions.PyMLSTError as err:
        raise click.ClickException(str(err))
Ejemplo n.º 5
0
def cli(force, prompt, database, species):
    """Create a wgMLST DATABASE from an online resource.

    The research can be filtered by adding a SPECIES name."""

    utils.create_logger()

    try:

        if os.path.exists(database):
            if force:
                open(database, "w").close()
            else:
                raise exceptions.PyMLSTError(
                    "Database alreadly exists, use --force to override it")

        url = web.retrieve_cgmlst(' '.join(species), prompt)

        if url is None:
            logging.info('No choice selected')
            return

        logging.info('Downloading the core genome...')

        with tempfile.NamedTemporaryFile('w+', delete=False) as tmp:

            skipped = web.get_cgmlst_file(url, tmp)
            tmp.close()
            if len(skipped) > 0:
                logging.info('Skipped the following malformed file(s): %s',
                             ', '.join(skipped))

            with pymlst.open_wg(os.path.abspath(database)) as mlst:
                mlst.create(tmp.name)

    except requests.exceptions.HTTPError:
        raise click.ClickException('Could not retrieve online data')
    except requests.exceptions.ConnectionError:
        raise click.ClickException(
            'Could not access to the server, please verify your internet connection'
        )
    except requests.exceptions.Timeout:
        raise click.ClickException('The server took too long to respond')
    except web.StructureError:
        raise click.ClickException(
            'It seems like the structure of the website/API changed '
            'since this application was developed.')
    except exceptions.PyMLSTError as err:
        raise click.ClickException(str(err))
Ejemplo n.º 6
0
def cli(database, strains, genes_or_strains, **kwargs):
    """Remove STRAINS or GENES from a wgMLST DATABASE."""

    utils.create_logger()

    try:
        with pymlst.open_wg(os.path.abspath(database)) as mlst:
            if strains:
                logging.info("We will remove one or more strain(s)")
                mlst.remove_strain(genes_or_strains, **utils.clean_kwargs(kwargs))
       
            else :
                logging.info("We will remove one or more gene(s)")
                mlst.remove_gene(genes_or_strains, **utils.clean_kwargs(kwargs))

    except exceptions.PyMLSTError as err:
        raise click.ClickException(str(err))
Ejemplo n.º 7
0
def cli(database, force, **kwargs):
    """Create a wgMLST DATABASE from a template COREGENE."""

    try:

        if os.path.exists(database):
            if force:
                open(database, "w").close()
            else:
                raise exceptions.PyMLSTError(
                    "Database alreadly exists, use --force to override it")

        with pymlst.open_wg(os.path.abspath(database)) as mlst:
            mlst.create(**utils.clean_kwargs(kwargs))

    except exceptions.DuplicatedGeneSequence as err:
        raise click.UsageError('{}, use -c or -r options to manage it'.format(
            str(err)))
    except exceptions.PyMLSTError as err:
        raise click.UsageError(str(err))
Ejemplo n.º 8
0
def wg():
    with pymlst.open_wg() as wg_mlst:
        yield wg_mlst