def plot_mriscan_weak(fu, mriscan, netname): print(mriscan) net = fu.nets.load(mriscan, netname) netfilepath = fu.nets.loadfilepath(mriscan, netname) netfiledir = os.path.dirname(netfilepath) atlasobj = fu.atlasobj attrdata = np.mean(net.data, axis=0) attr = netattr.Attr(attrdata, atlasobj) outfilepath = os.path.join(netfiledir, netname + '_circos_weak') title = '{}\n{}\n'.format(mriscan, netname) if netname == 'bold_net': p = WeakBOLDNetCircosPlot(atlasobj, title, outfilepath) p.add_circosvalue(braincircos.CircosValue(attr, (-1, 1))) p.add_circoslink(WeakCircosLink(net, 0.5, (-1, 1))) elif netname == 'dwi_net': p = WeakDWINetCircosPlot(atlasobj, title, outfilepath) p.add_circosvalue(braincircos.CircosValue(attr, (-100, 100))) p.add_circosvalue( braincircos.CircosValue(fu.attrs.load(mriscan, 'dwi_MD'), (-0.003, 0.003))) p.add_circosvalue( braincircos.CircosValue(fu.attrs.load(mriscan, 'dwi_FA'), (-1, 1))) p.add_circoslink(WeakCircosLink(net, 2, (-6, 6))) else: return p.plot()
def trans_netattr(self,subject_scan, atlas_name, feature_name, value): if value.ndim == 1: # 这里要改一下 arr = netattr.Attr(value, atlas.get(atlas_name),subject_scan, feature_name) return arr else: net = netattr.Net(value, atlas.get(atlas_name), subject_scan, feature_name) return net
def loadSingle(self, mriscan, attrname, csvfilename = None): """ Load the attribute object, with atlasobj. - mriscan: specify which scan to load from - attrname: the name of the attr to load - csvfilename: the name of the attr file name. Specify this parameter to override filename """ if csvfilename is not None: attrdata = self.loaddata(mriscan, attrname, csvfilename) else: attrdata = self.loaddata(mriscan, attrname) attr = netattr.Attr(attrdata, self.atlasobj, mriscan, attrname) return attr
def plot_mriscan(fu, mriscan): netname = 'bold_net' print(mriscan) net = fu.nets.load(mriscan, netname) netfilepath = fu.nets.loadfilepath(mriscan, netname) netfiledir = os.path.dirname(netfilepath) atlasobj = fu.atlasobj #attr = netattr.Attr(0.5*np.ones(atlasobj.count), atlasobj) mean = np.mean(net.data, axis=0) attr = netattr.Attr(mean, atlasobj) outfilepath = os.path.join(netfiledir, netname + '_circos') title = '{}\n{}'.format(mriscan, netname) p = braincircos.CircosPlot(net, attr, title, outfilepath) p.plot()
def get_static_attr(self, scan, atlas_name, feature, comment={}): """ Return to an attr object directly """ query = dict(scan=scan, comment=comment) col = self.getcol(atlas_name, feature) count = self.sadb[col].count_documents(query) if count == 0: raise NoRecordFoundException(scan + atlas_name + feature) elif count > 1: raise MultipleRecordException(scan + atlas_name + feature) else: AttrData = pickle.loads(self.sadb[col].find_one(query)['value']) atlasobj = atlas.get(atlas_name) attr = netattr.Attr(AttrData, atlasobj, scan, feature) return attr
def get_attr(self, scan, atlas_name, feature, comment_dict={}): #return to an attr object directly if self.exist_static(scan, atlas_name, feature, comment_dict): binary_data = self.query_static(scan, atlas_name, feature, comment_dict)[0]['value'] attrdata = pickle.loads(binary_data) atlasobj = atlas.get(atlas_name) attr = netattr.Attr(attrdata, atlasobj, scan, feature) return attr else: print( "can't find the document you look for. scan: %s, atlas: %s, feature: %s." % (scan, atlas_name, feature)) raise NoRecordFoundException(scan) return None
ChanggungPatientNets = io_utils.loadSpecificNets( mmdps_locale.ChanggungAllFullPath, atlasobj, subjectList=os.path.join(mmdps_locale.ChanggungRootPath, 'CS_subjects.txt')) ChanggungHealthyNets = io_utils.loadSpecificNets( mmdps_locale.ChanggungAllFullPath, atlasobj, subjectList=os.path.join(mmdps_locale.ChanggungRootPath, 'normal_subjects.txt')) sig_connections = stats_utils.filter_sigdiff_connections_Bonferroni( ChanggungPatientNets, ChanggungHealthyNets) sigDiffNet = netattr.Net(np.zeros((atlasobj.count, atlasobj.count)), atlasobj) for conn in sig_connections: sigDiffNet.data[conn[0], conn[1]] = 1 title = 'CS_signet' outfilepath = 'E:/Results/CS_signet/test.png' builder = braincircos.CircosPlotBuilder(atlasobj, title, outfilepath) builder.add_circoslink(braincircos.CircosLink(sigDiffNet)) builder.add_circosvalue( braincircos.CircosValue( netattr.Attr(np.random.uniform(size=atlasobj.count), atlasobj))) builder.customizeSize('0.80', '10p') builder.plot()
atlasobj = atlas.get('brodmann_lrce') # subject_list = ['tanenci_20170601', 'tanenci_20170706', 'tanenci_20170814', 'tanenci_20170922', 'tanenci_20171117'] subject_list = [ 'wangwei_20171107', 'wangwei_20171221', 'wangwei_20180124', 'wangwei_20180211', 'wangwei_20180520' ] # subject_list = ['xiezhihao_20180416', 'xiezhihao_20180524'] # load in the given subject's net net1 = netattr.Net( loadsave.load_csvmat('Y:/BOLD/%s/brodmann_lrce/bold_net/corrcoef.csv' % subject_list[0]), atlasobj) wd1 = netattr.Attr( loadsave.load_csvmat( 'Y:/BOLD/%s/brodmann_lrce/bold_net_attr/inter-region_wd.csv' % subject_list[0]), atlasobj) # net1.data = abs(net1.data) net2 = netattr.Net( loadsave.load_csvmat('Y:/BOLD/%s/brodmann_lrce/bold_net/corrcoef.csv' % subject_list[-1]), atlasobj) wd2 = netattr.Attr( loadsave.load_csvmat( 'Y:/BOLD/%s/brodmann_lrce/bold_net_attr/inter-region_wd.csv' % subject_list[-1]), atlasobj) # net2.data = abs(net2.data) net1, net2, ratio = all_neg(net1, net2) net2.data -= net1.data # net2.data = abs(net2.data) - abs(net1.data)
def run_feature(self, feature_name, feature_config): """ Override super run_feature. Stores csv files to MongoDB directly """ if feature_config['file_type'] != '.csv': # only supports csv features return in_file_list, out_file_list = self.get_feature_file_path(feature_config) if self.is_dynamic and feature_config['modal'] == 'BOLD': if len(in_file_list) < 1: print('==Not Exist:', self.mriscan, self.atlasname, feature_name) return if feature_name.find('net') != -1: feature = netattr.DynamicNet(None, self.atlasname, self.dataconfig['dynamic']['window_length'], self.dataconfig['dynamic']['step_size'], scan = self.mriscan, feature_name = feature_name) for file in in_file_list: feature.append_one_slice(load_csvmat(file)) try: self.mdb.save_dynamic_network(feature) except mongodb_database.MultipleRecordException: if self.force: # delete and overwrite self.mdb.remove_dynamic_network(self.mriscan, self.dataconfig['dynamic']['window_length'], self.dataconfig['dynamic']['step_size'], self.atlasname) self.mdb.save_dynamic_network(feature) else: print('!!!Already Exist: %s %s %s. Skipped' % (self.mriscan, self.atlasname, feature_name)) else: feature = netattr.DynamicAttr(None, self.atlasname, self.dataconfig['dynamic']['window_length'], self.dataconfig['dynamic']['step_size'], scan = self.mriscan, feature_name = feature_name) for file in in_file_list: feature.append_one_slice(load_csvmat(file)) try: self.mdb.save_dynamic_attr(feature) except mongodb_database.MultipleRecordException: if self.force: # delete and overwrite self.mdb.remove_dynamic_attr(self.mriscan, feature_name, self.dataconfig['dynamic']['window_length'], self.dataconfig['dynamic']['step_size'], self.atlasname) self.mdb.save_dynamic_attr(feature) else: print('!!!Already Exist: %s %s %s. Skipped' % (self.mriscan, self.atlasname, feature_name)) elif self.is_dynamic: # dynamic but not BOLD feature return else: # not dynamic for file in in_file_list: if not os.path.isfile(file): print('==Not Exist:', self.mriscan, self.atlasname, feature_name) continue if feature_name.find('net') != -1: feature = netattr.Net(load_csvmat(file), self.atlasname, self.mriscan, feature_name) else: feature = netattr.Attr(load_csvmat(file), self.atlasname, self.mriscan, feature_name) try: self.mdb.save_static_feature(feature) except mongodb_database.MultipleRecordException: if self.force: # delete and overwrite self.mdb.remove_static_feature(self.mriscan, self.atlasname, feature_name) self.mdb.save_static_feature(feature) else: print('!!!Already Exist: %s %s %s. Skipped' % (self.mriscan, self.atlasname, feature_name))
from mmdps.util import loadsave from mmdps.vis.bnv import gen_matlab, get_mesh import numpy as np # load in the given subject's attributes atlasobj = atlas.get('brodmann_lrce') subject_list = [ 'tanenci_20170601', 'tanenci_20170706', 'tanenci_20170814', 'tanenci_20170922', 'tanenci_20171117' ] # subject_list = ['wangwei_20171107', 'wangwei_20171221', 'wangwei_20180124', 'wangwei_20180211', 'wangwei_20180520'] # subject_list = ['xiezhihao_20180416', 'xiezhihao_20180524'] for i in range(0, len(subject_list)): attr1 = netattr.Attr( loadsave.load_csvmat( 'Y:/BOLD/%s/brodmann_lrce/bold_net_attr/inter-region_wd.csv' % subject_list[i - 1]), atlasobj) # prepare BNV node file atlasobj.bnvnode.change_value(attr1.data) atlasobj.bnvnode.change_modular([int(d) for d in (attr1.data > 0)]) atlasobj.bnvnode.write( 'E:/Changgung works/jixieshou_20180703/%s/%s %d node.node' % (subject_list[i].split('_')[0], subject_list[i].replace('_', ' '), i + 1)) mstr = gen_matlab( 'E:/Changgung works/jixieshou_20180703/%s/%s %d node.node' % (subject_list[i].split('_')[0], subject_list[i].replace( '_', ' '), i + 1), '', 'abc', 'E:/Changgung works/jixieshou_20180703/%s/%s %d node.png' % (subject_list[i].split('_')[0], subject_list[i].replace('_',
import csv from mmdps.proc import netattr, atlas, job from mmdps.util import loadsave from mmdps.vis.bnv import gen_matlab, get_mesh import numpy as np # load in the given subject's attributes atlasobj = atlas.get('brodmann_lrce') subject_list = [ 'tanenci_20170601', 'tanenci_20170706', 'tanenci_20170814', 'tanenci_20170922', 'tanenci_20171117' ] # subject_list = ['wangwei_20171107', 'wangwei_20171221', 'wangwei_20180124', 'wangwei_20180211', 'wangwei_20180520'] attr1 = netattr.Attr( loadsave.load_csvmat( 'Y:/BOLD/xiezhihao_20180416/brodmann_lrce/bold_net_attr/inter-region_wd.csv' ), atlasobj) attr2 = netattr.Attr( loadsave.load_csvmat( 'Y:/BOLD/xiezhihao_20180524/brodmann_lrce/bold_net_attr/inter-region_wd.csv' ), atlasobj) attr2.data -= attr1.data # prepare BNV node file atlasobj.bnvnode.change_value(attr2.data) atlasobj.bnvnode.change_modular([int(d) for d in (attr2.data > 0)]) atlasobj.bnvnode.write( 'E:/Changgung works/jixieshou_20180703/xiezhihao/xiezhihao 21 node.node') mstr = gen_matlab( 'E:/Changgung works/jixieshou_20180703/xiezhihao/xiezhihao 21 node.node',