Beispiel #1
0
        def check_api_keys(*args, **kwargs):
            global ELSEVIER_KEYS
            if ELSEVIER_KEYS is None:
                ELSEVIER_KEYS = {}
                # Try to read in Elsevier API keys. For each key, first check
                # the environment variables, then check the INDRA config file.
                if not has_config(INST_KEY_ENV_NAME):
                    logger.warning(
                        'Institution API key %s not found in config '
                        'file or environment variable: this will '
                        'limit access for %s' % (INST_KEY_ENV_NAME, task_desc))
                ELSEVIER_KEYS['X-ELS-Insttoken'] = get_config(
                    INST_KEY_ENV_NAME)

                if not has_config(API_KEY_ENV_NAME):
                    logger.error('API key %s not found in configuration file '
                                 'or environment variable: cannot %s' %
                                 (API_KEY_ENV_NAME, task_desc))
                    return failure_ret
                ELSEVIER_KEYS['X-ELS-APIKey'] = get_config(API_KEY_ENV_NAME)
            elif 'X-ELS-APIKey' not in ELSEVIER_KEYS.keys():
                logger.error('No Elsevier API key %s found: cannot %s' %
                             (API_KEY_ENV_NAME, task_desc))
                return failure_ret
            return func(*args, **kwargs)
Beispiel #2
0
def get_ndex_cred(config):
    ndex_cred = config.get('ndex')
    if not ndex_cred:
        return
    elif not ndex_cred.get('user') and not has_config('NDEX_USERNAME'):
        logger.info('NDEx user missing.')
        return
    elif not ndex_cred.get('password')and not has_config('NDEX_PASSWORD'):
        logger.info('NDEx password missing.')
        return
    elif not ndex_cred.get('network'):
        logger.info('NDEx network missing.')
        return
    return ndex_cred
Beispiel #3
0
def get_ndex_cred(config):
    ndex_cred = config.get('ndex')
    if not ndex_cred:
        return
    elif not ndex_cred.get('user') and not has_config('NDEX_USERNAME'):
        logger.info('NDEx user missing.')
        return
    elif not ndex_cred.get('password') and not has_config('NDEX_PASSWORD'):
        logger.info('NDEx password missing.')
        return
    elif not ndex_cred.get('network'):
        logger.info('NDEx network missing.')
        return
    return ndex_cred
Beispiel #4
0
def get_batch_command(command_list, project=None, purpose=None):
    """Get the command appropriate for running something on batch."""
    command_str = ' '.join(command_list)
    ret = ['python3', '-m', 'indra.util.aws', 'run_in_batch', command_str]
    if not project and has_config('DEFAULT_AWS_PROJECT'):
        project = get_config('DEFAULT_AWS_PROJECT')
    if project:
        ret += ['--project', project]
    if purpose:
        ret += ['--purpose', purpose]
    return ret
Beispiel #5
0
def get_batch_command(command_list, project=None, purpose=None):
    """Get the command appropriate for running something on batch."""
    command_str = ' '.join(command_list)
    ret = ['python', '-m', 'indra.util.aws', 'run_in_batch', command_str]
    if not project and has_config('DEFAULT_AWS_PROJECT'):
        project = get_config('DEFAULT_AWS_PROJECT')
    if project:
        ret += ['--project', project]
    if purpose:
        ret += ['--purpose', purpose]
    return ret
Beispiel #6
0
import os
import json
import logging
import requests
from collections import Counter
from indra.statements import Complex, Agent, Evidence
from indra.databases import hgnc_client
from indra import has_config, get_config

biogrid_url = 'http://webservice.thebiogrid.org/interactions/'

logger = logging.getLogger('biogrid')

# For more information see http://wiki.thebiogrid.org/doku.php/biogridrest
# Try to read the API key from a file
if not has_config('BIOGRID_API_KEY'):
    logger.error('BioGRID API key could not be found in config file or ' + \
                 'environment variable.')
else:
    api_key = get_config('BIOGRID_API_KEY')


def get_interactors(gene_name):
    res_dict = _send_request([gene_name], include_interactors=True)
    interaction_list = []
    for result in res_dict.values():
        if result['OFFICIAL_SYMBOL_A'] == gene_name and \
           result['OFFICIAL_SYMBOL_B'] == gene_name:
            interaction_list.append(gene_name)
        elif result['OFFICIAL_SYMBOL_A'] == gene_name:
            interaction_list.append(result['OFFICIAL_SYMBOL_B'])
Beispiel #7
0
from indra.preassembler.hierarchy_manager import hierarchies
from indra.statements import stmts_to_json, Complex, SelfModification,\
    ActiveForm
from indra import has_config

from kqml import KQMLPerformative, KQMLList, KQMLString

logging.basicConfig(format='%(levelname)s: %(name)s - %(message)s',
                    level=logging.INFO)
logger = logging.getLogger('MRA')

from bioagents import Bioagent, BioagentException
from .mra import MRA


if has_config('INDRA_DB_REST_URL') and has_config('INDRA_DB_REST_API_KEY'):
    from indra.sources.indra_db_rest import get_statements
    CAN_CHECK_STATEMENTS = True
else:
    logger.warning("Database web api not specified. Cannot get background.")
    CAN_CHECK_STATEMENTS = False


class MRA_Module(Bioagent):
    name = "MRA"
    tasks = ['BUILD-MODEL', 'EXPAND-MODEL', 'MODEL-HAS-MECHANISM',
             'MODEL-REPLACE-MECHANISM', 'MODEL-REMOVE-MECHANISM',
             'MODEL-UNDO', 'MODEL-GET-UPSTREAM', 'MODEL-GET-JSON',
             'USER-GOAL', 'DESCRIBE-MODEL']

    def __init__(self, **kwargs):
Beispiel #8
0
from indra.assemblers.english import EnglishAssembler
from indra.sources.trips.processor import TripsProcessor
from indra.statements import stmts_to_json, Complex, SelfModification,\
    ActiveForm
from indra import has_config

from kqml import KQMLPerformative, KQMLList, KQMLString

logging.basicConfig(format='%(levelname)s: %(name)s - %(message)s',
                    level=logging.INFO)
logger = logging.getLogger('MRA')

from bioagents import Bioagent, BioagentException
from .mra import MRA

if has_config('INDRA_DB_REST_URL') and has_config('INDRA_DB_REST_API_KEY'):
    from indra.sources.indra_db_rest import get_statements
    CAN_CHECK_STATEMENTS = True
else:
    logger.warning("Database web api not specified. Cannot get background.")
    CAN_CHECK_STATEMENTS = False


class MRA_Module(Bioagent):
    name = "MRA"
    tasks = [
        'BUILD-MODEL', 'EXPAND-MODEL', 'MODEL-HAS-MECHANISM',
        'MODEL-REPLACE-MECHANISM', 'MODEL-REMOVE-MECHANISM', 'MODEL-UNDO',
        'MODEL-GET-UPSTREAM', 'MODEL-GET-JSON', 'USER-GOAL', 'DESCRIBE-MODEL'
    ]
Beispiel #9
0
import os
import json
import logging
import requests
from collections import Counter
from indra.statements import Complex, Agent, Evidence
from indra.databases import hgnc_client
from indra import has_config, get_config

biogrid_url = 'http://webservice.thebiogrid.org/interactions/'

logger = logging.getLogger(__name__)

# For more information see http://wiki.thebiogrid.org/doku.php/biogridrest
# Try to read the API key from a file
if not has_config('BIOGRID_API_KEY'):
    logger.error('BioGRID API key could not be found in config file or ' + \
                 'environment variable.')
else:
    api_key = get_config('BIOGRID_API_KEY')


def get_interactors(gene_name):
    res_dict = _send_request([gene_name], include_interactors=True)
    interaction_list = []
    for result in res_dict.values():
        if result['OFFICIAL_SYMBOL_A'] == gene_name and \
           result['OFFICIAL_SYMBOL_B'] == gene_name:
            interaction_list.append(gene_name)
        elif result['OFFICIAL_SYMBOL_A'] == gene_name:
            interaction_list.append(result['OFFICIAL_SYMBOL_B'])
Beispiel #10
0
variable with the same name.

NewsAPI also requires attribution e.g. "powered by NewsAPI.org" for derived
uses.
"""
import math
import logging
import requests
from indra import has_config, get_config


logger = logging.getLogger(__name__)


api_key = None
if not has_config('NEWSAPI_API_KEY'):
    logger.error('NewsAPI API key could not be found in config file or ' + \
                 'environment variable.')
else:
    api_key = get_config('NEWSAPI_API_KEY')

newsapi_url = 'https://newsapi.org/v2'


def send_request(endpoint, **kwargs):
    """Return the response to a query as JSON from the NewsAPI web service.

    The basic API is limited to 100 results which is chosen unless explicitly
    given as an argument. Beyond that, paging is supported through the "page"
    argument, if needed.