def test_cfg(): logging.info("TEST") cfg = get_config() logging.info("GOT: {}".format(cfg)) print(str(cfg)) assert True #cfg = get_config() print("Main solr search: {}".format(_endpoint(cfg.solr_search))) print("Main solr assocs: {}".format(_endpoint(cfg.solr_assocs))) print("Pre-loaded ontologies: {}".format(cfg.ontologies)) set_config('tests/resources/test-config.yaml') cfg = get_config() # reset reset_config() assert cfg.solr_assocs.url == "https://example.org" assert cfg.get_category_class('anatomy') == 'PO:0025131' assert cfg.ontologies[0].id == "magic1234" assert cfg.ontologies[0].handle == "pato" assert cfg.ontologies[0].pre_load == True
def __init__(self, url: Optional[str]=None, timeout: Optional[int]=None): self.url = url if url is not None else get_config().owlsim2.url self.timeout = timeout if timeout is not None else get_config().owlsim2.timeout # Init ic stats stats = get_owlsim_stats(self.url) self._statistics = stats[0] self._category_statistics = stats[1]
def get_curie_map(url=None): """ Get CURIE prefix map from SciGraph cypher/curies endpoint """ if url is None: url = '{}/cypher/curies'.format(get_config().scigraph_data.url) response = requests.get(url) if response.status_code == 200: curie_map = response.json() else: curie_map = {} return curie_map
def __init__(self, handle=None, url=None, config=None): """ Constructor - typically you do not need to call this directly. Specify a scigraph handle in ontol_factory, e.g. `` OntologyFactory().create('scigraph:data') `` The Session instance will be consulted to determine the URL The handle can be - `scigraph:ontology` use scigraph_ontology from config - `scigraph:data` use scigraph_data from config - `scigraph:` use default """ if handle is not None: handle = handle.replace("scigraph:", "") else: handle = "ontology" logger.info("Connecting: {} {}".format(handle, url)) if url is None: if config is None: from ontobio.config import get_config config = get_config() if config is not None: logger.info( "Fetching scigraph URL from config: {}".format(handle)) urlObj = config.scigraph_ontology if handle == 'data': logger.info("Using scigraph_data URL") urlObj = config.scigraph_data if urlObj is not None: url = urlObj.url logger.info("Set URL from config={} {}".format( url, urlObj)) if url is None: url = 'https://scigraph-ontology.monarchinitiative.org/scigraph' self.url = url logger.info("Base SciGraph URL: {}".format(url)) return
def get_config(self): if self.config is None: from ontobio.config import Config, get_config self.config = get_config() return self.config
from ontobio.vocabulary.similarity import SimAlgorithm from ontobio.util.scigraph_util import get_nodes_from_ids, get_id_type_map, get_taxon from typing import List, Optional, Dict, Tuple, Union, FrozenSet from json.decoder import JSONDecodeError from diskcache import Cache import tempfile import logging import requests """ Functions that directly access the owlsim rest API were kept outside the class to utilize caching TODO: test if this is still the case with diskcache """ TIMEOUT = get_config().owlsim2.timeout cache = Cache(tempfile.gettempdir()) logger = logging.getLogger(__name__) @cache.memoize() def search_by_attribute_set(url: str, profile: FrozenSet[str], limit: Optional[int] = 100, namespace_filter: Optional[str] = None) -> Dict: """ Given a list of phenotypes, returns a ranked list of individuals individuals can be filtered by namespace, eg MONDO, MGI, HGNC :returns Dict with the structure: { 'unresolved' : [...]
def __init__(self, url: Optional[str] = None, timeout: Optional[int] = None): self.url = url if url is not None else get_config().owlsim3.url self.timeout = timeout if timeout is not None else get_config( ).owlsim3.timeout
import logging from ontobio.ontol_factory import OntologyFactory from ontobio.config import get_config cfg = get_config() omap = {} def get_ontology(id): handle = id print("HANDLE={}".format(handle)) for c in cfg.ontologies: print("ONT={}".format(c)) # temporary. TODO fix if not isinstance(c, dict): if c.id == id: handle = c.handle print("Using handle={} for {}".format(handle, id)) if handle not in omap: print("Creating a new ontology object for {}".format(handle)) omap[handle] = OntologyFactory().create(handle) else: print("Using cached for {}".format(handle)) return omap[handle]
from html3.html3 import XHTML ############################################################# # First, before loading all our analysis modules, we need # to tweak OntoBio to disable its @cachier cache. Our # patched Ontobio has an 'ignore_cache' flag which may be # overridden here before the rest of the system is loaded. # We do this because cachier seems to introduce an odd system # instability resulting in deep recursion on one method, # creating new threads and consuming stack memory to the point # of system resource exhaustion! We conjecture that cachier # caching is unnecessary since we read the pertinent ontology # catalogs in just once into memory, for readonly reuse. ############################################################## from ontobio.config import get_config get_config().ignore_cache = True # Now we can import the remainder of the modules (some which call Ontobio) from translator_modules.module0.module0 import DiseaseAssociatedGeneSet from translator_modules.module1.module1a import FunctionalSimilarity from translator_modules.module1.module1b import PhenotypeSimilarity from translator_modules.module1.module1e import GeneInteractions from translator_modules.util.standard_output import StandardOutput _SCRIPTNAME = 'WF2_automation.py' # Flag to control console output _echo_to_console = False # Data type of switch input is interpreted as a Boolean value
def __init__(self, url=None): if url is not None: self.url_prefix = url else: self.url_prefix = get_config()['scigraph_data']['url']