QuickUMLS Documentation

repository·master·Indexed 19 days ago

https://github.com/georgetown-ir-lab/quickumls

QuickUMLS is a tool for fast, unsupervised biomedical concept extraction from medical text using approximate string matching via Simstring. It requires a valid UMLS installation and provides a Python API for matching, a spaCy pipeline component (SpacyQuickUMLS), and a client-server architecture for network-based querying.

Tokens
2.3K
Snippets
8
Records
9
Agent score
66%

What's inside QuickUMLS

  1. Run QuickUMLS in Client-Server mode

    master

    QuickUMLS supports a client-server architecture to allow multiple scripts to query a single running server.

    1. Start the Server: Run the server module via CLI. You can specify host, port, and QuickUMLS options. python -m quickumls.server /path/to/quickumls/files {-P QuickUMLS port} {-H QuickUMLS host} {QuickUMLS options}

    • Default host/port: localhost:4645.
    • To run in background: Use nohup and redirect output to a .pid file.

    2. Use the Client: Import get_quickumls_client from quickumls. The client API is identical to the standard QuickUMLS object.

    from quickumls import get_quickumls_client
    
    # Connect to the running server
    matcher = get_quickumls_client()
    
    text = "The ulna has dislocated posteriorly from the trochlea of the humerus."
    results = matcher.match(text, best_match=True, ignore_syntax=False)
  2. Install QuickUMLS

    master

    QuickUMLS requires a valid UMLS installation on disk.

    1. Obtain UMLS: Obtain a license from the NLM, download UMLS files, and install them using MetamorphoSys. You will specifically need MRCONSO.RRF and MRSTY.RRF.
    2. Install the package: Use pip or setup.py.
      • pip install quickumls
      • python setup.py install
      • Note for macOS: Using Anaconda is strongly recommended. If installation fails, install leveldb first via conda install -c conda-forge python-leveldb.
    3. Initialize QuickUMLS: Run the installation module to create the QuickUMLS data files from your UMLS installation.
    python -m quickumls.install <umls_installation_path> <destination_path>
  3. Integrate QuickUMLS into a spaCy pipeline

    master

    QuickUMLS can be added as a SpacyQuickUMLS component to a spaCy pipeline. It adds entity objects to the Doc object. These entities store the CUI, similarity score, and Semantic Types in the spaCy ._ (underscore) attribute.

    from quickumls.spacy_component import SpacyQuickUMLS
    import spacy
    
    # common English pipeline
    nlp = spacy.load('en_core_web_sm')
    
    quickumls_component = SpacyQuickUMLS(nlp, 'PATH_TO_QUICKUMLS_DATA')
    nlp.add_pipe(quickumls_component)
    
    doc = nlp('Pt c/o shortness of breath, chest pain, nausea, vomiting, diarrrhea')
    
    for ent in doc.ents:
        print('Entity text : {}'.format(ent.text))
        print('Label (UMLS CUI) : {}'.format(ent.label_))
        print('Similarity : {}'.format(ent._.similarity))
        print('Semtypes : {}'.format(ent._.semtypes))
  4. Use the QuickUMLS API for concept extraction

    master

    Instantiate a QuickUMLS object to perform approximate string matching for biomedical concept extraction.

    Constructor Parameters:

    • quickumls_fp: Directory where QuickUMLS data files are installed.
    • overlapping_criteria (optional, default: "score"): "score" (match score priority) or "length" (longest concept priority).
    • threshold (optional, default: 0.7): Minimum similarity value.
    • similarity_name (optional, default: "jaccard"): One of "dice", "jaccard", "cosine", or "overlap".
    • window (optional, default: 5): Max tokens to consider for matching.
    • accepted_semtypes (optional): Set of UMLS semantic types (e.g., "T131").

    Matching: Call .match(text, best_match=True, ignore_syntax=False).

    • best_match=False: Returns overlapping candidates.
    • ignore_syntax=True: Disables heuristics introduced in Soldaini and Goharian (2016).
    from quickumls import QuickUMLS
    
    matcher = QuickUMLS(quickumls_fp, overlapping_criteria, threshold,
                        similarity_name, window, accepted_semtypes)
    
    text = "The ulna has dislocated posteriorly from the trochlea of the humerus."
    results = matcher.match(text, best_match=True, ignore_syntax=False)
  5. Initialize QuickUMLS data with quickumls.install

    master

    Use python -m quickumls.install to initialize the system. This process takes 5-30 minutes.

    Arguments:

    • <umls_installation_path>: Path to UMLS files (must contain MRCONSO.RRF and MRSTY.RRF).
    • <destination_path>: Directory where QuickUMLS data files will be created.
    • -L / --lowercase: Fold concept terms to lowercase (increases recall, may reduce precision).
    • -U / --normalize-unicode: Convert non-ASCII characters to closest ASCII equivalents.
    • -E / --language: Specify language (default is English).
    • -d / --database-backend: Specify backend. Options are leveldb or unqlite. unqlite is the default for v1.4+ and supports multi-process reading and better unicode support.
    python -m quickumls.install <umls_installation_path> <destination_path>
  6. Create a QuickUMLS client with get_quickumls_client()

    master

    Use the get_quickumls_client factory function to create a client instance for interacting with a QuickUMLS server. By default, it attempts to connect to localhost on port 4645. You can specify a custom host and port if your server is running elsewhere.

    from quickumls import get_quickumls_client
    
    # Connect to a server on the default localhost:4645
    client = get_quickumls_client()
    
    # Connect to a server on a specific host and port
    client = get_quickumls_client(host='192.168.1.100', port=5000)
  7. Use run_quickumls_server() to start a server programmatically

    master

    The run_quickumls_server(opts) function initializes a QuickUMLS matcher instance using the provided options and then starts the network server using run_server. This is the primary entry point for launching the server logic.

    from quickumls.server import run_quickumls_server
    from argparse import Namespace
    
    # Mocking the opts object expected by the function
    opts = Namespace(
        quickumls_fp='/path/to/data',
        threshold=0.7,
        overlapping_criteria='score',
        similarity_name='jaccard',
        window=5,
        min_match_length=3,
        verbose=False,
        keep_uppercase=False,
        host='localhost',
        port=4645
    )
    
    run_quickumls_server(opts)
  8. Configure QuickUMLS server arguments

    master

    When running the QuickUMLS server, use the following arguments to configure the matcher and the network interface:

    Required Arguments

    • quickumls_fp: The directory where the QuickUMLS data files are installed.

    Server Configuration

    • -H, --host: The host address the server should bind to (default: localhost).
    • -P, --port: The port number the server responds on (default: 4645).

    QuickUMLS Matching Options

    • -t, --threshold: Minimum similarity value between strings (default: 0.7).
    • -o, --overlapping_criteria: Criteria used to resolve overlapping concepts. Options: score or length (default: score).
    • -s, --similarity_name: The similarity metric to use. Options: dice, jaccard, cosine, or overlap (default: jaccard).
    • -w, --window: Maximum number of tokens to consider for matching (default: 5).
    • -l, --min-match-length: Minimum length of a match (default: 3).
    • -v, --verbose: Enable verbose information during execution.
    • -u, --keep_uppercase: Disables automatic lowercase conversion. This is useful for distinguishing acronyms from normal words, but requires the database to be installed without the -L option.
  9. Run the QuickUMLS server via CLI

    master

    You can start a QuickUMLS server from the command line to provide UMLS concept matching services over a network. The server requires the path to your QuickUMLS data files and accepts various configuration options for similarity thresholds, matching criteria, and server networking.

    # Example command to run the server
    python -m quickumls.server /path/to/quickumls_data --host 0.0.0.0 --port 4645 --threshold 0.8