# 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](http://heliosweb.io).
### Installation
You can easily install `xnetwork` by using `pip`:
```bash
pip install xnetwork
```
### Usage
#### Loading a Graph
To read a Graph from a `.xnet` formatted file, simply use the `load` function:
```python
from xnetwork import load
graph = load("path_to_file.xnet")
```
#### Saving a Graph
To save a graph object to `.xnet` format:
```python
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
- [GitHub Repository](https://github.com/filipinascimento/xnet)
---
Feel free to contribute and raise issues on the GitHub repository.
Raw data
{
"_id": null,
"home_page": "https://github.com/filipinascimento/xnet",
"name": "xnetwork",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.0",
"maintainer_email": "",
"keywords": "",
"author": "Filipi N. Silva and Cesar H. Comin",
"author_email": "filsilva@iu.edu",
"download_url": "https://files.pythonhosted.org/packages/95/f8/9e3a3ccb845121b9dd11df70b33eb3d966a524a77d429439f023b312f2e9/xnetwork-1.0.4.tar.gz",
"platform": null,
"description": "# XNET File format (xnetwork)\n\n`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.\n\nThis file format is used across several of my other projects, including [Helios-Web](http://heliosweb.io).\n\n### Installation\n\nYou can easily install `xnetwork` by using `pip`:\n\n```bash\npip install xnetwork\n```\n\n### Usage\n\n#### Loading a Graph\n\nTo read a Graph from a `.xnet` formatted file, simply use the `load` function:\n\n```python\nfrom xnetwork import load\n\ngraph = load(\"path_to_file.xnet\")\n```\n\n#### Saving a Graph\n\nTo save a graph object to `.xnet` format:\n\n```python\nfrom xnetwork import save\nfrom igraph import Graph\n\n# Your igraph graph object\ng = Graph()\n\nsave(g, \"output_file.xnet\")\n```\n\n### .xnet Format\n\nA brief overview of the `.xnet` format:\n\n```\n#vertices <number_of_vertices>\n<Vertex 0 name>\n<Vertex 1 name>\n...\n\n#edges weighted|nonweighted undirected|directed\n<source_vertex> <target_vertex> [weight]\n...\n\n#v \"<vertex_attribute_name>\" s|n|v2|v3\n<attribute_value>\n...\n\n#e \"<edge_attribute_name>\" s|n|v2|v3\n<attribute_value>\n...\n```\n\n\n - The `#vertices` tag specifies the number of vertices in the graph, followed by their labels.\n \n - 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.\n\n - 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`).\n\n - \n\n### Example\n\nConsider the following `.xnet` file:\n\n```\n#vertices 4 \n\"Label 0\"\n\"Label 1\"\n...\n#edges weighted undirected\n0 1 [0.1]\n0 2 [0.2]\n...\n#v \"A string property\" s\n\"A string value\"\n\"Another string value\"\n...\n```\n\nThis represents a graph with 4 vertices and 2 weighted, undirected edges.\n\n### API Reference\n### load(fileName='test.xnet', compressed=False)\n\nRead a Graph from a xnet formatted file.\n\n#### Parameters\n- `fileName` : string\n Input file path.\n- `compressed` : bool\n If True, input file is compressed using gzip.\n\n#### Returns\n- `igraph.Graph` : The graph object loaded from the file.\n\n### save(g, fileName='test.xnet', ignoredNodeAtts=[], ignoredEdgeAtts=[], compressed=False)\n\nWrite igraph object to .xnet format.\n\nVertex 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.\n\n#### Parameters\n- `g` : igraph.Graph\n Input graph.\n- `fileName` : string\n Output file.\n- `ignoredNodeAtts` : list\n List of node attributes to ignore when writing graph.\n- `ignoredEdgeAtts` : list\n List of edge attributes to ignore when writing graph.\n- `compressed` : bool\n If True, output file will be compressed using gzip.\n\n#### Returns\n- `None` : The function saves the graph object to the specified file.\n\n \n\n### Special network attribute names\nSome attribute names are interpreted by certain software in different ways.\n - Node attribute named `Label` is interpreted as vertex label.\n - Node attribute named `Position` is interpreted as vertex position (can be v2 or v3).\n - Node attribute named `weight` is interpreted as edge weight.\n\n### Authors\n\n- Filipi N. Silva (filipinascimento.github.io)\n- Cesar H. Comin\n\n### License\n\nThis project is licensed under the MIT License.\n\n### Links\n\n- [GitHub Repository](https://github.com/filipinascimento/xnet)\n\n---\n\nFeel free to contribute and raise issues on the GitHub repository.\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Small python package to read .xnet (compleX NETwork format) files used in my other scripts.",
"version": "1.0.4",
"project_urls": {
"Homepage": "https://github.com/filipinascimento/xnet"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "95f89e3a3ccb845121b9dd11df70b33eb3d966a524a77d429439f023b312f2e9",
"md5": "9705a5ce0ebd0b04c4c6913b3df15d6b",
"sha256": "503886f38c19feb167dc6779f05940d4050c65127451e4c4a42cbdbd542c4bbe"
},
"downloads": -1,
"filename": "xnetwork-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "9705a5ce0ebd0b04c4c6913b3df15d6b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.0",
"size": 7726,
"upload_time": "2023-10-11T07:55:42",
"upload_time_iso_8601": "2023-10-11T07:55:42.306858Z",
"url": "https://files.pythonhosted.org/packages/95/f8/9e3a3ccb845121b9dd11df70b33eb3d966a524a77d429439f023b312f2e9/xnetwork-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-11 07:55:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "filipinascimento",
"github_project": "xnet",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "python-igraph",
"specs": []
},
{
"name": "numpy",
"specs": []
}
],
"lcname": "xnetwork"
}