def omni_embed(pop_array): variance_threshold = VarianceThreshold(threshold=0.05) diags = np.array([np.triu(pop_array[i]) for i in range(len(pop_array))]) diags_red = diags.reshape(diags.shape[0], diags.shape[1] * diags.shape[2]) var_thr = variance_threshold.fit(diags_red.T) graphs_ix_keep = var_thr.get_support(indices=True) pop_array_red = [pop_array[i] for i in graphs_ix_keep] # Omnibus embedding -- random dot product graph (rdpg) print("%s%s%s" % ('Embedding ensemble for atlas: ', atlas, '...')) omni = OmnibusEmbed(check_lcc=False) try: omni_fit = omni.fit_transform(pop_array_red) mds = ClassicalMDS() mds_fit = mds.fit_transform(omni_fit) except: omni_fit = omni.fit_transform(pop_array) mds = ClassicalMDS() mds_fit = mds.fit_transform(omni_fit) # Transform omnibus tensor into dissimilarity feature dir_path = os.path.dirname(graph_path) out_path = "%s%s%s%s%s%s" % (dir_path, '/', list(flatten(ID))[0], '_omnetome_', atlas, '.npy') print('Saving...') np.save(out_path, mds_fit) del mds, mds_fit, omni, omni_fit return
def flatten(l): import collections for el in l: if isinstance( el, collections.Iterable) and not isinstance(el, (str, bytes)): for ell in flatten(el): yield ell else: yield el
def pass_meta_outs(conn_model_iterlist, est_path_iterlist, network_iterlist, node_size_iterlist, thr_iterlist, prune_iterlist, ID_iterlist, roi_iterlist, norm_iterlist, binary_iterlist, embed=True, multimodal=False): from pynets.utils import build_omnetome, flatten """ :param conn_model_iterlist: :param est_path_iterlist: :param network_iterlist: :param node_size_iterlist: :param thr_iterlist: :param prune_iterlist: :param ID_iterlist: :param roi_iterlist: :param norm_iterlist: :param binary_iterlist: :return: """ if embed is True: build_omnetome(list(flatten(est_path_iterlist)), list(flatten(ID_iterlist))[0], multimodal) return conn_model_iterlist, est_path_iterlist, network_iterlist, node_size_iterlist, thr_iterlist, prune_iterlist, ID_iterlist, roi_iterlist, norm_iterlist, binary_iterlist
def collect_pandas_df(network, ID, net_pickle_mt_list, plot_switch, multi_nets): from pynets.utils import collect_pandas_df_make, flatten net_pickle_mt_list = list(flatten(net_pickle_mt_list)) if multi_nets is not None: net_pickle_mt_list_nets = net_pickle_mt_list for network in multi_nets: net_pickle_mt_list = list( set([i for i in net_pickle_mt_list_nets if network in i])) collect_pandas_df_make(net_pickle_mt_list, ID, network, plot_switch) else: collect_pandas_df_make(net_pickle_mt_list, ID, network, plot_switch) return
def collect_pandas_df(network, ID, net_pickle_mt_list, plot_switch, multi_nets, multimodal): """ :param network: :param ID: :param net_pickle_mt_list: :param plot_switch: :param multi_nets: :return: """ from pynets.utils import collect_pandas_df_make, flatten func_models = ['corr', 'sps', 'cov', 'partcorr', 'QuicGraphicalLasso', 'QuicGraphicalLassoCV', 'QuicGraphicalLassoEBIC', 'AdaptiveQuicGraphicalLasso'] struct_models = ['csa', 'tensor', 'csd'] net_pickle_mt_list = list(flatten(net_pickle_mt_list)) if multi_nets is not None: net_pickle_mt_list_nets = net_pickle_mt_list for network in multi_nets: net_pickle_mt_list = list(set([i for i in net_pickle_mt_list_nets if network in i])) if multimodal is True: net_pickle_mt_list_dwi = list(set([i for i in net_pickle_mt_list if i.split('metrics_')[1].split('_')[0] in struct_models])) collect_pandas_df_make(net_pickle_mt_list_dwi, ID, network, plot_switch) net_pickle_mt_list_func = list(set([i for i in net_pickle_mt_list if i.split('metrics_')[1].split('_')[0] in func_models])) collect_pandas_df_make(net_pickle_mt_list_func, ID, network, plot_switch) else: collect_pandas_df_make(net_pickle_mt_list, ID, network, plot_switch) else: if multimodal is True: net_pickle_mt_list_dwi = list(set([i for i in net_pickle_mt_list if i.split('metrics_')[1].split('_')[0] in struct_models])) collect_pandas_df_make(net_pickle_mt_list_dwi, ID, network, plot_switch) net_pickle_mt_list_func = list(set([i for i in net_pickle_mt_list if i.split('metrics_')[1].split('_')[0] in func_models])) collect_pandas_df_make(net_pickle_mt_list_func, ID, network, plot_switch) else: collect_pandas_df_make(net_pickle_mt_list, ID, network, plot_switch) return