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

Uploaded CPython 3.13Windows x86-64

phrank_py-0.2.13-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.13-cp313-cp313-macosx_11_0_arm64.whl (961.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

phrank_py-0.2.13-cp312-cp312-win_amd64.whl (833.8 kB view details)

Uploaded CPython 3.12Windows x86-64

phrank_py-0.2.13-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.13-cp312-cp312-macosx_11_0_arm64.whl (961.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

phrank_py-0.2.13-cp311-cp311-win_amd64.whl (836.4 kB view details)

Uploaded CPython 3.11Windows x86-64

phrank_py-0.2.13-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.13-cp311-cp311-macosx_11_0_arm64.whl (967.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

phrank_py-0.2.13-cp310-cp310-win_amd64.whl (836.4 kB view details)

Uploaded CPython 3.10Windows x86-64

phrank_py-0.2.13-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.13-cp310-cp310-macosx_11_0_arm64.whl (967.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: phrank_py-0.2.13-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 833.9 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.13-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e2e4dc8f84ce1dac204906a0c33d57e2880406d0e517646dabb691dc21548108
MD5 56ca041ab78717f841066c3c2d5aefc0
BLAKE2b-256 09c0172185b1958634a13ca98dfc5a8544b727b4c621cd48b671f79c97b464d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.13-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 878c4d3056f1f0c43007f50c0c1042face2395318dea45289768c88d59881f88
MD5 3a46415eab14b6033ae55a4d474add7a
BLAKE2b-256 c9bef4fec11a1f555e6d76e17a2badf4ea3d929cac966d79a76a3ff7b387cdfe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.13-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f52df8e5e5661b704a8cf3112fe76455d8248dc77600d85b60e689499df865c
MD5 e83979c5d5964789e365528e5fa0490f
BLAKE2b-256 0f8bb9269ed4f40116aaeb9d85bf30a983737c9e896a8e21b2dbd16892e3ae04

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.13-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 833.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.13-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 39b260e70edff527171abb186cab248afdd7d3da3e28d8df1969f07531dcd70c
MD5 e8007142287359afa00397dc7ccc90ba
BLAKE2b-256 247aee8c353177333de13f6dde40b87e7c02a6944aef691ee0cb063d097973ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.13-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 177fb769c1a874a0b7031298a9838add8c0b64b48327be09fd98c8e62c73c7f8
MD5 5bec8600fd2bdeb756464eb06594bdc5
BLAKE2b-256 a49ea9872c8cca8cac64166e9bb07de6833f89ac3df6a204432ca06bfa8d8a1c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.13-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aee97005acd6c3ce34de4cc21f30c7f96679f61b9a3990bfc9d2e5336a7c5b3a
MD5 804272db08a93cabbccb65285f82b8cb
BLAKE2b-256 8faaeb8be5fd064a41119b58e4e625c10b560dafdf8e8574a0a5d8da98266a90

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.13-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 836.4 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.13-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4a2d2dbd5bdfcca3758e639288e5095341dbf0b9704d27715ae0f5bfdff0c3af
MD5 af182bfaa29ddd738c588b25c4f48989
BLAKE2b-256 6ed261ebb3e696bda72c3e9a8011e148f0568c7e280d46d545cdf3ae97a256b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.13-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3bd09a0fa930405fa0481bc32790077b80eb2e4a0e7750b2e406a88e59f77388
MD5 b0958415293bbed9d61dba601a3af826
BLAKE2b-256 7676a55b448afe43e973f0218b365786eaac5ac4ed6546c49348f5d6f9ceb080

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.13-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ef1f4c4c4bf361d95b00830a3284b3fbe0f3417826be092b7d0bb4acb07ea9b
MD5 470b152b214dcac94f9139dd554354e9
BLAKE2b-256 f516e603161dfb213596ef42c74e1c1970cd7d2117e77e180c7c536bbcb6e988

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.13-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 836.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.2.13-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a12389c0e58c5fec118fa6b5b56d11bcad866b7876ea6622eece60ad7803e471
MD5 301312d69e6aaaa2ebf35f03a9f96d91
BLAKE2b-256 317313b24038471ca415d72a70e1a16a8e913e3e8d53cefec804c6034c40da9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.13-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9ad084efdcdbb6beb37a3fd50a2af3906acd199f783a102e1776a50f17a87794
MD5 2781bb349b28a8661accee4c5c54e239
BLAKE2b-256 aa04e4597edbc3c907e290293caf3b0b07238bc11175239b449cb7011921abb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.13-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 95351008b7cb0005e9a89475e35167a6fcf16baeb205dfd7cd1b3a9eb9a333f4
MD5 29816126e7f234c4a276bc33dc7bc992
BLAKE2b-256 42ede94a52016531a4cb079073c8c0387479a8a5b4042de6ebdbb8c5761c812c

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