Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename redis_connection[0-6] to their database names #271

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions node_normalizer/normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ async def get_info_content(
return {}

# call redis and get the value
info_contents = await app.state.redis_connection4.mget(*canonical_nonan, encoding='utf8')
info_contents = await app.state.info_content_db.mget(*canonical_nonan, encoding='utf8')

# get this into a list
info_contents = [round(float(ic_ids), 1) if ic_ids is not None else None for ic_ids in info_contents]
Expand All @@ -515,9 +515,9 @@ async def get_eqids_and_types(
batch_size = int(os.environ.get("EQ_BATCH_SIZE", 2500))
eqids = []
for i in range(0, len(canonical_nonan), batch_size):
eqids += await app.state.redis_connection1.mget(*canonical_nonan[i:i+batch_size], encoding='utf-8')
eqids += await app.state.id_to_eqids_db.mget(*canonical_nonan[i:i + batch_size], encoding='utf-8')
eqids = [json.loads(value) if value is not None else [None] for value in eqids]
types = await app.state.redis_connection2.mget(*canonical_nonan, encoding='utf-8')
types = await app.state.id_to_type_db.mget(*canonical_nonan, encoding='utf-8')
types_with_ancestors = []
for index, typ in enumerate(types):
if not typ:
Expand Down Expand Up @@ -552,7 +552,7 @@ async def get_normalized_nodes(

upper_curies = [c.upper() for c in curies]
try:
canonical_ids = await app.state.redis_connection0.mget(*upper_curies, encoding='utf-8')
canonical_ids = await app.state.eq_id_to_id_db.mget(*upper_curies, encoding='utf-8')
canonical_nonan = [canonical_id for canonical_id in canonical_ids if canonical_id is not None]
info_contents = {}

Expand All @@ -569,12 +569,12 @@ async def get_normalized_nodes(
other_ids = []

if conflate_gene_protein:
other_ids.extend(await app.state.redis_connection5.mget(*canonical_nonan, encoding='utf8'))
other_ids.extend(await app.state.gene_protein_db.mget(*canonical_nonan, encoding='utf8'))

# logger.error(f"After conflate_gene_protein: {other_ids}")

if conflate_chemical_drug:
other_ids.extend(await app.state.redis_connection6.mget(*canonical_nonan, encoding='utf8'))
other_ids.extend(await app.state.chemical_drug_db.mget(*canonical_nonan, encoding='utf8'))

# logger.error(f"After conflate_chemical_drug: {other_ids}")

Expand Down Expand Up @@ -657,7 +657,7 @@ async def get_info_content_attribute(app, canonical_nonan) -> dict:
:return:
"""
# get the information content value
ic_val = await app.state.redis_connection4.get(canonical_nonan, encoding='utf8')
ic_val = await app.state.info_content_db.get(canonical_nonan, encoding='utf8')

# did we get a good value
if ic_val is not None:
Expand Down Expand Up @@ -776,7 +776,7 @@ async def get_curie_prefixes(
if semantic_types:
for item in semantic_types:
# get the curies for this type
curies = await app.state.redis_connection3.get(item, encoding='utf-8')
curies = await app.state.curie_to_bl_type_db.get(item, encoding='utf-8')

# did we get any data
if not curies:
Expand All @@ -787,11 +787,11 @@ async def get_curie_prefixes(
# set the return data
ret_val[item] = {'curie_prefix': curies}
else:
types = await app.state.redis_connection3.lrange('semantic_types', 0, -1, encoding='utf-8')
types = await app.state.curie_to_bl_type_db.lrange('semantic_types', 0, -1, encoding='utf-8')

for item in types:
# get the curies for this type
curies = await app.state.redis_connection3.get(item, encoding='utf-8')
curies = await app.state.curie_to_bl_type_db.get(item, encoding='utf-8')

# did we get any data
if not curies:
Expand Down
44 changes: 22 additions & 22 deletions node_normalizer/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ async def startup_event():
"""
redis_config_file = Path(__file__).parent.parent / "redis_config.yaml"
connection_factory = await RedisConnectionFactory.create_connection_pool(redis_config_file)
app.state.redis_connection0 = connection_factory.get_connection(connection_id="eq_id_to_id_db")
app.state.redis_connection1 = connection_factory.get_connection(connection_id="id_to_eqids_db")
app.state.redis_connection2 = connection_factory.get_connection(connection_id="id_to_type_db")
app.state.redis_connection3 = connection_factory.get_connection(connection_id="curie_to_bl_type_db")
app.state.redis_connection4 = connection_factory.get_connection(connection_id="info_content_db")
app.state.redis_connection5 = connection_factory.get_connection(connection_id="gene_protein_db")
app.state.redis_connection6 = connection_factory.get_connection(connection_id="chemical_drug_db")
app.state.eq_id_to_id_db = connection_factory.get_connection(connection_id="eq_id_to_id_db")
app.state.id_to_eqids_db = connection_factory.get_connection(connection_id="id_to_eqids_db")
app.state.id_to_type_db = connection_factory.get_connection(connection_id="id_to_type_db")
app.state.curie_to_bl_type_db = connection_factory.get_connection(connection_id="curie_to_bl_type_db")
app.state.info_content_db = connection_factory.get_connection(connection_id="info_content_db")
app.state.gene_protein_db = connection_factory.get_connection(connection_id="gene_protein_db")
app.state.chemical_drug_db = connection_factory.get_connection(connection_id="chemical_drug_db")
app.state.toolkit = Toolkit()
app.state.ancestor_map = {}

Expand All @@ -74,20 +74,20 @@ async def shutdown_event():
"""
Shut down Redis connection
"""
app.state.redis_connection0.close()
await app.state.redis_connection0.wait_closed()
app.state.redis_connection1.close()
await app.state.redis_connection1.wait_closed()
app.state.redis_connection2.close()
await app.state.redis_connection2.wait_closed()
app.state.redis_connection3.close()
await app.state.redis_connection3.wait_closed()
app.state.redis_connection4.close()
await app.state.redis_connection4.wait_closed()
app.state.redis_connection5.close()
await app.state.redis_connection5.wait_closed()
app.state.redis_connection6.close()
await app.state.redis_connection6.wait_closed()
app.state.eq_id_to_id_db.close()
await app.state.eq_id_to_id_db.wait_closed()
app.state.id_to_eqids_db.close()
await app.state.id_to_eqids_db.wait_closed()
app.state.id_to_type_db.close()
await app.state.id_to_type_db.wait_closed()
app.state.curie_to_bl_type_db.close()
await app.state.curie_to_bl_type_db.wait_closed()
app.state.info_content_db.close()
await app.state.info_content_db.wait_closed()
app.state.gene_protein_db.close()
await app.state.gene_protein_db.wait_closed()
app.state.chemical_drug_db.close()
await app.state.chemical_drug_db.wait_closed()


@app.post(
Expand Down Expand Up @@ -230,7 +230,7 @@ async def get_normalized_node_handler(curies: CurieList):
)
async def get_semantic_types_handler() -> SemanticTypes:
# look for all biolink semantic types
types = await app.state.redis_connection3.lrange("semantic_types", 0, -1, encoding="utf-8")
types = await app.state.curie_to_bl_type_db.lrange("semantic_types", 0, -1, encoding="utf-8")

# did we get any data
if not types:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ async def mget(self, *args, **kwargs):


# Id -> Canonical
app.state.redis_connection0 = MockRedis(
app.state.eq_id_to_id_db = MockRedis(
{"DOID:3812": "MONDO:0005002", "MONDO:0005002": "MONDO:0005002"}
)
# Canonical->Equiv
app.state.redis_connection1 = MockRedis(
app.state.id_to_eqids_db = MockRedis(
{"MONDO:0005002": json.dumps([{"i": "MONDO:0005002"}, {"i": "DOID:3812"}])}
)
app.state.redis_connection2 = MockRedis({"MONDO:0005002": "biolink:Disease"})
app.state.redis_connection3 = MockRedis({})
app.state.redis_connection4 = MockRedis({})
app.state.redis_connection5 = MockRedis({})
app.state.id_to_type_db = MockRedis({"MONDO:0005002": "biolink:Disease"})
app.state.curie_to_bl_type_db = MockRedis({})
app.state.info_content_db = MockRedis({})
app.state.gene_protein_db = MockRedis({})
#app.state.ancestor_map = {"biolink:Disease": ["biolink:Disease", "biolink:NamedThing"]}
app.state.toolkit = Toolkit()
app.state.ancestor_map = {}
Expand Down