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

Uploaded CPython 3.13Windows x86-64

phrank_py-0.2.15-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.15-cp313-cp313-macosx_11_0_arm64.whl (962.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

phrank_py-0.2.15-cp312-cp312-win_amd64.whl (836.9 kB view details)

Uploaded CPython 3.12Windows x86-64

phrank_py-0.2.15-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.15-cp312-cp312-macosx_11_0_arm64.whl (962.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

phrank_py-0.2.15-cp311-cp311-win_amd64.whl (839.8 kB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

phrank_py-0.2.15-cp310-cp310-win_amd64.whl (839.8 kB view details)

Uploaded CPython 3.10Windows x86-64

phrank_py-0.2.15-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.15-cp310-cp310-macosx_11_0_arm64.whl (964.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: phrank_py-0.2.15-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 836.7 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.15-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 bc032300fd2e1530dbdc9d3bb21937abcbd9adb2efc2176f9ebb8a4ec6c3a03e
MD5 20a702de954d7984cd19ce6bf81eb5c3
BLAKE2b-256 277743875433e89b9f29da3557d1e2cdeb1665638c43489efa4d22f6156df5ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.15-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4f640f39f25105465fae718020c21da4e73efbdb78da68476a54a4f9a5368dcb
MD5 f05069a7963f8abb5bd5e1dcd3fd97f5
BLAKE2b-256 f75ff43c7f9f183f55715bb8721bec30d13641a5d344c47d486d45ba240648c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.15-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2e1c789cd2f9e101670ed671ff552aac6db7e7f318364d735b61d09fc13bb7ae
MD5 1ad4724f107b9b64afae0d9320bba7f2
BLAKE2b-256 466b24a989f38e227bdeeec9f0350558a557ad87ca91ddfc2eac03dde2a99689

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.15-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 836.9 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.15-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2c74359f7182c5ca7125e97b015a31cadf7d744df435ac243bba28c30b839bd7
MD5 0ae1f94f133ba49110266ed450ad0382
BLAKE2b-256 d622be6049cbc8b5a084780e02551bea656a42317da9f64fc4f8fe4ff5278233

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.15-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ca0843b85da72efd293a55985a307071648cddafa419d35146b07bf07714afb0
MD5 d87d18e7830ae6879a563caa08e4e2af
BLAKE2b-256 0bbd8234ea91498b914462c3ec38b844347afeaf84f59f58a6e0413304b81dbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.15-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f7a9a30b0e225e775e2db832fd75a90d143afad19ea000eb9ad6896c3296c87
MD5 153a16823b0e6d550b6b34b7050a3086
BLAKE2b-256 cc118ebf10b76c48e9ebaffe35be0b7ba3437e66619d4571ad48db07731c75ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.15-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 839.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.15-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 399f7ce4e8c4d9f154410d61b6929131abb478170bf4f9e7be4e73fd80a056ea
MD5 a9cf3fe3ceb0db6e5b08cfb600a127ca
BLAKE2b-256 e10cb16245ad1945977bc980e367a776370431918a159602c844338e6bb058b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.15-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5173ef00c64dba7e10f58e932341409f0ae828d75f6510b1e671b3b98b92c605
MD5 da5fa622f60452d1819c9a6a91d26765
BLAKE2b-256 e1b3b028823f2eb5933ebbc4b28887df9cc861a266eaec32a2804b7599282631

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.15-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0754330cba4b7eb20e91065f49ed8fd5ebbe9823c8a577d83dba017146a31d5d
MD5 14ac8ad7d6b7f7428c8d879b5c894b5b
BLAKE2b-256 705c10d2f5ce4b5f210d7342cc675f8c6145775a3a7dc7e27224b0e38c0ac9dc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.15-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 839.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.15-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f543a0b4bebf5d887faf1f905daaecdb87071ba2597926a62642aed59ec3653e
MD5 4b548db464263b45c63c5482f61c92ad
BLAKE2b-256 0b8a54ac69cc52de375c421fd8d2a81b3349681c971b2ba927f981a6dd7f90b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.15-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b08445eefe0ea082e9f3a65bb0154ef41928d6e772ac5dcf606e7d0b8be34909
MD5 cb0451fe2fbcca953195ba0c881d7bf4
BLAKE2b-256 288a5de87292f6c67ba1a1c1f9b28fc19725a60030a14e52d5e8197308b056ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.15-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 baf08fe3090eabf593c1fd1254a616035299e378de49ebfa3fec67da9f621756
MD5 8707325f79ddf31004e56fc70b2f8385
BLAKE2b-256 841455907bcff1a510d4057661801ce67c8dfc6ab132a1be6103110fdd689a46

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