diff --git a/Multilayer/Multilayer_Main_code.py b/Multilayer/Multilayer_Main_code.py new file mode 100755 index 0000000..885ac6d --- /dev/null +++ b/Multilayer/Multilayer_Main_code.py @@ -0,0 +1,839 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""This is the main code used at the MULTINETLAB for multilayer network analyses. + It uses a supra-adjacency matrix (generated in MATLAB) as input, and creates a + multilayer network object - similar to the ones in Networkx. + For privacy reasons, we provide a random MST file. +""" + +__author__ = "Fernando Nobrega" +__contact__ = "f.nobregasantos@amsterdamumc.nl" +__date__ = "2019/10/15" +__status__ = "Production" + + +#################### +# Review History # +#################### + +# Reviewed by Eduarda Centeno 20200909 +# Reviewed by Lucas Breedt 20201125 + + +#################### +# Libraries # +#################### + +# Standard imports +import itertools #no attribute version +from multiprocessing import Pool #no attribute version +import time as time #no attribute version + +# Third party imports +import matplotlib.pyplot as plt # version '3.1.1' +import multinetx as mx #no attribute version +import networkx as nx#version 2.3 +import numpy as np#version '1.19.0' +import pandas as pd# version '0.25.1' +from pylab import pcolor, show, colorbar, xticks, yticks +import pyreadstat #version '0.2.9' +import scipy as sio #version '1.3.1' +import scipy.io +from sklearn import preprocessing #version 0.21.3 +from sklearn.preprocessing import MinMaxScaler + + +################################################################################################################################ + + +# THE VARIABLES DEFINED BELOW NEED TO BE MODIFIED TO CORRESPOND WITH THE DATA OF THE USER. +# Please see the comments in this code as well as the readme on Github for instructions on how +# to use this code. Note that comments with more than one # should be ignored - they are for further developments. + +""" The user should define the input file (supra-adjacency matrix) in the beginning of the code. +The code is quite robust - as long as the matrices are created using a pipeline similar to the one in the Lab.""" + +#################### +# SETTINGS # +#################### + +layer_size = 197 # Define the number of nodes per layer. We used the BNA, with some regions removed +weighted = False # We are now using MST matrices. Matrices are thus not weighted - if weighted, change to True + +# Specify the the supra adjacency matrices here +# TRAINING RANDOM MATRIX +filename = 'supra_randmst.mat' + + +######################################### +# CREATING LAYER TAGS # +######################################### + +# Associating tags for each layer will be helpful for our coding. We used the ones below +# These are the tags for the Multilayer Networks - It should match with the layers in the supra-adjacency matrix + +print('0 = fmri, 1 = pli delta, 2 = pli theta, 3 = pli alpha1, 4 = pli alpha2, 5 = pli beta, 6 = pli gamma, 7 = DWI .') + +### IMPROVEMENT! WE CAN INCLUDE A FUNCTION TO CHECK THE TAGS FROM OUR FILES + +layer_tags=['0 = fmri', '1 = pli delta', '2 = pli theta', '3 = pli alpha1', '4 = pli alpha2', '5 = pli beta', '6 = pli gamma', '7 = DWI'] +just_tags=['fmri', 'pli_delta', 'pli_theta', 'pli_alpha1', 'pli_alpha2', 'pli_beta', 'pli_gamma', 'DWI'] +plot_tags=['fMRI', 'PLI delta', 'PLI theta', 'PLI alpha1', 'PLI alpha2', 'PLI beta', 'PLI gamma', 'DWI'] + +layer_dic = {} +for i in range(0 , len(just_tags)): + layer_dic[i] = just_tags[i] +print(layer_dic) + + +############################################# +# LOADING THE MATRICES # +############################################# + +# This is where the real data for computing all multilayer functions is loaded +# Every function defined from now on uses these data as input + +# ATTENTION: THIS IS THE OBJECT THAT WILL BE USED FOR THE REMAINDER OF THE CODE! +supra_mst = scipy.io.loadmat(filename) + +### IMPROVEMENT - INCLUDE VERBOSE FUNCTION TO MAKE CHECKS IN THE CODE + + +####################### +# SANITY CHECK # +####################### + +# ATTENTION: CHECK THE OUTPUT OF THESE LINES OF CODE TO ENSURE DATA IS LOADED CORRECTLY +# Check that this is in fact a dicionary +print(type(supra_mst)) +# Check that the keys are correct +print(supra_mst.keys()) + + +################################################################################################################################ + + +# FROM THIS POINT FORWARD, NO FURTHER USER MODIFICATION/INPUT IS REQUIRED. +# This is where all of the functions are defined. None of these should require +# modification or user input - only the last function, function_output, is needed +# for the user to calculate any multilayer network measure. Please also see the readme + +################################### +# PREPARING THE MULTILAYER # +################################### + +def prepare_multilayer(data, list_of_layers, N=layer_size): + """Converts the data to a Multinetx friendly object based on the inputed data. + Parameters + ---------- + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta, pli theta, and pli beta using the tags: 0=fmri', '1=pli delta', '2= pli theta','5 = pli beta' + list_of_layers = [0,1,2,5] + + Returns + ------- + out : list of layers. + Note: This is convenient - since we can have a database with all 14 layers, but we may want to study only a smaller number of layers. + In short, the layers are based in the supra-adjacency matrices - but you can choose exactly the layers you want here" + """ + + + #In the matlab file the element [-1] gives the matrices + name = list(data.keys())[-1] + if len(data[name].shape)==2: + multilayer=np.expand_dims(data[name], axis=0).T + else: + multilayer = data[name] + + # Just checking if there are NaNs + where_are_NaNs = np.isnan(multilayer) + multilayer[where_are_NaNs] = 0 + #layer_size = 197 # This are the numbers of nodes in the layer + #N = layer_size + layer_list = list_of_layers + + layers=[] + for i in layer_list: + layers.append(multilayer[(i*N):(i+1)*N,(i*N):(i+1)*N,:]) + + return layers + + +# This creates a multilayer network for each individual (This is the new one) +def multilayer_g(individual, data, list_of_single_layers, N=layer_size): + """Creates a Multilayer graph object for an individual, given the data, and a list of layers. + Parameters + ---------- + + Individual: an integer from [0, S-1], where S is the size of the cohort. + + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta and pli theta, using the tags: 0=fmri', '1=pli delta', '2= pli theta' + list_of_layers = [0,1,2] + + Returns + ------- + out: A Multilayer Object for a single individual in the data. + + """ + + + "Creates a multilayer for an individual i, knowing the number of layers, and the size of the layers" + layers= prepare_multilayer(data, list_of_single_layers) + #N =197 # before was 205 + number_of_layers=len(list_of_single_layers) + G=[] + for j in range(0,len(list_of_single_layers)): + "j is running over all layers for a fixed individual i" + G.append(mx.from_numpy_matrix(layers[j][:,:,individual])) + +# Define the type of interconnection between the layers + +# This creates the supra adjacency matrix + adj_block = mx.lil_matrix(np.zeros((N*number_of_layers,N*number_of_layers))) # N is the size of the layer + +# Need to create generic adjacency blocks!!!! + +# These are generic interconnection blocks!!! + for i in range(number_of_layers): + for j in range(number_of_layers): + if i == j: + adj_block[i*N: (i+1)*N, j*N:(j+1)*N] = np.zeros(N) + else: + adj_block[i*N: (i+1)*N, j*N:(j+1)*N] = np.identity(N) + + mg = mx.MultilayerGraph(list_of_layers=G,inter_adjacency_matrix=adj_block) + mg.set_edges_weights(intra_layer_edges_weight=1,inter_layer_edges_weight=1) + + return mg + + +############################# +# CREATING THE AGGREGATE # +############################# + +# ATTENTION: THERE ARE SEVERAL OPTIONS HERE - WE ARE USING A SIMILAR AGGREGATION AS MUXVIZ (see http://muxviz.net/tutorial.php) +# THIS IS AN INTERMEDIATE FUNCTION SO THAT THE OUTPUT OF THE OTHER FUNCTIONS IS PRINTED 'PER NODE' +def muxviz_aggregate(multiple_layers_list, number_layers): + """Creates an aggregate output from a Multilayer Network, given a multiple_layers_list and the number of layers + Parameters + ---------- + + multiple_layers_list: output of a multilayer network metric + + number_layers: number of layers in the multilayer + + Returns + ------- + out: An aggregate list which is the mean of the values of a Network property per node in each layer + + """ + k, m = divmod(len(multiple_layers_list), number_layers) + temp = list(multiple_layers_list[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(number_layers)) + temp_mean = np.mean(temp,axis=0) + temp_mean = temp_mean/max(temp_mean) + #for sublists in temp: + # m=np.max(temp[sublists]) + # for i in sublists: + # temp[sublists][i]=temp[sublists][i]/m + + return temp_mean + + +########################################## +# MULTILAYER NETWORK FUNCTIONS # +########################################## + +# The strategy to create the functions is the same for every function; we can +# parse all NetworkX functions here. + +def group_eigenvector_centrality(data, list_of_single_layers): + """Returns a flat list with the muxviz_aggregate output for EC, given a data, and a list_of_single_layers + + Parameters + ---------- + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta, pli theta, and pli beta using the tags: 0=fmri', '1=pli delta', '2= pli theta','5 = pli beta' + list_of_layers = [0,1,2,5] + + Returns + ------- + out: An aggregate list which is the mean of the values of the EC per node in each layer + + """ + + "This list will save all the eigenvector centralities for all individuals in all layers." + name = list(data.keys())[-1] + #fixed it!!! + if len(data[name].shape)==2: + number_of_individuals=1 + else: + number_of_individuals = data[name].shape[2] + + group_eigenvector = [] + for individual in range(number_of_individuals): + temp = multilayer_g(individual,data,list_of_single_layers) + + m = mx.eigenvector_centrality_numpy(temp) + #m=mx.eigenvector_centrality(multilayer_g(individual,number_of_layers,list_of_layers)) + temp1 = list(m.values()) + temp2 = muxviz_aggregate(temp1, len(list_of_single_layers)) + #temp2=aggregate(temp1,len(list_of_single_layers)) + # This is a list of lists with all centralities for all individuals + group_eigenvector.append(temp2) + # since we want to buid a flat list + flat_list = [item for sublist in group_eigenvector for item in sublist] + + return flat_list + + +def group_clustering(data, list_of_single_layers): + """Returns a flat list with the aggregate output for group clustering, given a data, and a list_of_single_layers + + Parameters + ---------- + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta, pli theta, and pli beta using the tags: 0=fmri', '1=pli delta', + '2= pli theta','5 = pli beta' + list_of_layers = [0,1,2,5] + + Returns + ------- + out: An aggregate list which is the mean of the values of the Clustering per node in each layer + + """ + + name = list(data.keys())[-1] + if len(data[name].shape)==2: + number_of_individuals=1 + else: + number_of_individuals = data[name].shape[2] + + group_clustering = [] + for individual in range(number_of_individuals): + temp = multilayer_g(individual, data, list_of_single_layers) + + m = mx.clustering(temp) + temp1 = list(m.values()) + temp2 = muxviz_aggregate(temp1, len(list_of_single_layers)) + # This is a list of lists with all centralities for all individuals + group_clustering.append(temp2) + # We want to buid a flat list + # Check this flattened = [val for sublist in list_of_lists for val in sublist] + flat_list = [item for sublist in group_clustering for item in sublist] + + return flat_list + + +def group_degree_centrality(data, list_of_single_layers): + """Returns a flat list with the aggregate output for group degree centrality, given a data, and a list_of_single_layers + + Parameters + ---------- + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta, pli theta, and pli beta using the tags: 0=fmri', '1=pli delta', + '2= pli theta','5 = pli beta' + list_of_layers = [0,1,2,5] + + Returns + ------- + out: An aggregate list which is the mean of the values of the degree centrality per node in each layer + + """ + + name = list(data.keys())[-1] + if len(data[name].shape)==2: + number_of_individuals=1 + else: + number_of_individuals = data[name].shape[2] + + group_deg_centrality = [] + for individual in range(number_of_individuals): + temp = multilayer_g(individual, data, list_of_single_layers) + + m = mx.degree_centrality(temp) + + temp1 = list(m.values()) + temp2 = muxviz_aggregate(temp1, len(list_of_single_layers)) + #temp2=aggregate(temp1,len(list_of_single_layers)) + # This is a list of lists with all centralities for all individuals + group_deg_centrality.append(temp2) + # since we want to buid a flat list + # Check this flattened = [val for sublist in list_of_lists for val in sublist] + flat_list = [item for sublist in group_deg_centrality for item in sublist] + + return flat_list + + +def group_eccentricity(data, list_of_single_layers): + """Returns a flat list with the aggregate output for group eccentricity, given a data, and a list_of_single_layers + + Parameters + ---------- + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta, pli theta, and pli beta using the tags: 0=fmri', '1=pli delta', + '2= pli theta','5 = pli beta' + list_of_layers = [0,1,2,5] + + Returns + ------- + out: An aggregate list which is the mean of the values of the eccentricity per node in each layer + + """ + + name = list(data.keys())[-1] + if len(data[name].shape)==2: + number_of_individuals=1 + else: + number_of_individuals = data[name].shape[2] + + group_eccentricity = [] + for individual in range(number_of_individuals): + temp = multilayer_g(individual, data, list_of_single_layers) + m = mx.eccentricity(temp) + temp1 = list(m.values()) + temp2 = muxviz_aggregate(temp1, len(list_of_single_layers)) + # This is a list of lists with all eccentricities for all individuals + group_eccentricity.append(temp2) + # We want to buid a flat list + flat_list = [item for sublist in group_eccentricity for item in sublist] + + return flat_list + + +def non_norm_group_eccentricity(data, list_of_single_layers): + """Returns a flat list with the aggregate output for group eccentricity without normalization, given a data, and a list_of_single_layers + + Parameters + ---------- + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta, pli theta, and pli beta using the tags: 0=fmri', '1=pli delta', + '2= pli theta','5 = pli beta' + list_of_layers = [0,1,2,5] + + Returns + ------- + out: An aggregate list which is the mean of the values of the eccentricity per node in each layer without normalization + + """ + name = list(data.keys())[-1] + if len(data[name].shape)==2: + number_of_individuals=1 + else: + number_of_individuals = data[name].shape[2] + + group_eccentricity = [] + for individual in range(number_of_individuals): + temp = multilayer_g(individual, data, list_of_single_layers) + + m = mx.eccentricity(temp) + temp1 = list(m.values()) + temp2 = temp1 + # For non normalized, we don't apply the muxviz_aggregate function + #muxviz_aggregate(temp1, len(list_of_single_layers)) + + #temp2=aggregate(temp1,len(list_of_single_layers)) + # This is a list of lists with all eccentricities for all individuals + group_eccentricity.append(temp2) + # since we want to buid a flat list + flat_list = [item for sublist in group_eccentricity for item in sublist] + + return flat_list + + +def group_bet_centrality(data, list_of_single_layers): + """Returns a flat list with the aggregate output for group betweeness centralities, given a data, and a list_of_single_layers + + Parameters + ---------- + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta, pli theta, and pli beta using the tags: 0=fmri', '1=pli delta', + '2= pli theta','5 = pli beta' + list_of_layers = [0,1,2,5] + + Returns + ------- + out: An aggregate list which is the mean of the values of the betweeness centralities per node in each layer + + """ + + name = list(data.keys())[-1] + if len(data[name].shape)==2: + number_of_individuals=1 + else: + number_of_individuals = data[name].shape[2] + + group_bet_centrality = [] + for individual in range(number_of_individuals): + temp = multilayer_g(individual,data,list_of_single_layers) + + m = mx.betweenness_centrality(temp) + #m=mx.eigenvector_centrality(multilayer_g(individual,number_of_layers,list_of_layers)) + temp1 = list(m.values()) + temp2 = muxviz_aggregate(temp1, len(list_of_single_layers)) + #temp2=aggregate(temp1,len(list_of_single_layers)) + # This is a list of lists with all centralities for all individuals + group_bet_centrality.append(temp2) + # We want to buid a flat list + # Check this flattened = [val for sublist in list_of_lists for val in sublist] + flat_list = [item for sublist in group_bet_centrality for item in sublist] + + return flat_list + + +# The functions below calculate mean and standard deviation of the measures + +def group_eigenvector_centrality_mean(data, list_of_single_layers): + """Returns a flat list with the aggregate output for group eigenvector centrality mean, given a data, and a list_of_single_layers + + Parameters + ---------- + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta, pli theta, and pli beta using the tags: 0=fmri', '1=pli delta', + '2= pli theta','5 = pli beta' + list_of_layers = [0,1,2,5] + + Returns + ------- + out: An aggregate list which is the mean of the values of the eigenvector centralities per node in each layer + + """ + + "This function returns the group eigenvector centrality mean for all individuals" + name = list(data.keys())[-1] + if len(data[name].shape)==2: + number_of_individuals=1 + else: + number_of_individuals = data[name].shape[2] + + group_eigenvector_mean = [] + for individual in range(number_of_individuals): + temp = multilayer_g(individual, data, list_of_single_layers) + + m = mx.eigenvector_centrality_numpy(temp) + temp1 = list(m.values()) + temp2 = muxviz_aggregate(temp1, len(list_of_single_layers)) + # Now we just compute the mean + group_eigenvector_mean.append(np.mean(temp2)) + + return (group_eigenvector_mean) + + +def group_eigenvector_centrality_std(data, list_of_single_layers): + """Returns a flat list with the aggregate output for group eigenvector centrality standard deviation, given a data, and a list_of_single_layers + + Parameters + ---------- + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta, pli theta, and pli beta using the tags: 0=fmri', '1=pli delta', + '2= pli theta','5 = pli beta' + list_of_layers = [0,1,2,5] + + Returns + ------- + out: An aggregate list which is the standard deviation of the eigenvector centralities per subject + + """ + + "This function returns the group eigenvector centrality standard deviation for all individuals" + + name = list(data.keys())[-1] + if len(data[name].shape)==2: + number_of_individuals=1 + + else: + number_of_individuals = data[name].shape[2] + group_eigenvector_std = [] + for individual in range(number_of_individuals): + temp = multilayer_g(individual, data, list_of_single_layers) + m = mx.eigenvector_centrality_numpy(temp) + #m=mx.eigenvector_centrality(multilayer_g(individual,number_of_layers,list_of_layers)) + temp1 = list(m.values()) + temp2 = muxviz_aggregate(temp1, len(list_of_single_layers)) + # This is MV aggregate - we can change then later for something else if needed + + group_eigenvector_std.append(np.std(temp2)) + + return (group_eigenvector_std) + + +def eigenvector_centrality(individual, data, list_of_single_layers): + """Returns a histogram with the values of the Eigenvector centrality for all nodes for a chosen individual." + Parameters + ---------- + individual: an integer from [0, S-1], where S is the size of the cohort. + + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta and pli theta, using the tags: 0=fmri', '1=pli delta', '2= pli theta' + list_of_layers = [0,1,2] + + Returns + ------- + out: A list with EC for one individual + + """ + print('layers =',[layer_tags[i] for i in list_of_single_layers]) + m = mx.eigenvector_centrality_numpy(multilayer_g(individual, data, list_of_single_layers)) + temp1 = list(m.values()) + temp2=muxviz_aggregate(temp1,len(list_of_single_layers)) + + return temp2 + + +def group_degree_centrality_mean(data,list_of_single_layers): + """Returns a flat list with the aggregate output for group degree centrality mean, given a data, and a list_of_single_layers + + Parameters + ---------- + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta, pli theta, and pli beta using the tags: 0=fmri', '1=pli delta', + '2= pli theta','5 = pli beta' + list_of_single_layers = [0,1,2,5] + + Returns + ------- + out: An aggregate list which is the mean of the values of the degree centralities per node in each layer + + """ + +# "This function returns the group degree centrality mean for all individuals" + + print('layers =',[layer_tags[i] for i in list_of_single_layers]) + name = list(data.keys())[-1] + if len(data[name].shape)==2: + number_of_individuals=1 + else: + number_of_individuals = data[name].shape[2] + + "This list will save all the eigenvector centralities means for all individuals" + group_degree_centrality_mean = [] + for individual in range(number_of_individuals): + m = mx.degree_centrality(multilayer_g(individual,data,list_of_single_layers)) + temp1 = list(m.values()) # this is not aggregated + temp2 = muxviz_aggregate(temp1, len(list_of_single_layers)) # This is Mux Viz aggregate + #temp2=aggregate(temp1,len(list_of_single_layers)) + # IF you want - by any chance to do a different agreggate you should change the line above + group_degree_centrality_mean.append(np.mean(temp2)) + + return (group_degree_centrality_mean) + + +def group_degree_centrality_std(data, list_of_single_layers): + """Returns a flat list with the aggregate output for group degree centrality std, given a data, and a list_of_single_layers + + Parameters + ---------- + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta, pli theta, and pli beta using the tags: 0=fmri', '1=pli delta', + '2= pli theta','5 = pli beta' + list_of_single_layers = [0,1,2,5] + + Returns + ------- + out: An aggregate list which is the standard deviation of the values of the betweeness centralities per subject + + """ + print('layers =',[layer_tags[i] for i in list_of_single_layers]) + name = list(data.keys())[-1] + if len(data[name].shape)==2: + number_of_individuals=1 + else: + number_of_individuals = data[name].shape[2] + "This list will save all the eigenvector centralities means for all individuals" + group_degree_centrality_std = [] + for individual in range(number_of_individuals): + m = mx.degree_centrality(multilayer_g(individual, data, list_of_single_layers)) + temp1 = list(m.values()) + temp2 = muxviz_aggregate(temp1, len(list_of_single_layers)) # This is Mux Viz aggregate + #temp2=aggregate(temp1,len(list_of_single_layers)) You can change the aggregate here + print(temp2) + group_degree_centrality_std.append(np.std(temp2)) + + return (group_degree_centrality_std) + + +###################### +# PLOTTING FUNCTIONS # +###################### + +def plot_group_ec(data, list_of_single_layers): + """Returns a histogram plot with the values of the Eigenvalue centrality for all nodes across all individuals." + Parameters + ---------- + + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta and pli theta, using the tags: 0=fmri', '1=pli delta', '2= pli theta' + list_of_layers = [0,1,2] + + Returns + ------- + out : A histogram plot with EC for all nodes across all individuals + + """ + + print('layers =',[layer_tags[i] for i in list_of_single_layers]) + + temp = group_eigenvector_centrality(data,list_of_single_layers) + plt.figure(figsize=(8,5)) + plt.hist(temp) + # We can edit here the output if we have a vector with the name of the layers + plt.xlabel('Eig. centr. - aggr- all nodes all individuals ', fontsize=20) + #plt.xlim(-5,220) + plt.ylabel("frequence", fontsize=20) + #plt.xlim(40, 160) + plt.ylim(0, 3500) + #plt.title('individual '+str(individual)) + plt.show() + + +def plot_ec(individual, data, list_of_single_layers): + """Returns a histogram with the values of the Eigenvalue centrality for all nodes for a chosen individual." + Parameters + ---------- + individual: an integer from [0, S-1], where S is the size of the cohort. + + data : A preloaded .mat - Ex: supra_mst + + + list_of_layers: a list of numbers corresponding to the Multilayer you want to create - + Ex: If you want a Multilayer with fmri, pli_delta and pli theta, using the tags: 0=fmri', '1=pli delta', '2= pli theta' + list_of_layers = [0,1,2] + + Returns + ------- + out: A histogram with EC for one individual + + """ + + print('layers =',[layer_tags[i] for i in list_of_single_layers]) + #multilayer_g(individual,data,list_of_single_layers) + m = mx.eigenvector_centrality_numpy(multilayer_g(individual,data,list_of_single_layers)) + #temp=multlayer3(i) + temp1 = list(m.values()) + temp2 = muxviz_aggregate(temp1, len(list_of_single_layers)) + # This is the Mux Viz aggregate - We change the aggregate here if yo want later + plt.hist((temp2)) + ###IMPROVEMENT: We can edit here the output if we have a vector with the name of the layers + plt.xlabel('Eigenvector centrality - aggregate ', fontsize=20) + #We may also want to choose the range for the plot. + #plt.xlim(min,max) + plt.ylabel("frequence", fontsize=20) + plt.ylim(0, 100) + plt.title('individual '+ str(individual)) + plt.show() + return + + +################### +# OTHER FUNCTIONS # +################### + +# This function extracts data from specific nodes - e.g. FPN or DMN +#### IMPROVEMENT: ALSO COMPUTE MEASURES WITHIN SPECIFIC SUBNETWORK IN THE FUTURE +def mask_subnetwork(result, target): + """Returns a multilayer metric narrowed for a given list of nodes, which for our purposes are subnetworks"" + + Parameters + ---------- + result: A list with the results (output) of any of Multilayer functions in this code + + target : A list of target nodes of interest, e.g., nodes from DFN or FPN + + Returns + ------- + out: A list for the results narrowed for the target nodes, i.e., If you say the target nodes for a given subnetwork, this function returns only the results of the list associated with the target nodes" + """ + + chunks = [result[x:x+layer_size] for x in range(0, len(result), layer_size)] + mask = [chunk[x] for chunk in chunks for x in target] + + return mask + + +# This function saves data to a csv file +def save_csv(data, name, tag): + """Returns a .csv file for further analysis using SPSS + Parameters + ---------- + data: The desired data you want to save + name: The name of the file you want to save + tag: The tag for the variable/column in your .csv file + """ + # Obs: Notice that if you want to get results only for a subnetwork, we should first do: + #data=mask_subnetwork(result,target) + #before saving this file + cols = [tag] + df = pd.DataFrame(data, columns=cols) + df.to_csv(name+'.csv') + + return + +# ATTENTION: THIS IS THE ONLY FUNCTION THAT THE USER NEEDS TO CALCULATE ANY MULTILAYER +# NETWORK MEASURE +### IMPROVEMENT: create a boolean that does stuff when a mask is chosen or not +def function_output(function, data, filename, colname, layers, N=layer_size): + """Returns the desired output for the MumoBrain database, or any other database organized similarly + + THIS IS PROBABLY THE MOST IMPORTANT FUNCTION FOR THE USER OF THIS CODE, SINCE EVERYTHING WAS BUILT TO REACH THIS STAGE HERE + + Parameters + ---------- + function: One of the functions developed in this code for Multilayer Networks + data: The data we want to use: e.g., supra_mst + filename: The name of the file you want to save + colname: the name of the column tag in your file + layers: list of desired layers. + + """ + temp = function(data, layers) + #You should include the desired subnetwork here. Now we have the whole Network. + sub_net = list(range(0,N)) + # Ex: If you want FPN, sub_net=[16,17,18,19,20,21,28,29,30,31,93,94,123,124,133,134,163,164] + + temp_sub_net = mask_subnetwork(temp, sub_net) + save_csv(temp_sub_net, filename, colname) + + return diff --git a/Multilayer/readme.md b/Multilayer/readme.md new file mode 100644 index 0000000..beba266 --- /dev/null +++ b/Multilayer/readme.md @@ -0,0 +1,108 @@ +# Multilayer_Main_code.py - readme +This readme explains how to use the main multilayer code used in the MULTINET lab. This script is used to calculate a multitude of multilayer network metrics: it takes supra-adjacency matrices as input, converts them to multiNetX objects, and defines multiple functions to compute multilayer measures. As most of the code is based on multiNetX, see also the [multiNetX github repository](https://github.com/nkoub/multinetx "multiNetX github repository"). + +The script consists of three sections. In the first section, the required packages as well as the data are loaded and a quick sanity check is performed. All necessary functions for multilayer analyses are defined in the second section. Finally, in the third section, you will find the main function *function_output* that can be used to calculate any of the multilayer network measures. Note that the majority of the code (i.e. the entirety of Section 2) can thus be executed without any input or modification: if you're only looking to calculate some network measures on either the provided random data or your own multilayer dataset, please see [Section 1](#section-1:-setting-things-up "Goto Section 1") and [Section 3](#section-3:-calculating-multilayer-metrics") for instructions on how to do so. + +##### Table of contents +[Section 1: Setting things up](#section-1-setting-things-up "Goto Section 1") + * [Input file](#input-file "Goto Input file") + * [Required packages](#required-packages "Goto Required packages") + * [Settings](#settings "Goto Settings") + * [Creating layer tags](#creating-layer-tags "Goto Creating layer tags") + * [Loading the matrices](#loading-the-matrices "Goto Loading the matrices") + * [Sanity check](#sanity-check "Goto Sanity check") + +[Section 2: Defining the functions](#section-2-defining-the-functions "Goto Section 2") + * [Preparing the multilayer](#preparing-the-multilayer "Goto Preparing the multilayer") + * [Creating the aggregate](#creating-the-aggregate "Goto Creating the aggregate") + * [Multilayer functions](#multilayer-functions "Goto Multilayer functions") + * [Plotting functions](#plotting-functions "Goto Plotting functions") + * [Other functions](#other-functions "Goto Other functions") + +[Section 3: Calculating multilayer metrics](#section-3-calculating-multilayer-metrics") + * [Function_output](#function_output "Goto Function_output") + +## Section 1: Setting things up +### Input file +As some of the pre-processing of our data was performed using MATLAB and we also constructed our connectivity matrices in MATLAB, this code expects a supra-adjacency matrix of shape regions\*layers *by* regions\*layers *by* subjects, saved in a MATLAB _.mat_ file. + +### Required packages +##### Standard imports +* itertools +* multiprocessing _from_ Pool +* time + +##### Third party imports +* matplotlib.pyplot _version 3.1.1_ +* multinetx +* networkx _version 2.3_ +* numpy _version 1.19.0_ +* pandas _version 0.25.1_ +* pcolor, show, colorbar, xticks, yticks _from_ pylab +* pyreadstat _version 0.2.9_ +* scipy _version 1.3.1_ +* preprocessing _from_ sklearn _version 0.21.3_ +* MinMaxScaler _from_ sklearn.preprocessing + +### Settings +Here, the input file and its attributes are defined. +Specify the number of regions/nodes per layer by changing *layer_size*, and specify whether data is weighted or unweighted by changing the value of *weighted*. Finally, specify the location of the input data under *filename*. +Example: supra_mst = scipy.io.loadmat('/path to your data/supra_mst_full.mat') + +### Creating layer tags +The layer tags created here are used throughout the code to identify the individual layers of the multilayer, and should thus match the ordering of the layers in the supra-adjacency matrix. Change accordingly. Obs: Notice that Python starts couting from zero, not one (like in other programs such as Matlab). + +### Loading the matrices +The matlab supra-adjacency matrix specified in [Settings](#settings "Goto Settings") is loaded. + +### Sanity check +A quick check to ensure data is loaded correctly. __Note that this is not an automatic process:__ the output should be checked explicitly. Data should be of class 'dict', and the keys of the dictionary should correspond with the layer tags you created in the previous step. + +## Section 2: Defining the functions +### Preparing the multilayer +The two functions defined here (*prepare_multilayer* and *multilayer_g*) convert the input data from a Matlab file to a Multinetx friendly object. These functions are used in all the functions for computation of multilayer network measures that are defined later in this code, and do not need any user input. + +### Creating the aggregate +This function calculates an aggregate output from nodal multilayer metrics to ensure one value per multilayer node. The aggregate used is the mean of the value of a network property per node in each layer, and is the same method as is used in MuxViz (see the [MuxViz github repository](https://github.com/manlius/muxViz "MuxViz github repository")). + +### Multilayer functions +In this section, a multitude of functions for the calculation of multilayer network metrics are defined. A more in-depth description of these functions as well as their required input and output can be found in each functions' docstrings. Briefly, the following functions are defined: +Function | Output +-------- | -------- +group_eigenvector_centrality | Nodal eigenvector centrality per subject +group_clustering | Nodal clustering coefficient per subject +group_degree_centrality | Nodal degree centrality per subject +group_eccentricity | Nodal eccentricity per subject +non_norm_group_eccentricity | Non-aggregated nodal eccentricity per subject +group_bet_centrality | Nodal betweenness centrality per subject +group_eigenvector_centrality_mean | Mean eigenvector centrality per subject +group_eigenvector_centrality_std | Standard deviation of eigenvector centrality per subject +eigenvector_centrality | Nodal eigenvector centrality of a single subject +group_degree_centrality_mean | Mean degree centrality per subject +group_degree_centrality_std | Standard deviation of degree centrality per subject + +### Plotting functions +Here, two functions to plot histograms of the network metrics are defined: +Function | Output +-------- | -------- +plot_group_ec | Histogram of nodal eigenvector centrality across all subjects +plot_ec | Histogram of nodal eigenvector centrality of a single subject + +### Other functions +The function *mask_subnetwork* extracts specific nodes from a previously calculated list of network measures (e.g. nodes from the FPN or DMN); *save_csv* saves data (i.e. a list values) to a .csv file for further analysis. +OBS: If you want to calculate a certain metric within a specific subnetwork (e.g. FPN), make sure to subtract the number of the regions by -1 since python starts at 0. + +## Section 3: Calculating multilayer metrics +### Function_output +This final function, *function_output*, is the only function that is needed to calculate any of the multilayer network measures described above. It takes five input parameters (described below) and outputs a .csv file containing the desired multilayer network metric. +Input parameter | Description +--------------- | -------------- +function | One of the functions described above +data | Multilayer data that has been loaded +filename | Determines name of file to be saved +colname | Determines column name in savefile +layers | List of layers to be included for calculation of multilayer measures + +OBS: When you run this final command, specialy in the server, make sure to indicate the path of the output file, otherwhise your may be lost in your computer. +Example: function_output(group_eigenvector_centrality, supra_mst,'/path to your output/whole_multilayer_EC_mean', 'EC', list(range(6))) + diff --git a/Multilayer/readme.txt b/Multilayer/readme.txt new file mode 100644 index 0000000..81f3b57 --- /dev/null +++ b/Multilayer/readme.txt @@ -0,0 +1 @@ +This folder includes all scripts for the Multilayer analysis . All instructions will be found here! diff --git a/Multilayer/supra_randmst.mat b/Multilayer/supra_randmst.mat new file mode 100644 index 0000000..5739597 Binary files /dev/null and b/Multilayer/supra_randmst.mat differ diff --git a/Multilayer_user.py b/Multilayer_user.py new file mode 100644 index 0000000..4dca247 --- /dev/null +++ b/Multilayer_user.py @@ -0,0 +1,397 @@ +#!/usr/bin/env python3 + # -*- coding: utf-8 -*- + """ + Created on Thu Oct 1 14:43:55 2020 + @author: fernando + """ + + import Multilayer_Main_code as Multinet + + + ####################################################################### + # HERE ARE NEARLY ALL THE RUNNING ANALYSIS WE DID FOR THE MUMO PROJECT# + ####################################################################### + + + ######################## + #Monolayer EC - No Mask# + ######################## + + for i in range(0,8): + filename='Random_No_Mask_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + colname='Random_No_Mask_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + print(filename) + print(colname) + function=Group_eigenvector_centrality + Data=Supra_MST + Multinet.Function_output(function,Data,filename,colname,[i]) + print('we did it') + + + ############### + #MULTILAYER-EC# + ############### + + filename='EC_No_Mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + colname='EC_No_Mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + print(filename) + print(colname) + function=Group_eigenvector_centrality + Data=Supra_MST + Multinet.Function_output(function,Data,filename,colname,list(range(8))) + print('we did it') + + + + ########################## + #Monolayer Bet_centrality# + ########################## + + for i in range(0,8): + filename='Bet_cent_FPN_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + colname='Bet_cent_FPN_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + print(filename) + print(colname) + function=Group_bet_centrality + Data=Supra_MST + Multinet.Function_output(function,Data,filename,colname,[i]) + print('we did it') + + + ################ + #MULTILAYER - BC# + ################ + filename='Bet_cent_FPN_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + colname='Bet_cent_FPN_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + print(filename) + print(colname) + function=Group_bet_centrality + Data=Supra_MST + Multinet.Function_output(function,Data,filename,colname,list(range(8))) + print('we did it') + #-------------------- + + + #M0no RANDOM_EC----------------- + #for i in range(0,8): + # filename='EC_No_Mask_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # colname='EC_No_Mask_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # print(filename) + # print(colname) + # function=Group_eigenvector_centrality + # Data=Supra_MST_random + # Function_output(function,Data,filename,colname,[i]) + # print('we did it') + + + # + #MULTILAYER _EC-----real ------ + #filename='EC_No_Mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='EC_No_Mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Group_eigenvector_centrality + #Data=Supra_MST + #Function_output(function,Data,filename,colname,list(range(8))) + #print('we did it') + + #MULTI_EC------random + + #filename='EC_No_Mask_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='EC_No_Mask_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Group_eigenvector_centrality + #Data=Supra_MST_random + #Function_output(function,Data,filename,colname,list(range(8))) + #print('we did it') + + #___________________________________________________________ + #------------------- + + #MULTILAYER clustering + #filename='Clustering_no_mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Clustering_no_mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Group_clustering + #Data=Supra_MST + #Function_output(function,Data,filename,colname,list(range(8))) + #print('we did it') + #------------------------------------------------------------ + + + + #MULTILAYER Degree Centrality + #filename='Degree_cent_no_mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Degree_cent_no_mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Group_degree_centrality + #Data=Supra_MST + #Function_output(function,Data,filename,colname,list(range(8))) + #print('we did it') + #------------------------------------------------------------ + + + + #mono Group_bet_centrality + + #for i in range(0,8): + # filename='Bet_cent_FPN_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + # colname='Bet_cent_FPN_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + # print(filename) + # print(colname) + # function=Group_bet_centrality + # Data=Supra_MST + # Function_output(function,Data,filename,colname,[i]) + # print('we did it') + #---------------------------- + + # mono BET_CENT_RANDOM + #for i in range(0,8): + # filename='Bet_cent_FPN_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # colname='Bet_cent_FPN_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # print(filename) + # print(colname) + # function=Group_bet_centrality + # Data=Supra_MST_random + # Function_output(function,Data,filename,colname,[i]) + # print('we did it') + + + + #------------------- + #MULTILAYER _BC + #filename='Bet_cent_FPN_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Bet_cent_FPN_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Group_bet_centrality + #Data=Supra_MST + #Function_output(function,Data,filename,colname,list(range(8))) + #print('we did it') + #-------------------- + #MUltilayer_BC_RANDOM + + #filename='Bet_cent_FPN_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Bet_cent_FPN_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Group_bet_centrality + #Data=Supra_MST_random + #Function_output(function,Data,filename,colname,list(range(8))) + #print('we did it') + + + + #-------------------------------------------------------- + + + + #MULTILAYER_ECC + #filename='Eccentricity_FPN_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Eccentricity_FPN_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Group_eccentricity + #Data=Supra_MST + #Function_output(function,Data,filename,colname,list(range(8))) + #print('we did it') + + #----------------- + #Multi ecc random + #filename='Eccentricity_FPN_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Eccentricity_FPN_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Group_eccentricity + #Data=Supra_MST_random + #Function_output(function,Data,filename,colname,[i]) + #print('we did it') + + #---------------- + #Group_eccentricity_monolayer + + #for i in range(0,8): + # filename='Eccentricity_FPN_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + # colname='Eccentricity_FPN_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + # print(filename) + # print(colname) + # function=Group_eccentricity + # Data=Supra_MST + # Function_output(function,Data,filename,colname,[i]) + # print('we did it') + #-------------- + # ECC_RANDOM_monolayer + + #for i in range(0,8): + # filename='Eccentricity_FPN_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # colname='Eccentricity_FPN_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # print(filename) + # print(colname) + # function=Group_eccentricity + # Data=Supra_MST_random + # Function_output(function,Data,filename,colname,[i]) + # print('we did it') + + + # This just get some list - result from a Multilayer computation and convert to the target subnetwork - here is FPN + + #Non_norm_Group_eccentricity + + + #MULTILAYER_ECC - Without Normalization + #filename='Non_norm_Eccentricity_FPN_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Non_norm_Eccentricity_FPN_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Non_norm_Group_eccentricity + #Data=Supra_MST + #Function_output(function,Data,filename,colname,list(range(8))) + #print('we did it') + + #----------------- + #Multi ecc random + #filename='Non_norm_Eccentricity_FPN_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Non_norm_Eccentricity_FPN_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Non_norm_Group_eccentricity + #Data=Supra_MST_random + #Function_output(function,Data,filename,colname,[i]) + #print('we did it') + + #---------------- + #Group_eccentricity_monolayer + + #for i in range(0,8): + # filename='Non_norm_Eccentricity_FPN_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + # colname='Non_norm_Eccentricity_FPN_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + # print(filename) + # print(colname) + # function=Non_norm_Group_eccentricity + # Data=Supra_MST + # Function_output(function,Data,filename,colname,[i]) + # print('we did it') + #-------------- + # ECC_RANDOM_monolayer + + #for i in range(0,8): + # filename='Non_norm_Eccentricity_FPN_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # colname='Non_norm_Eccentricity_FPN_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # print(filename) + # print(colname) + # function=Non_norm_Group_eccentricity + # Data=Supra_MST_random + # Function_output(function,Data,filename,colname,[i]) + # print('we did it') + + + + + + #MULTILAYER_ECC - Without Normalization and no mask + #filename='Non_norm_Eccentricity_No_Mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Non_norm_Eccentricity_No_Mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Non_norm_Group_eccentricity + #Data=Supra_MST + #Function_output(function,Data,filename,colname,list(range(8))) + #print('we did it') + + #----------------- + #Multi ecc random + #filename='Non_norm_Eccentricity_No_Mask_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Non_norm_Eccentricity_No_Mask_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Non_norm_Group_eccentricity + #Data=Supra_MST_random + #Function_output(function,Data,filename,colname,[i]) + #print('we did it') + + #---------------- + #Group_eccentricity_monolayer + + #for i in range(0,8): + # filename='Non_norm_Eccentricity_No_Mask_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + # colname='Non_norm_Eccentricity_No_Mask_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + # print(filename) + # print(colname) + # function=Non_norm_Group_eccentricity + # Data=Supra_MST + # Function_output(function,Data,filename,colname,[i]) + # print('we did it') + #-------------- + # ECC_RANDOM_monolayer + + #for i in range(0,8): + # filename='Non_norm_Eccentricity_No_Mask_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # colname='Non_norm_Eccentricity_No_Mask_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # print(filename) + # print(colname) + # function=Non_norm_Group_eccentricity + # Data=Supra_MST_random + # Function_output(function,Data,filename,colname,[i]) + # print('we did it') + + + #MULTILAYER_ECC - Without Normalization and no mask + #filename='Non_norm_Eccentricity_No_Mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Non_norm_Eccentricity_No_Mask_Group_MST_Multi_layer_real_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Non_norm_Group_eccentricity + #Data=Supra_MST + #Function_output(function,Data,filename,colname,list(range(8))) + #print('we did it') + + #----------------- + #Multi ecc random + #filename='Non_norm_Eccentricity_No_Mask_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #colname='Non_norm_Eccentricity_No_Mask_Group_MST_Multi_layer_random_'#+Layer_dic[i]+'_tag_'+str(i) + #print(filename) + #print(colname) + #function=Non_norm_Group_eccentricity + #Data=Supra_MST_random + #Function_output(function,Data,filename,colname,[i]) + #print('we did it') + + #---------------- + #Group_eccentricity_monolayer + + #for i in range(0,8): + # filename='Non_norm_Eccentricity_No_Mask_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + # colname='Non_norm_Eccentricity_No_Mask_Group_MST_Mono_layer_real_'+Layer_dic[i]+'_tag_'+str(i) + # print(filename) + # print(colname) + # function=Non_norm_Group_eccentricity + # Data=Supra_MST + # Function_output(function,Data,filename,colname,[i]) + # print('we did it') + #-------------- + # ECC_RANDOM_monolayer + + #for i in range(0,8): + # filename='Non_norm_Eccentricity_No_Mask_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # colname='Non_norm_Eccentricity_No_Mask_Group_MST_Mono_layer_random_'+Layer_dic[i]+'_tag_'+str(i) + # print(filename) + # print(colname) + # function=Non_norm_Group_eccentricity + # Data=Supra_MST_random + # Function_output(function,Data,filename,colname,[i]) + # print('we did it') + + + # Same for other stuff + #FPN=[16,17,18,19,20,21,28,29,30,31,93,94,129,130,139,140,169,170] + #Group_bet_cent=Group_bet_centrality(Supra_MST,list(range(13))) + #print('done') + #Group_bet_cent_DWI=Group_bet_centrality(Supra_MST_DWI,list(range(14))) + #Group_bet_cent_FPN=Mask_subnetwork(Group_bet_cent,FPN) + #Group_bet_cent_FPN_DWI=Mask_subnetwork(Group_bet_cent_DWI,FPN) + + #SaveSPSS(Group_bet_cent_FPN,'Lucas_Bet_Cen_FPN','BC_Group') + #SaveSPSS(Group_bet_cent_FPN_DWI,'Lucas_Bet_Cen_FPN_DWI','BC_Group_DWI')