Skip to main content

Python library for programmatically creating and manipulating GraphPad Prism (.pzfx) files

Project description

prismWriter

Python library and GUI for programmatically creating and manipulating GraphPad Prism (.pzfx) files. Convert pandas DataFrames into Prism's XML-based table format with complex grouping structures.

Version: 1.0.0

Features

  • Convert pandas DataFrames to GraphPad Prism format
  • Flexible grouping: main groups, sub-columns, row labels
  • Multiple interfaces: Python API, Qt GUI, and Streamlit Web interface
  • Load and modify existing .pzfx files
  • Validate table structure with preview functionality
  • Automatic backup creation when loading existing files

Installation

pip install -e .

Requirements

  • Python >= 3.7
  • numpy
  • pandas
  • PySide2 (for Qt GUI)
  • streamlit >= 1.28.0 (for web interface)
  • openpyxl (for Excel file support)

Quick Start

Python API

from prismWriter.prism_writer import PrismFile
import pandas as pd

# Create a new PrismFile
pf = PrismFile()

# Load your data
df = pd.read_csv('data.csv')

# Create a grouped table
pf.make_group_table(
    group_name="MyTable",
    group_values=df,
    groupby="condition",  # Main grouping column
    cols=["value1", "value2"],  # Data columns
    subgroupby="replicate"  # Sub-grouping
)

# Save to Prism file
pf.save("output.pzfx")

Web Interface (Streamlit)

The easiest way to use prismWriter:

streamlit run prismWriter/streamlit_app.py

Or use the provided launch script:

  • Windows: run_web.bat

Or after installation:

prismwriter-web

Features:

  • Upload CSV/Excel files (with multi-sheet Excel support)
  • Live data preview with automatic column type detection
  • Interactive grouping configuration
  • Preview table structure before generating
  • Direct download of generated .pzfx files
  • Load and view existing Prism files

Qt GUI

python prismWriter/gui.py

Or after installation:

prismwriter-gui

API Reference

PrismFile Class

pf = PrismFile(file=None)  # Create new or load existing file

Methods:

  • load(file_path, backup=True) - Load an existing Prism file
  • smake_group_table(group_name, group_values, groupby=None, cols=None, subgroupby=None, rowgroupby=None, append=True) - Create a grouped table
  • get_table_names() - Get list of all table names
  • to_dataframe(table_name) - Convert a table to pandas DataFrame
  • save(file_path) - Save to file
  • write(file_path, xml_declaration=True, encoding='utf-8', pretty_print=True) - Write with options
  • remove_table(table_name) - Remove a table from the file

Grouping Parameters

  • groupby: Main column grouping - creates separate Y-columns for each category
  • subgroupby: Sub-columns within each Y-column (string for column name, or list for data columns)
  • rowgroupby: Row labels on the vertical axis (string for column name, or list for data columns)
  • cols: Data columns to include

Note: Use either column name (subgroupby='condition') OR list of data columns (subgroupby=['col1', 'col2']) - not both.

Example Data Structure

import pandas as pd
from prismWriter.prism_writer import PrismFile

# Sample data
data = {
    'treatment': ['Control', 'Control', 'Drug A', 'Drug A'],
    'time': [0, 24, 0, 24],
    'replicate': [1, 1, 1, 1],
    'value': [10.5, 15.2, 12.1, 25.8]
}
df = pd.DataFrame(data)

# Create Prism file
pf = PrismFile()
pf.make_group_table(
    group_name="Treatment_Data",
    group_values=df,
    groupby="treatment",    # Separate columns for Control vs Drug A
    rowgroupby="time",      # Rows labeled by timepoint
    cols=["value"]          # Data column
)
pf.save("treatment_data.pzfx")

Loading Existing Files

from prismWriter.prism_writer import PrismFile

# Load existing Prism file (creates automatic backup)
pf = PrismFile()
pf.load("existing.pzfx")

# Or load directly in constructor
pf = PrismFile(file="existing.pzfx")

# Get table names
tables = pf.get_table_names()
print(f"Found tables: {tables}")

# Convert table to DataFrame
df = pf.to_dataframe("TableName")

# Add new table
pf.make_group_table(
    group_name="NewTable",
    group_values=df,
    groupby="category",
    cols=["value"]
)

# Save (use write() for more options)
pf.save("modified.pzfx")

Dependencies

  • Core: pandas, numpy
  • GUI: PySide2 (Qt bindings)
  • Web: streamlit >= 1.28.0
  • Files: openpyxl for Excel support

Project Structure

prismWriter/
├── prismWriter/
│   ├── __init__.py          # Package exports
│   ├── prism_writer.py      # Core XML generation engine
│   ├── gui.py               # PySide2 Qt GUI wrapper
│   ├── streamlit_app.py     # Streamlit web interface
│   ├── prism_template2.pzfx # XML structure template
│   └── schema/              # Prism XML schemas
├── tests/
│   ├── test_prism_writer.py
│   ├── test_gui.py
│   └── test_data.csv
├── pyproject.toml
└── README.md

Development

Running Tests

pytest tests/

Key Implementation Details

  • Uses prism_template2.pzfx as XML structure blueprint
  • XML Namespace: {http://graphpad.com/prism/Prism.htm}
  • "Raveling" strategy: transforms DataFrames into flat structure via melt(), then rebuilds into nested XML hierarchy
  • Automatic backup files created as {filename}.backup{timestamp} when loading existing files
  • Logging enabled at INFO level for debugging table creation

Known Limitations

  • No validation for duplicate table names
  • Row mismatch warnings can occur with sparse data
  • Template system hardcoded to specific Prism XML schema version
  • No undo functionality - backup files are the safety net

License

MIT License

Contributing

Contributions welcome! Please feel free to submit a Pull Request.

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

prismwriter-1.0.0.tar.gz (59.8 kB view details)

Uploaded Source

Built Distribution

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

prismwriter-1.0.0-py3-none-any.whl (55.8 kB view details)

Uploaded Python 3

File details

Details for the file prismwriter-1.0.0.tar.gz.

File metadata

  • Download URL: prismwriter-1.0.0.tar.gz
  • Upload date:
  • Size: 59.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for prismwriter-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9068322317634c62d95576414ad195cf35066c40ecd6e051a32254083cb0a6f3
MD5 f0d3fb9bc9c70051ec4f0c1f47b935ab
BLAKE2b-256 a4d4cc47440cc8d3eee28edfe42d4e31c33db26dbd0ca9dacffc8b38ef873dab

See more details on using hashes here.

File details

Details for the file prismwriter-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: prismwriter-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 55.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for prismwriter-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 703234d61a609de335bceb174336ecb68449afae870a9d5921786d0ef8b8749a
MD5 c667e55fcbb7840a58f2db349b81c7ea
BLAKE2b-256 1ff38aed667110e0932fee2a8a1724be25889da5e51dee3997b857f5737733be

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