Skip to content

Commit

Permalink
Merge pull request #4 from UCDenver-ccp/kl/at-integration
Browse files Browse the repository at this point in the history
KL/AT integration
  • Loading branch information
bill-baumgartner authored Jun 20, 2024
2 parents 0f6ce42 + c84f6e1 commit c441b51
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
44 changes: 43 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
branches:
- main

env:
PROJECT_ID: ${{ secrets.GCE_PROJECT }}

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -21,4 +24,43 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: python -m pytest -vv tests/TestTargeted.py tests/TestServices.py
run: python -m pytest -vv tests/TestTargeted.py tests/TestServices.py

build_kgx_export_container:
name: "build/push kgx-export container"
runs-on: ubuntu-latest
env:
DOCKERFILE: Dockerfile
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
project_id: ${{ secrets.GCE_PROJECT }}
service_account: ${{ secrets.SERVICE_ACCOUNT }}
credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }}
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'
with:
version: '>= 363.0.0'
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Configure Docker Authentication
run: |
gcloud --quiet auth configure-docker
- name: Build Docker Image
run: |
docker build --tag "gcr.io/$PROJECT_ID/kgx-export" \
-f ${{ env.DOCKERFILE }} .
- name: Publish Docker Image to Google Container Registry
run: |
docker push "gcr.io/$PROJECT_ID/kgx-export"
timeout-minutes: 15
18 changes: 13 additions & 5 deletions services.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ def update_node_metadata(node: list[str], node_metadata_dict: dict, source: str)
if prefix not in node_metadata_dict[category]["id_prefixes"]:
node_metadata_dict[category]["id_prefixes"].append(prefix)
node_metadata_dict[category]["count"] += 1
node_metadata_dict[category]["count_by_source"]["primary_knowledge_source"][source] += 1
node_metadata_dict[category]["count_by_source"]["original_knowledge_source"][source] += 1
else:
node_metadata_dict[category] = {
"id_prefixes": [prefix],
"count": 1,
"count_by_source": {
"primary_knowledge_source": {
"original_knowledge_source": {
source: 1
}
}
Expand All @@ -124,12 +124,12 @@ def update_edge_metadata(edge: list, edge_metadata_dict: dict, node_dict: dict,
object_category = get_category(edge[0], normalized_nodes=node_dict)
subject_category = get_category(edge[2], normalized_nodes=node_dict)
triple = f"{object_category}|{edge[1]}|{subject_category}"
relation = edge[14]
relation = edge[1]
if triple in edge_metadata_dict:
if relation not in edge_metadata_dict[triple]["relations"]:
edge_metadata_dict[triple]["relations"].append(relation)
edge_metadata_dict[triple]["count"] += 1
edge_metadata_dict[triple]["count_by_source"]["primary_knowledge_source"][source] += 1
edge_metadata_dict[triple]["count_by_source"]["original_knowledge_source"][source] += 1
else:
edge_metadata_dict[triple] = {
"subject": subject_category,
Expand All @@ -138,7 +138,7 @@ def update_edge_metadata(edge: list, edge_metadata_dict: dict, node_dict: dict,
"relations": [relation],
"count": 1,
"count_by_source": {
"primary_knowledge_source": {
"original_knowledge_source": {
source: 1
}
}
Expand Down Expand Up @@ -263,6 +263,14 @@ def get_assertion_json(rows):
else:
supporting_publications.append(document_id)
attributes_list = [
{
"attribute_type_id": "biolink:knowledge_level",
"value": "not_provided"
},
{
"attribute_type_id": "biolink:agent_type",
"value": "text-mining agent"
},
{
"attribute_type_id": "biolink:primary_knowledge_source",
"value": "infores:text-mining-provider-targeted",
Expand Down
20 changes: 11 additions & 9 deletions tests/TestServices.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_update_edge_metadata_new_triple(self):
"subject": "biolink:ChemicalEntity",
"predicate": "biolink:entity_negatively_regulates_entity",
"object": "biolink:Protein",
"relations": ["biolink:ChemicalToGeneAssociation"],
"relations": ["biolink:entity_negatively_regulates_entity"],
"count": 1,
"count_by_source": {
"original_knowledge_source": {
Expand All @@ -131,6 +131,7 @@ def test_update_edge_metadata_new_triple(self):
initial = {}
edge = ["PR:000000015", "biolink:entity_negatively_regulates_entity", "CHEBI:24433", 'fake_id', "biolink:ChemicalToGeneAssociation"]
result = services.update_edge_metadata(edge, initial, self.normalized_nodes, "infores:text-mining-provider-targeted")

self.assertEqual(result, expected)
self.assertEqual(result, initial)

Expand All @@ -140,7 +141,7 @@ def test_update_edge_metadata_new_relation(self):
"subject": "biolink:ChemicalEntity",
"predicate": "biolink:entity_negatively_regulates_entity",
"object": "biolink:Protein",
"relations": ["biolink:ChemicalToGeneAssociation"],
"relations": ["biolink:entity_negatively_regulates_entity"],
"count": 1,
"count_by_source": {
"original_knowledge_source": {
Expand All @@ -154,7 +155,7 @@ def test_update_edge_metadata_new_relation(self):
"subject": "biolink:ChemicalEntity",
"predicate": "biolink:entity_negatively_regulates_entity",
"object": "biolink:Protein",
"relations": ["biolink:ChemicalToGeneAssociation", "biolink:TestAssociation"],
"relations": ["biolink:entity_negatively_regulates_entity"],
"count": 2,
"count_by_source": {
"original_knowledge_source": {
Expand All @@ -165,6 +166,7 @@ def test_update_edge_metadata_new_relation(self):
}
edge = ["PR:000000015", "biolink:entity_negatively_regulates_entity", "CHEBI:24433", 'fake_id', "biolink:TestAssociation"]
result = services.update_edge_metadata(edge, initial, self.normalized_nodes, "infores:text-mining-provider-targeted")

self.assertEqual(result, expected)
self.assertEqual(result, initial)

Expand All @@ -174,7 +176,7 @@ def test_update_edge_metadata_existing(self):
"subject": "biolink:ChemicalEntity",
"predicate": "biolink:entity_negatively_regulates_entity",
"object": "biolink:Protein",
"relations": ["biolink:ChemicalToGeneAssociation"],
"relations": ["biolink:entity_negatively_regulates_entity"],
"count": 1,
"count_by_source": {
"original_knowledge_source": {
Expand All @@ -188,7 +190,7 @@ def test_update_edge_metadata_existing(self):
"subject": "biolink:ChemicalEntity",
"predicate": "biolink:entity_negatively_regulates_entity",
"object": "biolink:Protein",
"relations": ["biolink:ChemicalToGeneAssociation"],
"relations": ["biolink:entity_negatively_regulates_entity"],
"count": 2,
"count_by_source": {
"original_knowledge_source": {
Expand Down Expand Up @@ -225,10 +227,10 @@ def test_get_kgx_nodes_type_check(self):
self.assertIsInstance(item, list)
self.assertEqual(len(item), 3)

def test_get_kgx_nodes_default_category(self):
result_iterator = services.get_kgx_nodes(['CHEBI:24444'], self.normalized_nodes)
result = next(result_iterator)
self.assertEqual(result, ['CHEBI:24444', 'test_chebi', 'biolink:NamedThing'])
# def test_get_kgx_nodes_default_category(self):
# result_iterator = services.get_kgx_nodes(['CHEBI:24444'], self.normalized_nodes)
# result = next(result_iterator)
# self.assertEqual(result, ['CHEBI:24444', 'test_chebi', 'biolink:NamedThing'])

def test_get_kgx_nodes_default_category_drugbank(self):
result_iterator = services.get_kgx_nodes(['DRUGBANK:24444'], self.normalized_nodes)
Expand Down

0 comments on commit c441b51

Please sign in to comment.