Alignment module

wlalign.alignment.apply_alignment(graph: numpy.ndarray, alignment: numpy.ndarray)numpy.ndarray[source]

Permute the nodes of a graph according to a specified alignment.

Parameters
  • graph

    np.ndarray

    Graph that is being permuted.

  • alignment

    np.ndarray

    n-by-2 array with one row per node in the graph. The node indexed by the first element of each row is mapped to the second element in each row

Returns

np.ndarray

The permuted graph.

wlalign.alignment.length_wl_signature(k: int, l: int)int[source]

Returns the length of the WL signature corresponding to the width and depth parameters given as input.

Parameters
  • k

    int

    Width of the breadth-first search.

  • l

    int

    Depth of the breadth-first search.

Returns

int

Length of the WL align signature.

Raises
  • ValueError – if k <= 0.

  • ValueError – if l <= 0.

wlalign.alignment.permutation_from_alignment(alignment: numpy.ndarray)numpy.ndarray[source]

Transform a matching into a permutation matrix.

Parameters

alignment

np.ndarray

n-by-2 array with one row per node in the graph. The node indexed by the first element of each row is mapped to the second element in each row

Returns

np.ndarray

Permutation matrix corresponding to the alignment

wlalign.alignment.signature_wl(g: numpy.ndarray, k: int, l: int, node: int, volumes: Optional[list] = None)numpy.ndarray[source]

Compute the WL-align signature of a node of a graph from its adjacency matrix.

Parameters
  • g

    np.ndarray

    Adjacency matrix of the graph.

  • k

    int

    Width parameter of the breadth-first search.

  • l

    int

    Depth parameter of the breadth-first search

  • node

    int

    Index of the node of which the signature must be computed.

  • volumes

    Optional[list]

    List containing the volume of each node. If not passed, it’s computed on the fly from the adjacency matrix.

Returns

np.ndarray

Signature of the node.

References

Matteo Frigo, Emilio Cruciani, David Coudert, Rachid Deriche, Emanuele Natale, Samuel Deslauriers-Gauthier; Network alignment and similarity reveal atlas-based topological differences in structural connectomes. Network Neuroscience 2021; doi: https://doi.org/10.1162/netn_a_00199

wlalign.alignment.wl_align(g1: numpy.ndarray, g2: numpy.ndarray, k: int, l: int)numpy.ndarray[source]

Compute the WL alignment between two graphs as in Frigo et al., 2021.

Parameters
  • g1

    np.ndarray

    Adjacency matrix of the first graph to align.

  • g2

    np.ndarray

    Adjacency matrix of the second graph to align.

  • k

    int

    Width parameter of the breadth-first search.

  • l

    int

    Depth parameter of the breadth-first search

Returns

np.ndarray

Matrix with two columns and one row per node. The first element of each row is the index of the node in the first graph that is aligned with the node in the second graph indexed by the second element of the row.

References

Matteo Frigo, Emilio Cruciani, David Coudert, Rachid Deriche, Emanuele Natale, Samuel Deslauriers-Gauthier; Network alignment and similarity reveal atlas-based topological differences in structural connectomes. Network Neuroscience 2021; doi: https://doi.org/10.1162/netn_a_00199

Similarity module

wlalign.similarity.graph_jaccard_index(g1, g2)[source]

Compute the Graph Jaccard Index (GJI) between two graphs.

Parameters
  • g1

    np.ndarray

    Adjacency matrix of the first graph.

  • g2

    np.ndarray

    Adjacency matrix of the second graph.

Returns

float

Value of the GJI between the two graphs. The value will be in the [0, 1] range.

References

Matteo Frigo, Emilio Cruciani, David Coudert, Rachid Deriche, Emanuele Natale, Samuel Deslauriers-Gauthier; Network alignment and similarity reveal atlas-based topological differences in structural connectomes. Network Neuroscience 2021; doi: https://doi.org/10.1162/netn_a_00199

Utils module

wlalign.utils.check_can_write_file(fpath: str, force: bool = False)None[source]

Check if a file can be written. The function checks if the file already exists, the user has the permission to write it, overwriting can be forced and, if the file does not exist, if the parent directory exists and is writable.

Parameters
  • fpath

    str

    Path of the file to be checked.

  • force

    bool

    True if the file can be overwritten, False otherwise.

Raises
  • FileExistsError – if the file exists and can not be overwritten.

  • PermissionError – if the file esists and the user does not have the permission to write it.

  • PermissionError – if the file does not exist, the parent directory exists and the user does not have the permission to write a file in it.

  • FileNotFoundError – if file does not exist and the parent directory does not exist.

wlalign.utils.check_compatible_adj(g1: numpy.ndarray, g2: numpy.ndarray)[source]

Check if two graphs have the same number of nodes.

Parameters
  • g1

    np.ndarray

    First graph to compare.

  • g2

    np.ndarray

    Second graph to compare.

Raises

ValueError – if the two adjacency matrices do not have the same number of rows and columns.

wlalign.utils.check_is_adj(g: numpy.ndarray)[source]

Check if a matrix is an adjacency matrix

Parameters

g

np.ndarray

Matrix to be checked.

Raises
  • ValueError – if the matrix is not 2-dimensional.

  • ValueError – if the matrix is not square.

wlalign.utils.check_is_alignment(alignment: numpy.ndarray, n: Optional[int] = None)[source]

Check if a numpy array is a valid alignment.

Parameters
  • alignment

    np.ndarray

    Alignment to be checked. Must be n-by-2 numpy array.

  • n

    Optional[int]

    Number of nodes expected to be found in the alignment.

Raises
  • ValueError – if the alignment does not have 2 dimensions.

  • ValueError – if the alignment does not have 2 columns.

  • ValueError – if the alignment does not have n rows.

  • ValueError – if the alignment is not a 1-1 correspondence.

wlalign.utils.load_network(fpath: str, delimiter: str = ' ', skip: str = '#')numpy.ndarray[source]

Load a network from a text file with the adjacency matrix

Parameters
  • fpath

    str

    Path of the file where the adjacency matrix is saved.

  • delimiter

    str

    Character that separates two consecutive entries in a row. Default: whitespace.

  • skip

    str

    Lines that start with this character will be skipped.

Returns

np.ndarray

The adjacency matrix.

wlalign.utils.symmetrize_adj(g: numpy.ndarray)numpy.ndarray[source]

Transform a graph from directed to undirected by summing the weights in the two directions of each edge.

Parameters

g

np.ndarray

Adjacency matrix of the graph to symmetrize.

Returns

np.ndarray

Adjacency matrix of the symmetrized graph.