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

Uploaded CPython 3.13Windows x86-64

phrank_py-0.2.14-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.14-cp313-cp313-macosx_11_0_arm64.whl (962.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

phrank_py-0.2.14-cp312-cp312-win_amd64.whl (837.1 kB view details)

Uploaded CPython 3.12Windows x86-64

phrank_py-0.2.14-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.14-cp312-cp312-macosx_11_0_arm64.whl (962.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

phrank_py-0.2.14-cp311-cp311-win_amd64.whl (839.4 kB view details)

Uploaded CPython 3.11Windows x86-64

phrank_py-0.2.14-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.14-cp311-cp311-macosx_11_0_arm64.whl (963.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

phrank_py-0.2.14-cp310-cp310-win_amd64.whl (839.4 kB view details)

Uploaded CPython 3.10Windows x86-64

phrank_py-0.2.14-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.14-cp310-cp310-macosx_11_0_arm64.whl (963.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: phrank_py-0.2.14-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 836.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.14-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 674bd75bd746ab6f7a6bd99a1286c392a3c9ae0ef087ab7e3142e356954ff394
MD5 95f3d345ed80845be595c01e745d5e60
BLAKE2b-256 c94c378e8b8ba451bc87dc73d32148c8d52b4ba0d8547b5165be3c63353f59ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.14-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a7753a0ccf1f9157c27b82da2d9316357361c82d6a211868739cf42116b8e6aa
MD5 b7166685de5dd8b2d7b4f0928e14ca79
BLAKE2b-256 a5757f0f3444089d1da90135bfdec0e7f297722ee73d418079bac6a5551152e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.14-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5fac5530e31038e56faba6ffbe402560de8589214ab8a627cf8308143c112529
MD5 2d9f2b170cb1cc40dce3790554238e13
BLAKE2b-256 84864e04ef1daeed58c76d9baa7cc9df52aa49f4f246aca22b6f257a03936735

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.14-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 837.1 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.14-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b614f843b25b925c0f6d2c6c2b8129f1df744822f90d1cc43a0c914bf3def1b6
MD5 d872fa31df8e0cb03def415c2e6891b7
BLAKE2b-256 f2145d03603ba04ecdfc0d950d75a7282a2209166f71aea3972f956a6bb06ba9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.14-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e1c9a26bb281317106663c9c0ac09a0f9ee8c904c534abf012b7a310498edf1f
MD5 67edf49791c7828cf9cc7622c618e469
BLAKE2b-256 f3b77e65c2e6ab0b326283e8ceec001c5e7cdcb26f1ceabca2e330aef5dd6156

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7aab430fb70ce1fc2cba676adcae4c061da1f7030d54f85bab3ed8c45e408b4d
MD5 2e86124f8de4e500681e12e4c9f1266b
BLAKE2b-256 7498e517dba24a9459c6dc01b3dec716bb7d4fce34a71696e35245099fc5356c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.14-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 839.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.14-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 92997ed57ac3af2dafe01112fdbb4c6b4da3b531a5c5241f2b7cf48f91480716
MD5 208fb27fbddb6dc78b63545a520f8604
BLAKE2b-256 df5d2e33776222d7b06eda2fbe8bee0500bd4780b45ab19e1dbd35025d00eb7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.14-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2be648c25ba6bcb41991ab951e3b6cc82fbaf855b1486350246cf61c86e28262
MD5 4e1a2eef90c31cb0e544afb6fddce5d2
BLAKE2b-256 d39ef14bc00f74048ee5303750cf2453600910a872349872f45d3a0ad138bf57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.14-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b746adb6b37deb5a137a28d704dfc855e89282a7ff1f93277a1fa3a5263d79e8
MD5 c90a3cd646650d838c88ea342dbb4927
BLAKE2b-256 ac4cae743b4451872c852ba410195d5a70f77d527dc057c3fd07c4ef02ec0764

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phrank_py-0.2.14-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 839.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.14-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 20a6759b548290828cac0f6bda2364a934f3d7abbfcd0d4af4c76a2eda575762
MD5 7d7b2c37fa4ae98e7ed3008e3743364d
BLAKE2b-256 0944d1d792fcfc373f084301a7c2c6ef4c38d4a92be297937af2e23565c2a55b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.14-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4c2a3e6f842362226fd1a97731852e3858570fc2e81d479128d832a4367f2f5e
MD5 028259434abeca62469918bd59294715
BLAKE2b-256 a96f0ba230153706eee776b5f8a3e1b29b4d26f4359e01e311cee325c4f3b894

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for phrank_py-0.2.14-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bcfcabd43e2b3217aaa04b956c0225c10b4155f1dc2fb2785bc055aa9713ea51
MD5 9ddb7b1a0e3a1df0135c659ae758f073
BLAKE2b-256 fd5e9cdd6b55cb33c650b5aee642159bcb0a042767f0e02b377da78924ea99cc

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