Skip to main content

Fast low-level graph utilities for metabolomics pipelines (BBQGraph)

Project description

KBBQGraph - Barebones and Quick for k-partite graphs

This is a WIP for a memory-efficient replacement for NetworkX for a specific application.

I work with k-partite graphs when matching datasets, where each dataset is a partite. Most immediately, I need to handle 100s of partites each with 10,000's of nodes, and ~5,000 directed edges connecting each partite set. This quickly saturates NetworkX.

I also need efficient indexing based on partite number and feature number -- this is not offered by any other graphing library.

Someday, I would like to add some very specific homegrown k-partite clustering algorithms. These also assume one-to-one constraints when compressed to undirected, i.e. at most a node u from partite i can only be connected to one node from partite j.

License - Free to distribute and use as long as credit to the developers is given. Also, if you make something better, please tell me.

In addition to the basic usage below, check out compress, weakly_connected_components and find_cliques.

import networkx as nx
from kbbqgraph import KBBQGraph

# ------------------------------------------------------------
# Create a new graph
# ------------------------------------------------------------
g = KBBQGraph(isDiGraph=0, preAllocate=10, name="example")

# ------------------------------------------------------------
# Add nodes
# ------------------------------------------------------------
# Add nodes to “dataset/partite 0”
g.add_nodes(0, [0, 1, 2])

# Add nodes to “dataset/partite 1”
g.add_nodes(1, [0, 1])

# ------------------------------------------------------------
# Add edges (batched)
# ------------------------------------------------------------
# Each node is a (dataset, id) tuple, i.e. (partite, local_index)
source_nodes = [
    (0, 0),  # node 0 in dataset 0
    (0, 2),  # node 2 in dataset 0
]

target_nodes = [
    (1, 1),  # node 1 in dataset 1
    (1, 0),  # node 0 in dataset 1
]

weights = [1.0, 0.5]  # optional; can also pass None

g.add_edges(
    source_nodes=source_nodes,
    target_nodes=target_nodes,
    weights=weights,
    check_duplicates=True,
)

print("Nodes:", g.num_nodes)
print("Edges:", g.num_edges)

# ------------------------------------------------------------
# Convert to NetworkX
# ------------------------------------------------------------
nx_graph = g.to_networkx()

print("NetworkX edges (u, v, data):")
for u, v, data in nx_graph.edges(data=True):
    print(u, "→", v, "weight=", data.get("weight"))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kbbqgraph-0.1.1.tar.gz (152.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kbbqgraph-0.1.1-py3-none-any.whl (152.1 kB view details)

Uploaded Python 3

File details

Details for the file kbbqgraph-0.1.1.tar.gz.

File metadata

  • Download URL: kbbqgraph-0.1.1.tar.gz
  • Upload date:
  • Size: 152.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for kbbqgraph-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c0bffcda782b5a916861d468bec8b56607387fe8517bc53b7a030c6a6dfcb4e4
MD5 f1ed1163a17918ec2cf6b603fed1b2eb
BLAKE2b-256 a725b1ac766fba44b46a0cc342de6557a9e40a688d54e27240538f46c2ad75a3

See more details on using hashes here.

File details

Details for the file kbbqgraph-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kbbqgraph-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 152.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for kbbqgraph-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae2fbd64cbe8a35e7c1028192e88c465237b0cb9ced713cec8aff2042e6a8029
MD5 ac2631cefd96d55477e57d0cb4949ef1
BLAKE2b-256 9ecb8464e5c069778da4b6f4c40308ff0e0a5dbd104e2f77f615ce2eec2e0803

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