Ejemplo n.º 1
0
    def initialize_classifier(self):
        filesnpaths.is_file_exists(self.classifier_object_path)

        try:
            if anvio.DEBUG:
                classifier_obj = pickle.load(
                    open(self.classifier_object_path, 'rb'))
            else:
                with terminal.SuppressAllOutput():
                    classifier_obj = pickle.load(
                        open(self.classifier_object_path, 'rb'))
        except UnicodeDecodeError:
            raise ConfigError(
                "Your classifier object is broken. Probably because you generated is using a different verison "
                "of anvi'o. Please create a new one from scratch, and you will probably be golden."
            )

        try:
            self.features = classifier_obj['features']
            self.classes = classifier_obj['classes']
            self.classifier = classifier_obj['classifier']
        except:
            raise ConfigError(
                "RF class does not like the classifier object it was sent for processing :/ Are you sure you "
                "generated it the way you were supposed to?")

        self.classifier_initialized = True

        self.run.info(
            'Random Forest Classifier',
            "Initialized with %d features grouped into %d classes." %
            (len(self.features), len(self.classes)))
Ejemplo n.º 2
0
import random
import itertools
from collections import Counter

import anvio
import anvio.db as db
import anvio.tables as t
import anvio.dbops as dbops
import anvio.utils as utils
import anvio.terminal as terminal
import anvio.filesnpaths as filesnpaths

from anvio.learning import RF
from anvio.errors import ConfigError, FilesNPathsError

with terminal.SuppressAllOutput():
    import anvio.data.hmm as hmm_data

__author__ = "Developers of anvi'o (see AUTHORS.txt)"
__copyright__ = "Copyleft 2015-2019, the Meren Lab (http://merenlab.org/)"
__credits__ = []
__license__ = "GPL 3.0"
__version__ = anvio.__version__
__maintainer__ = "A. Murat Eren"
__email__ = "*****@*****.**"
__status__ = "Development"


class SCGDomainClassifier(object):
    """The base class for training and predicting"""
    def __init__(self, args, run=terminal.Run(), progress=terminal.Progress()):