def test_permutation(self): #test permutation function for dn in self.datasets: D = data.load(os.path.join(self.dir_name,dn)) perm = SP.random.permutation(D['X'].shape[0]) #1. set permuattion lmm = dlimix.CLMM() lmm.setK(D['K']) lmm.setSNPs(D['X']) lmm.setCovs(D['Cov']) lmm.setPheno(D['Y']) if 1: #pdb.set_trace() perm = SP.array(perm,dtype='int32')#Windows needs int32 as long -> fix interface to accept int64 types lmm.setPermutation(perm) lmm.process() pv_perm1 = lmm.getPv().ravel() #2. do by hand lmm = dlimix.CLMM() lmm.setK(D['K']) lmm.setSNPs(D['X'][perm]) lmm.setCovs(D['Cov']) lmm.setPheno(D['Y']) lmm.process() pv_perm2 = lmm.getPv().ravel() D2 = (SP.log10(pv_perm1)-SP.log10(pv_perm2))**2 RV = SP.sqrt(D2.mean()) self.assertTrue(RV<1E-6)
def test_exceptions(self): D = data.load(os.path.join(self.dir_name,self.datasets[0])) lmm = dlimix.CLMM() N = 100 K = SP.eye(N) X = SP.randn(N,100) Y = SP.randn(N+1,1) Cov = SP.randn(N,1) lmm.setK(K) lmm.setSNPs(X) lmm.setCovs(Cov) lmm.setPheno(Y) try: lmm.process() except Exception,e: self.assertTrue(1==1) pass
def _getH2singleTrait(self, K, verbose=None): """ Internal function for parameter initialization estimate variance components and fixed effect using a linear mixed model with an intercept and 2 random effects (one is noise) Args: K: covariance matrix of the non-noise random effect term """ verbose = dlimix.getVerbose(verbose) # Fit single trait model varg = sp.zeros(self.P) varn = sp.zeros(self.P) fixed = sp.zeros((1, self.P)) for p in range(self.P): y = self.Y[:, p:p + 1] # check if some sull value I = sp.isnan(y[:, 0]) if I.sum() > 0: y = y[~I, :] _K = K[~I, :][:, ~I] else: _K = copy.copy(K) lmm = dlimix.CLMM() lmm.setK(_K) lmm.setSNPs(sp.ones((y.shape[0], 1))) lmm.setPheno(y) lmm.setCovs(sp.zeros((y.shape[0], 1))) lmm.setVarcompApprox0(-20, 20, 1000) lmm.process() delta = sp.exp(lmm.getLdelta0()[0, 0]) Vtot = sp.exp(lmm.getLSigma()[0, 0]) varg[p] = Vtot varn[p] = delta * Vtot fixed[:, p] = lmm.getBetaSNP() if verbose: print p sth = {} sth['varg'] = varg sth['varn'] = varn sth['fixed'] = fixed return sth
def test_lmm1(self): """basic test, comapring pv""" for dn in self.datasets: D = data.load(os.path.join(self.dir_name,dn)) lmm = dlimix.CLMM() lmm.setK(D['K']) lmm.setSNPs(D['X']) lmm.setCovs(D['Cov']) lmm.setPheno(D['Y']) lmm.process() pv = lmm.getPv().ravel() BetaSte = lmm.getBetaSNPste().ravel() Beta = lmm.getBetaSNP() D2pv= ((SP.log10(pv)-SP.log10(D['pv']))**2) # D2Beta= (Beta-D['Beta'])**2 # D2BetaSte = (BetaSte-D['BetaSte'])**2 RV = SP.sqrt(D2pv.mean())<1E-6 # RV = RV & (D2Beta.mean()<1E-6) # RV = RV & (D2BetaSte.mean()<1E-6) self.assertTrue(RV)
def test_lmm1(self): """basic test, comapring pv""" for dn in self.datasets: D = data.load(os.path.join(self.dir_name, dn)) #make vllarg X. This needs to be changed later NL = 1000 self.NL = NL X = SP.tile(D['X'], (1, self.NL)) lmm = dlimix.CLMM() lmm.setK(D['K']) lmm.setSNPs(X) lmm.setCovs(D['Cov']) lmm.setPheno(D['Y']) lmm.process() pv = lmm.getPv().ravel() BetaSte = lmm.getBetaSNPste().ravel() Beta = lmm.getBetaSNP() D2pv = (SP.log10(pv) - SP.log10(SP.tile(D['pv'], self.NL))**2) # D2Beta= (Beta-SP.tile(D['Beta'],self.NL))**2 # D2BetaSte = (BetaSte-SP.tile(D['BetaSte'],self.NL))**2 RV = SP.sqrt(D2pv.mean()) < 1E-6 # RV = RV & (D2Beta.mean()<1E-6) # RV = RV & (D2BetaSte.mean()<1E-6) self.assertTrue(RV)