Exemplo n.º 1
0
    def _check_reach_env():
        """Check that the environment supports runnig reach."""
        # Get the path to the REACH JAR
        path_to_reach = get_config('REACHPATH')
        if path_to_reach is None:
            path_to_reach = environ.get('REACHPATH', None)
        if path_to_reach is None or not path.exists(path_to_reach):
            raise ReachError(
                'Reach path unset or invalid. Check REACHPATH environment var '
                'and/or config file.'
            )

        logger.debug('Using REACH jar at: %s' % path_to_reach)

        # Get the reach version.
        reach_version = get_config('REACH_VERSION')
        if reach_version is None:
            reach_version = environ.get('REACH_VERSION', None)
        if reach_version is None:
            logger.debug('REACH version not set in REACH_VERSION')
            m = re.match('reach-(.*?)\.jar', path.basename(path_to_reach))
            reach_version = re.sub('-SNAP.*?$', '', m.groups()[0])

        logger.debug('Using REACH version: %s' % reach_version)
        return path_to_reach, reach_version
Exemplo n.º 2
0
 def __init__(self,
              storage_mode='web',
              dart_url=None,
              dart_uname=None,
              dart_pwd=None,
              local_storage=None):
     self.storage_mode = storage_mode
     # We set the local storage in either mode, since even in web mode
     # it is used as a cache
     self.local_storage = local_storage if local_storage else \
         get_config('INDRA_WM_CACHE')
     # In web mode, we try to get a URL, a username and a password. In order
     # of priority, we first take arguments provided directly, otherwise
     # we take configuration values.
     if self.storage_mode == 'web':
         if dart_url:
             self.dart_url = dart_url
         else:
             dart_config_url = get_config('DART_WM_URL')
             self.dart_url = dart_config_url if dart_config_url else \
                 default_dart_url
         if dart_uname:
             self.dart_uname = dart_uname
         else:
             self.dart_uname = get_config('DART_WM_USERNAME')
         if dart_pwd:
             self.dart_pwd = dart_pwd
         else:
             self.dart_pwd = get_config('DART_WM_PASSWORD')
         if not self.dart_uname or not self.dart_pwd:
             logger.warning('DART is used in web mode but username or '
                            'password were not provided or set in the '
                            'DART_WM_USERNAME and DART_WM_PASSWORD '
                            'configurations.')
     # In local mode, we need to have a local storage set
     else:
         self.dart_url = None
         if not self.local_storage:
             raise ValueError('DART client initialized in local mode '
                              'without a local storage path.')
     # If the local storage doesn't exist, we try create the folder
     if not os.path.exists(self.local_storage):
         logger.info('The local storage path %s for the DART client '
                     'doesn\'t exist and will now be created' %
                     self.local_storage)
         try:
             os.makedirs(self.local_storage)
         except Exception as e:
             logger.error('Could not create DART client local storage: %s' %
                          e)
     logger.info('Running DART client in %s mode with local storage at %s' %
                 (self.storage_mode, self.local_storage))
Exemplo n.º 3
0
def test_curation_submission():
    from indra.config import get_config
    api_key = get_config('INDRA_DB_REST_API_KEY', failure_ok=True)
    if not api_key:
        raise SkipTest("No API Key, this test will not work.")
    res = dbr.submit_curation(32760831642168299, 'TEST', 'This is a test.',
                              'tester', is_test=True)
    assert res['result'] == 'test passed', res
Exemplo n.º 4
0
def test_get_curations():
    from indra.config import get_config
    api_key = get_config('INDRA_DB_REST_API_KEY', failure_ok=True)
    if not api_key:
        raise SkipTest("No API Key, this test will not work.")
    stmt_hash = -13159234982749425
    src_hash = 3817298406742073624
    res = dbr.get_curations(stmt_hash, src_hash)
    assert isinstance(res, list)
    assert len(res) > 0
    assert all(c['pa_hash'] == stmt_hash and c['source_hash'] == src_hash
               for c in res)
Exemplo n.º 5
0
def get_config_extended(key):
    """Return config either from INDRA, environemnt, or AWS SSM."""
    from indra.config import get_config
    val = get_config(key)
    if val:
        logger.info('Got %s from environment' % key)
        return val
    import boto3
    client = boto3.client('ssm')
    response = client.get_parameter(Name=key, WithDecryption=True)
    val = response['Parameter']['Value']
    logger.info('Got %s from SSM' % key)
    return val
Exemplo n.º 6
0
 def _run_drum(self, host, port):
     drum_path = get_config('DRUMPATH')
     cmd_path = os.path.join(drum_path, 'bin', 'trips-drum')
     options = ['-nouser']
     if host:
         options += ['-host', host]
     if port:
         options += ['-port', str(port)]
     cmd = [cmd_path] + options
     # The os.setsid() is passed in the argument preexec_fn so
     # it's run after the fork() and before  exec() to run the shell.
     # Uncomment the stdout line to supress printing to stdout
     drum_proc = subprocess.Popen(cmd,
                                  stdout=subprocess.PIPE,
                                  preexec_fn=os.setsid)
     # TODO: Here we could monitor the stdout and wait for the "Ready" line
     time.sleep(20)
     return drum_proc
Exemplo n.º 7
0
        ga.save_pdf(fname)
        return fname
    elif output_format == 'json':
        msg = json.dumps(stmts_to_json(stmts), indent=1)
        return msg
    elif output_format == 'html':
        ev_counts = {} if not ev_counts else ev_counts
        ha = HtmlAssembler(stmts, ev_totals=ev_counts,
                           source_counts=source_counts)
        fname = 'indrabot.html'
        ha.save_model(fname)
        return fname
    return None


db_rest_url = get_config('INDRA_DB_REST_URL')


def dump_to_s3(stmts, ev_counts, source_counts):
    s3 = boto3.client('s3')
    bucket = 'indrabot-results'
    fname = '%s.html' % uuid.uuid4()
    ha = HtmlAssembler(stmts, db_rest_url=db_rest_url, ev_totals=ev_totals,
                       source_counts=source_counts)
    html_str = ha.make_model()
    url = 'https://s3.amazonaws.com/%s/%s' % (bucket, fname)
    logger.info('Dumping to %s' % url)
    s3.put_object(Key=fname, Body=html_str.encode('utf-8'),
                  Bucket=bucket, ContentType='text/html')
    logger.info('Dumped to %s' % url)
    return url
Exemplo n.º 8
0
 def get_version(cls):
     jar_name = path.basename(get_config('EIDOSPATH'))
     return re.match(r'eidos-assembly-(.+).jar', jar_name).groups()[0]
Exemplo n.º 9
0
from indra.statements import *
from indra.util import read_unicode_csv
from indra.config import has_config, get_config
from indra.databases import uniprot_client, hgnc_client, phosphosite_client
# Python 2
try:
    basestring
# Python 3
except:
    basestring = str

logger = logging.getLogger('sitemapper')


if has_config('SITEMAPPER_CACHE_PATH'):
    sitemapper_cache = get_config('SITEMAPPER_CACHE_PATH')
else:
    sitemapper_cache = None


class MappedStatement(object):
    """Information about a Statement found to have invalid sites.

    Parameters
    ----------
    original_stmt : :py:class:`indra.statements.Statement`
        The statement prior to mapping.
    mapped_mods : list of tuples
        A list of invalid sites, where each entry in the list has two
        elements: ((gene_name, residue, position), mapped_site).  If the
        invalid position was not found in the site map, mapped_site is
Exemplo n.º 10
0
"""This module implements a client to the Gilda grounding web service,
and contains functions to help apply it during the course of INDRA assembly."""
import logging
import requests
from copy import deepcopy
from urllib.parse import urljoin
from indra.ontology.standardize \
    import standardize_agent_name
from indra.config import get_config, has_config
from indra.pipeline import register_pipeline

logger = logging.getLogger(__name__)

grounding_service_url = get_config('GILDA_URL', failure_ok=True) \
    if has_config('GILDA_URL') else 'http://grounding.indra.bio/'


def get_grounding(txt, context=None, mode='web'):
    """Return the top Gilda grounding for a given text.

    Parameters
    ----------
    txt : str
        The text to ground.
    context : Optional[str]
        Any context for the grounding.
    mode : Optional[str]
        If 'web', the web service given in the GILDA_URL config setting or
        environmental variable is used. Otherwise, the gilda package is
        attempted to be imported and used. Default: web
Exemplo n.º 11
0
def get_api_key():
    return get_config('CROSSREF_CLICKTHROUGH_KEY')
Exemplo n.º 12
0
__all__ = ['process_annotations', 'get_annotations']

import requests
from indra.config import get_config
from .processor import HypothesisProcessor

base_url = 'https://api.hypothes.is/api/'
api_key = get_config('HYPOTHESIS_API_KEY')
headers = {
    'Authorization': 'Bearer %s' % api_key,
    'Accept': 'application/vnd.hypothesis.v1+json',
    'content-type': 'application/json'
}
indra_group = get_config('HYPOTHESIS_GROUP')


def send_request(endpoint, **params):
    """Send a request to the hypothes.is web service and return JSON response.

    Note that it is assumed that `HYPOTHESIS_API_KEY` is set either as a
    configuration entry or as an environmental variable.

    Parameters
    ----------
    endpoint : str
        The endpoint to call, e.g., `search`.
    params : kwargs
        A set of keyword arguments that are passed to the `requests.get` call
        as `params.
    """
    if api_key is None:
Exemplo n.º 13
0
def _get_sofia_auth():
    sofia_username = get_config('SOFIA_USERNAME')
    sofia_password = get_config('SOFIA_PASSWORD')
    return sofia_username, sofia_password
Exemplo n.º 14
0
"""Module containing the implementation of an IndraOntology for the
 general biology use case."""
__all__ = ['bio_ontology', 'BioOntology']

from indra.config import get_config
from .ontology import BioOntology
from ..virtual import VirtualOntology

indra_ontology_url = get_config('INDRA_ONTOLOGY_URL')
bio_ontology = BioOntology() if not indra_ontology_url else \
    VirtualOntology(url=indra_ontology_url)
Exemplo n.º 15
0
"""A client for accessing reader output from the DART system."""
import os
import tqdm
import json
import logging
import requests
import itertools
from datetime import datetime
from collections import defaultdict
from indra.config import get_config


logger = logging.getLogger(__name__)


dart_uname = get_config('DART_WM_USERNAME')
dart_pwd = get_config('DART_WM_PASSWORD')
# The URL is configurable since it is subject to change per use case
dart_base_url = get_config('DART_WM_URL')
if dart_base_url is None:
    dart_base_url = ('https://wm-ingest-pipeline-rest-1.prod.dart'
                     '.worldmodelers.com/dart/api/v1/readers')
meta_endpoint = dart_base_url + '/query'
downl_endpoint = dart_base_url + '/download/'


def get_content_by_storage_key(storage_key):
    """Return content from DART based on its storage key.

    Parameters
    ----------
Exemplo n.º 16
0
from pathlib import Path
from indra.config import get_config

default_bucket = 'world-modelers'
default_key_base = 'indra_models'
default_profile = 'wm'
cache_config = get_config('INDRA_WM_CACHE')
if cache_config:
    CACHE = Path(cache_config)
    CACHE.mkdir(exist_ok=True)
else:
    CACHE = None
Exemplo n.º 17
0
import os
import logging
import argparse
from flask import jsonify, Flask, render_template, request
from flask_wtf import FlaskForm
from wtforms import SubmitField, validators, SelectMultipleField, \
    StringField, TextAreaField, SelectField
from wtforms.fields.html5 import DateField
from flask_bootstrap import Bootstrap

from indra.config import get_config
from indra_world.sources.dart import DartClient, prioritize_records
from indra_world.service.corpus_manager import CorpusManager


DB_URL = get_config('INDRA_WM_SERVICE_DB', failure_ok=False)
dart_client = DartClient()


logger = logging.getLogger('indra_wm_service.assembly_dashboard')
app = Flask(__name__)
app.config['SECRET_KEY'] = 'dev_key'
Bootstrap(app)


reader_names = [('eidos', 'eidos'),
                ('hume', 'hume'),
                ('sofia', 'sofia')]

assembly_levels = [('grounding', 'grounding'),
                   ('location', 'location'),
Exemplo n.º 18
0
def get_api_key():
    return get_config('CROSSREF_CLICKTHROUGH_KEY')
Exemplo n.º 19
0
                                'type': 'xref',
                                'source': 'mirbase'
                            }))
        self.add_edges_from(edges)

    def add_activity_hierarchy(self):
        rels = [('transcription', 'activity'), ('catalytic', 'activity'),
                ('gtpbound', 'activity'), ('kinase', 'catalytic'),
                ('phosphatase', 'catalytic'), ('gef', 'catalytic'),
                ('gap', 'catalytic')]
        self.add_edges_from([(self.label('INDRA_ACTIVITIES', source),
                              self.label('INDRA_ACTIVITIES', target), {
                                  'type': 'isa'
                              }) for source, target in rels])

    def add_modification_hierarchy(self):
        self.add_edges_from([(self.label('INDRA_MODS', source),
                              self.label('INDRA_MODS', 'modification'), {
                                  'type': 'isa'
                              }) for source in modtype_conditions
                             if source != 'modification'])


HERE = os.path.dirname(os.path.abspath(__file__))
resources = os.path.join(HERE, os.pardir, os.pardir, 'resources')
CACHE_DIR = get_config('INDRA_RESOURCES') or \
            os.path.join(os.path.expanduser('~'), '.indra',
                         '%s_ontology' % BioOntology.name,
                         BioOntology.version)
CACHE_FILE = os.path.join(CACHE_DIR, 'bio_ontology.pkl')
Exemplo n.º 20
0
def test_api():
    health_ep = dart_client.dart_base_url + '/health'
    dart_uname = get_config('DART_WM_USERNAME', failure_ok=False)
    dart_pwd = get_config('DART_WM_PASSWORD', failure_ok=False)
    res = requests.get(health_ep, auth=(dart_uname, dart_pwd))
    assert res.status_code == 200
Exemplo n.º 21
0
import logging
import json
from indra.config import get_config
from indra.statements import stmts_to_json
from flask import Flask, request, abort
from flask_restx import Api, Resource, fields
from .controller import ServiceController
from ..sources.dart import DartClient
from ..sources import hume, cwms, sofia, eidos

logger = logging.getLogger('indra_world.service.app')

db_url = get_config('INDRA_WM_SERVICE_DB', failure_ok=False)
if not get_config('DART_WM_URL'):
    dart_client = DartClient(storage_mode='local')
else:
    dart_client = DartClient(storage_mode='web')
sc = ServiceController(db_url, dart_client=dart_client)


app = Flask(__name__)
app.config['RESTX_MASK_SWAGGER'] = False
api = Api(app, title='INDRA World Modelers API',
          description='REST API for INDRA World Modelers')

# Namespaces
base_ns = api.namespace('Basic functions',
                        'Basic functions',
                        path='/')
dart_ns = api.namespace('DART endpoints',
                        'DART endpoints',
Exemplo n.º 22
0
                              self.label('INDRA_MODS', 'modification'), {
                                  'type': 'isa'
                              }) for source in modtype_conditions
                             if source != 'modification'])

    def add_nodes_from(self, nodes_for_adding, **attr):
        for label, _ in nodes_for_adding:
            self.assert_valid_node(label)
        super().add_nodes_from(nodes_for_adding, **attr)

    def add_edges_from(self, ebunch_to_add, **attr):
        for source, target, _ in ebunch_to_add:
            for label in [source, target]:
                self.assert_valid_node(label)
        super().add_edges_from(ebunch_to_add, **attr)

    def assert_valid_node(self, label):
        db_ns, db_id = self.get_ns_id(label)
        if db_ns in {'INDRA_ACTIVITIES', 'INDRA_MODS'}:
            return
        try:
            assert_valid_db_refs({db_ns: db_id})
        except Exception as e:
            logger.warning(e)


CACHE_DIR = os.path.join((get_config('INDRA_RESOURCES')
                          or os.path.join(os.path.expanduser('~'), '.indra')),
                         '%s_ontology' % BioOntology.name, BioOntology.version)
CACHE_FILE = os.path.join(CACHE_DIR, 'bio_ontology.pkl')
Exemplo n.º 23
0
def _get_sofia_auth():
    sofia_username = get_config('SOFIA_USERNAME')
    sofia_password = get_config('SOFIA_PASSWORD')
    return sofia_username, sofia_password