def test_blacklist_index_fname_to_blacklist_bool_list(self): ind_bl_fname = copy(self.cfg['blacklist_fname']).replace("bool", "ind") out_bl_fname = self.cfg['blacklist_fname'].replace("bool", "bool_test") assert "all_fnames" in self.cfg assert self.cfg["all_fnames"] dataio.blacklist_index_fname_to_blacklist_bool_list( ind_bl_fname, out_bl_fname, self.cfg["all_fnames"][0]) bl = dataio.get_ok_nodes(out_bl_fname) assert type(bl) is np.ndarray assert bl.dtype == bool # specific for the blacklist provided in the testdata: assert not bl[0] assert not bl[-1] os.remove(out_bl_fname) assert not os.path.exists(out_bl_fname)
def test_modules_igraph(self): tag = "multilevel" compcoms.comp_communities_igraph(self.cfg, tag) # viz individual individual = 0 viz.viz_com_stru_for_ind( self.cfg['all_fnames'][individual], self.cfg ) consensus_out_fname = (self.cfg['outdata_dir'] + tag + "_" + "all_fnames" + "_" + str(self.cfg['density']) + ".pkl") compcoms.comp_consensus_partition( self.cfg, 'all_fnames', consensus_out_fname, comdet_tag=tag ) data = dataio.load(consensus_out_fname) partition = data[tag] filtered_partition = partition[ dataio.get_ok_nodes(self.cfg['blacklist_fname']) ] fig = viz.viz_com_structure_using_slices(filtered_partition, self.cfg) fig.savefig(consensus_out_fname.replace(".pkl", ".pdf"), format="pdf") fig = viz.comp_and_viz_cluster_diff_matrices( partition, self.cfg, self.cfg['all_fnames'], len(self.cfg['group_1_mat_fnames']), vmin=-5, vmax=5, suptitle="", recompute=True ) fig.savefig(consensus_out_fname.replace(".pkl", "_coarse-grained.pdf"))
comdet_tag=comdet_tag) print "Matching modules algorithmically" consensus_clu_movie = \ dataio.load_pickle(consensus_fname0)[comdet_tag] consensus_clu_rest = \ dataio.load_pickle(consensus_fname1)[comdet_tag] consensus_clu_movie, consensus_clu_rest, n_clu_1, n_clu_2 = \ viz._get_matched_renumbered_communities_for_viz( consensus_clu_movie, consensus_clu_rest ) uf_consensus_clus = [consensus_clu_movie, consensus_clu_rest] print "Setting colors for modules" ok_nodes = dataio.get_ok_nodes(cfg['blacklist_fname']) filtered_consensus_clus = [ consensus_clu_movie[ok_nodes], consensus_clu_rest[ok_nodes] ] n_cols = np.maximum(np.max(consensus_clu_movie), np.max(consensus_clu_rest)) + 1 # +1 because indexing starts from zero colors_list = np.array([ "#e41a1c", # red "#f781bf", # pink "#377eb8", # blue "#95c3dd", # light blue "#1f8f61", # dark green "#a6dc6c", # light green
def comp_node_pvals(cfg, matlabQValComps=False): """ Computes the permutation-based p-values for the precomputed nodeproperties The comparison is made between ``cfg["group_1_mat_fnames"]`` and ``cfg["group_1_mat_fnames"]`` Parameters ---------- cfg : dict brainnets config dict """ if not cfg['paired']: assert cfg['n_it_permutation'] != "all", \ "all is not allowed for non-paired tests" fnames_group1 = cfg['group_1_mat_fnames'] fnames_group2 = cfg['group_2_mat_fnames'] fnames = fnames_group1 + fnames_group2 node_props_data = dataio.merge_and_load_props_data(fnames, "node_props", cfg['node_props'], cfg) ok_nodes = dataio.get_ok_nodes(cfg['blacklist_fname']) for key in node_props_data: if key != settings.densities_tag: node_props_data[key] = node_props_data[key][:, ok_nodes] n1 = len(fnames_group1) n2 = len(fnames_group2) node_pval_stats = _comp_perm_test_stats_for_some_props( node_props_data, n1, n2, cfg['paired'], cfg['n_it_permutation'], measures.mean_difference, matlabQValComps=False) # print node_pval_stats.keys() # for nodeProp in settings.node_props: # if nodeProp == settings.densities_tag: # continue # propPValStats = node_pval_stats[nodeProp] # data = node_pval_stats[nodeProp] # out_dict[settings.pval_tag] = \ # dataio.expand_1D_node_vals_to_non_blacklisted_array( # propPValStats[settings.pval_tag], ok_nodes) # out_dict[settings.meandifference_tag] = \ # dataio.expand_1D_node_vals_to_non_blacklisted_array( # propPValStats[settings.meandifference_tag], ok_nodes) # if matlabQValComps: # out_dict[settings.pfdrs_tag] = \ # dataio.expand_1D_node_vals_to_non_blacklisted_array( # propPValStats[settings.pfdrs_tag], ok_nodes) # out_dict[settings.qval_tag] = \ # dataio.expand_1D_node_vals_to_non_blacklisted_array( # propPValStats[settings.qval_tag], ok_nodes) # except: # raise out_fname = fnc.get_stats_fname(cfg, "node_props") dataio.save_pickle(out_fname, node_pval_stats)