Exemplo n.º 1
0
 def process(self):
     """
     Subsample the data set to include only those languages and features
     which are compatible with the settings.
     """
     self.apply_language_filter()
     self.compute_feature_properties()
     self.remove_unwanted_features()
     self.load_rate_partition()
     if self.rate_partition:
         self.all_rates = sorted(list(set(self.rate_partition.values())))
     elif self.rate_variation or self.feature_rates:
         self.all_rates = self.features
     self.load_feature_rates()
     if self.rate_partition and not (self.feature_rates
                                     or self.rate_variation):
         log.warning(
             "Estimating rates for feature partitions because no fixed rates "
             "were provided, is this what you wanted?  Use rate_variation=True to make "
             "this implicit.",
             model=self)
         self.rate_variation = True
     self.compute_weights()
     if self.pruned:
         log.dependency("Pruned trees", "BEASTlabs", model=self)
Exemplo n.º 2
0
def test_dependency_only_logged_once(caplog):
    with caplog.at_level(logging.INFO, logger=beastling.__name__):
        log._dependencies = set()
        log.dependency('f', 'p')
        assert len(caplog.records) == 1
        log.dependency('f', 'p')
        assert len(caplog.records) == 1
Exemplo n.º 3
0
 def get_model(self, global_config):
     for cls in all_subclasses(BaseModel):
         if cls.__model_name__() == self.model:
             if cls.package_notice:
                 log.dependency(*cls.package_notice)
             return cls(self, global_config)
     try:
         module_path, class_name = self.model.rsplit(".", 1)
         cls = getattr(importlib.import_module(module_path), class_name)
         return cls(self, global_config)
     except:
         raise ValueError(
             "Unknown model type '%s' for model section '%s', and failed to import a "
             "third-party model." % (self.model, self.name))
Exemplo n.º 4
0
    def process(self):
        """
        Prepares a Configuration object for being passed to the BeastXml

        constructor.

        This method checks the values of all options for invalid or ambiguous
        settings, internal consistency, etc.  Information is read from
        external files as required.  If this method returns without raising
        any exceptions then this should function as a guarantee that a
        BeastXml object can be instantiated from this Configuration with no
        problems.
        """
        if self.processed:
            log.warning('Configuration has already been processed')
            return

        # Add dependency notices if required
        if self.languages.monophyly and not self.languages.starting_tree:
            log.dependency("ConstrainedRandomTree", "BEASTLabs")
        if self.mcmc.path_sampling:
            log.dependency("Path sampling", "MODEL_SELECTION")

        self.load_glottolog_data()
        self.load_user_geo()
        self.instantiate_models()
        self.build_language_filter()
        self.process_models()
        self.build_language_list()
        self.define_language_groups()
        self.handle_monophyly()
        self.instantiate_calibrations()
        # At this point, we can tell whether or not the tree's length units
        # can be treated as arbitrary
        self.arbitrary_tree = self.languages.sample_branch_lengths and not self.calibrations

        # We also know what kind of tree prior we need to have –
        # instantiate_calibrations may have changed the type if tip
        # calibrations exist.
        self.treeprior = {
            "uniform": treepriors.UniformTree,
            "yule": treepriors.YuleTree,
            "birthdeath": treepriors.BirthDeathTree,
            "coalescent": CoalescentTree
        }[self.languages.tree_prior]()

        # Now we can set the value of the ascertained attribute of each model
        # Ideally this would happen during process_models, but this is impossible
        # as set_ascertained() relies upon the value of arbitrary_tree defined above,
        # which itself depends on process_models().  Ugly...
        for m in self.models:
            m.set_ascertained()
        self.instantiate_clocks()
        self.link_clocks_to_models()
        self.processed = True

        # Decide whether or not to log trees
        if (self.languages.starting_tree and not self.languages.sample_topology
                and not self.languages.sample_branch_lengths
                and all([c.is_strict for c in self.clocks if c.is_used])):
            self.tree_logging_pointless = True
            log.info(
                "Tree logging disabled because starting tree is known and fixed and all clocks "
                "are strict.")
        else:
            self.tree_logging_pointless = False