def create_seq_kernels(self, all_pw_map, pat_ids, kms_file_name):
        # experiment variables
        num_pat = pat_ids.shape[0]
        num_pw = len(all_pw_map)
        kms_path = self.exp_data_dir / f'{kms_file_name}-{self.label}.npz'
        if kms_path.exists(): return np_load_data(kms_path, key='kms')
        # calculate kernel matrices for over expressed genes
        over_exp_kms = np.zeros((num_pw, num_pat, num_pat))
        for ind, (pw_id, pw) in enumerate(all_pw_map.items()):  # for each pathway
            over_exp_kms[ind] = kernel(pat_ids, pw, label_key=f'label-oe-{self.label}', alpha=self.smoothing_alpha,
                                       normalization=self.kernel_normalization)
            logr(f'Calculating oe pathway kernel {ind + 1:4}/{num_pat} pw_id={pw_id}')
        log()

        # calculate kernel matrices for under expressed genes
        under_exp_kms = np.zeros((num_pw, num_pat, num_pat))
        for ind, (pw_id, pw) in enumerate(all_pw_map.items()):  # for each pathway
            under_exp_kms[ind] = kernel(pat_ids, pw, label_key=f'label-ue-{self.label}', alpha=self.smoothing_alpha,
                                        normalization=self.kernel_normalization)
            logr(f'Calculating ue pathway kernel {ind + 1:4}/{num_pat} pw_id={pw_id}')
        log()

        kms = np.vstack([over_exp_kms, under_exp_kms])  # stack all kernels
        np.savez_compressed(kms_path, kms=kms)  # save kernels

        return kms
    def create_som_kernels(self, all_pw_map, patients):
        # experiment variables
        num_pat = len(patients)
        num_pw = len(all_pw_map)
        kms_path = self.exp_data_dir / 'som-kms.npz'
        if kms_path.exists(): return np_load_data(kms_path, key='kms')
        # calculate kernel matrices for over expressed genes
        kms = np.zeros((num_pw, num_pat, num_pat))
        pat_ids = np.array([pat['pat_id'] for pat in patients])
        for ind, (pw_id, pw) in enumerate(all_pw_map.items()):  # for each pathway
            kms[ind] = kernel(pat_ids, pw, label_key='label-som', alpha=self.smoothing_alpha,
                              normalization=self.kernel_normalization)
            logr(f'Calculating som mut pathway kernel {ind + 1:4}/{num_pat} pw_id={pw_id}')
        log()

        np.savez_compressed(kms_path, kms=kms)  # save kernels

        return kms
Example #3
0
    def create_cnv_kernels(self, all_pw_map, patients, cnv_type):
        # experiment variables
        num_pat = len(patients)
        num_pw = len(all_pw_map)
        kms_path = self.kernel_dir / f'cnv-kms-{cnv_type}.npz'
        if kms_path.exists(): return np_load_data(kms_path, key='kms')
        # calculate kernel matrices for over expressed genes
        kms = np.zeros((num_pw, num_pat, num_pat))
        pat_ids = np.array(list(patients.keys()))
        for ind, (pw_id,
                  pw) in enumerate(all_pw_map.items()):  # for each pathway
            kms[ind] = kernel(pat_ids,
                              pw,
                              label_key=f'label-cnv_{cnv_type}',
                              alpha=self.smoothing_alpha,
                              normalization=self.kernel_normalization)
            logr(
                f'Calculating cnv {cnv_type} pathway kernel {ind + 1:4}/{num_pw} pw_id={pw_id}'
            )
        log()

        np.savez_compressed(kms_path, kms=kms)  # save kernels

        return kms