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

Uploaded CPython 3.10Windows x86-64

phrank_py-0.2.8-cp310-cp310-manylinux_2_34_x86_64.whl (732.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

phrank_py-0.2.8-cp310-cp310-macosx_11_0_arm64.whl (657.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: phrank_py-0.2.8-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 530.3 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.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 419011ee5c3554be9bec20a1a7d1085ea86ca1c8e1f646fc4e5699136bfec116
MD5 ed1758f023ae78980e2dcf7b58862ee8
BLAKE2b-256 1461f8e7ad945bd0f9865aaa118872097b59fded96b827275ac1e4f821f57676

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.8-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 79adc40cbd10ea2833e56b0e2de21e73a6d3b999fa8bf2575b13d1f0f51942ee
MD5 fdbf7f9ab91ea43a294547626a0c32a3
BLAKE2b-256 fded7fd57e8a3ff8331d2d07725c5f4236e0d3c1b21b64b1dbcc603642f0de40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72e3be7be73f665d9b83ecc97348244bc9bdb998665a521e9148e671141d1265
MD5 23ac62bdc0b9c756e8c3486788bf9823
BLAKE2b-256 2bdd5f9b6465e70d404de9eed86e25b224fc7d0f09d83983acee06c868f4f527

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