Skip to main content

An ontology base similarity algorithm for patient wise similarity. Has been originally published by Karthik A. Jagadeesh 2018. It uses Rust under the hood.

Project description

Phrank Python Bindings (phrank_py)

phrank_py provides Python bindings for the Phrank similarity engine. It is a high-performance, phenotype-driven similarity engine that calculates the structural similarity between patient cohorts using Information Content (IC) derived from an underlying ontology.

By wrapping the core Rust implementation, phrank_py delivers the performance of Rust's parallelization combined with zero-copy memory transfers directly into Python's SciPy ecosystem.

🚀 Key Features

High Performance: Leverages Rust's multithreading to compute pairwise similarity matrices rapidly.

Zero-Copy SciPy Integration: Returns the similarity matrix directly as a scipy.sparse.csr_matrix without duplicating large arrays in memory.

Phenopacket Compatible: Easily parses standard Phenopacket JSON files to build feature dictionaries.

🛠 Getting Started

Prerequisites You will need the scipy package installed to handle the sparse matrix output. If you are parsing Phenopackets, ensure you have the appropriate protobuf/JSON parsers installed.

Example Usage The following example demonstrates how to load an ontology, parse a directory of Phenopacket JSON files, and compute a similarity matrix for the entire cohort.

import os
from pathlib import Path
from google.protobuf.json_format import Parse
from phenopackets import Phenopacket
from phrank_py import PyPhrank

# 1. Initialize the Phrank Engine with your ontology JSON
phrank = PyPhrank("./hp.json", cache_size=1500, normalize=false)

# 2. Load your patient cohort (e.g., from a directory of Phenopackets)
pp_dir = Path(os.path.expanduser("./phenopackets"))
cohort: list[Phenopacket] = [
Parse(json_file.read_text(encoding="utf-8"), Phenopacket())
for json_file in pp_dir.glob("*.json")
]

# 3. Map Patient IDs to a list of their phenotypic feature IDs
id_by_feature_id = {
pp.id: list({pt.type.id for pt in pp.phenotypic_features})
for pp in cohort
}

# 4. Calculate the similarity matrix
# Returns a SciPy CSR matrix and a mapping of matrix indices to Patient IDs
matrix, mapping = phrank.calculate_similarity(id_by_feature_id)

print(f"Generated sparse matrix of shape: {matrix.shape}")

Credit

Original Publication by Karthik A. Jagadeesh et al. here

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

phrank_py-0.2.9-cp310-cp310-win_amd64.whl (543.5 kB view details)

Uploaded CPython 3.10Windows x86-64

phrank_py-0.2.9-cp310-cp310-manylinux_2_34_x86_64.whl (751.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

phrank_py-0.2.9-cp310-cp310-macosx_11_0_arm64.whl (670.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file phrank_py-0.2.9-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: phrank_py-0.2.9-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 543.5 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for phrank_py-0.2.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 db97dfc3c85fa6b91ae2e832280e75638f93745649b5c69a590d109c59800fb0
MD5 f7bdae2e74888ae1b05c2e905c7dcd8a
BLAKE2b-256 c4e0662f69b83dd99fdf318d26f59f2348f50a251d17be79d53963b5c1a36730

See more details on using hashes here.

File details

Details for the file phrank_py-0.2.9-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for phrank_py-0.2.9-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 cbf617ee1fb92072f91df791c289c243ac490e9923aab3be4d576ccbed1f9fcb
MD5 ebfcaf7f4cf3f66a467ed2f0f8729eef
BLAKE2b-256 70d404f2dd4f3cb4278e9ae6d947f6a20766e31506de84e36b8e488483e40c24

See more details on using hashes here.

File details

Details for the file phrank_py-0.2.9-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for phrank_py-0.2.9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8db65ee93ecee7adce5b1d71a8b76e0e209e60615f097409ebb8b2d2ab4de093
MD5 3b67a5921c034b52116546f227b63c44
BLAKE2b-256 7edad551546a6dec2d55dc729b9ffeb940ef6652b2159de03d0b547578090721

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