from maybrain import utils
from maybrain import resources as rr
from maybrain import brain as mbt
import bct

a = mbt.Brain()
a.import_adj_file(rr.DUMMY_ADJ_FILE_500, nodes_to_exclude=[0,1,2,3,4,5])
a.import_spatial_info(rr.MNI_SPACE_COORDINATES_500)
a.apply_threshold()

"""
Explanation: Integration with Other Tools
Throught the utils package, Maybrain provides some support to interact with other tools. 
Let's start by importing it and initialising a Brain (we are not including some nodes just for the sake of some later examples):
End of explanation
"""


bct_mat = utils.makebctmat(a, nonedge=0)
print("Shape of bct_mat: " + str(bct_mat.shape))
print("Number of nodes in a.G: " + str(a.G.number_of_nodes()))
print("Shape of the original a.adjMat: " + str(a.adjMat.shape))
print(bct_mat)

"""
Explanation: Integration with bctpy
Maybrain can be used with the pythonic version of the Brain Connectivity Toolbox which can be found here. 
For this, the G networkx object needs to be saved in a specific format. We also indicate that when a connection is not present, it will be filled with the value zero:
End of explanation
"""


bct_res = bct.modularity_louvain_und_sign(bct_mat) # calculate the Louvain modularity
print(bct_res[0])
print(bct_res[0].shape)

"""
Explanation: Functions can then be called on the resulting matrix:
End of explanation
"""


dict_info = utils.assignbctresult(a, bct_res[0])
print(dict_info)

"""
Explanation: As you can see from the above output, the result is a simple list of numbers, one for each node of our originally a.G. We need to assign them back for each a.G node, which you can do by having a dictionary with that information (you can check from the output that our nodes start with the label 6 because when importing our adjacency matrix we didn't import the first 6 nodes):
End of explanation
"""


