Skip to content
Snippets Groups Projects
Commit 95c3d5cf authored by mjbonifa's avatar mjbonifa
Browse files

refactored map to phen; refactored to standard directories for phenotypes that...

refactored map to phen; refactored to standard directories for phenotypes that user can set with subdirectory codes, config.json, phen_output.csv; defaults to build/phen if not specified as makes cli much simpler
parent 42564803
No related branches found
No related tags found
No related merge requests found
Showing
with 28 additions and 57 deletions
...@@ -14,12 +14,7 @@ __pycache__ ...@@ -14,12 +14,7 @@ __pycache__
# Build # Build
build/* build/*
output/ *output*
concepts-output/
archive/
maps/*
concepts-new/
codes/
# temporary # temporary
script script
......
...@@ -2,61 +2,36 @@ import argparse ...@@ -2,61 +2,36 @@ import argparse
import trud import trud
import omop import omop
import map import phen
from pathlib import Path from pathlib import Path
def trud_install(args): def trud_install(args):
"""Handle the `trud install` command.""" """Handle the `trud install` command."""
print(f"Installing TRUD")
trud.install(args.api_key) trud.install(args.api_key)
print(f"TRUD installation completed")
def omop_install(args): def omop_install(args):
"""Handle the `omop install` command.""" """Handle the `omop install` command."""
print(f"Installing OMOP database")
omop.install(omop.OMOP_DB_PATH, args.omop_folder) omop.install(omop.OMOP_DB_PATH, args.omop_folder)
print(f"OMOP installation completed")
def omop_clear(args): def omop_clear(args):
"""Handle the `omop clear` command.""" """Handle the `omop clear` command."""
print(f"Clearing OMOP data from database")
omop.clear(omop.OMOP_DB_PATH) omop.clear(omop.OMOP_DB_PATH)
print(f"OMOP database cleared")
def omop_delete(args): def omop_delete(args):
"""Handle the `omop delete` command.""" """Handle the `omop delete` command."""
print(f"Deleting OMOP database")
omop.delete(omop.OMOP_DB_PATH) omop.delete(omop.OMOP_DB_PATH)
print(f"OMOP database deleted")
def phen_init(args):
def map_process(args): """Handle the `phen init` command."""
"""Handle the `map process` command.""" phen.init(args.phen_dir)
print(f"Processing map with phenotype config file: {args.config_file}")
print(f"Output directory: {args.output_file}") def phen_map(args):
print(f"Target coding format: {args.target_coding}") """Handle the `phen map` command."""
if args.translate: phen.map(args.phen_dir,
print("Translating code types.")
else:
print("Not translating codes")
if args.verify:
print("Verifying codes.")
else:
print("Not verifying codes.")
if args.error_log:
print(f"Saving errors to: {args.error_log}")
else:
args.error_log = 'errors.csv'
map.process(args.config_file,
args.source_codes_dir,
args.target_coding, args.target_coding,
args.translate, args.translate,
args.verify, args.verify)
error_path=Path(args.error_log),
output_path=Path(args.output_file))
print(f"Phenotype processing completed")
def main(): def main():
parser = argparse.ArgumentParser(description="ACMC command-line tool") parser = argparse.ArgumentParser(description="ACMC command-line tool")
...@@ -85,30 +60,31 @@ def main(): ...@@ -85,30 +60,31 @@ def main():
# omop clear # omop clear
omop_clear_parser = omop_subparsers.add_parser("clear", help="Clear OMOP data from database") omop_clear_parser = omop_subparsers.add_parser("clear", help="Clear OMOP data from database")
omop_clear_parser.set_defaults(func=omop_clear) omop_clear_parser.set_defaults(func=omop_clear)
# omop delete # omop delete
omop_delete_parser = omop_subparsers.add_parser("delete", help="Delete OMOP database") omop_delete_parser = omop_subparsers.add_parser("delete", help="Delete OMOP database")
omop_delete_parser.set_defaults(func=omop_delete) omop_delete_parser.set_defaults(func=omop_delete)
### MAP Command ### ### PHEN Command ###
map_parser = subparsers.add_parser("map", help="Map commands") phen_parser = subparsers.add_parser("phen", help="Phen commands")
map_subparsers = map_parser.add_subparsers(dest="subcommand", required=True, help="Map subcommands") phen_subparsers = phen_parser.add_subparsers(dest="subcommand", required=True, help="Phen subcommands")
# map process # phen init
map_process_parser = map_subparsers.add_parser("process", help="Process map configuration file") phen_init_parser = phen_subparsers.add_parser("init", help="Initiatise phenotype configuration")
map_process_parser.add_argument("-c", "--config-file", required=True, help="Phenotype configuration file") phen_init_parser.add_argument("-d", "--phen-dir", type=str, default=phen.DEFAULT_PHEN_PATH.resolve, help="Phenotype directory")
map_process_parser.add_argument("-s", "--source-codes-dir", required=True, help="Source codes root directory") phen_init_parser.set_defaults(func=phen_init)
map_process_parser.add_argument("-t", "--target-coding", required=True, choices=['read2_code', 'read3_code', 'icd10_code', 'snomed_code', 'opcs4_code'], help="Specify the target coding (read2, read3, icd10, snomed, opcs4)")
map_process_parser.add_argument("-o", "--output-file", type=str, default=str(map.OUTPUT_PATH.resolve()), help="Output directory for CSV or OMOP database")
# Flags # phen map
map_process_parser.add_argument("-tr", "--translate", action="store_true", default=False, help="Do not translate code types") phen_map_parser = phen_subparsers.add_parser("map", help="Process phen configuration file")
map_process_parser.add_argument("-v", "--verify", action="store_true", default=False, help="Do not verify codes") phen_map_parser.add_argument("-d", "--phen-dir", type=str, default=phen.DEFAULT_PHEN_PATH.resolve, help="Phenotype directory")
phen_map_parser.add_argument("-t", "--target-coding", required=True, choices=['read2_code', 'read3_code', 'icd10_code', 'snomed_code', 'opcs4_code'], help="Specify the target coding (read2, read3, icd10, snomed, opcs4)")
# Error log file # Flags
map_process_parser.add_argument("-l", "--error-log", type=str, default=str(map.ERROR_PATH.resolve()), help="Filepath to save error log to") phen_map_parser.add_argument("-tr", "--translate", action="store_true", default=False, help="Do not translate code types")
phen_map_parser.add_argument("-v", "--verify", action="store_true", default=False, help="Do not verify codes")
# Set the function to call when 'process' subcommand is used # Set the function to call when 'process' subcommand is used
map_process_parser.set_defaults(func=map_process) phen_map_parser.set_defaults(func=phen_map)
# Parse arguments # Parse arguments
args = parser.parse_args() args = parser.parse_args()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment