コード例 #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
    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)},
                    },
            }
コード例 #3
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
コード例 #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
ファイル: contigops.py プロジェクト: farukuzun/anvio
# -*- coding: utf-8
"""Classes and functions for handling, storing, and retrieving atomic data from contigs and splits"""

import anvio

from anvio.sequence import Coverage
from anvio.terminal import Run, Progress
from anvio.terminal import pretty_print as pp
from anvio.variability import VariablityTestFactory

import anvio.tables as t

run = Run()
progress = Progress()
progress.verbose = False

try:
    from anvio.columnprofile import ColumnProfile
except ImportError:
    run.info_single('C extension for ColumnProfile failed to load, falling back to the Python implementation...', mc = 'gray', nl_after = 1)
    from anvio.variability import ColumnProfile


__author__ = "A. Murat Eren"
__copyright__ = "Copyright 2015, The anvio Project"
__credits__ = ["Faruk Uzun"]
__license__ = "GPL 3.0"
__version__ = anvio.__version__
__maintainer__ = "A. Murat Eren"
__email__ = "*****@*****.**"
__status__ = "Development"
コード例 #7
0
ファイル: contigops.py プロジェクト: banfieldlab/anvio
# -*- coding: utf-8
"""Classes and functions for handling, storing, and retrieving atomic data from contigs and splits"""

import anvio

from anvio.sequence import Coverage
from anvio.terminal import Run, Progress
from anvio.terminal import pretty_print as pp
from anvio.variability import VariablityTestFactory

import anvio.tables as t

run = Run()
progress = Progress()
progress.verbose = False

try:
    from anvio.columnprofile import ColumnProfile
except ImportError:
    run.info_single(
        'C extension for ColumnProfile failed to load, falling back to the Python implementation...',
        mc='gray',
        nl_after=1)
    from anvio.variability import ColumnProfile

__author__ = "A. Murat Eren"
__copyright__ = "Copyright 2015, The anvio Project"
__credits__ = ["Faruk Uzun"]
__license__ = "GPL 3.0"
__version__ = anvio.__version__
__maintainer__ = "A. Murat Eren"
コード例 #8
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:
コード例 #9
0
__author__ = "A. Murat Eren"
__copyright__ = "Copyright 2015, The anvio Project"
__credits__ = []
__license__ = "GPL 3.0"
__version__ = anvio.__version__
__maintainer__ = "A. Murat Eren"
__email__ = "*****@*****.**"
__status__ = "Development"


# Mock progress object that will not report anything, for general clarity.
progress = Progress()
progress.verbose = False

run = Run()
run.verbose = False

def rev_comp(seq):
    return seq.translate(complements)[::-1]


class Multiprocessing:
    def __init__(self, target_function, num_thread = None):
        self.cpu_count = multiprocessing.cpu_count()
        self.num_thread = num_thread or (self.cpu_count - (int(round(self.cpu_count / 10.0)) or 1))
        self.target_function = target_function
        self.processes = []
        self.manager = multiprocessing.Manager()

コード例 #10
0
ファイル: utils.py プロジェクト: farukuzun/anvio
__author__ = "A. Murat Eren"
__copyright__ = "Copyright 2015, The anvio Project"
__credits__ = []
__license__ = "GPL 3.0"
__version__ = anvio.__version__
__maintainer__ = "A. Murat Eren"
__email__ = "*****@*****.**"
__status__ = "Development"


# Mock progress object that will not report anything, for general clarity.
progress = Progress()
progress.verbose = False

run = Run()
run.verbose = False


def rev_comp(seq):
    return seq.translate(complements)[::-1]


class Multiprocessing:
    def __init__(self, target_function, num_thread=None):
        self.cpu_count = multiprocessing.cpu_count()
        self.num_thread = num_thread or (self.cpu_count - (int(round(self.cpu_count / 10.0)) or 1))
        self.target_function = target_function
        self.processes = []
        self.manager = multiprocessing.Manager()
コード例 #11
0
ファイル: contig.py プロジェクト: caglar10ur/anvio
# -*- coding: utf-8
"""Classes for handling contigs and splits"""

import anvio

from anvio.terminal import Run
from anvio.variability import VariablityTestFactory
from anvio.sequence import Coverage

run = Run()

try:
    from anvio.columnprofile import ColumnProfile
except ImportError:
    run.info_single(
        "C extension for ColumnProfile failed to load, falling back to the Python implementation...",
        mc="gray",
        nl_after=1,
    )
    from anvio.variability import ColumnProfile


__author__ = "A. Murat Eren"
__copyright__ = "Copyright 2015, The anvio Project"
__credits__ = ["Faruk Uzun"]
__license__ = "GPL 3.0"
__version__ = anvio.__version__
__maintainer__ = "A. Murat Eren"
__email__ = "*****@*****.**"
__status__ = "Development"