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

# 1. Initialize the Phrank Engine with your ontology JSON
phrank = PyPhrank(Ontology.Json("./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.16-cp313-cp313-win_amd64.whl (837.0 kB view details)

Uploaded CPython 3.13Windows x86-64

phrank_py-0.2.16-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.16-cp313-cp313-macosx_11_0_arm64.whl (963.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

phrank_py-0.2.16-cp312-cp312-win_amd64.whl (837.2 kB view details)

Uploaded CPython 3.12Windows x86-64

phrank_py-0.2.16-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.16-cp312-cp312-macosx_11_0_arm64.whl (963.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

phrank_py-0.2.16-cp311-cp311-win_amd64.whl (837.6 kB view details)

Uploaded CPython 3.11Windows x86-64

phrank_py-0.2.16-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.16-cp311-cp311-macosx_11_0_arm64.whl (963.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

phrank_py-0.2.16-cp310-cp310-win_amd64.whl (837.6 kB view details)

Uploaded CPython 3.10Windows x86-64

phrank_py-0.2.16-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.16-cp310-cp310-macosx_11_0_arm64.whl (964.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: phrank_py-0.2.16-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 837.0 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.16-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 82c00a0951972e10623cac10c1d64aa3201d9c79b9fc8644769c6db1f667c8fe
MD5 1e58b4460d48fd5a92bcf0becde97127
BLAKE2b-256 eb9b43c510e7b0baebaae37151ae4073b1abffcaa2acb54d392e7f25b1cb0d5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.16-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a98efc8c4609dd54f007b5fa089b80e0be3f856a67601edb455806b14ccd64d3
MD5 fdf828b22abe74f61be6b03c83240f34
BLAKE2b-256 0fae9a7a45862265e9fea3474c562723c7751a74781f9e2a1376815ab8b48319

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.16-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 60d9fe0956cd5d02f014d8b3287aa93bcdc297d031cc84baac5542f85fc24417
MD5 219c3c829db2161f966147b419aac4d9
BLAKE2b-256 e590d70472501d1f8457a4ce376c15e3644d9d4ea5d620eef366f58618556c9e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.16-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 837.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.16-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 febd2a59bf5f7f1c267c07ff4cc39d766f054c436507012e0012381ac19d5624
MD5 a911720f1dc60c07d4ba68ea8fa535cc
BLAKE2b-256 cad0d0475773a93d821dd0871f52ca0c3d2244d45c73368d131e298a60c71d4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.16-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 56d3988d360e11c2bfa16bea81c2e5b7bd61c874e1f097d5aefcc19fc2c3e16f
MD5 72a88173818c34a0e1879094c72ffdf9
BLAKE2b-256 eb00196de2cc5d747f9e5c6e943efd644417d2a4d47009c03b2a63e8ab76a057

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.16-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a27a455cdde4cafc1ba38524a908161a39486659f19134c5e68ea20e930c8d00
MD5 0f9ddfae6dfcda5c882b4928f5051c79
BLAKE2b-256 5341341475882bfee4d5a19ae94375e4b3950ac3f7f98f11683f29e63b337b5a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.16-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 837.6 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.16-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f884974dd624eca26966a3ce915669a2e1e23d17169f0b9cc6c546d866c5137f
MD5 5e081104c5b832ebf70702dd699011cd
BLAKE2b-256 643ef91a184c3226f5ea694fe13295067b893034aa8600bc2aadd6717012dbda

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.16-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 41854f00168924716df5874dd242699ef559e45b14015e4ef5a33a89186037a0
MD5 bb0c26bc7129be6eb9afe62b01eefbec
BLAKE2b-256 82aa247975579542409cbc843d36de9a79d7234ce788d74ac5a64f1efda50821

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.16-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4fba2e9974ad4558d44715db66de7bba94032fdc269b62fcc0c82a20fd71e402
MD5 1c17be8193840ec106442c9d973f51b4
BLAKE2b-256 787803009f16207fe5fcb1f3a85a64ab1ee4b89a3bb936c81c6c077eab89abb8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.16-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 837.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.16-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2e81807ca9873336c0c86acc3178d2753d2c834faaf5331a21b60f6ccc4e2220
MD5 d7d8556d01bab6d6a2ef41acbeedf393
BLAKE2b-256 ea5b8f4f706d378dd44cc00bdb1404460c29fb29da686a7709d6aacf33355e7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.16-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2f5561a592368af321e1155872539b613f8f55423f5491c06fb03da238eac1bf
MD5 e9b283f97c301eda54c35e4fddea78d5
BLAKE2b-256 5c139c55c5ffce4fa3aa8662ba4c3981061c796397ff3a99aa5c0d5d6683d65c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.16-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2d82677291425acce34de9f442a1d8a9e81baa90e7f11c4cdb3e629626150b30
MD5 05685f6afb148dea0e1cdac17d193167
BLAKE2b-256 27cb2a720925c7cac42f95ca3fec85a9a7fe24be1d89ca9361c31c4979894ead

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