Skip to content

Commit

Permalink
misc commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wshayes committed Apr 9, 2021
1 parent 7f3d182 commit 61f874b
Show file tree
Hide file tree
Showing 33 changed files with 1,203 additions and 1,020 deletions.
Empty file removed api/app/__init__.py
Empty file.
69 changes: 0 additions & 69 deletions api/app/core/jwt.py

This file was deleted.

43 changes: 0 additions & 43 deletions api/app/core/middleware.py

This file was deleted.

43 changes: 0 additions & 43 deletions api/app/gunicorn_conf.py

This file was deleted.

135 changes: 0 additions & 135 deletions api/app/main.py

This file was deleted.

35 changes: 33 additions & 2 deletions bel/api/endpoints/bel.py
Expand Up @@ -5,14 +5,14 @@

# Third Party
import fastapi
from fastapi import APIRouter, Depends, Query
from fastapi import APIRouter, Body, Depends, Query
from loguru import logger

# Local
import bel.belspec.crud
import bel.lang.ast
import bel.nanopub.validate
from bel.schemas.bel import AssertionStr
from bel.schemas.bel import AssertionRequest, AssertionStr

router = APIRouter()

Expand Down Expand Up @@ -68,3 +68,34 @@ def validate_assertion(bel_assertion: str):
logger.info(f"Validated: {validated}")

return validated


@router.post("/optimize")
def optimize_assertion(
assertion: AssertionStr,
triple: bool = Query(
False,
description="Return Assertion as a Triple in a dictionary, default is to return Assertion as a single string",
),
):
"""Optimize BEL Assertion
Transform BEL Assertion into more canonical BEL format
Current transformations implemented:
1. reactants(A, B) -> products(complex(A, B)) CONVERTED TO complex(A, B)
1. reactants(A, loc(X)) -> products(A, loc(Y)) CONVERTED TO tloc(A, fromLoc(X), toLoc(Y))
1. tloc(A, fromLoc(X), toLoc(extracellular region)) CONVERTED TO sec(A)
1. tloc(A, fromLoc(X), toLoc(plasma membrane)) CONVERTED TO surf(A)
"""

# BEL AST optimizations
ast = bel.lang.ast.BELAst(assertion=assertion)
ast.optimize()

if triple:
return ast.to_triple()

return ast.to_string()
8 changes: 4 additions & 4 deletions bel/belspec/enhance.py
Expand Up @@ -182,7 +182,7 @@ def add_functions(specification: Mapping[str, Any]) -> Mapping[str, Any]:
specification["functions"]["list_long"].append(func_name)
specification["functions"]["list_short"].append(abbreviated_name)

if specification["functions"]["info"][func_name]["type"] == "primary":
if specification["functions"]["info"][func_name]["type"] == "Primary":
specification["functions"]["primary"].append(func_name)
specification["functions"]["primary"].append(abbreviated_name)
specification["functions"]["primary_list_long"].append(func_name)
Expand Down Expand Up @@ -248,7 +248,7 @@ def enhance_function_signatures(specification: Mapping[str, Any]) -> Mapping[str
for func in specification["functions"]["signatures"]:

# Add primary parent functions to modifier functions
if specification["functions"]["signatures"][func]["func_type"] == "modifier":
if specification["functions"]["signatures"][func]["func_type"] == "Modifier":
specification["functions"]["signatures"][func]["primary_function"] = specification[
"functions"
]["info"][func]["primary_function"]
Expand Down Expand Up @@ -342,14 +342,14 @@ def create_ebnf_parser(specification):
functions_list = [
(function, specification["functions"]["info"][function]["abbreviation"])
for function in specification["functions"]["info"]
if specification["functions"]["info"][function]["type"] == "primary"
if specification["functions"]["info"][function]["type"] == "Primary"
]
functions_list = sorted(list(itertools.chain(*functions_list)), key=len, reverse=True)

modifiers_list = [
(function, specification["functions"]["info"][function]["abbreviation"])
for function in specification["functions"]["info"]
if specification["functions"]["info"][function]["type"] == "modifier"
if specification["functions"]["info"][function]["type"] == "Modifier"
]
modifiers_list = sorted(list(itertools.chain(*modifiers_list)), key=len, reverse=True)

Expand Down
4 changes: 2 additions & 2 deletions bel/core/mail.py
Expand Up @@ -2,7 +2,7 @@
from typing import List

# Third Party
import requests
import httpx
from loguru import logger

# Local
Expand All @@ -22,7 +22,7 @@ def send_simple_email(to: List[str], subject: str, body: str, body_html: str = "
if body_html:
data["html"] = body_html

r = requests.post(
r = httpx.post(
f"{settings.MAIL_API}/messages",
auth=("api", settings.MAIL_API_TOKEN),
data=data,
Expand Down

0 comments on commit 61f874b

Please sign in to comment.