xgi.readwrite.bipartite#
Read from and write to bipartite formats.
Functions
- generate_bipartite_edgelist(H, delimiter=' ')[source]#
A helper function to generate a bipartite edge list from a Hypergraph object.
- Parameters:
H (Hypergraph object) – The hypergraph of interest
delimiter (char, default: space (" ")) – Specifies the delimiter between hyperedge members
- Yields:
A iterator of strings – Each entry is a line to be written to the output file.
- parse_bipartite_edgelist(lines, comments='#', delimiter=None, create_using=None, nodetype=None, edgetype=None, dual=False)[source]#
A helper function to read a iterable of strings containing a bipartite edge list and convert it to a Hypergraph object.
Reads the first two entries of each line and assumes that the first entry is a node ID and that the second entry is an edge ID. Raises error if there are fewer than two entries.
- Parameters:
lines (iterable of strings) – Lines where each line is a bipartite edge
comments (string, default: "#") – The token that denotes comments to ignore
delimiter (char, default: space (" ")) – Specifies the delimiter between hyperedge members
create_using (Hypergraph constructor, optional) – The hypergraph object to add the data to, by default None
nodetype (type) – type that the node labels will be cast to
edgetype (type) – type that the edge labels will be cast to
data (bool, default: False) – Specifies whether there is a dictionary of data at the end of the line.
- Raises:
XGIError – If a line contains fewer than two entries
TypeError – If node types fail to be converted
- Returns:
The loaded hypergraph.
- Return type:
- read_bipartite_edgelist(path, comments='#', delimiter=None, create_using=None, nodetype=None, edgetype=None, dual=False, encoding='utf-8')[source]#
Read a file containing a bipartite edge list and convert it to a Hypergraph object.
- Parameters:
path (string) – The path of the file to read from
comments (string, default: "#") – The token that denotes comments in the file
delimiter (char, default: space (" ")) – Specifies the delimiter between hyperedge members
create_using (Hypergraph constructor, optional) – The hypergraph object to add the data to, by default None
nodetype (type) – type that the node labels will be cast to
edgetype (type) – type that the edge labels will be cast to
dual (bool, default: False) – Specifies whether the node IDs are in the second column. If False, the node IDs are in the first column.
encoding (string, default: "utf-8") – Encoding of the file
- Returns:
The loaded hypergraph
- Return type:
A Hypergraph object
See also
Example
>>> import xgi >>> # H = xgi.read_bipartite_edgelist("test.csv", delimiter=",")
- write_bipartite_edgelist(H, path, delimiter=' ', encoding='utf-8')[source]#
Write a Hypergraph object to a file as a bipartite edgelist.
- Parameters:
H (Hypergraph object) – The hypergraph of interest
path (string) – The path of the file to write to
delimiter (char, default: space (" ")) – Specifies the delimiter between hyperedge members
encoding (string, default: "utf-8") – Encoding of the file
See also
Example
>>> import xgi >>> H = xgi.random_hypergraph(50, [0.01, 0.001]) >>> # xgi.write_bipartite_edgelist(H, "test.csv", delimiter=",")