Skip to content

Commit

Permalink
Merge pull request #97 from geneontology/issue-94-get-models-by-taxon
Browse files Browse the repository at this point in the history
refactor SPARQL to be faster and just return models by taxon id
  • Loading branch information
sierra-moxon authored Jun 18, 2024
2 parents 9411c34 + b8554bf commit ee56256
Show file tree
Hide file tree
Showing 30 changed files with 97 additions and 295 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pr-test-qc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ name: go-fastapi-QC

on:
pull_request:
branches:
- no_op
types: [opened, synchronize, reopened]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.9", "3.10" ]
python-version: [ "3.11", "3.12" ]

steps:
- uses: actions/[email protected]
Expand Down
1 change: 1 addition & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""main application entry point."""

import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
Expand Down
2 changes: 1 addition & 1 deletion app/middleware/logging_middleware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Middleware to log requests."""

import logging

from fastapi import Request
Expand All @@ -12,7 +13,6 @@


class LoggingMiddleware(BaseHTTPMiddleware):

"""Middleware to log requests."""

async def dispatch(self, request: Request, call_next):
Expand Down
2 changes: 1 addition & 1 deletion app/routers/bioentity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""bioentity router."""

import logging
from enum import Enum
from typing import List
Expand Down Expand Up @@ -29,7 +30,6 @@


class RelationshipType(str, Enum):

"""
Enumeration for Gene Ontology relationship types used for filtering associations.
Expand Down
1 change: 1 addition & 0 deletions app/routers/labeler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provides a route for fetching labels for CURIEs/IDs."""

import logging
from typing import List

Expand Down
33 changes: 14 additions & 19 deletions app/routers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,28 +621,23 @@ async def get_term_details_by_taxon_id(
final_taxon = final_taxon + new_taxon
query = (
"""
PREFIX metago: <http://model.geneontology.org/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX enabled_by: <http://purl.obolibrary.org/obo/RO_0002333>
PREFIX in_taxon: <http://purl.obolibrary.org/obo/RO_0002162>
PREFIX metago: <http://model.geneontology.org/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX enabled_by: <http://purl.obolibrary.org/obo/RO_0002333>
PREFIX in_taxon: <http://purl.obolibrary.org/obo/RO_0002162>
PREFIX pav: <http://purl.org/pav/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX biolink: <https://w3id.org/biolink/vocab/>
SELECT distinct ?gocam
SELECT ?gocam
WHERE
{
GRAPH ?gocam {
?gocam metago:graphType metago:noctuaCam .
?s enabled_by: ?gpnode .
?gpnode rdf:type ?identifier .
FILTER(?identifier != owl:NamedIndividual) .
}
?identifier rdfs:subClassOf ?v0 .
?identifier rdfs:label ?name .
WHERE
{
?gocam rdf:type owl:Ontology ;
biolink:in_taxon <%s> ;
?v0 owl:onProperty in_taxon: .
?v0 owl:someValuesFrom <%s>
}
}
"""
% final_taxon
)
Expand Down
2 changes: 1 addition & 1 deletion app/routers/ontology.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ontology-related endpoints."""

import json
import logging
from enum import Enum
Expand All @@ -22,7 +23,6 @@


class GraphType(str, Enum):

"""Enum for the different types of graphs that can be returned."""

topology_graph = "topology_graph"
Expand Down
1 change: 1 addition & 0 deletions app/routers/pathway_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pathway widget API endpoints."""

import logging

from curies import Converter
Expand Down
1 change: 1 addition & 0 deletions app/routers/prefixes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module contains the API endpoints for handling prefixes and expansions."""

import logging

from curies import Converter
Expand Down
2 changes: 1 addition & 1 deletion app/routers/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""search router."""

import logging
from enum import Enum

Expand All @@ -14,7 +15,6 @@


class AutocompleteCategory(str, Enum):

"""The category of items to retrieve, can be 'gene' or 'term'."""

gene = "gene"
Expand Down
2 changes: 1 addition & 1 deletion app/routers/slimmer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""slimmer router."""

import logging
from enum import Enum
from typing import List
Expand All @@ -20,7 +21,6 @@


class RelationshipType(str, Enum):

"""Relationship type for slimmer."""

acts_upstream_of_or_within = ACTS_UPSTREAM_OF_OR_WITHIN
Expand Down
17 changes: 2 additions & 15 deletions app/routers/users_and_groups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The users and groups endpoints."""

import logging

from fastapi import APIRouter, Path
Expand Down Expand Up @@ -77,9 +78,7 @@ async def get_user_by_orcid(
PREFIX MF: <http://purl.obolibrary.org/obo/GO_0003674>
PREFIX CC: <http://purl.obolibrary.org/obo/GO_0005575>
SELECT ?name (GROUP_CONCAT(distinct ?organization;separator="@|@") AS ?organizations)
(GROUP_CONCAT(distinct ?affiliationIRI;separator="@|@") AS ?affiliationsIRI)
(GROUP_CONCAT(distinct ?affiliation;separator="@|@") AS ?affiliations)
SELECT ?name
(GROUP_CONCAT(distinct ?gocam;separator="@|@") as ?gocams)
(GROUP_CONCAT(distinct ?date;separator="@|@") as ?gocamsDate)
(GROUP_CONCAT(distinct ?title;separator="@|@") as ?gocamsTitle)
Expand Down Expand Up @@ -126,15 +125,6 @@ async def get_user_by_orcid(
?goid rdfs:label ?goname .
# Getting some information on the contributor
optional { ?orcidIRI rdfs:label ?name } .
BIND(IF(bound(?name), ?name, ?orcid) as ?name) .
optional { ?orcidIRI vcard:organization-name ?organization } .
optional {
?orcidIRI has_affiliation: ?affiliationIRI .
?affiliationIRI rdfs:label ?affiliation
} .
# crash the query for SYNGO user "http://orcid.org/0000-0002-1190-4481"^^xsd:string
optional {
?gpid rdfs:label ?gpname .
Expand All @@ -150,9 +140,6 @@ async def get_user_by_orcid(
collated = {}
results = si._sparql_query(query)
for result in results:
collated["organizations"] = result["organizations"].get("value")
collated["affiliations"] = result["affiliations"].get("value")
collated["affiliationsIRI"] = result["affiliationsIRI"].get("value")
collated["gocams"] = result["gocams"].get("value")
collated["gocamsDate"] = result["gocamsDate"].get("value")
collated["gocamsTitle"] = result["gocamsTitle"].get("value")
Expand Down
1 change: 1 addition & 0 deletions app/utils/ontology_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""ontology utility functions."""

import logging

from linkml_runtime.utils.namespaces import Namespaces
Expand Down
1 change: 1 addition & 0 deletions app/utils/prefix_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""prefix utility functions."""

import logging

from curies import Converter
Expand Down
4 changes: 1 addition & 3 deletions app/utils/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""settings for the application."""

import logging
from enum import Enum
from os import path
Expand Down Expand Up @@ -41,21 +42,18 @@ def get_golr_config():


class ESOLR(Enum):

"""Enum for the GOLR URL."""

GOLR = get_golr_config()["solr_url"]["url"]


class ESPARQL(Enum):

"""Enum for the SPARQL endpoint URL."""

SPARQL = get_sparql_endpoint()


class ESOLRDoc(Enum):

"""Enum for the GOLR document type."""

ONTOLOGY = "ontology_class"
Expand Down
Loading

0 comments on commit ee56256

Please sign in to comment.