This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconfig.py
217 lines (172 loc) · 8.3 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import ConfigParser
import ast
import logging
import os
import random
import string
import sys
from collections import defaultdict
from functools import partial
from logging import getLogger
from envparse import env
from pythonjsonlogger import jsonlogger
from app.common.scoring_conf import ScoringMethods
basedir = os.path.abspath(os.path.dirname(__file__))
__author__ = 'andreap'
def init_from_file(filename):
cfg = ConfigParser.ConfigParser()
if cfg.read(filename):
return cfg
else:
return None
def prefix_or_custom_idx(prefix, name, ini, suffix=''):
section_name = 'indexes'
idx_name = ini.get(section_name, name) \
if ini and \
ini.has_option(section_name, name) \
else prefix + '_' + name
from_envar = env('OPENTARGETS_ES_' + name.upper(), default=None)
idx_name = from_envar if from_envar else idx_name
return idx_name + suffix
class Config:
## [read from an .env file, if there]
env.read_envfile()
## the API version number comes from the VERSION file as single point of truth
env.read_envfile('VERSION')
API_VERSION = env('API_VERSION', cast=str)
API_VERSION_MINOR = env('API_VERSION_MINOR', cast=str)
## [key configurations]
ELASTICSEARCH_URL = env('ELASTICSEARCH_URL', default='')
# TODO - would be better to throw an error instead of falling back to a default if this parameter is not set.
DATA_VERSION = env('OPENTARGETS_DATA_VERSION', default='20.09')
# tagged version from expression_hierarchy repository must have same DATA_VERSION tag
ES_TISSUE_MAP_URL = 'https://raw.githubusercontent.com/opentargets/expression_hierarchy/{0}/process/map_with_efos.json'
ES_TISSUE_MAP = None
## logic to point to custom indices in ES
ES_CUSTOM_IDXS_FILENAME = basedir + os.path.sep + 'es_custom_idxs.ini'
ES_CUSTOM_IDXS = ast.literal_eval(env('OPENTARGETS_ES_CUSTOM_IDXS',default='False'))
ES_CUSTOM_IDXS_INI = init_from_file(ES_CUSTOM_IDXS_FILENAME) \
if ES_CUSTOM_IDXS else None
## indices to point to in ES
ES_PREFIX = partial(prefix_or_custom_idx,
prefix=DATA_VERSION,
ini=ES_CUSTOM_IDXS_INI)
ELASTICSEARCH_DATA_INDEX_NAME = ES_PREFIX(name='evidence-data', suffix='*')
ELASTICSEARCH_DATA_DOC_NAME = 'evidencestring'
ELASTICSEARCH_DRUG_INDEX_NAME = ES_PREFIX(name='drug-data')
ELASTICSEARCH_DRUG_DOC_NAME = 'drug'
ELASTICSEARCH_EFO_LABEL_INDEX_NAME = ES_PREFIX(name='efo-data')
ELASTICSEARCH_EFO_LABEL_DOC_NAME = 'efo'
ELASTICSEARCH_ECO_INDEX_NAME = ES_PREFIX(name='eco-data')
ELASTICSEARCH_ECO_DOC_NAME = 'eco'
ELASTICSEARCH_GENE_NAME_INDEX_NAME = ES_PREFIX(name='gene-data')
ELASTICSEARCH_GENE_NAME_DOC_NAME = 'genedata'
ELASTICSEARCH_EXPRESSION_INDEX_NAME = ES_PREFIX(name='expression-data')
ELASTICSEARCH_EXPRESSION_DOC_NAME = 'expression'
ELASTICSEARCH_REACTOME_INDEX_NAME = ES_PREFIX(name='reactome-data')
ELASTICSEARCH_REACTOME_REACTION_DOC_NAME = 'reactome-reaction'
ELASTICSEARCH_DATA_ASSOCIATION_INDEX_NAME = ES_PREFIX(name='association-data')
ELASTICSEARCH_DATA_ASSOCIATION_DOC_NAME = 'association'
ELASTICSEARCH_DATA_SEARCH_INDEX_NAME = ES_PREFIX(name='search-data')
ELASTICSEARCH_DATA_SEARCH_DOC_NAME = 'search-object'
ELASTICSEARCH_DATA_RELATION_INDEX_NAME = ES_PREFIX(name='relation-data')
ELASTICSEARCH_DATA_RELATION_DOC_NAME = 'relation'
ELASTICSEARCH_LOG_EVENT_INDEX_NAME = '!eventlog'
DEBUG = env('API_DEBUG', cast=bool, default=False)
TESTING = False
PROFILE = False
SECRET_KEY = env('SECRET_KEY', default=''.join(
random.SystemRandom().choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(32)))
'''datatype configuration'''
DATATYPES = defaultdict(lambda: "other")
DATATYPES['rna_expression'] = ['expression_atlas', ]
DATATYPES['genetic_association'] = ['phewas_catalog', 'twentythreeandme', 'eva',
'uniprot_literature', 'gene2phenotype', 'genomics_england','ot_genetics_portal','clingen']
DATATYPES['affected_pathway'] = ['reactome', 'slapenrich', 'progeny', 'sysbio', 'crispr']
DATATYPES['animal_model'] = ['phenodigm', ]
DATATYPES['somatic_mutation'] = ['cancer_gene_census', 'eva_somatic', 'intogen', 'uniprot_somatic']
DATATYPES['known_drug'] = ['chembl', ]
DATATYPES['literature'] = ['europepmc']
DATATYPE_ORDERED = ['genetic_association', 'somatic_mutation', 'known_drug', 'rna_expression', 'affected_pathway',
'animal_model', 'literature']
# DATATYPES['protein_expression'] = ['hpa']
# Allow addition of custom datatypes from environment variable
# Environment variable must be named CUSTOM_DATASOURCE
# Format is new_source:type e.g. genomics_england_tiering:genetic_association
# Multiple custom data sources of the same type can be passed as a comma-separated list
env_var = env('CUSTOM_DATASOURCE', default='')
if env_var:
for source_and_type in env_var.split(','):
source, datatype = source_and_type.split(':')
if datatype not in DATATYPES:
print "Cannot add env_var as %s is not a recognised datatype" % datatype
else:
DATATYPES[datatype].append(source)
print "Added %s to list of %s data sources, list is now " % (source, datatype), DATATYPES[datatype]
DATASOURCE_SCORING_METHOD = defaultdict(lambda: ScoringMethods.SUM)
# DATASOURCE_SCORING_METHOD['phenodigm'] = ScoringMethods.MAX
PROXY_SETTINGS = {'allowed_targets': {'ensembl': 'https://rest.ensembl.org/',
'gxa': 'https://www.ebi.ac.uk/gxa/',
'pdbe': 'https://www.ebi.ac.uk/pdbe/',
'epmc': 'http://www.ebi.ac.uk/europepmc/',
},
'allowed_domains': ['www.ebi.ac.uk'],
'allowed_request_domains': ['targetvalidation.org', 'alpha.targetvalidation.org',
'beta.targetvalidation.org', 'localhost', '127.0.0.1'],
}
REDIS_SERVER_PATH = env('REDIS_SERVER_PATH', default='/tmp/api_redis.db')
SECRET_PATH = env('SECRET_PATH', default='app/authconf/')
SECRET_IP_RESOLVER_FILE = env('SECRET_IP_RESOLVER_FILE', default='ip_list.csv')
IP_RESOLVER_LIST_PATH = os.path.join(SECRET_PATH, SECRET_IP_RESOLVER_FILE)
NO_CACHE_PARAMS = 'no_cache'
MIXPANEL_TOKEN = env('MIXPANEL_TOKEN', default=None)
@staticmethod
def init_app(app):
pass
class DevelopmentConfig(Config):
# default settings
DEBUG = True
APP_CACHE_EXPIRY_TIMEOUT = 60
@classmethod
def init_app(cls, app):
file_handler = logging.FileHandler('output.log')
file_handler.setLevel(logging.DEBUG)
jsonformatter = jsonlogger.JsonFormatter(
'%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
file_handler.setFormatter(jsonformatter)
loggers = [app.logger,
getLogger('elasticsearch'),
getLogger('redislite')]
for logger in loggers:
logger.addHandler(file_handler)
Config.init_app(app)
class TestingConfig(Config):
TESTING = True
APP_CACHE_EXPIRY_TIMEOUT = 60
SERVER_NAME = 'localhost:5000'
class ProductionConfig(Config):
APP_CACHE_EXPIRY_TIMEOUT = 60 * 60 * 6 # 6 hours
@classmethod
def init_app(cls, app):
console_handler = logging.StreamHandler(stream=sys.stdout)
console_handler.setLevel(logging.WARN)
jsonformatter = jsonlogger.JsonFormatter(
'%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
console_handler.setFormatter(jsonformatter)
loggers = [app.logger,
getLogger('elasticsearch'),
getLogger('redislite')]
# Sadly, this does not work:
# wlog = getLogger('werkzeug')
# # log.setLevel(logging.ERROR)
# wlog.disabled = True
for logger in loggers:
logger.addHandler(console_handler)
logger.setLevel(logging.WARN)
Config.init_app(app)
config = {
'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig,
'default': DevelopmentConfig
}