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)

# 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.11-cp313-cp313-win_amd64.whl (542.5 kB view details)

Uploaded CPython 3.13Windows x86-64

phrank_py-0.2.11-cp313-cp313-manylinux_2_34_x86_64.whl (748.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

phrank_py-0.2.11-cp313-cp313-macosx_11_0_arm64.whl (669.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

phrank_py-0.2.11-cp312-cp312-win_amd64.whl (542.4 kB view details)

Uploaded CPython 3.12Windows x86-64

phrank_py-0.2.11-cp312-cp312-manylinux_2_34_x86_64.whl (750.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

phrank_py-0.2.11-cp312-cp312-macosx_11_0_arm64.whl (669.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

phrank_py-0.2.11-cp311-cp311-win_amd64.whl (542.9 kB view details)

Uploaded CPython 3.11Windows x86-64

phrank_py-0.2.11-cp311-cp311-manylinux_2_34_x86_64.whl (750.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

phrank_py-0.2.11-cp311-cp311-macosx_11_0_arm64.whl (669.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

phrank_py-0.2.11-cp310-cp310-win_amd64.whl (543.0 kB view details)

Uploaded CPython 3.10Windows x86-64

phrank_py-0.2.11-cp310-cp310-manylinux_2_34_x86_64.whl (750.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

phrank_py-0.2.11-cp310-cp310-macosx_11_0_arm64.whl (670.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: phrank_py-0.2.11-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 542.5 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.11-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6b52deb4e2018e8bde18c83e91d873f1345b88e2fe081cab51e4095e50d3d321
MD5 30fcfabbb8a88e3a3723b5777465c79c
BLAKE2b-256 2f07e616e1de0137742f576a8cefa2966edf0f8c609ac8e62a8cb00c69d60dc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.11-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4f380f59806148337b024bc85b03805707e8c0d6c52169f9a5735f8f9a782593
MD5 86de46b40eced68f9df857a825de75a8
BLAKE2b-256 6349274ac77b5fe61a7fec9047ae5c38d16b000702b3262a4ac039e2981a298f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.11-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c1c3d40f6ea00078633d3570e92d2b190eeef32dec24a784d1020fc4b66eebc
MD5 c6f858e067520a183f4496db94d45981
BLAKE2b-256 d04df4b227cd106b6eaabd34d4411d999c1efdea80f1675beb8c4958093f8b11

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.11-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 542.4 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.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f90a9b2c2d535bba4f9d35c0c1a2cf421eac0bd96613f9c224ecb0c87da0aaa3
MD5 4e355e11ed7a7584ad0bd74532a9c39c
BLAKE2b-256 deee31874fa3581df1d0f67f5681ad3700f3953ed263d7658af0eba103af05d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.11-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 602a560be123e023de2cbf73107e39b7a7dfac876565cfe824ee11344e5c4c2a
MD5 d052b2b0489bb396f4fc209d3bb89bee
BLAKE2b-256 3ef94c2eb21903ff1605b608c7c0fc36cc040541724690196601c3911953c679

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b6c6276b8457da8a9dfc581c13ed5c221a954e32457d290dda59089a702dbd3c
MD5 57bdf4e384b60c2419d64fe61d2ce2a6
BLAKE2b-256 f430853a84c449e3080c154a4ed1ead13f108c7ccba845a3ad0bfda0d9a7b39e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.11-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 542.9 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.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 42e5e2adf5246dee18f51486559576d0b6a0e7371adf47e0b8c4419e1ecc4ece
MD5 a32e1f85b48f8aa9d05ff5937594c480
BLAKE2b-256 493bb981622e3cbe5e6d230549b4a1edcaaee0069c726a5eb93660e61a3858fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.11-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6dafd57123eee8335927aab4fbc4445332178d4d20fcc8b677931ac3f7a53cea
MD5 28257f57f91bbb7f5f8b9ed97361501e
BLAKE2b-256 5f79a1099969349ce00e5dee8d2666cd6f8e73131c799ab27c9b105b9ed232c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2ded521723a70440cefecf4fa41bded9164dbae131f13c3ea6fd27fccd470abd
MD5 b1a92ce1bdfddada63821a0a8e6c8f04
BLAKE2b-256 058ec13d716c498ebee5e67c05a7b58848ca98a31ed2ca1a7bb826778b6685cd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.11-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 543.0 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.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e540e191bdbaa6777ae120982ce5a896f7af10515847a487ec9bbe11226d58f8
MD5 1ba66e0b9226a7a152a16facb50d1f0d
BLAKE2b-256 d22ea91e3765b9b4e1e320d6fdf9ccb06490ca8de167d8db09a7507dae642c90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.11-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 eabf06222f772719855587e7501b0d0fbaa9531d1b00c84cc93449dbba6bb705
MD5 18ed3c9f2b4c493acb330b64a6f5f82d
BLAKE2b-256 0a0293e073ec756aef148e658e4032640edd7a5adaf49aa7bfe2dc04bb3f9546

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b6e74d95d4d9fba232253f1ed6a70f09378ea39949c45107916b8956b82f654a
MD5 7aa49a72cb4a9d35ef0456047ebb17ab
BLAKE2b-256 144e9a4fca902d256ee3aecf89a99fc9d832fdcd8732bdcf2fe37a6445ca0d49

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