sica.mutualknn.MNNgraph

class sica.mutualknn.MNNgraph(data, names, k, metric='pearson', weighted=True)[source]

Given a list of data sets, draws the MNN graph with a networkx object (compatible with the software Cytoscape)

Parameters:
datalist of 2D data sets of shape (n_components_i , n_features_i)
nameslist of strings

Names of the data sets.

kint > 0

Parameter for the Mutual Nearest Neighbors method.

metricstring, optional

Metric for the computation of the adjacency matrices. The default is “pearson”.

weightedbool
If True each coefficient of the adjacency matrix is weighted by the associated distance,

otherwise the coefficients are 0 or 1.

Attributes:
graph_networkx object

Each edge of the graph is associated with the following attributes: - distance - corresponds to the distance between the two nodes (e.g. if metric = “pearson” this distance corresponds to 1 - pearson coefficient). For an unweighted graph (i.e. when weighted = False), it equals to 1 every time. - weight - corresponds to the “strength of association” between the two nodes. For correlation metrics, it corresponds to the correlation coefficient itself while for other metrics it corresponds to 1 - minmax scaled distance (min and max are computed over all the between-nodes distances, including those that are not associated to an edge in the graph). For an unweighted graph, it equals 1 every time.

Notes

If the elements of data are not dataframes, we assume that they all share the same features.

Examples

>>> from sica.mutualknn import MNNgraph
>>> cg = MNNgraph(data = [df1 , df2 , df3] , names=['dataframe1' , 'dataframe2' , 'dataframe3'] , k=1)
>>> cg.draw(colors = ['r', 'g' , 'b'] , spacing = 2)
>>> cg.export_json("example.json")

Methods

create_graph(data, names, k, metric, weighted)

Create the MNN graph associated to the list of data sets.

draw([bipartite_graph, ax, colors, spacing])

Draw the MNN graph.

export_json(file_name)

Save the graph in a json file adapted to cytoscape format

static create_graph(data, names, k, metric, weighted)[source]

Create the MNN graph associated to the list of data sets. Two situations are distinguished : one with only two data sets and another with more than two data sets.

Parameters:
datalist of 2D arrays of shape (n_components_i , n_features_i)
nameslist of strings

Names of the data sets.

kinteger >= 1

Parameter for the Mutual Nearest Neighbors Method.

metricstring

Metric for the computation of the adjacency matrices.

weightedbool

If True each coefficient of the adjacency matrix is weighted by the associated distance, otherwise the coefficients are 0 or 1.

Returns:
Ggraph (networkx object)

MNN graph for the data sets contained in the list “data”.

draw(bipartite_graph=False, ax=None, colors=None, spacing=1)[source]

Draw the MNN graph.

Parameters:
bipartite_graphboolean, optional

If True a custom bipartite layout is used (only with two data sets). The default is False

axmatplotlib.axes, optional

The default is None.

colorslist of matplotlib.colors, optional

List of colors you want each data set to be associated with. The default is None.

spacingfloat >= 1, optional

Deal with the space between nodes. Increase this value to move nodes farther apart.

Returns:
None.
export_json(file_name)[source]

Save the graph in a json file adapted to cytoscape format

Parameters:
file_namestring

Name of the json file.

Returns:
None.