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

PyRRA is a Python implementation of the Robust Rank Aggregation method, ported from the RobustRankAggreg (RRA) R package. RRA enables 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 - please report bugs, missing features, or incorrect results
  • 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. Disclaimer: This is an independent Python implementation of RobustRankAggreg. Identical results are not guaranteed.


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

The comparison uses pd.testing.assert_frame_equal(py_res, r_res, check_dtype=False, atol=1e-12) to validate that Python and R outputs are numerically identical within a tolerance of 1e-12.

Total tests: 7
Passed: 7
Failed: 0

🎉 ALL TESTS PASSED! Python and R implementations are identical.

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.1.tar.gz (9.0 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.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyrra-0.1.1.tar.gz
  • Upload date:
  • Size: 9.0 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.1.tar.gz
Algorithm Hash digest
SHA256 5f871006080e845b979a8eac3cf5ba99b0b9b4a1dd3b808badcd9fe9122769f3
MD5 38300697a8b47d377b2f78ac0c95e05c
BLAKE2b-256 b10d0aced6f10da7579705a47e3ca13d91cdcfc40de615579c16f81bf01d2ce5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrra-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: pyrra-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed4e16de244c51dc4caf2dfd975ea37fee6410b6e30963cd23334e09ca2066f4
MD5 54241e70afcef5d6dbb0a23819062966
BLAKE2b-256 1aac540ec0ce499b0e82157808281423c5317299eb24c14910c6a8df67216acc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrra-0.1.1-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