Skip to main content

PyPangraph

This repository contains a collection of utilities to load, explore and analyze pangrenome graphs produced by PanGraph.

The package can be installed via pip, see the documentation:

pip install pypangraph

Below are some examples showcasing some of the main functions in the package. More detailed information and examples can be found in the documentation.

Loading and interacting with pangraph objects:

A pangraph object can be loaded from a json file with:

# load the library
import pypangraph as pp
# this returns a pangraph object
graph = pp.Pangraph.from_json("path/to/pangraph.json")

Pangraph objects have three main properties: blocks, paths, and nodes.

  • blocks encode for alignments of homologous sequences across genomes. Each entry in the alignment is a node.
  • paths encode genomes as a list of nodes.
  • nodes connect paths and blocks.

See the documentation for more details on this data structure.

These elements are contained in different properties of the graph:

graph.blocks # dictionary of block ids -> block objects
graph.paths # dictionary of path ids -> path objects
graph.nodes # dataframe of nodes

And can be accessed by either iterating through the items or via their ids.

Block object

Block object have these properties/methods:

# get a block by its id
block = graph.blocks[12252014572476775186]

block.id # unique id of the block
block.consensus() # block consensus sequence
block.depth() # n. of nodes in the block alignment
block.to_biopython_alignment() # returns a biopython alignment object

Path object

# paths can be accessed by their name
path = graph.paths['NZ_CP014647']
# or by their numerical id
path = graph.paths.list[4]

path.id # path numerical id
path.name # path name
path.nuc_len # total length of the path in nucleotides
path.circular # whether the path is circular or linear
path.nodes # list of node ids in the path

Node object

The nodes property of the pangraph is a pandas dataframe with the following columns:

graph.nodes
                    
# node_id                           block_id path_id strand  start    end
# 11484376918084368      6227233701292645975      12   True  87911  88000
# 31660532043830364     12252014572476775186       7  False  88597  91675
# 35440216894469496      5326177636996110751      12   True  12629  13292
# ...
  • node_id is the unique id of the node
  • block_id is the id of the block the node belongs to
  • path_id is the id of the path the node belongs to
  • strand is a boolean indicating whether the node occurs in forward (True) or reverse (False) orientation in the path.
  • start and end are the start and end positions of the node in the input genome.

Nodes can be accessed by their id:

node = graph.nodes[12252014572476775186]

Block statistics

The function to_blockstats_df() returns a pandas dataframe containing summary statistics on the blocks, indexed by block id:

graph.to_blockstats_df()

# block_id              count  n_strains  duplicated   core   len
# 124231456905500231       15         15       False   True  2202
# 149501466629434994        2          2       False  False   210
# 279570196774736738        4          2        True  False  1308
# ...                     ...        ...         ...    ...   ...
  • count is the number of entries in the block alignment, i.e. the total number of times the block appears in all paths.
  • n_strains is the number of unique paths in which the block appears. It can be different from count if the block is duplicated in some paths.
  • duplicated indicates whether the block is duplicated in any paths.
  • core indicates whether the block is core, i.e. present exactly once in every path.
  • len is the length of the block consensus sequence in basepairs.

Block count matrix

The function to_blockcount_df() returns a pandas dataframe whose columns are path ids, and indices are block ids. The entries are the number of times a block is present in a given strain.

graph.to_blockcount_df()
# path_id               RCS48_p1  RCS49_p1  RCS64_p2  ...
# block_id
# 124231456905500231           1         1         1  ...
# 149501466629434994           0         1         0  ...
# 279570196774736738           0         0         2  ...
# ...                        ...       ...       ...  ...

Metadata

Release files for pypangraph 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypangraph 1.1.1
File Size Uploaded Provenance Actions
pypangraph-1.1.1.tar.gz 43.7 kB Without provenance Details for pypangraph-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pypangraph 1.1.1
File Interpreter ABI Platform Actions
pypangraph-1.1.1-py3-none-any.whl Python 3 none any Details for pypangraph-1.1.1-py3-none-any.whl

Total release size: 78.2 kB

Release files / pypangraph-1.1.1.tar.gz

Download URL pypangraph-1.1.1.tar.gz
Size 43.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e4bb379c0679cdb1c0a0eb9da9554bcd0dc8cc4822215a07ba54a9cdc3c5a89c
BLAKE2b-256 checksum
How to use checksums
db1eb600a11052a46ea59f4b61bddc0f5fdbf0186c22a9e798c686f3db683b1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.1

Release files / pypangraph-1.1.1-py3-none-any.whl

Download URL pypangraph-1.1.1-py3-none-any.whl
Size 34.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4bb04520a962d737f32486ab9911d0e5699d7160e8d922e0038abedfb7aa9c4
BLAKE2b-256 checksum
How to use checksums
b0269882372d799526604cf776764644b3f7c593dea6fe30dd34f2edf9f4707a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.1

Security for pypangraph 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page