-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from cancervariants/issue-89
Issue 89
- Loading branch information
Showing
15 changed files
with
201 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Add item_type attribute to all items.""" | ||
import sys | ||
from pathlib import Path | ||
from timeit import default_timer as timer | ||
import click | ||
from botocore.exceptions import ClientError | ||
import logging | ||
|
||
PROJECT_ROOT = Path(__file__).resolve().parents[1] | ||
sys.path.append(f"{PROJECT_ROOT}") | ||
|
||
from therapy.database import Database # noqa: E402 | ||
|
||
|
||
logger = logging.getLogger('therapy') | ||
logger.setLevel(logging.DEBUG) | ||
|
||
db = Database() | ||
|
||
|
||
def add_item_type(label_and_type: str, concept_id: str, item_type: str): | ||
"""Add item_type to individual db item.""" | ||
key = { | ||
'label_and_type': label_and_type, | ||
'concept_id': concept_id | ||
} | ||
update_expression = "set item_type=:r" | ||
update_values = {':r': item_type} | ||
try: | ||
db.therapies.update_item(Key=key, | ||
UpdateExpression=update_expression, | ||
ExpressionAttributeValues=update_values) | ||
except ClientError as e: | ||
logger.error(f"boto3 client error in `database.update_record()`: " | ||
f"{e.response['Error']['Message']}") | ||
|
||
|
||
VALID_TYPES = {'identity', 'label', 'trade_name', 'rx_brand', 'alias', | ||
'other_id', 'xref', 'merger'} | ||
|
||
|
||
def add_item_types(): | ||
"""Add item_type attribute to all items.""" | ||
last_evaluated_key = None | ||
while True: | ||
if last_evaluated_key: | ||
response = db.therapies.scan(ExclusiveStartKey=last_evaluated_key) | ||
else: | ||
response = db.therapies.scan() | ||
|
||
records = response['Items'] | ||
for record in records: | ||
label_and_type = record['label_and_type'] | ||
item_type = label_and_type.split('##')[-1] | ||
if item_type in VALID_TYPES: | ||
add_item_type(label_and_type, record['concept_id'], item_type) | ||
else: | ||
logger.error(f"Couldn't parse item type for record: {record}") | ||
|
||
last_evaluated_key = response.get('LastEvaluatedKey') | ||
if not last_evaluated_key: | ||
break | ||
|
||
|
||
if __name__ == '__main__': | ||
click.echo("Adding item_types...") | ||
start = timer() | ||
add_item_types() | ||
end = timer() | ||
click.echo(f"finished adding item_types in {end - start:.5f}s.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""Defines how metakb is packaged and distributed.""" | ||
from setuptools import setup | ||
|
||
setup(version="0.2.14") | ||
setup(version="0.2.15") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.