示例#1
0
文件: core.py 项目: bvalot/pyMLST
 def __init__(self, file, ref):
     """
     :param file: The path to the database file to work with.
     :param ref: The name that will be given to the reference strain in the database.
     """
     self.__database = DatabaseCLA(file, ref)
     self.__file = file
     create_logger()
示例#2
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))
示例#3
0
文件: import.py 项目: bvalot/pyMLST
def cli(force, prompt, mlst, database, species):
    """Create a claMLST 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_mlst(' '.join(species), prompt, mlst)

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

        logging.info('Downloading mlst...')

        with tempfile.TemporaryDirectory() as tmp_dir, \
                pymlst.open_cla(os.path.abspath(database)) as mlst_db:

            web.get_mlst_files(url, tmp_dir)

            mlst_db.create(open(tmp_dir + '/profiles.csv', 'rt'), [
                open(tmp_dir + '/locus/' + locus, 'r')
                for locus in os.listdir(tmp_dir + '/locus')
            ])

    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))
示例#4
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))