Skip to main content

polars-mas

A fast Python library for multiple association studies, built on Polars.

polars-mas is designed as a drop-in replacement for the R PheWAS package, providing 3-14x speedup while producing numerically identical results (within 1e-8 tolerance).

Features

  • Fast: Leverages Polars for efficient data processing with multi-threaded computation
  • Accurate: Produces results identical to the R PheWAS package
  • Flexible: Supports multiple regression models and input/output formats
  • PheCode-aware: Built-in PheCode definitions and sex-specific code handling

Supported Models

Model Use Case Flag
Firth logistic regression Binary outcomes (default) -m firth
Standard logistic regression Binary outcomes -m logistic
Linear regression Quantitative outcomes -m linear

Supported Formats

  • Input: Parquet, CSV, TSV, TXT (tab-delimited)
  • Output: Parquet, CSV, TSV, TXT

Installation

pip install polars-mas

Or with uv:

uv add polars-mas

Quick Start

Basic Usage

polars-mas \
  -i data.csv \
  -o results \
  -p exposure \
  -d i:10- \
  -c age,sex,bmi

This runs Firth logistic regression with:

  • exposure as the predictor
  • Columns 10 onwards as dependent variables (phecodes)
  • age, sex, bmi as covariates

PheWAS Analysis

polars-mas \
  -i phewas_data.parquet \
  -o phewas_results \
  -p genetic_variant \
  -d i:20-1850 \
  -c age,sex,pc1,pc2,pc3 \
  --phewas \
  -n 4 \
  -t 8

The --phewas flag enables automatic PheCode annotation in results.

CLI Reference

polars-mas [OPTIONS]

Input Options:
  -i, --input PATH              Input file (parquet, csv, tsv, txt)
  -o, --output PATH             Output file prefix
  -p, --predictors COLS         Predictor columns (comma-separated)
  -d, --dependents COLS         Dependent columns (comma-separated)
  -c, --covariates COLS         Covariate columns (comma-separated)
  -cc, --categorical-covariates Categorical covariate columns
  -nv, --null-values VALUES     Values to treat as null (comma-separated)
  -ot, --output-type TYPE       Output format: parquet, csv, tsv, txt

Association Parameters:
  -m, --model MODEL             firth (default), logistic, or linear
  -mc, --min-case-count N       Minimum cases/controls required (default: 20)
  -mcv, --missing-covariate-values
                                How to handle missing covariates:
                                fail, drop, forward, backward, min, max, mean, zero, one
  -qt, --quantitative           Dependent variables are quantitative

Performance:
  -n, --num-workers N           Number of worker processes (default: 1)
  -t, --threads N               Threads per worker (default: 2)

PheCode Options:
  --phewas                      PheCodes are dependent variables
  --flipwas                     PheCodes are predictor variables
  --sex-col COL                 Sex column name (default: sex)
  --female-code N               Code for female (default: 1)
  --male-only                   Include only male samples
  --female-only                 Include only female samples

Other:
  --dry-run                     Show configuration without running
  -v, --verbose                 Enable verbose logging
  -q, --quiet                   Suppress most output

Column Selection

Columns can be specified by name or index:

# By name in comma-separated list
-p age,sex,bmi

# By index (0-based)
-d i:10          # Column 10
-d i:10-20       # Columns 10-19
-d i:10-         # Column 10 to end

# Can be used in conjuction as well!
-c age,sex,i:8-12

Output

Results include:

Column Description
predictor Predictor variable name
dependent Dependent variable name
pval P-value (LRT for Firth)
beta Coefficient estimate
se Standard error
OR Odds ratio (logistic models)
ci_low, ci_high 95% confidence interval
cases, controls Sample counts (binary outcomes)
converged Model convergence status
bonferroni_significant Bonferroni-corrected significance
phenotype, category PheCode annotations (if --phewas)

Performance

See the benchmarks for detailed comparisons against the R PheWAS package.

Summary: polars-mas achieves 3-14x speedup depending on the number of covariates, with identical numerical results.

Current Limitations

The following features from the R PheWAS package are not yet implemented:

  • Multiple testing correction: Only Bonferroni correction is available (FDR/BH planned)
  • Variable transformations: RINT and log transformations are not yet functional
  • Covariate scaling: Standard and min-max scaling not yet implemented
  • Parallel workers: Currently works best with one polars worker; -n flag reserved for future use. More threads with the -t option is fine.
  • Python API: Only CLI interface is currently documented; programmatic API in development

Roadmap

Planned features for future releases:

  • FDR (Benjamini-Hochberg) multiple testing correction
  • Rank-based inverse normal transformation (RINT)
  • Log transformation for dependent variables
  • Covariate standardization options
  • True parallel processing with multiple workers
  • Python API with DataFrame input/output
  • Manhattan and QQ plot generation
  • ICD-to-PheCode mapping utilities

Requirements

  • Python >= 3.11
  • polars >= 1.9.0
  • firthmodels >= 0.4.0
  • statsmodels >= 0.14.4

License

MIT

Citation

If you use polars-mas in your research, please cite:

polars-mas: A fast Python library for multiple association studies
https://github.com/PheWAS/polars-mas

Metadata

Release files for polars-mas 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polars-mas 0.5.0
File Size Uploaded Provenance Actions
polars_mas-0.5.0.tar.gz 922.9 kB Without provenance Details for polars_mas-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polars-mas 0.5.0
File Interpreter ABI Platform Actions
polars_mas-0.5.0-py3-none-any.whl Python 3 none any Details for polars_mas-0.5.0-py3-none-any.whl

Total release size: 1.1 MB

Release files / polars_mas-0.5.0.tar.gz

Download URL polars_mas-0.5.0.tar.gz
Size 922.9 kB
Tags Source
SHA-256 checksum
How to use checksums
49d1f48c4e1b684ff082283f707ad1026277ad7a3de6066cfa0afeaaafc9fad8
BLAKE2b-256 checksum
How to use checksums
a2723f8c8c0ea819d1da01458b568c032aa4a404d900a9c741a226fa9e32b7b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / polars_mas-0.5.0-py3-none-any.whl

Download URL polars_mas-0.5.0-py3-none-any.whl
Size 187.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
541c14bfd1ddddb19d4c66a15a5fa7299b417b53d7ee0d7d60d67906aaaff829
BLAKE2b-256 checksum
How to use checksums
f49ea12c77aef72b7d9bfcd010eb761e904132dfc511e3e2de278dc6c88e1834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for polars-mas 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page