Пример #1
0
    def _run_interface(self, runtime):

        int_mat_file = self.inputs.int_mat_file
        threshold = self.inputs.threshold

        print("loading int_mat_file")

        int_mat = np.load(int_mat_file)
        if not isdefined(threshold):
            threshold = 0

        int_list = return_int_net_list(int_mat, threshold)

        net_List_file = os.path.abspath('int_List.txt')

        export_List_net_from_list(net_List_file, int_list)

        # int correl_mat as Louvain format
        if self.inputs.export_Louvain:

            coords = np.loadtxt(self.inputs.coords_file)
            net_Louvain_file = os.path.abspath('Z_Louvain.txt')
            export_Louvain_net_from_list(net_Louvain_file, int_list, coords)

        return runtime
Пример #2
0
def test_export_Louvain_net_from_list():
    """testing Louvain Traag file building (for sake of compatibility of older
    codes)"""
    coords = np.loadtxt(coords_file)
    Z_list = np.loadtxt(Z_list_file)
    Z_Louvain_file = os.path.join(tmp_dir, "Z_Louvain.txt")
    export_Louvain_net_from_list(Z_Louvain_file, Z_list, coords)

    assert os.path.exists(Z_Louvain_file)
Пример #3
0
    def _run_interface(self, runtime):

        Z_cor_mat_file = self.inputs.Z_cor_mat_file
        threshold = self.inputs.threshold
        density = self.inputs.density

        Z_cor_mat = np.load(Z_cor_mat_file)

        if threshold != traits.Undefined and density == traits.Undefined:

            Z_cor_mat[np.abs(Z_cor_mat) < threshold] = 0.0
            Z_list = return_net_list(Z_cor_mat)

        elif threshold == traits.Undefined and density != traits.Undefined:

            Z_list = return_net_list(Z_cor_mat)
            N = int(Z_list.shape[0] * density)
            all_sorted_indexes = (-np.abs(Z_list[:, 2])).argsort()
            sorted_indexes = all_sorted_indexes[:N]
            max_thr_for_den_file = os.path.abspath('max_thr_for_den.txt')

            if N == Z_list.shape[0]:
                N = N - 1

            max_thr_for_den = np.array(Z_list[all_sorted_indexes[N], 2])

            with open(max_thr_for_den_file, "w") as f:
                f.write("max_thr_for_den:{}".format(max_thr_for_den))

            Z_list = Z_list[sorted_indexes, :]
        else:

            Z_list = return_net_list(Z_cor_mat)

        # Z correl_mat as list of edges
        net_List_file = os.path.abspath('Z_List.txt')
        export_List_net_from_list(net_List_file, Z_list)

        if self.inputs.export_Louvain:

            coords = np.loadtxt(self.inputs.coords_file)
            net_Louvain_file = os.path.abspath('Z_Louvain.txt')
            export_Louvain_net_from_list(net_Louvain_file, Z_list, coords)

        if self.inputs.export_np_bin:

            bin_mat = np.zeros(shape=Z_cor_mat.shape, dtype="int")
            bin_mat[Z_list[:, 0] - 1, Z_list[:, 1] - 1] = 1

            np_bin_mat_file = os.path.abspath("bin_mat.npy")
            np.save(np_bin_mat_file, bin_mat)

        return runtime