Skip to content

Commit

Permalink
Merge pull request #37 from biolink/biolink-issue-48
Browse files Browse the repository at this point in the history
Added configurability of remove services
  • Loading branch information
cmungall committed May 31, 2017
2 parents dd3c751 + 78b2d5a commit cc23ee1
Show file tree
Hide file tree
Showing 16 changed files with 365 additions and 144 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ subpackage_tests: $(patsubst %,test-%,$(PACKAGES))
test:
pytest tests/*.py

debug_test:
pytest -s -vvvv tests/*.py

t-%:
pytest tests/test_$*.py

foo:
which pytest

# only run local tests
travis_test:
pytest tests/test_*local*.py tests/test_*parser*.py
Expand All @@ -25,5 +34,5 @@ release: cleandist
nb:
PYTHONPATH=.. jupyter notebook

foo:
mm:
./bin/flask2marshmallow.pl ../biolink-api/biolink/datamodel/serializers.py
28 changes: 21 additions & 7 deletions bin/ontobio-assoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@
Examples:
```
ogr-assoc -v -r go -T NCBITaxon:9606 -C gene function enrichment -q GO:1903010
ontobio-assoc.py -v -r go -T NCBITaxon:9606 -C gene function query -q GO:1903010
ogr-assoc -v -r go -T NCBITaxon:10090 -C gene function dendrogram GO:0003700 GO:0005215 GO:0005634 GO:0005737 GO:0005739 GO:0005694 GO:0005730 GO:0000228 GO:0000262
Query planteome:
ogr-assoc -v -r go -T NCBITaxon:10090 -C gene function simmatrix MGI:1890081 MGI:97487 MGI:106593 MGI:97250 MGI:2151057 MGI:1347473
ontobio-assoc.py -v -y conf/planteome-config.yaml -r po -T NCBITaxon:3702 -C gene anatomy query -q PO:0025034
ogr-assoc -C gene function -T pombe -r go -f tests/resources/truncated-pombase.gaf query -q GO:0005622
ontobio-assoc.py -v -r go -T NCBITaxon:9606 -C gene function enrichment -q GO:1903010
ontobio-assoc.py -v -r go -T NCBITaxon:10090 -C gene function dendrogram GO:0003700 GO:0005215 GO:0005634 GO:0005737 GO:0005739 GO:0005694 GO:0005730 GO:0000228 GO:0000262
ontobio-assoc.py -v -r go -T NCBITaxon:10090 -C gene function simmatrix MGI:1890081 MGI:97487 MGI:106593 MGI:97250 MGI:2151057 MGI:1347473
ontobio-assoc.py -C gene function -T pombe -r go -f tests/resources/truncated-pombase.gaf query -q GO:0005622
# requires files from ftp://ftp.rgd.mcw.edu/pub/ontology/annotated_rgd_objects_by_ontology
ogr-assoc -T . -C gene disease -r doid -f homo_genes_do phenolog -R pw -F homo_genes_pw > PAIRS.txt
ontobio-assoc.py -T . -C gene disease -r doid -f homo_genes_do phenolog -R pw -F homo_genes_pw > PAIRS.txt
```
"""
Expand Down Expand Up @@ -61,8 +67,8 @@ def main():
help='ECO class')
parser.add_argument('-p', '--properties', nargs='*', type=str, required=False,
help='Properties')
parser.add_argument('-s', '--search', type=str, default='', required=False,
help='Search type. p=partial, r=regex')
parser.add_argument('-y', '--yamlconfig', type=str, required=False,
help='Path to setup/configuration yaml file')
parser.add_argument('-S', '--slim', type=str, default='', required=False,
help='Slim type. m=minimal')
parser.add_argument('-c', '--container_properties', nargs='*', type=str, required=False,
Expand Down Expand Up @@ -136,6 +142,14 @@ def main():
if args.verbosity == 1:
logging.basicConfig(level=logging.INFO)
logging.info("Welcome!")

if args.yamlconfig is not None:
logging.info("Setting config from: {}".format(args.yamlconfig))
# note this sets a global:
# we would not do this outside the context of a standalone script
from ontobio.config import set_config
set_config(args.yamlconfig)


handle = args.resource

Expand Down
34 changes: 25 additions & 9 deletions conf/config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
solr_assocs_url: "https://solr.monarchinitiative.org/solr/golr"
amigo_solr_assocs_url: "http://golr.berkeleybop.org"
solr_search_url: "https://solr-dev.monarchinitiative.org/solr/search"
amigo_solr_search_url: "http://golr.berkeleybop.org"
sparql_url: "http://sparql.hegroup.org/sparql"
scigraph_ontology_url: "https://scigraph-ontology.monarchinitiative.org/scigraph/"
scigraph_data_url: "https://scigraph-ontology.monarchinitiative.org/scigraph/"
use_amigo_for: function
solr_assocs:
url: "https://solr.monarchinitiative.org/solr/golr"
timeout: 5
amigo_solr_assocs:
url: "http://golr.berkeleybop.org"
timeout: 4
solr_search:
url: "https://solr.monarchinitiative.org/solr/search"
timeout: 2
amigo_solr_search:
url: "http://golr.berkeleybop.org"
timeout: 2
sparql:
url: "http://sparql.hegroup.org/sparql"
timeout: 2
scigraph_ontology:
url: "https://scigraph-ontology.monarchinitiative.org/scigraph/"
timeout: 2
scigraph_data:
url: "https://scigraph-ontology.monarchinitiative.org/scigraph/"
timeout: 2
use_amigo_for:
- function
ontologies:
- id: magic1234
handle: ceph
handle: pato
pre_load: true

38 changes: 34 additions & 4 deletions conf/planteome-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
amigo_solr_assocs_url: http://browser.planteome.org/solr
amigo_solr_search_url: http://browser.planteome.org/solr
sparql_url: http://sparql.hegroup.org/sparql
use_amigo_for: *
solr_assocs:
url: "http://browser.planteome.org/solr"
timeout: 5
amigo_solr_assocs:
url: "http://browser.planteome.org/solr"
timeout: 8
solr_search:
url: "http://browser.planteome.org/solr"
timeout: 2
amigo_solr_search:
url: "http://browser.planteome.org/solr"
timeout: 2
sparql:
url: "http://sparql.hegroup.org/sparql"
timeout: 2
scigraph_ontology:
url: "https://scigraph-ontology.monarchinitiative.org/scigraph/"
timeout: 2
scigraph_data:
url: "https://scigraph-ontology.monarchinitiative.org/scigraph/"
timeout: 2
categories:
- id: anatomy
superclass: PO:0025131
- id: phenotype
superclass: TO:0000387
- id: environment
superclass: TO:0000387
default_solr_schema: amigo
ontologies:
- id: magic1234
handle: pato
pre_load: true

136 changes: 105 additions & 31 deletions ontobio/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,67 @@ class OntologyConfigSchema(Schema):
handle = fields.Str(description="ontology handle")
pre_load = fields.Bool(description="if true, load this ontology at startup")

class EndpointSchema(Schema):
"""
Configuration for a REST or RESTish endpoint
"""
url = fields.Url()
timeout = fields.Int()

@post_load
def make_object(self, data):
return Endpoint(**data)

class CategorySchema(Schema):
"""
Maps a category label to a root ontology class
"""
id = fields.Str()
superclass = fields.Str()

@post_load
def make_object(self, data):
return Category(**data)

class ConfigSchema(Schema):
"""
Marshmallow schema for configuration objects.
"""
sparql_url = fields.Url(description="SPARQL URL to use for ontology queries")
solr_url = fields.Url()
solr_search_url = fields.Url()
go_solr_url = fields.Url()
go_solr_search_url = fields.Url()
scigraph_ontology_url = fields.Url()
scigraph_data_url = fields.Url()
sparql = fields.Nested(EndpointSchema, description="SPARQL URL to use for ontology queries")
solr_assocs = fields.Nested(EndpointSchema)
solr_search = fields.Nested(EndpointSchema)
amigo_solr_assocs = fields.Nested(EndpointSchema)
amigo_solr_search = fields.Nested(EndpointSchema)
scigraph_ontology = fields.Nested(EndpointSchema)
scigraph_data = fields.Nested(EndpointSchema)
default_solr_schema = fields.Str()
ontologies = fields.List(fields.Nested(OntologyConfigSchema))
categories = fields.List(fields.Nested(CategorySchema))
use_amigo_for = fields.List(fields.Str(description="category to use amigo for"))

@post_load
def make_object(self, data):
logging.info("POST-LOAD: {}".format(data))
return Config(**data)

class Endpoint():
"""
RESTish endpoint
"""
def __init__(self,
url = None,
timeout = None):
self.url = url
self.timeout = timeout

class Category():
"""
Maps category to class
"""
def __init__(self,
id = None,
superclass = None):
self.id = id
self.superclass = superclass

class Config():
"""
Expand All @@ -36,26 +79,42 @@ class Config():
"""
def __init__(self,
solr_assocs_url = "https://solr.monarchinitiative.org/solr/golr",
amigo_solr_assocs_url = "http://golr.berkeleybop.org",
solr_search_url = "https://solr-dev.monarchinitiative.org/solr/search",
amigo_solr_search_url = "http://golr.berkeleybop.org",
sparql_url = "http://sparql.hegroup.org/sparql",
scigraph_ontology_url = None,
scigraph_data_url = None,
ontologies = {},
solr_assocs = None,
amigo_solr_assocs = None,
solr_search = None,
amigo_solr_search = None,
sparql = None,
scigraph_ontology = None,
scigraph_data = None,
ontologies = [],
categories = [],
default_solr_schema = None,
use_amigo_for = "function"):
self.solr_assocs_url = solr_assocs_url
self.amigo_solr_assocs_url = amigo_solr_assocs_url
self.solr_search_url = solr_assocs_url
self.amigo_solr_search_url = amigo_solr_assocs_url
self.sparql_url = sparql_url
self.scigraph_ontology_url = scigraph_ontology_url
self.scigraph_data_url = scigraph_data_url
self.solr_assocs = solr_assocs
self.amigo_solr_assocs = amigo_solr_assocs
self.solr_search = solr_search
self.amigo_solr_search = amigo_solr_search
self.sparql = sparql
self.scigraph_ontology = scigraph_ontology
self.scigraph_data = scigraph_data
self.ontologies = ontologies
self.categories = categories
self.default_solr_schema = default_solr_schema
self.use_amigo_for = use_amigo_for

def get_solr_search_url(use_amigo=False):
def endpoint_url(self, endpoint):
if endpoint is None:
return None
else:
return endpoint.url

def get_category_class(self, categ):
matches = [c.superclass for c in self.categories if c.id == categ]
if len(matches) > 0:
return matches[0]
return None

def get_solr_search_url(self, use_amigo=False):
"""
Return solr URL to be used for lexical entity searches
Expand All @@ -66,9 +125,9 @@ def get_solr_search_url(use_amigo=False):
use_amigo : bool
If true, get the URL for the GO/AmiGO instance of GOlr. This is typically used for category='function' queries
"""
url = self.solr_search_url
url = self.endpoint_url(self.solr_search)
if use_amigo:
url = self.amigo_solr_search_url
url = self.endpoint_url(self.amigo_solr_search)
return url

def get_solr_assocs_url(use_amigo=False):
Expand All @@ -80,17 +139,18 @@ def get_solr_assocs_url(use_amigo=False):
There are two possible schemas: Monarch and AmiGO. The AmiGO schema is used for
querying the GO and Planteome Golr instances
"""
url = self.solr_assocs_url
url = self.endpoint_url(self.solr_assocs)
if use_amigo:
url = self.amigo_solr_assocs_url
url = self.endpoint_url(self.amigo_solr_assocs)
return url

class Session():
"""
Configuration for current session
"""
default_config_path = 'conf/config.yaml'
config = None
def __init__(self):
self.default_config_path = 'conf/config.yaml'
self.config = None

"""
Current session
Expand All @@ -111,14 +171,28 @@ def get_config():
logging.info("Using pre-loaded object: {}".format(session.config))
return session.config

def set_config(path):
"""
Set configuration for current session.
"""
logging.info("LOADING FROM: {}".format(path))
session.config = load_config(path)
return session.config

def reset_config():
"""
Reset currrent session configuration
"""
session.config = None

def load_config(path):
f = open(path,'r')
obj = yaml.load(f)
schema = ConfigSchema()
config = schema.load(obj).data
errs = schema.validate(obj)
if len(errs) > 0:
logging.error("ERRS: {}".format(errs))
logging.error("CONFIG ERRS: {}".format(errs))
raise ValueError('Error loading '+path)
#config = Config()
return config

0 comments on commit cc23ee1

Please sign in to comment.