Skip to main content

Package to compute TP distances between nodes in a network.

Project description

XNET File format (xnetwork)

xnetwork is a small python package that allows you to read .xnet files (compleX NETwork format), a format designed to easily handle graph data with multiple attributes.

This file format is used across several of my other projects, including Helios-Web.

Installation

You can easily install xnetwork by using pip:

pip install xnetwork

Usage

Loading a Graph

To read a Graph from a .xnet formatted file, simply use the load function:

from xnetwork import load

graph = load("path_to_file.xnet")

Saving a Graph

To save a graph object to .xnet format:

from xnetwork import save
from igraph import Graph

# Your igraph graph object
g = Graph()

save(g, "output_file.xnet")

.xnet Format

A brief overview of the .xnet format:

#vertices <number_of_vertices>
<Vertex 0 name>
<Vertex 1 name>
...

#edges weighted|nonweighted undirected|directed
<source_vertex> <target_vertex> [weight]
...

#v "<vertex_attribute_name>" s|n|v2|v3
<attribute_value>
...

#e "<edge_attribute_name>" s|n|v2|v3
<attribute_value>
...
  • The #vertices tag specifies the number of vertices in the graph, followed by their labels.

  • The #edges tag specifies if edges are weighted or non-weighted and whether they are directed or undirected. Each subsequent line lists an edge by its source and target vertices, optionally followed by a weight in square brackets.

  • The #v and #e tags specify vertex and edge attributes respectively. These tags are followed by the attribute name and its type. The type can be a string (s), number (n), 2D vector (v2), or 3D vector (v3).

Example

Consider the following .xnet file:

#vertices 4 
"Label 0"
"Label 1"
...
#edges weighted undirected
0 1 [0.1]
0 2 [0.2]
...
#v "A string property" s
"A string value"
"Another string value"
...

This represents a graph with 4 vertices and 2 weighted, undirected edges.

API Reference

load(fileName='test.xnet', compressed=False)

Read a Graph from a xnet formatted file.

Parameters

  • fileName : string Input file path.
  • compressed : bool If True, input file is compressed using gzip.

Returns

  • igraph.Graph : The graph object loaded from the file.

save(g, fileName='test.xnet', ignoredNodeAtts=[], ignoredEdgeAtts=[], compressed=False)

Write igraph object to .xnet format.

Vertex attributes 'name' and 'weight' are treated in a special manner. They correspond to attributes assigned inside the #vertices tag. Edge attribute 'weight' is assigned to edges inside the #edges tag.

Parameters

  • g : igraph.Graph Input graph.
  • fileName : string Output file.
  • ignoredNodeAtts : list List of node attributes to ignore when writing graph.
  • ignoredEdgeAtts : list List of edge attributes to ignore when writing graph.
  • compressed : bool If True, output file will be compressed using gzip.

Returns

  • None : The function saves the graph object to the specified file.

Special network attribute names

Some attribute names are interpreted by certain software in different ways.

  • Node attribute named Label is interpreted as vertex label.
  • Node attribute named Position is interpreted as vertex position (can be v2 or v3).
  • Node attribute named weight is interpreted as edge weight.

Authors

  • Filipi N. Silva (filipinascimento.github.io)
  • Cesar H. Comin

License

This project is licensed under the MIT License.

Links


Feel free to contribute and raise issues on the GitHub repository.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

tpdistance-0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

tpdistance-0.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file tpdistance-0.1.tar.gz.

File metadata

  • Download URL: tpdistance-0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.13

File hashes

Hashes for tpdistance-0.1.tar.gz
Algorithm Hash digest
SHA256 b6e976e7811c094d9467abbf7a29320ebb8b304c75c2471b89484aaad8b847bb
MD5 4ed6b81789f6807027c5cdef61fb4b9a
BLAKE2b-256 57ce2abfe7b370483f3de171d4d95ffee460cda9f06dd50db66e7ec403292760

See more details on using hashes here.

File details

Details for the file tpdistance-0.1-py3-none-any.whl.

File metadata

  • Download URL: tpdistance-0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.13

File hashes

Hashes for tpdistance-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6891c3ce7672fa9335a00684397197652606b54544a5d849230d50ceca1c33ba
MD5 ffddea527846f894b8b2871b8e4ea081
BLAKE2b-256 bb86b5aadaaa4eb607fab8a9578afc95194ad5f241a9c1d6d4d6c988a9eb618b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page