Skip to main content

Port of RobustRankAggreg for robust aggregate ranking in Python.

Project description

PyRRA: Python Implementation of the RobustRankAggreg R package

Disclaimer: The PyRRA (Python Robust Rank Aggregation) project is an attempted port of the RobustRankAggreg R package (v1.2.1; cran.r-project.org/web/packages/RobustRankAggreg). PyRRA is under development and the outputs between the original R package and this Python implementation are not guaranteed to be identical. This python reimplementation is independent of the original authors and code maintainers (DOI: 10.1093/bioinformatics/btr709).

License: MIT

A Python port of the RobustRankAggreg (RRA) package for robust aggregation of ranked lists with missing/unmatched elements. PyRRA enables reproducible meta-analyses, gene integration, and other robust ranking applications right from Python.


Features

  • PyRRA is still under development
  • Robust aggregation of partial or full ranked lists (no requirement that sets overlap)
  • Ports of RRA's rankMatrix, betaScores, rhoScores, and all aggregation methods (RRA, stuart, mean, min, median, geom.mean)
  • Validated with cross-language testing against the original R package
  • Helper utilities for thresholding, multiple testing correction, and Stuart p-value computation

Installation

Suggested Conda environment:

conda env create -f environment.yml 
conda activate pyrra

Install from PyPi (recommended):

pip install pyrra

Install directly from source via pip:

pip install .

Usage

from pyrra import rank_matrix, aggregate_ranks

# A list of ranked gene symbols (or any unique items)
glists = [
    ['b', 'c', 'd', 'a'],
    ['h', 'b', 'f', 'e', 'd', 'c', 'g', 'a', 'j', 'i'],
    ['m', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b']
]

rank_mat = rank_matrix(glists)
print(rank_mat)
#           L1   L2   L3
# a  1.000000 0.125  NaN
# b  0.250000 0.175 0.917
# ...

# Aggregate with the default RRA method
agg = aggregate_ranks(glist=glists, method='RRA')
print(agg.head())
#     Name     Score
# 0      ...     ...

You can also pass a pandas DataFrame rank matrix to aggregate_ranks via rmat=....

Aggregation Methods

  • RRA (default)
  • stuart: Stuart-Aerts p-value
  • min, mean, median, geom.mean: Aggregate using these statistics

Advanced Arguments

  • full (default=False): Set True if all input lists are full rankings (for structural NA treatment)
  • N: Total number of rankable items (overrides default: union of elements)
  • exact (default: auto): Use exact p-value (slower, may be numerically unstable for many lists)
  • top_cutoff: Vector of cutoff values (for sensitivity when lists are truncated at different points)

API Reference

rank_matrix(glist, N=None, full=False)

  • Converts ranked lists to a normalized rank matrix.
  • Parameters:
    • glist: list of lists
    • N: total number of rankable elements (default: union of glist)
    • full: If True, treat all as full-length rankings with NA for structural gaps
  • Returns: pandas DataFrame

aggregate_ranks(glist=None, rmat=None, N=None, method='RRA', full=False, exact=None, top_cutoff=None)

  • Main aggregation method (RRA, mean, min, etc).
  • Returns: pandas DataFrame of scores, sorted.

Citing


Contributors

Elly Poretsky (@eporetsky) — Python port, test suite, data validation.


See Also


Comparison with the R implementation

For users seeking direct comparison and validation against the original R RobustRankAggreg package, see the output in compare/comprehensive_comparison.txt or follow the instructions below to run your own validations:

cd compare

# Conda environment with Python and R
conda env create -f environment.yml 
conda activate pyrra_compare
pip install pyrra

# Run tests to comparee
python comprehensive_comparison.py

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

pyrra-0.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

pyrra-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file pyrra-0.1.0.tar.gz.

File metadata

  • Download URL: pyrra-0.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyrra-0.1.0.tar.gz
Algorithm Hash digest
SHA256 22643024bfc929b1848ea8741218fa721d6646220f3f3b0382913564ae196700
MD5 b586070a73b908229685df543a083f28
BLAKE2b-256 59fde510e782733af04b46146cba9e007edcbcf1653837e546033ab740082108

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrra-0.1.0.tar.gz:

Publisher: publish.yml on eporetsky/PyRRA

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrra-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyrra-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyrra-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54f743b40acc3aff34dfc02f89ba161eb6f3c83898c0fcdb322bafc9b3029fa4
MD5 8376dfbcece6cc640a0b0c8d02227491
BLAKE2b-256 cf4f9f8589a4987bb9b97b388b79a6a36e8c642386cd9d13ab6c4579f5b9ee2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrra-0.1.0-py3-none-any.whl:

Publisher: publish.yml on eporetsky/PyRRA

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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