コード例 #1
0
ファイル: dbinfo.py プロジェクト: simatei/anvio
    def __init__(self, search_path='.', max_files_and_dirs_to_process=50000, run=Run(), progress=Progress()):
        self.run = run
        self.progress = progress

        self.search_path = search_path
        self.max_files_and_dirs_to_process = max_files_and_dirs_to_process

        self.anvio_dbs = {}

        for db_path, level in self.walk(depth=3):
            db_info = DBInfo(db_path, dont_raise=True)

            if db_info is not None:
                if db_info.db_type not in self.anvio_dbs:
                    self.anvio_dbs[db_info.db_type] = []

                # Add a cheeky `level` attribute to db_info for no other reason than to order dbs after the walk
                db_info.level = level
                self.anvio_dbs[db_info.db_type].append(db_info)

        # sort by level, so we know what is closest to the search_path root directory
        for db_type in self.anvio_dbs:
            self.anvio_dbs[db_type] = sorted(self.anvio_dbs[db_type], key=lambda d: d.level)

        self.anvio_dbs_found = True
コード例 #2
0
ファイル: filesnpaths.py プロジェクト: fauziharoon/anvio
def gen_output_directory(output_directory,
                         progress=Progress(verbose=False),
                         run=Run(),
                         delete_if_exists=False):
    if os.path.exists(output_directory) and delete_if_exists:
        try:
            run.warning(
                'filesnpaths::gen_output_directory: the client asked the existing directory \
                         "%s" to be removed.. Just so you know :/ (You have 5 seconds to press\
                         CTRL + C).' % output_directory)
            time.sleep(5)
            shutil.rmtree(output_directory)
        except:
            progress.end()
            raise FilesNPathsError, "I was instructed to remove this directory, but I failed: '%s' :/" % output_directory

    if not os.path.exists(output_directory):
        try:
            os.makedirs(output_directory)
        except:
            progress.end()
            raise FilesNPathsError, "Output directory does not exist (attempt to create one failed as well): '%s'" % \
                                                            (output_directory)
    if not os.access(output_directory, os.W_OK):
        progress.end()
        raise FilesNPathsError, "You do not have write permission for the output directory: '%s'" % output_directory

    return output_directory
コード例 #3
0
    def __init__(self, from_address='admin@localhost', server_address='localhost', server_port=25,
                 init_tls=False, username = None, password = None, run = Run(verbose = False),
                 progress = Progress(verbose=False)):
        self.from_address = from_address
        self.server_address = server_address
        self.server_port = server_port
        self.init_tls = init_tls
        self.username = username
        self.password = password

        self.server = None
        self.config_ini_path = None

        self.run = run
        self.progress = progress

        self.config_template = {
                'SMTP': {
                        'from_address'   : {'mandatory': True, 'test': lambda x: str(x)},
                        'server_address' : {'mandatory': True, 'test': lambda x: str(x)},
                        'server_port'    : {'mandatory': True, 'test': lambda x: RepresentsInt(x) and int(x) > 0, 'required': 'an integer'},
                        'init_tls'       : {'mandatory': True, 'test': lambda x: x in ['True', 'False'], 'required': 'True or False'},
                        'username'       : {'mandatory': True, 'test': lambda x: str(x)},
                        'password'       : {'mandatory': True, 'test': lambda x: str(x)},
                    },
            }
コード例 #4
0
ファイル: filesnpaths.py プロジェクト: semiller10/anvio
def gen_output_directory(output_directory, progress=Progress(verbose=False), run=Run(), delete_if_exists=False, dont_warn=False):
    if not output_directory:
        raise FilesNPathsError("Someone called `gen_output_directory` function without an output\
                                directory name :( An embarrassing moment for everyone involved.")

    if os.path.exists(output_directory) and delete_if_exists and not is_dir_empty(output_directory):
        try:
            if not dont_warn:
                run.warning('The existing directory "%s" is about to be removed... (You have \
                             20 seconds to press CTRL + C). [filesnpaths::gen_output_directory]' % output_directory,
                             header = '!!! READ THIS NOW !!!')
                time.sleep(20)
            shutil.rmtree(output_directory)
        except:
            progress.end()
            raise FilesNPathsError("I was instructed to remove this directory, but I failed: '%s' :/" % output_directory)

    if not os.path.exists(output_directory):
        try:
            os.makedirs(output_directory)
        except:
            progress.end()
            raise FilesNPathsError("Output directory does not exist (attempt to create one failed as well): '%s'" % \
                                                            (output_directory))
    if not os.access(output_directory, os.W_OK):
        progress.end()
        raise FilesNPathsError("You do not have write permission for the output directory: '%s'" % output_directory)

    return output_directory
コード例 #5
0
ファイル: __init__.py プロジェクト: paczian/anvio
def K(param_id, params_dict={}):
    kwargs = copy.deepcopy(D[param_id][1])
    for key in params_dict:
        kwargs[key] = params_dict[key]

    return kwargs


# The rest of this file is composed of code that responds to '-v' or '--version' calls from clients,
# and provides access to the database version numbers for all anvi'o modules.

import anvio.tables as t
from anvio.terminal import Run

run = Run()


def set_version():
    try:
        __version__ = pkg_resources.require("anvio")[0].version
    except:
        # maybe it is not installed but being run from the codebase dir?
        try:
            __version__ = open(
                os.path.normpath(os.path.dirname(os.path.abspath(__file__))) +
                '/../VERSION').read().strip()
        except:
            __version__ = 'unknown'

    return __version__, t.contigs_db_version, t.profile_db_version, t.samples_info_db_version, t.auxiliary_hdf5_db_version
コード例 #6
0
#!/usr/bin/env python
# -*- coding: utf-8

import time

from anvio.columnprofile import ColumnProfile as ColumnProfile_in_C
from anvio.variability import ColumnProfile as ColumnProfile_in_Python

# setup the test factory:
from anvio.variability import VariablityTestFactory
variability_test_class = VariablityTestFactory()

# pretty output
from anvio.summaryhtml import pretty
from anvio.terminal import Run
run = Run(width=55)

# available profiles dict:
ColumnProfile = {'Python': ColumnProfile_in_Python, 'C': ColumnProfile_in_C}


# test function:
def test(column,
         consensus='A',
         quiet=False,
         test_class=variability_test_class):
    coverage = len(column)

    results = {}

    if not quiet: