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, CohortEntity

# 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
cohort_entities = [
    CohortEntity(pp.id, pt.type.id)
    for pp in cohort
    for pt in pp.phenotypic_features 
]

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

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

Uploaded CPython 3.13Windows x86-64

phrank_py-0.2.12-cp313-cp313-manylinux_2_34_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

phrank_py-0.2.12-cp313-cp313-macosx_11_0_arm64.whl (958.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

phrank_py-0.2.12-cp312-cp312-win_amd64.whl (835.2 kB view details)

Uploaded CPython 3.12Windows x86-64

phrank_py-0.2.12-cp312-cp312-manylinux_2_34_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

phrank_py-0.2.12-cp312-cp312-macosx_11_0_arm64.whl (958.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

phrank_py-0.2.12-cp311-cp311-win_amd64.whl (836.5 kB view details)

Uploaded CPython 3.11Windows x86-64

phrank_py-0.2.12-cp311-cp311-manylinux_2_34_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

phrank_py-0.2.12-cp311-cp311-macosx_11_0_arm64.whl (962.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

phrank_py-0.2.12-cp310-cp310-win_amd64.whl (836.8 kB view details)

Uploaded CPython 3.10Windows x86-64

phrank_py-0.2.12-cp310-cp310-manylinux_2_34_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

phrank_py-0.2.12-cp310-cp310-macosx_11_0_arm64.whl (962.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: phrank_py-0.2.12-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 835.1 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.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d7352429735c10f86a118efdcc9f1a9eccaefb1a08d936815272961a60e6f439
MD5 b780d9f59f0c3e830446e2af3a3323f0
BLAKE2b-256 9efc99fd8a8ec4186c4c46a8db72e9b18d84453b8f0a6a46c27216aaa0e2554b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.12-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 003f355a399efcc4b9f4839bd13c67fe3fbf03348faa248c491b5dbffb132f2b
MD5 1317908c30e9771236afde83d5875c76
BLAKE2b-256 4cdf87d7e154a54d93a97adcccf7eaa3314791eaa02a0353a98825b17d69e238

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.12-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 248d8463d7eb3182437285ad5489ab8684966e3b87e70b088f45f59813d49e97
MD5 1ab81be7bd98c958abee051e69529810
BLAKE2b-256 acce7fc72256626b69bd81cc994b092fff172a1e7b3a4609560c2d7a83df1162

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.12-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 835.2 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.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a13bc111959b29313f62cf0b9ee24a3b46f4805c57b899e22c751f08507784a4
MD5 b5cfbe7564f8d5d7f55f1c4596d6cbe6
BLAKE2b-256 8f63adcdbbc1780f78331e8425bc808ae50b9460b8b8e6d4a4b55b7fd14c0502

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.12-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 fce377035c56daf3929612876f5902f33a4040d3eb53d499d8efab1edf86d1bf
MD5 5a3b77a93f3b96004822698af1b75518
BLAKE2b-256 590afbaac94709319b20f6dd08bc686d5efc612e8337ed9609c6d7c542e52e17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa07f12c9001357c5ead7d98809253137165eb80fb7d35730fb82d42bab7556c
MD5 9af21f6b13b70777e758eb61a93a4087
BLAKE2b-256 67eb44131b786d42d99cb6cb4840d60436c82daf043d2b78cb34eb90ba82949b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.12-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 836.5 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.12-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 da450cbfdc0b0a3d8633edea9835e72c6c0c86987835380d39363e01cce5521f
MD5 7246adb3214acb30a85315e99f2c985b
BLAKE2b-256 95fcc0226231a8179f00694fb71c82b6e02b84f7e3d943205abce00ff79c808f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.12-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 038be655e700375fc6156143127f1e16a50f8716d5a5ce146dcf9aff14781cd5
MD5 34ce427233ad64544f412f64c84f29a1
BLAKE2b-256 6d18499e2391e4070f457db219c16e09b82e853169cd0a785e424103b887791b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.12-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e86656f9e9588f5a84453777898627ed582ee24e4952a355aff41176c6e7a7b7
MD5 f609090cd2f3b264ad3e9ceb8f8da5d3
BLAKE2b-256 402d46acd918642956ca3bf0e0a5dc8e401a7a296be7f60f4b95e76bf44a44e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.12-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 836.8 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.12-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ea0e4c076ef6c6c6e9c3f94e32f6a7bb4ee292cd3e24a65aa6dbebd183260c58
MD5 5c149b4b2ff39a28e39ed3cfb2155776
BLAKE2b-256 be1ea7dfecc1021993c07a729ba68b7275c88045223745fcb7505af7da082233

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.12-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 db08a8002a73372f46fcd6b745f8b27706423a176958f2a6cf7c4b0969e1025a
MD5 975d2dcbeca34ef2e27bde4b30fef780
BLAKE2b-256 52b5bcd5e25b9db6f95e97275eccc42617656ad1b64299a222afd6212d453d5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.12-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ecfbcddde232e29ed271cb4ddec41c718b34e5edb14cf76b352f3f8d30f99e5e
MD5 bd09ba3892e48d44015aeabb970c22da
BLAKE2b-256 f54ac12085e6325526640439a78cce94a70140b46a15f5efa181af45fcfd8f09

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