Exemple #1
0
	def compare_BOLD_networks(self, group1_name, group2_name, comparison_method):
		group1_scan_list = self.get_scan_in_group(group1_name)
		group2_scan_list = self.get_scan_in_group(group2_name)
		self.group_nets[group1_name] = [loader.load_single_network(self.atlasobj, scan) for scan in group1_scan_list]
		self.group_nets[group2_name] = [loader.load_single_network(self.atlasobj, scan) for scan in group2_scan_list]
		stats_network, comp_p_network = netattr.networks_comparisons(self.group_nets[group2_name], self.group_nets[group1_name], comparison_method)
		return stats_network, comp_p_network
def test_real_data():
    from mmdps.proc import loader, atlas
    atlasobj = atlas.get('brodmann_lrce')
    subject_1 = loader.load_single_network(atlasobj, 'caochangsheng_20161027')
    subject_1 = subject_1.threshold(0.85)
    subject_1_data = (np.abs(subject_1.data) > 0).astype(int)

    subject_2 = loader.load_single_network(atlasobj, 'caochangsheng_20161114')
    subject_2 = subject_2.threshold(0.85)
    subject_2_data = (np.abs(subject_2.data) > 0).astype(int)

    # subject_2_data = subject_1_data.copy()
    # subject_2_data[0, 3] = 0
    # subject_2_data[3, 0] = 0
    print('graph similarity: ',
          compare_two_graphs(subject_1_data, subject_2_data, 4, 4))
def calculate_real_healthy_range_threshold():
    """
	This function loads in the healthy networks, calculate graph similarities, and plot them in one graph.
	"""
    atlasobj = atlas.get('brodmann_lrce')
    healthy_group = group_manager.getHealthyGroup()
    healthy_scans = [scan.filename for scan in healthy_group.scans]
    healthy_nets = [
        loader.load_single_network(atlasobj, filename)
        for filename in healthy_scans
    ]
    thresh_list = list(range(60, 100))
    curve_mat = np.zeros((int(len(healthy_nets) * (len(healthy_nets) - 1) / 2),
                          len(thresh_list)))  # each row is a curve
    for count, threshold in enumerate(thresh_list):
        print('Threshold: %d' % threshold)
        threshold = threshold / 100.0
        counter = 0  # counter in curve_mat row index
        for i in range(len(healthy_nets)):
            for j in range(i + 1, len(healthy_nets)):
                # calculate similarities between each pair of networks
                curve_mat[counter, count] = compare_two_graphs(
                    healthy_nets[i].binarize(threshold).data,
                    healthy_nets[j].binarize(threshold).data, 4, 4)
                counter += 1
    mdb = mongodb_database.MongoDBDatabase(None)
    mdb.put_temp_data(
        curve_mat, 'graph kernel inter-healthy',
        'The inter-healthy network similarity calculated by graph kernel method with d = 4, h = 4. The binary threshold is varied range(60, 100). The data is of shape (cases, thresh_list length). Each row is a curve'
    )
def calculate_SCI_vs_healthy():
    """
	This function loads in healthy networks and SCI patients networks, calculate each
	patients network similarity to each healthy controls, and plot each person's similarity
	in one figure.
	"""
    atlasobj = atlas.get('brodmann_lrce')
    healthy_group = group_manager.getHealthyGroup()
    healthy_scans = [scan.filename for scan in healthy_group.scans]
    healthy_nets = [
        loader.load_single_network(atlasobj, filename)
        for filename in healthy_scans
    ]

    assistant = analysis_report.GroupAnalysisAssistant('jisuizhenjiaciji',
                                                       atlasobj)
    study = assistant.study
    group1 = study.getGroup('control 1')
    scans = [scan.filename for scan in group1.scans]
    group2 = study.getGroup('treatment 1')
    scans += [scan.filename for scan in group2.scans]
    SCI_nets = [loader.load_single_network(atlasobj, scan) for scan in scans]

    curve_mat = np.zeros((len(scans) * len(healthy_scans),
                          len(thresh_list)))  # each row is a curve
    column_counter = 0
    for subj_num, SCI_net in enumerate(SCI_nets):
        for healthy_net in healthy_nets:
            for count, threshold in enumerate(thresh_list):
                print('Threshold: %d, pair: %d/%d' %
                      (threshold, column_counter, curve_mat.shape[0]))
                threshold = threshold / 100.0
                curve_mat[column_counter, count] = compare_two_graphs(
                    SCI_net.binarize(threshold).data,
                    healthy_net.binarize(threshold).data, 4, 4)
            column_counter += 1
    mdb = mongodb_database.MongoDBDatabase(None)
    mdb.put_temp_data(
        curve_mat, 'graph kernel SCI 1 x HC',
        'The network similarity of each pair of SCI 1 and HC calculated by graph kernel method with d = 4, h = 4. The binary threshold is varied range(60, 100). The data is of shape (cases, thresh_list length). Each row is a curve.'
    )
def calculate_real_range_parameters():
    mdb = mongodb_database.MongoDBDatabase(None)
    atlasobj = atlas.get('brodmann_lrce')
    subject_1 = loader.load_single_network(atlasobj, 'caochangsheng_20161027')
    subject_2 = loader.load_single_network(atlasobj, 'caochangsheng_20161114')
    subject_3 = loader.load_single_network(atlasobj, 'chenyifan_20150612')
    subject_4 = loader.load_single_network(atlasobj, 'chenyifan_20150629')

    threshold_list = range(40, 60, 5)
    h_list = list(range(1, int(atlasobj.count / 2)))
    d_list = list(range(2, 10))
    for thresh_count, threshold in enumerate(threshold_list, 1):
        threshold = threshold / 100.0
        sim_list_1 = np.zeros(len(h_list))
        sim_list_2 = np.zeros(len(h_list))
        sim_list_3 = np.zeros(len(h_list))
        for idx, h in enumerate(h_list):
            print('threshold: %d/%d, depth: %d/%d' %
                  (thresh_count, len(threshold_list), h, h_list[-1]))
            sim_list_1[idx] = compare_two_graphs(
                subject_1.binarize(threshold).data,
                subject_2.binarize(threshold).data, h, 4)
            sim_list_2[idx] = compare_two_graphs(
                subject_3.binarize(threshold).data,
                subject_4.binarize(threshold).data, h, 4)
            sim_list_3[idx] = compare_two_graphs(
                subject_1.binarize(threshold).data,
                subject_3.binarize(threshold).data, h, 4)
        threshold = int(threshold * 100.0)
        mdb.put_temp_data(
            sim_list_1, 'gk cao range h threshold %d' % threshold,
            'caochangsheng_20161027 vs caochangsheng_20161114 network similarity measured by graph kernel with brodmann_lrce, threshold = %d, d = 4, h range(1, int(atlasobj.count/2))'
            % threshold)
        mdb.put_temp_data(
            sim_list_2, 'gk chen range h threshold %d' % threshold,
            'chenyifan_20150612 vs chenyifan_20150629 network similarity measured by graph kernel with brodmann_lrce, threshold = %d, d = 4, h range(1, int(atlasobj.count/2))'
            % threshold)
        mdb.put_temp_data(
            sim_list_3, 'gk cao vs chen range h threshold %d' % threshold,
            'caochangsheng_20161027 vs chenyifan_20150612 network similarity measured by graph kernel with brodmann_lrce, threshold = %d, d = 4, h range(1, int(atlasobj.count/2))'
            % threshold)