Skip to content

Commit

Permalink
cliniwiz_keywords.diff_orig.tsv moved file
Browse files Browse the repository at this point in the history
expand.sql
fixed table create "expand_keywords"

make_all.sh
now links "curated.tsv" per dataset, good enough to run

vsac.py
ported from Matts branch
  • Loading branch information
comorbidity committed Jul 25, 2024
1 parent 194a3cb commit 4cf8391
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 57 deletions.
15 changes: 6 additions & 9 deletions cumulus_library_opioid/vocab/analyze/expand.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,18 @@ and rules.TTY2 = relax.TTY2
and rules.RELA = relax.RELA ;


-- ##############################################
call log('expand_keywords', 'refresh');

-- ##############################################
call log('expand_keywords', 'refresh');

drop table if exists expand_keywords;
create table expand_keywords
select distinct relax.*
from expand_relax as relax,
expand_rules as rules
where rules.include is NULL
and relax.REL not in ('RB', 'PAR')
and relax.keyword_len >= 4
and rules.TTY1 = relax.TTY1
and rules.TTY2 = relax.TTY2
and rules.RELA = relax.RELA ;

from expand_relax as relax
where relax.REL not in ('RB', 'PAR')
and relax.keyword_len >=4;

-- ##############################################
call log('expand', 'refresh');
Expand Down
43 changes: 0 additions & 43 deletions cumulus_library_opioid/vocab/data/cliniwiz_keywords.diff_orig.tsv

This file was deleted.

14 changes: 13 additions & 1 deletion cumulus_library_opioid/vocab/make_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,58 @@ source db.config
source env_table_schema.sh

export CURATED='acep'
cd data; rm -f curated.tsv; ln -s VSAC/$CURATED.tsv curated.tsv; cd ..
./make.sh

export CURATED='bioportal'
cd data; rm -f curated.tsv; ln -s bioportal.curated.tsv curated.tsv; cd ..
./make.sh

export CURATED='CancerLinQ'
cd data; rm -f curated.tsv; ln -s VSAC/$CURATED.tsv curated.tsv; cd ..
./make.sh

export CURATED='ecri'
cd data; rm -f curated.tsv; ln -s VSAC/$CURATED.tsv curated.tsv; cd ..
./make.sh

export CURATED='impaq'
cd data; rm -f curated.tsv; ln -s VSAC/$CURATED.tsv curated.tsv; cd ..
./make.sh

export CURATED='lantana'
cd data; rm -f curated.tsv; ln -s VSAC/$CURATED.tsv curated.tsv; cd ..
./make.sh

export CURATED='math_349'
cd data; rm -f curated.tsv; ln -s VSAC/$CURATED.tsv curated.tsv; cd ..
./make.sh

#export CURATED='medrt'
#./make.sh

export CURATED='mitre'
cd data; rm -f curated.tsv; ln -s VSAC/$CURATED.tsv curated.tsv; cd ..
./make.sh

export CURATED='CancerLinQ_non'
cd data; rm -f curated.tsv; ln -s VSAC/$CURATED.tsv curated.tsv; cd ..
./make.sh

export CURATED='mdpartners_non'
cd data; rm -f curated.tsv; ln -s VSAC/$CURATED.tsv curated.tsv; cd ..
./make.sh

export CURATED='atc_non'
cd data; rm -f curated.tsv; ln -s VSAC/$CURATED.tsv curated.tsv; cd ..
./make.sh

#export CURATED='medrt_non'
#./make.sh

export CURATED='cliniwiz_keywords'
cd data; rm -f curated.tsv; ln -s VSAC/$CURATED.tsv curated.tsv; cd ..
./make.sh

#export CURATED='keywords'
#./make.sh
#./make.sh
39 changes: 35 additions & 4 deletions cumulus_library_opioid/vocab/vsac.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import json
import pathlib
import sys
Expand All @@ -13,7 +14,7 @@
"CancerLinQ_non": "2.16.840.1.113762.1.4.1260.173",
"CancerLinQ": "2.16.840.1.113762.1.4.1116.449",
"cliniwiz_keywords": "2.16.840.1.113762.1.4.1200.163",
"clinwiz": "2.16.840.1.113762.1.4.1200.14",
"cliniwiz": "2.16.840.1.113762.1.4.1200.14",
"ecri": "1.3.6.1.4.1.6997.4.1.2.234.999.3.2",
"impaq": "2.16.840.1.113762.1.4.1196.87",
"lantana": "2.16.840.1.113762.1.4.1046.241",
Expand All @@ -30,7 +31,9 @@
def download_oid_data(
source_vocab: str,
*,
config: base_utils.StudyConfig,
api_key: str | None = None,
config: base_utils.StudyConfig | None = None,
force_upload:str | None = None,
path: pathlib.Path | None = None,
) -> bool:
"""Fetches code definitions (assumed to be RXNorm coded) from VSAC
Expand All @@ -40,10 +43,13 @@ def download_oid_data(
:keyword path: A path to write data to (default: ../data)
:returns: True if file created, false otherwise (mostly for testing)
"""
if config:
api_key=config.umls_key
force_upload=config.force_upload
if not path:
path = pathlib.Path(__file__).parent.parent / "data"
path.mkdir(exist_ok=True, parents=True)
if not config.force_upload and (path / f"{source_vocab}.parquet").exists():
if not (force_upload) and (path / f"{source_vocab}.parquet").exists():
print(f"{source_vocab} data present, skipping download")
return False
if source_vocab not in VSAC_OIDS.keys():
Expand All @@ -52,7 +58,7 @@ def download_oid_data(
# TODO: Impove this exist message when porting to library
sys.exit(f"No available OID for {source_vocab}.")
print(f"Downloading {source_vocab} to {path}")
api = umls.UmlsApi(api_key=config.umls_key)
api = umls.UmlsApi(api_key=api_key or api_key)
output = []

response = api.get_vsac_valuesets(oid=VSAC_OIDS[source_vocab])
Expand Down Expand Up @@ -92,3 +98,28 @@ def get_vsac_stewards(config:base_utils.StudyConfig) -> list[str]:
"'--option steward:name' to specify which value sets to use.\n\n"
f"{VALID_MSG}"
)

def main(cli_args=None):
"""Temporary CLI interface"""
parser = argparse.ArgumentParser()
parser.add_argument(
"source_vocab", help="Name of vocab to look up codes for", default=None
)
parser.add_argument("--api_key", help="UMLS api key", default=None)
parser.add_argument(
"--force-upload",
help="Force redownloading of data even if it already exists",
action="store_true",
)
parser.add_argument("--path", help="optional path to write data to", default=None)
args = parser.parse_args(cli_args)
return download_oid_data(
args.source_vocab,
api_key=args.api_key,
force_upload=args.force_upload,
path=pathlib.Path(args.path),
)


if __name__ == "__main__":
main()

0 comments on commit 4cf8391

Please sign in to comment.