Exemple #1
0
    def set_ontology(self,
                     ontology_type: DataType,
                     ontology: Ontology,
                     config: GenedescConfigParser,
                     slim_cache_path: str = None) -> None:
        """set the go ontology and apply terms renaming

        Args:
            ontology_type (DataType): the type of ontology to set
            ontology (Ontology): an ontology object to set as go ontology
            config (GenedescConfigParser): configuration object where to read properties
            slim_cache_path (str): path to slim file to use
        """
        if ontology_type == DataType.GO:
            logger.info("Setting GO ontology")
            if self.go_relations:
                self.go_ontology = ontology.subontology(
                    relations=self.go_relations)
            else:
                self.go_ontology = ontology
        elif ontology_type == DataType.DO:
            logger.info("Setting DO ontology")
            if self.do_relations:
                self.do_ontology = ontology.subontology(
                    relations=self.do_relations)
            else:
                self.do_ontology = ontology
        elif ontology_type == DataType.EXPR:
            logger.info("Setting Expression ontology")
            if self.expr_relations:
                self.expression_ontology = ontology.subontology(
                    relations=self.expr_relations)
            else:
                self.expression_ontology = ontology
        module = get_module_from_data_type(ontology_type)
        ontology = self.get_ontology(data_type=ontology_type)
        terms_replacement_regex = config.get_module_property(
            module=module, prop=ConfigModuleProperty.RENAME_TERMS)
        if terms_replacement_regex:
            self.rename_ontology_terms(
                ontology=ontology,
                terms_replacement_regex=terms_replacement_regex)
        set_all_depths(ontology=ontology,
                       relations=self.get_relations(ontology_type))
        if config.get_module_property(
                module=module,
                prop=ConfigModuleProperty.TRIMMING_ALGORITHM) == "ic":
            set_ic_ontology_struct(ontology=ontology,
                                   relations=self.get_relations(ontology_type))
        if slim_cache_path:
            slim_url = config.get_module_property(
                module=module, prop=ConfigModuleProperty.SLIM_URL)
            self.load_slim(module=module,
                           slim_url=slim_url,
                           slim_cache_path=slim_cache_path)
Exemple #2
0
    def set_ontology(self,
                     ontology_type: DataType,
                     ontology: Ontology,
                     terms_replacement_regex: Dict[str, str] = None) -> None:
        """set the go ontology and apply terms renaming

        Args:
            ontology_type (DataType): the type of ontology to set
            ontology (Ontology): an ontology object to set as go ontology
            terms_replacement_regex (Dict[str, str]): a dictionary containing the regular expression to be applied for
                renaming terms. Each key must be a regular expression to search for terms and the associated value
                another regular expression that defines the final result
        """
        new_ontology = None
        if ontology_type == DataType.GO:
            logger.info("Setting GO ontology")
            self.go_ontology = ontology.subontology(
                relations=self.go_relations)
            new_ontology = self.go_ontology
        elif ontology_type == DataType.DO:
            logger.info("Setting DO ontology")
            self.do_ontology = ontology.subontology(
                relations=self.do_relations)
            new_ontology = self.do_ontology
        elif ontology_type == DataType.EXPR:
            logger.info("Setting Expression ontology")
            self.expression_ontology = ontology.subontology()
            DataManager.add_article_to_expression_nodes(
                self.expression_ontology)
            new_ontology = self.expression_ontology
        self.rename_ontology_terms(
            ontology=new_ontology,
            terms_replacement_regex=terms_replacement_regex)
        for root_id in new_ontology.get_roots():
            set_all_depths_in_subgraph(ontology=new_ontology,
                                       root_id=root_id,
                                       relations=None)