Skip to main content

Python tools for analyzing Paper Analytical Devices (PADs) to detect and quantify pharmaceutical compounds through colorimetric analysis

Project description

PAD ML Workflow

A Python package for researchers to explore and analyze Paper Analytical Device (PAD) data, build machine learning models, and develop new analytical methods for pharmaceutical quality testing.

About PADs

Paper Analytical Devices (PADs) are low-cost diagnostic tools designed to verify pharmaceutical authenticity in low-resource settings. When a dissolved drug sample is applied to a PAD card, it produces colorimetric patterns that can be analyzed to determine drug quality and composition.

This package provides programmatic access to PAD image data collected through the PADReader mobile app and enables researchers to:

  • Explore historical PAD test data
  • Apply and evaluate machine learning models
  • Develop new analytical methods
  • Build custom ML pipelines for PAD analysis

Installation

pip install pad-analytics

Or install directly from GitHub:

pip install git+https://github.com/PaperAnalyticalDeviceND/pad-analytics.git

For development:

git clone https://github.com/PaperAnalyticalDeviceND/pad-analytics.git
cd pad-analytics
pip install -e .

Debug Mode

By default, the package suppresses technical warnings for a cleaner user experience. To enable debug output:

PAD_DEBUG=1 python your_script.py
# or
export PAD_DEBUG=1
python -c "import pad_analytics as pad; pad.predict(19208, 18)"

Note: You may see libpng error: Read Error messages during prediction - these are harmless warnings from corrupted image data on the server side and do not affect the prediction results.

Quick Start

import pad_analytics as pad

# Explore available projects
projects = pad.get_projects()
print(f"Found {len(projects)} projects")

# Get PAD test cards from a specific project
cards = pad.get_project_cards(project_name="ChemoPADNNtraining2024")

# Analyze a specific PAD card
card_data = pad.get_card(card_id=19208)
print(f"Drug tested: {card_data['sample_name'].values[0]}")
print(f"Concentration: {card_data['quantity'].values[0]} %")

# Apply a pre-trained model
actual, prediction = pad.predict(card_id=19208, model_id=18)

Key Features

1. Data Exploration

Access the complete PAD database through the OAS-compliant API:

# List all projects
projects = pad.get_projects()

# Get cards by various criteria
cards = pad.get_project_cards(project_ids=12)
cards = pad.get_card_by_sample_id(65490)

# View available ML models
models = pad.get_models()

2. Model Application

Apply pre-trained models to PAD images:

# Neural Network models (for classification)
actual, (drug_name, confidence, energy) = pad.predict(card_id=19208, model_id=16)

# PLS models (for concentration quantification)
actual_conc, predicted_conc = pad.predict(card_id=19208, model_id=18)

3. Visualization

Interactive widgets for Jupyter notebooks:

# Display PAD card with metadata
pad.show_card(card_id=19208)

# Show prediction results
pad.show_prediction(card_id=19208, model_id=18)

# Display multiple cards grouped by drug type
cards_df = pad.get_project_cards(project_name="ChemoPADNNtraining2024")
pad.show_grouped_cards(cards_df, group_column='sample_name')

Example Notebook

See notebooks/using_padml_package.ipynb for a comprehensive example of:

  • Exploring PAD projects and data
  • Applying different model types
  • Visualizing results
  • Evaluating model performance
  • Building custom analysis pipelines

Research Applications

This package supports various research activities:

For Chemistry Researchers

  • Analyze PAD performance across different drug formulations
  • Evaluate colorimetric response patterns
  • Optimize PAD card designs
  • Validate new analytical methods

For Computer Science Researchers

  • Develop new ML models for PAD analysis
  • Compare algorithm performance (NN vs PLS vs custom)
  • Implement novel image processing techniques
  • Create ensemble methods for improved accuracy

The PAD Workflow

  1. Sample Preparation: Dissolve pharmaceutical sample
  2. Application: Apply sample to PAD card
  3. Reaction: Chemical indicators produce color patterns
  4. Imaging: Capture with PADReader mobile app
  5. Analysis: ML algorithms interpret patterns
  6. Results: Determine drug identity and quality

This package focuses on steps 5-6, providing tools to analyze the collected images and develop better analytical methods.

API Documentation

Core Functions

Function Description Returns
get_projects() List all PAD projects DataFrame of projects
get_card(card_id) Get specific card data Card metadata + image URL
predict(card_id, model_id) Apply model to card (actual, prediction)
get_models() List available models DataFrame of models
show_card(card_id) Display card in notebook Interactive widget

Model Types

Neural Networks (TensorFlow Lite)

  • Purpose: Drug identification and multi-class classification
  • Output: (predicted_class, probability, energy_score)

PLS (Partial Least Squares)

  • Purpose: Concentration quantification
  • Output: predicted_concentration (float)

Requirements

  • Python >= 3.8
  • TensorFlow >= 2.13.0
  • OpenCV-Python >= 4.5.0
  • NumPy, Pandas, scikit-learn
  • ipywidgets (for notebook visualizations)

Contributing

We welcome contributions from both chemistry and computer science researchers! Please see our Contributing Guide.

Citation

If you use this package in your research, please cite:

@software{pad_analytics,
  title = {PAD Analytics: Python Tools for Paper Analytical Device Research},
  author = {Paper Analytical Device Project Team},
  institution = {University of Notre Dame},
  year = {2024},
  url = {https://github.com/PaperAnalyticalDeviceND/pad-analytics}
}

License

MIT License - see LICENSE

Links

Support

For questions about:

Security Notice

Note about Keras dependency: This package uses Keras 2.14.0 which has a known security vulnerability (CVE-2024-55459) related to the keras.utils.get_file() function. However, pad-analytics is not affected because we do not use this function in our codebase.

If you are extending this package and need to download files programmatically:

  • DO NOT use keras.utils.get_file() with untrusted URLs
  • If you must use it, add security measures to validate any downloaded files
  • Only download files from trusted sources

We plan to upgrade to Keras 3.8.0+ in a future release to eliminate this dependency concern. See Issue #2 for more details.

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

pad_analytics-0.2.0.tar.gz (5.2 MB view details)

Uploaded Source

Built Distribution

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

pad_analytics-0.2.0-py3-none-any.whl (45.7 kB view details)

Uploaded Python 3

File details

Details for the file pad_analytics-0.2.0.tar.gz.

File metadata

  • Download URL: pad_analytics-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.8

File hashes

Hashes for pad_analytics-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d1b4088dc7b3ffe3968965e7674c154022b949d62d244e28e7a1708f869b181f
MD5 f66436339fc9c4af9370733803e2d0ea
BLAKE2b-256 a2675e741105cbdd492d86cfd82a94c96f0ff37a30e3df72111beba952cb2066

See more details on using hashes here.

File details

Details for the file pad_analytics-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pad_analytics-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 45.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.8

File hashes

Hashes for pad_analytics-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe2cb8fe187960982bfb60c2464fe957977c449aeb65095a4d7629972146b88d
MD5 e63ae1ae0d1b79f91a7ef2f79ea2165c
BLAKE2b-256 a761a4df9d374b28099499d98b6df5755df17faa30e4bcf7eb5127aafb4792ce

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