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)

# 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}")

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.7-cp310-cp310-win_amd64.whl (528.6 kB view details)

Uploaded CPython 3.10Windows x86-64

phrank_py-0.2.7-cp310-cp310-manylinux_2_34_x86_64.whl (729.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

phrank_py-0.2.7-cp310-cp310-macosx_11_0_arm64.whl (654.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: phrank_py-0.2.7-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 528.6 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.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 225e6bbdf995a605ab6fd4a205fcd826b272417c7477ad3cb41424576aefb064
MD5 69dbd0bd4771e1fa41d527629f99af9d
BLAKE2b-256 64a9d140adf2bb741200a03b9428c8efe551dc047ed81bb49a081871bf16b8bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.7-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1be86ea1df3d4e66857471070e086996754001629e37477ede5128689a2175cf
MD5 781e33d6fe9bc310607ab6c389c68136
BLAKE2b-256 a1f4a309a9ee93fade7e93ea0da81a46d3f05cbbb9926a74bcc36d4dbe1af940

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 977358e89efc10b425310510fbd3b7a17697a933fe4a196faa77e369b6af89f2
MD5 4031189f911bc198268edfa01394ba3e
BLAKE2b-256 9dcdae63b15e001435a86dd8a2046a7e4282645e8a562741d162ea97c20862f2

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