Exemplo n.º 1
0
def intra_calc_dynamic():
	# print(os.getcwd())
	atlasobj = path.curatlas()
	volumename = '3mm'

	nii_path = os.path.join(path.curparent(), 'pBOLD.nii')
	outfolder = os.path.join(os.getcwd(), OUTFOLDER_INTRA)
	json_path = path.fullfile("intra_attr_dynamic.json")
	# print(nii_path)
	# print(outfolder)
	if not os.path.isdir(outfolder):
		os.mkdir(outfolder)
	intra_ac = IntraAttrCalcDynamic(nii_path,atlasobj,outfolder,json_path)
	intra_ac.calc()
Exemplo n.º 2
0
def intra_calc():
    print(os.getcwd())
    atlasobj = path.curatlas()
    volumename = '3mm'

    nii_path = os.path.join(path.curparent(), 'pBOLD.nii')
    outfolder = os.path.join(os.getcwd(), 'bold_net_attr_zzl')
    json_path = path.fullfile("intra_attr.json")
    print(nii_path)
    print(outfolder)
    if not os.path.isdir(outfolder):
        os.mkdir(outfolder)
    intra_ac = IntraAttrCalc(nii_path, atlasobj, outfolder, json_path)
    intra_ac.calc()
Exemplo n.º 3
0
import os
import numpy as np
import nibabel as nib

from mmdps.proc import atlas
# from mmdps.util.loadsave import load_nii, save_csvmat
from mmdps.util import path
from mmdps.proc import job

if __name__ == '__main__':
	
	atlasobj = path.curatlas()
	volumename = '3mm'
	print(os.path.join(path.curparent(), 'pBOLD.nii'))
	print(os.getcwd())
	
	outfolder = os.path.join(os.getcwd(), 'bold_net_attr_zzl')
	print(outfolder)

Exemplo n.º 4
0
def function_bnv_nii(net_path, outPath):
    edges, vertex = [], []
    i = 0
    size = 0
    netthreshold = 0.4
    with open(net_path, 'r') as f:
        for row in csv.reader(f.read().splitlines()):
            size = len(row)
            ifHasEdge = False
            for j in range(0, len(row)):
                if abs(float(row[j])) > netthreshold and j != i:
                    if j > i:
                        edges.append((i, j, 1 / abs(float(row[j]))))
                    ifHasEdge = True
            if not ifHasEdge:
                print(i)
                vertex.append(i)
            i = i + 1

    g = igraph.Graph.TupleList(edges,
                               directed=False,
                               vertex_name_attr='name',
                               weights=True)
    g.add_vertices(vertex)
    # print(vertex)
    size = len(g.vs)
    # print(size)
    louvain_community = g.community_multilevel(weights=g.es['weight'])

    member = louvain_community.membership
    print(member, louvain_community.modularity)
    atl = path.curatlas()
    re = [atl.ticks[i] for i in g.vs['name']]
    names = g.vs['name']
    color_atlas_region(atlasobj=atl,
                       regions=re,
                       colors=[member[i] + 1 for i in range(len(member))],
                       outfilepath=os.path.join(
                           outPath,
                           'community_hub_{}.nii'.format(netthreshold)),
                       resolution="3mm")
    curNodeData = atl.bnvnode.nodedata

    color = ncolors(louvain_community._len)
    visual_style = {}
    visual_style["vertex_color"] = [color[member[i]] for i in range(size)]
    visual_style["vertex_label"] = g.vs["name"]

    # bc_path = os.path.join(outPath,"bold_net_attr","inter-region_bc_hub.csv")
    # bc_temp = []
    # with open(bc_path,'r') as f:
    #     for row in csv.reader(f.read().splitlines()):
    #         for i in row:
    #             bc_temp.append(int(i))

    bc_temp = g.betweenness(weights=g.es['weight'])

    temp_np = np.array(bc_temp)
    temp_np = (temp_np - temp_np.min()) / (temp_np.max() -
                                           temp_np.min()) * 20 + 15
    max_size = temp_np.max()
    for i in range(size):
        # curNodeData[names[i]][4],curNodeData[names[i]][3] = str(bc_temp[names[i]]),str(member[i]+1)
        curNodeData[names[i]][4], curNodeData[names[i]][3] = str(
            temp_np[i]), str(member[i] + 1)  #bc和curnodedata同顺序
        # curNodeData[names[i]][4],curNodeData[names[i]][3] = str(temp_np[names[i]]),str(member[i]+1) #bc和curnodedata同顺序

    bc = {}
    for i in range(size):
        if member[i] not in bc.keys():
            bc[member[i]] = {}
        bc[member[i]][i] = bc_temp[names[i]]

    # print(visual_style['vertex_color'])
    for v in bc.values():
        visual_style['vertex_color'][max(v, key=lambda s: v[s])] = 'white'

    for v in bc.values():
        curNodeData[names[max(v, key=lambda s: v[s])]][4] = str(max_size + 5)

    with open(
            os.path.join(outPath,
                         'community_hub_{}vis.node'.format(netthreshold)),
            'w') as f:
        for i in range(size):
            content = "\t".join(curNodeData[i]) + "\n"
            f.write(content)