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.10-cp313-cp313-win_amd64.whl (542.4 kB view details)

Uploaded CPython 3.13Windows x86-64

phrank_py-0.2.10-cp313-cp313-manylinux_2_34_x86_64.whl (748.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

phrank_py-0.2.10-cp313-cp313-macosx_11_0_arm64.whl (669.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

phrank_py-0.2.10-cp312-cp312-win_amd64.whl (542.8 kB view details)

Uploaded CPython 3.12Windows x86-64

phrank_py-0.2.10-cp312-cp312-manylinux_2_34_x86_64.whl (749.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

phrank_py-0.2.10-cp312-cp312-macosx_11_0_arm64.whl (669.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

phrank_py-0.2.10-cp311-cp311-win_amd64.whl (543.8 kB view details)

Uploaded CPython 3.11Windows x86-64

phrank_py-0.2.10-cp311-cp311-manylinux_2_34_x86_64.whl (752.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

phrank_py-0.2.10-cp311-cp311-macosx_11_0_arm64.whl (671.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

phrank_py-0.2.10-cp310-cp310-win_amd64.whl (543.7 kB view details)

Uploaded CPython 3.10Windows x86-64

phrank_py-0.2.10-cp310-cp310-manylinux_2_34_x86_64.whl (751.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

phrank_py-0.2.10-cp310-cp310-macosx_11_0_arm64.whl (671.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file phrank_py-0.2.10-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: phrank_py-0.2.10-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 542.4 kB
  • Tags: CPython 3.13, 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.10-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1322081bde2a43f908c4b6ff2005ae8f649b4e3e8bbe0b5b3d141316151c0373
MD5 0858c6d17572b2dead198bd0ff4182d9
BLAKE2b-256 dbe25cf6c43c5e69268064b607b75e6d7a3d2e520c13cda379ef9f0ee1759bca

See more details on using hashes here.

File details

Details for the file phrank_py-0.2.10-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for phrank_py-0.2.10-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b77f9125f895510a8864eeac5c144ab8f4d5ba607304b1f6c90626ee6ac538fb
MD5 15eb8ce218fe9af5f10ce8494568cc22
BLAKE2b-256 0595576915938990fe915fb3b1dfdf0f2f4b650384618b75a1e94ca8aae54a7c

See more details on using hashes here.

File details

Details for the file phrank_py-0.2.10-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for phrank_py-0.2.10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e76807d8c12e1a75915fd1712f83475801bd706c94c4c8a5ec3abc87bc8bb81
MD5 921d28280e9223a736c02c8ac7dbe342
BLAKE2b-256 c87282fbdcfd1ac43073777f9eeb2317c9009f576cd511e0837d08ecf24eea46

See more details on using hashes here.

File details

Details for the file phrank_py-0.2.10-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: phrank_py-0.2.10-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 542.8 kB
  • Tags: CPython 3.12, 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.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b5aaf1ace2b0c7df3285ad32690f63b7a375395cfc5c8f64be48e18e4a5429a5
MD5 8ca7da907bd4e68579a95063f737a895
BLAKE2b-256 a3aa9a903f5984879d6cf4270a103082817c3130bbef3d7dd392763b761601d1

See more details on using hashes here.

File details

Details for the file phrank_py-0.2.10-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for phrank_py-0.2.10-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 112ee4909580a4208ef8dfbcc2723db27b517bcfc6d15728b32350d78961490f
MD5 3b545abb549beca4750716a2246a3707
BLAKE2b-256 f285ced683e09ad2135768dfec0d8c462f94e0827b0280c4167ac9d9a7d4527a

See more details on using hashes here.

File details

Details for the file phrank_py-0.2.10-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for phrank_py-0.2.10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a7151a096d917a07d207a913f469195913c9aa052f6613e4a7aa70a028188e69
MD5 cf85791a1c3b783ecb88798389fd773c
BLAKE2b-256 f55b9f2b5de4777bc60ce0bc16506b91a16a4222073fe3fe66bb9ae9b97bde57

See more details on using hashes here.

File details

Details for the file phrank_py-0.2.10-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: phrank_py-0.2.10-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 543.8 kB
  • Tags: CPython 3.11, 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.10-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b5b269cc1373c21dc8ec7ecb9dd0a5ec937fad6bbec8b2823740fb51d3d32e71
MD5 a87c1df48a03dee5a74f338210c30608
BLAKE2b-256 a09856dbb4e41badad3095b47b1436a41c0c0946e2eca2ee303a1cf627027982

See more details on using hashes here.

File details

Details for the file phrank_py-0.2.10-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for phrank_py-0.2.10-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 74c22858149f6b75ae8e23ebb3d84e8c5b8b840e2fda65a8250930adab0f03ca
MD5 4e6969283aba85fc4f18f6180c179b01
BLAKE2b-256 aabf7f379d26a35704674cb56f0b208c0b597c10ba513db855db15928587ec5d

See more details on using hashes here.

File details

Details for the file phrank_py-0.2.10-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for phrank_py-0.2.10-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e888a0aaaa8701aceeb35adbfa7cc50c9cd7a77cc71ef4703b4ef94e789c133e
MD5 ef9dc18c00b689c0e487804bc0207d13
BLAKE2b-256 d7fbcea593131d60e05dbd3b4cd70a602fd1d4a3e7630b5d4dceb26daa2b37e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.10-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 543.7 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.10-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e9cd5e470411b6f2107e4a1d1e26a5c6060d9d9754e5557587b15a02323ffa86
MD5 e4dbeb6d227551d8c86c71d5538592b7
BLAKE2b-256 455f0f84daf5f039c738d9ef4243391ae094c682a2418868ca4fd4f3941846e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.10-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3698d553f58de1c992cd0e91ec83b199aded016be826230a89e89e356685ffd2
MD5 aead8c46655dcf36e5bcba59e1d74dbb
BLAKE2b-256 137248aac581a9fd437699ba4904790d66dfd0d5515dbb9c25c11e13f7d00be4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.10-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a058f1b826d13c805f79a319baa7f55acfe900e0341c7a18edf96c42bd4691ca
MD5 15f6b20b6a24cfbf8e0d212b35153136
BLAKE2b-256 411da3aa350e846be355b673d13540144d0d2932f8b677cc342416dcf12d35e5

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