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

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

Uploaded CPython 3.10Windows x86-64

phrank_py-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl (744.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

phrank_py-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (668.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: phrank_py-0.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 533.4 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.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4b8340755a7105733056d8d15300e5aceae6a3dfc81fada67244c1941f30b2d0
MD5 e4ee7717e0c77b04a2aeaec6e46e277d
BLAKE2b-256 d044b5ba885d7606cd481ba29be42b9d8690be5641a592b292435d00c900d820

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1f3637642893a4606ec12e62785a460b13e7ff8d421ab9ddd6f5db90377e3a5b
MD5 60bcc4bf19e4b6d10f206a4a3d96bef8
BLAKE2b-256 e4452a99dc7d0b28fdae5b795b6ed8b7e30c331a1907589fcd9a82488de19838

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 25edbedf55be47f331f023c83e02ad8c361859b9ae467674e6d0fda1293fd1b8
MD5 9bd87e5cf52e4fbf2559fa7f524a243c
BLAKE2b-256 0ad0aac516497bf4dd55520179bed88ce1c0cdbdf856a6e5f74a308a20b78b04

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