Skip to main content

A data science and machine learning framework for nursing research

Project description

MIMIC-IV Analysis Toolkit

License: MIT Python Version last-commit repo-top-language

Unlock Insights from Healthcare Data Effortlessly

A comprehensive analytical toolkit for exploring and modeling data from the MIMIC-IV clinical database. This project provides tools for data loading, preprocessing, feature engineering, clustering, and visualization, primarily focusing on provider order pattern analysis.

Table of Contents

About MIMIC-IV Data

This toolkit is designed to analyze data from the MIMIC-IV (Medical Information Mart for Intensive Care IV) clinical database. MIMIC-IV is a large, freely-available database comprising de-identified health-related data associated with patients who stayed in critical care units at the Beth Israel Deaconess Medical Center.

For detailed information on the MIMIC-IV data structure used by this project, please refer to the documentation:

Features

  • Comprehensive Data Loader: Utilities for loading and preparing MIMIC-IV data, simplifying the process of loading and preprocessing MIMIC-IV datasets, addressing common data management challenges. Supports both CSV and Parquet formats, with options for Dask integration for large datasets.
  • Interactive Visualization: A Streamlit application for visualizing data, cluster results, and analysis. Utilizes Streamlit for real-time data exploration, enhancing user engagement and understanding of complex datasets.
  • Feature Engineering Tools: Tools for creating meaningful features from clinical temporal data, including order frequency matrices, temporal order sequences, and order timing features. Provides utilities for identifying and extracting relevant features, streamlining the data preparation process.
  • Clustering Analysis Capabilities: Implementations for K-Means, Hierarchical, DBSCAN clustering, and LDA Topic Modeling to identify patterns in clinical data.
  • Predictive Modeling Support: Designed to prepare data for various predictive tasks.
  • Configuration Management: Easy-to-use YAML configuration for managing data paths and application settings.
  • MIMIC-IV Data Focus: Specifically designed to work with the MIMIC-IV clinical database structure.
  • Modular Architecture: Facilitates easy updates and maintenance, promoting a seamless development experience.
  • Exploratory Data Analysis
  • Patient Trajectory Visualization
  • Order Pattern Analysis

Project Structure

The repository is organized as follows:

mimic_iv_analysis/
├── mimic_iv_analysis/ # Main package source code
│   ├── __init__.py # Package initialization
│   ├── configurations/ # Configuration files (e.g., config.yaml)
│   ├── core/ # Core functionalities (data loading, clustering, feature engineering)
│   │   ├── __init__.py
│   │   ├── clustering.py
│   │   ├── data_loader.py
│   │   ├── feature_engineering.py
│   │   └── filtering.py
│   ├── examples/ # Example scripts and notebooks
│   └── visualization/ # Streamlit dashboard application and utilities
│       ├── __init__.py
│       ├── app.py
│       └── app_components/
├── documentations/ # Project documentation
├── scripts/ # Utility and helper scripts (install, run dashboard)
├── setup_config/ # Configuration for setup and testing (e.g., pytest.ini)
├── tests/ # Test suite for the project
├── .streamlit/ # Configuration for Streamlit Cloud deployment
├── README.md # This file
├── requirements.txt # Python package dependencies
└── setup.py # Package setup script

(Note: The src/ directory mentioned in one of the older READMEs is now represented by the top-level mimic_iv_analysis/ package directory for source code.)

Installation

Prerequisites

  • Python 3.12 or higher
  • pip or conda package manager

Installation Steps

  1. Clone the repository:

    git clone https://github.com/artinmajdi/mimic_iv_analysis.git
    cd mimic_iv_analysis
    
  2. Create a virtual environment (recommended):

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install dependencies: The requirements.txt file lists all necessary Python packages.

    pip install -r requirements.txt
    

    To install the package in editable mode along with development dependencies:

    pip install -e ".[dev]"
    

    Alternatively, you can use the provided installation script which offers environment choices (venv, conda, docker):

    bash scripts/install.sh
    

Configuration

The main configuration for the application is located in mimic_iv_analysis/configurations/config.yaml.

You must update the mimic_data_path in this file to point to the root directory of your local MIMIC-IV dataset (version 3.1 or compatible).

Example config.yaml structure:

data:
  mimic_data_path: "/path/to/your/mimic-iv-data" # <-- IMPORTANT: Update this path

app:
  port: 8501
  theme: "light"
  debug: false

# ... other configurations

Usage

Running the Streamlit Dashboard

  1. Ensure your virtual environment is activated (if you created one).
  2. Make sure you have configured the mimic_data_path in config.yaml.
  3. Run the application using:
    streamlit run mimic_iv_analysis/visualization/app.py
    
    Alternatively, if the package was installed using pip (e.g., via pip install -e . or from PyPI), you might be able to use a command like:
    mimic-iv
    

The dashboard should open in your web browser, typically at http://localhost:8501 (or the port specified in config.yaml).

Install the package from TestPyPI (Example for version 0.5.8)

If a version is available on TestPyPI, you can install it using:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ mimic_iv_analysis==0.5.8

(Replace 0.5.8 with the desired version if applicable.)

Core Modules Overview

  • mimic_iv_analysis.core: Contains the fundamental logic for data handling and analysis.
    • data_loader.py: Utilities for loading MIMIC-IV tables efficiently, supporting both CSV and Parquet formats, with options for Dask integration for large datasets.
    • feature_engineering.py: Tools to create meaningful features from raw clinical data, such as order frequencies and temporal sequences.
    • clustering.py: Implements various clustering algorithms (K-Means, Hierarchical, DBSCAN) and LDA topic modeling.
    • filtering.py: Enables applying inclusion and exclusion criteria to the dataset.
  • mimic_iv_analysis.visualization: Houses the Streamlit application.
    • app.py: The main entry point for the interactive dashboard.
    • app_components/: Contains different tabs and UI elements of the dashboard.
  • mimic_iv_analysis.configurations: Manages application settings.

Development

Code Style

This project uses the following tools to maintain code quality:

  • Black: For code formatting.
  • isort: For import sorting.
  • Flake8: For style guide enforcement (PEP 8).
  • MyPy: For static type checking.

To format your code:

black .
isort .

To check your code:

flake8 .
mypy .

Running Tests

Tests are located in the tests/ directory. To run the test suite:

pytest tests/

To run tests with coverage:

pytest --cov=mimic_iv_analysis tests/

Test configuration can be found in setup_config/pytest.ini (or pytest.ini / pyproject.toml depending on project setup).

Documentation

Further documentation can be found in the documentations/ directory:

  • DATA_STRUCTURE.md: Describes the expected structure of the MIMIC-IV data.
  • mimic_iv_data_structure.md: Provides an overview of MIMIC-IV tables and identifiers.
  • .streamlit/README.md: Guide for deploying the Streamlit application to Streamlit Cloud.
  • The documentations/pyhealth/ directory contains documentation for the PyHealth library, which might be a dependency or a related project.

Streamlit Cloud Deployment

For deploying the dashboard to Streamlit Cloud, refer to the guide in .streamlit/README.md. This includes steps for repository preparation, secret management, and dependency configuration.

Contributing

Contributions are welcome! Please follow these general steps:

  1. Fork the repository.
  2. Create a new feature branch (git checkout -b feature/your-feature-name).
  3. Make your changes.
  4. Ensure all tests pass (pytest tests/).
  5. Format your code (black . and isort .).
  6. Submit a pull request with a clear description of your changes.

License

This project is licensed under the MIT License. See the LICENSE.md file for details.

Author

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mimic_iv_analysis-1.3.0.tar.gz (191.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mimic_iv_analysis-1.3.0-py3-none-any.whl (203.2 kB view details)

Uploaded Python 3

File details

Details for the file mimic_iv_analysis-1.3.0.tar.gz.

File metadata

  • Download URL: mimic_iv_analysis-1.3.0.tar.gz
  • Upload date:
  • Size: 191.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for mimic_iv_analysis-1.3.0.tar.gz
Algorithm Hash digest
SHA256 7c00277381398eb2c415fa05e84a27671ed0d29a3788c1e2e5c81727057c8b23
MD5 05b53a9d05c185080f108a67a291cd36
BLAKE2b-256 41d98e91f70195cefe1e07565b460746166340b03c62b49a60a60b5f9815e34a

See more details on using hashes here.

File details

Details for the file mimic_iv_analysis-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mimic_iv_analysis-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d87cee97596cc0b59f37b0b563916cbf2fd8db05da7cbddc3db7e09f8b80c97
MD5 f657825df8dda92ee1cacc524b2c24c2
BLAKE2b-256 264119fa02636cbb388df0e6c437d287fce54c0688cd2283b73cd49aaa199d67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page