{% include "idbr_description.html" %}
111 | {% endblock %} 112 | -------------------------------------------------------------------------------- /indra_db_service/templates/search.html: -------------------------------------------------------------------------------- 1 | {% extends "idbr_template.html" %} 2 | 3 | {% block scripts %} 4 | {{ super() }} 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 63 | 64 | {% endblock %} 65 | 66 | {% block body %} 67 | {{ super() }} 68 |{{ message }}
82 | 142 | {% endblock %} 143 | -------------------------------------------------------------------------------- /indra_db_service/templates/welcome.html: -------------------------------------------------------------------------------- 1 | {% extends 'idbr_template.html' %} 2 | 3 | {% block body %} 4 | Click the button to the right to sign in and get access to the DB 5 | search page 6 | 10 | {% endblock %} -------------------------------------------------------------------------------- /indra_db_service/util.py: -------------------------------------------------------------------------------- 1 | import json 2 | import logging 3 | from io import StringIO 4 | from datetime import datetime 5 | 6 | from indra.assemblers.html.assembler import _format_stmt_text 7 | from indra_db.client import stmt_from_interaction 8 | 9 | from indra_db.client.readonly.query import gilda_ground 10 | 11 | logger = logging.getLogger('db rest api - util') 12 | 13 | 14 | class DbAPIError(Exception): 15 | pass 16 | 17 | 18 | class NoGroundingFound(DbAPIError): 19 | pass 20 | 21 | 22 | def get_s3_client(): 23 | import boto3 24 | from botocore import config 25 | return boto3.client('s3', boto3.session.Session().region_name, 26 | config=config.Config(s3={'addressing_style': 'path'})) 27 | 28 | # ============================================== 29 | # Define some utilities used to resolve queries. 30 | # ============================================== 31 | 32 | 33 | def process_agent(agent_param): 34 | """Get the agent id and namespace from an input param.""" 35 | 36 | if not agent_param.endswith('@TEXT'): 37 | param_parts = agent_param.split('@') 38 | if len(param_parts) == 2: 39 | ag, ns = param_parts 40 | elif len(param_parts) == 1: 41 | ns = 'NAME' 42 | ag = param_parts[0] 43 | else: 44 | raise DbAPIError('Unrecognized agent spec: \"%s\"' % agent_param) 45 | else: 46 | ag = agent_param[:-5] 47 | ns = 'TEXT' 48 | 49 | if ns == 'HGNC-SYMBOL': 50 | ns = 'NAME' 51 | 52 | logger.info("Resolved %s to ag=%s, ns=%s" % (agent_param, ag, ns)) 53 | return ag, ns 54 | 55 | 56 | def process_mesh_term(mesh_term): 57 | """Use gilda to translate a mesh term into a MESH ID if possible.""" 58 | if mesh_term is None: 59 | return mesh_term 60 | 61 | # Check to see if this is a mesh ID. 62 | if any(mesh_term.startswith(c) for c in ['D', 'C']) \ 63 | and mesh_term[1:].isdigit(): 64 | return mesh_term 65 | 66 | # Try to ground the term. 67 | results = gilda_ground(mesh_term) 68 | for res in results: 69 | if res['term']['db'] == 'MESH': 70 | logger.info(f"Auto-mapped {mesh_term} to {res['term']['id']} " 71 | f"({res['term']['entry_name']}) using Gilda.") 72 | return res['term']['id'] 73 | raise NoGroundingFound(f"Could not find MESH id for {mesh_term} among " 74 | f"gilda results:\n{json.dumps(results, indent=2)}") 75 | 76 | 77 | def get_source(ev_json): 78 | notes = ev_json.get('annotations') 79 | if notes is None: 80 | return 81 | src = notes.get('content_source') 82 | if src is None: 83 | return 84 | return src.lower() 85 | 86 | 87 | def sec_since(t): 88 | return (datetime.now() - t).total_seconds() 89 | 90 | 91 | class LogTracker(object): 92 | log_path = '.rest_api_tracker.log' 93 | 94 | def __init__(self): 95 | root_logger = logging.getLogger() 96 | self.stream = StringIO() 97 | sh = logging.StreamHandler(self.stream) 98 | formatter = logging.Formatter('%(levelname)s: %(name)s %(message)s') 99 | sh.setFormatter(formatter) 100 | sh.setLevel(logging.WARNING) 101 | root_logger.addHandler(sh) 102 | self.root_logger = root_logger 103 | return 104 | 105 | def get_messages(self): 106 | conts = self.stream.getvalue() 107 | print(conts) 108 | ret = conts.splitlines() 109 | return ret 110 | 111 | def get_level_stats(self): 112 | msg_list = self.get_messages() 113 | ret = {} 114 | for msg in msg_list: 115 | level = msg.split(':')[0] 116 | if level not in ret.keys(): 117 | ret[level] = 0 118 | ret[level] += 1 119 | return ret 120 | 121 | 122 | def iter_free_agents(query_dict): 123 | agent_keys = {k for k in query_dict.keys() if k.startswith('agent')} 124 | for k in agent_keys: 125 | entry = query_dict.pop(k) 126 | if isinstance(entry, list): 127 | for agent in entry: 128 | yield agent 129 | else: 130 | yield entry 131 | 132 | 133 | def _make_english_from_meta(interaction): 134 | stmt_type = interaction.get('type') 135 | agent_json = interaction['agents'] 136 | if stmt_type is None: 137 | if len(agent_json) == 0: 138 | eng = '' 139 | else: 140 | ag_list = list(agent_json.values()) 141 | eng = f'{ag_list[0]}' 142 | if len(agent_json) > 1: 143 | eng += ' affects ' + f'{ag_list[1]}' 144 | if len(agent_json) > 3: 145 | eng += ', ' \ 146 | + ', '.join(f'{ag}' 147 | for ag in ag_list[2:-1]) 148 | if len(agent_json) > 2: 149 | eng += ', and ' + f'{ag_list[-1]}' 150 | else: 151 | eng += ' is modified' 152 | else: 153 | eng = _format_stmt_text(stmt_from_interaction(interaction)) 154 | return eng -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | 4 | def main(): 5 | packages = find_packages() 6 | print("Installing `indra_db` Packages:\n", '\n'.join(packages)) 7 | extras_require = {'test': ['nose', 'coverage', 'python-coveralls', 8 | 'nose-timer'], 9 | 'service': ['flask', 'flask-jwt-extended', 'flask-cors', 10 | 'flask-compress', 'numpy'], 11 | 'cli': ['click', 'boto3'], 12 | 'copy': ['pgcopy'], 13 | 'misc': ['matplotlib', 'numpy']} 14 | extras_require['all'] = list({dep for deps in extras_require.values() 15 | for dep in deps}) 16 | setup(name='indra_db', 17 | version='0.0.1', 18 | description='INDRA Database', 19 | long_description='INDRA Database', 20 | url='https://github.com/indralab/indra_db', 21 | author='Patrick Greene', 22 | author_email='patrick_greene@hms.harvard.edu', 23 | packages=packages, 24 | include_package_data=True, 25 | install_requires=['sqlalchemy<1.4', 'psycopg2', 'cachetools', 26 | 'termcolor', 'bs4', 'pyyaml'], 27 | extras_require=extras_require, 28 | entry_points=""" 29 | [console_scripts] 30 | indra-db=indra_db.cli:main 31 | indra-db-service=indra_db_service.cli:main 32 | indra-db-benchmarker=benchmarker.cli:main 33 | """) 34 | 35 | 36 | if __name__ == '__main__': 37 | main() 38 | --------------------------------------------------------------------------------