Exemple #1
0
    def find_incoming_edges(self, t):
        """
        find incoming edges that build a v-structure a-->t<--b with
        a) corr(a,t)
        b) corr(b,t)
        c) ind(a,b)
        d) corr(a,b  t)

        input:
        t   :   index of the gene t
        """

        # incoming edges are associated with the gene of interest...
        pv_genes = self.genecorr_reader.getRows([t])[0]
        idx_assoc = qvalue.estimate(pv_genes) < self.thresh_corr
        idx_assoc[t] = False
        if not (idx_assoc).any():
            return None, None

        # independent of each other
        _idx_assoc = np.nonzero(idx_assoc)[0]
        pv_genes = self.genecorr_reader.getRows(_idx_assoc)[:, idx_assoc]
        idx_vstruct = np.nonzero(idx_assoc)[0]
        vstruct = pv_genes > self.thresh_ind
        idx_ind = vstruct.any(axis=1)
        idx_vstruct = idx_vstruct[idx_ind]
        vstruct = vstruct[idx_ind][:, idx_ind]
        if not (idx_vstruct).any():
            return None, None

        # becoming dependent once we condition on the gene under observation
        Yv = self.phenoreader.getRows(idx_vstruct)
        Yt = self.phenoreader.getRows([t])[0]
        _, pv_cond = pcor.pcorParallel(Yv, Yt)
        qv_cond = qvalue.estimate(pv_cond)
        vstruct *= qv_cond < self.thresh_corr
        idx_partcorr = vstruct.any(axis=0)
        if not (idx_partcorr).any():
            return None, None
        vstruct = vstruct[idx_partcorr][:, idx_partcorr]
        idx_vstruct = idx_vstruct[idx_partcorr]

        return vstruct, idx_vstruct
Exemple #2
0
    def find_incoming_edges(self, t):
        """
        find incoming edges that build a v-structure a-->t<--b with
        a) corr(a,t)
        b) corr(b,t)
        c) ind(a,b)
        d) corr(a,b  t)

        input:
        t   :   index of the gene t
        """

        # incoming edges are associated with the gene of interest...
        pv_genes = self.genecorr_reader.getRows([t])[0]
        idx_assoc = qvalue.estimate(pv_genes) < self.thresh_corr
        idx_assoc[t] = False
        if not (idx_assoc).any(): return None, None

        # independent of each other
        _idx_assoc = np.nonzero(idx_assoc)[0]
        pv_genes = self.genecorr_reader.getRows(_idx_assoc)[:, idx_assoc]
        idx_vstruct = np.nonzero(idx_assoc)[0]
        vstruct = pv_genes > self.thresh_ind
        idx_ind = vstruct.any(axis=1)
        idx_vstruct = idx_vstruct[idx_ind]
        vstruct = vstruct[idx_ind][:, idx_ind]
        if not (idx_vstruct).any(): return None, None

        # becoming dependent once we condition on the gene under observation
        Yv = self.phenoreader.getRows(idx_vstruct)
        Yt = self.phenoreader.getRows([t])[0]
        _, pv_cond = pcor.pcorParallel(Yv, Yt)
        qv_cond = qvalue.estimate(pv_cond)
        vstruct *= (qv_cond < self.thresh_corr)
        idx_partcorr = vstruct.any(axis=0)
        if not (idx_partcorr).any(): return None, None
        vstruct = vstruct[idx_partcorr][:, idx_partcorr]
        idx_vstruct = idx_vstruct[idx_partcorr]

        return vstruct, idx_vstruct
Exemple #3
0
    def find_incoming_edges(self,t):
        """
        find incoming edges that build a v-structure a-->t<--b with
        a) corr(a,t)
        b) corr(b,t)
        c) ind(a,b)
        d) corr(a,b  t)

        input:
        t   :   index of the gene t
f        """
        # incoming edges are associated with the gene of interest...        
        pv_genes = self.genecorr_reader.getRows([t])[0]
        pv_genes[t] = np.inf # don't count self-correlation in when estimating q-values (always 0)
        qv_genes = np.ones(pv_genes.shape)
        qv_genes[np.isfinite(pv_genes)] = qvalue.estimate(pv_genes[np.isfinite(pv_genes)])
        idx_assoc = qv_genes<self.thresh_corr
        idx_assoc[t] = False
        if not(idx_assoc).any(): return None,None

        # independent of each other
        _idx_assoc = np.nonzero(idx_assoc)[0]
        pv_genes = self.genecorr_reader.getRows(_idx_assoc)[:,idx_assoc]
        idx_vstruct = np.nonzero(idx_assoc)[0]
        pv_genes[~np.isfinite(pv_genes)] = 0
        vstruct     = pv_genes > self.thresh_ind
        idx_ind     = vstruct.any(axis=1)
        idx_vstruct = idx_vstruct[idx_ind]
        vstruct = vstruct[idx_ind][:,idx_ind]
        if not(idx_vstruct).any(): return None,None
         
        # becoming dependent once we condition on the gene under observation
        Yv = self.phenoreader.getRows(idx_vstruct)
        Yt = self.phenoreader.getRows([t])[0]
        _,pv_cond = pcor.pcorParallel(Yv,Yt)

        # take nans into account
        #qv_cond = qvalue.estimate(pv_cond)
        np.fill_diagonal(pv_cond,np.nan)
        qv_cond = np.ones(pv_cond.shape)
        
        # upper triangular matrix
        iu = np.triu_indices(pv_cond.shape[0])
        pv_cond_iu = pv_cond[iu]
        idx_finite = np.isfinite(pv_cond_iu)
        qv_cond_iu = np.ones(pv_cond_iu.shape)
        qv_cond_iu[idx_finite] = qvalue.estimate(pv_cond_iu[idx_finite])
        qv_cond[iu] = qv_cond_iu

        # lower triangular matrix
        il = np.tril_indices(pv_cond.shape[0])
        qv_cond[il] = 0
        qv_cond += qv_cond.T
        
        vstruct*= (qv_cond < self.thresh_corr)
        idx_partcorr = vstruct.any(axis=0)
        if not(idx_partcorr).any(): return None,None
        vstruct = vstruct[idx_partcorr][:,idx_partcorr]
        idx_vstruct = idx_vstruct[idx_partcorr]

        return vstruct, idx_vstruct
Exemple #4
0
    def find_incoming_edges(self, t):
        """
        find incoming edges that build a v-structure a-->t<--b with
        a) corr(a,t)
        b) corr(b,t)
        c) ind(a,b)
        d) corr(a,b  t)

        input:
        t   :   index of the gene t
f        """
        # incoming edges are associated with the gene of interest...
        pv_genes = self.genecorr_reader.getRows([t])[0]
        pv_genes[t] = np.inf  # don't count self-correlation in when estimating q-values (always 0)
        qv_genes = np.ones(pv_genes.shape)
        qv_genes[np.isfinite(pv_genes)] = qvalue.estimate(pv_genes[np.isfinite(pv_genes)])
        idx_assoc = qv_genes < self.thresh_corr
        idx_assoc[t] = False
        if not (idx_assoc).any():
            return None, None

        # independent of each other
        _idx_assoc = np.nonzero(idx_assoc)[0]
        pv_genes = self.genecorr_reader.getRows(_idx_assoc)[:, idx_assoc]
        idx_vstruct = np.nonzero(idx_assoc)[0]
        pv_genes[~np.isfinite(pv_genes)] = 0
        vstruct = pv_genes > self.thresh_ind
        idx_ind = vstruct.any(axis=1)
        idx_vstruct = idx_vstruct[idx_ind]
        vstruct = vstruct[idx_ind][:, idx_ind]
        if not (idx_vstruct).any():
            return None, None

        # becoming dependent once we condition on the gene under observation
        Yv = self.phenoreader.getRows(idx_vstruct)
        Yt = self.phenoreader.getRows([t])[0]
        _, pv_cond = pcor.pcorParallel(Yv, Yt)

        # take nans into account
        # qv_cond = qvalue.estimate(pv_cond)
        np.fill_diagonal(pv_cond, np.nan)
        qv_cond = np.ones(pv_cond.shape)

        # upper triangular matrix
        iu = np.triu_indices(pv_cond.shape[0])
        pv_cond_iu = pv_cond[iu]
        idx_finite = np.isfinite(pv_cond_iu)
        qv_cond_iu = np.ones(pv_cond_iu.shape)
        qv_cond_iu[idx_finite] = qvalue.estimate(pv_cond_iu[idx_finite])
        qv_cond[iu] = qv_cond_iu

        # lower triangular matrix
        il = np.tril_indices(pv_cond.shape[0])
        qv_cond[il] = 0
        qv_cond += qv_cond.T

        vstruct *= qv_cond < self.thresh_corr
        idx_partcorr = vstruct.any(axis=0)
        if not (idx_partcorr).any():
            return None, None
        vstruct = vstruct[idx_partcorr][:, idx_partcorr]
        idx_vstruct = idx_vstruct[idx_partcorr]

        return vstruct, idx_vstruct