Exemplo n.º 1
0
def compute_snp(collect):
   snp = collect[0]
   id = collect[1]
   # result = []
   # Check SNPs for missing values
   x = snp[keep].reshape((n,1))  # all the SNPs
   v = np.isnan(x).reshape((-1,))
   if v.sum():
      keeps = True - v
      xs = x[keeps,:]
      if keeps.sum() <= 1 or xs.var() <= 1e-6: 
         # PS.append(np.nan)
         # TS.append(np.nan)
         # result.append(formatResult(id,np.nan,np.nan,np.nan,np.nan))
         # continue
         return formatResult(id,np.nan,np.nan,np.nan,np.nan)

      # Its ok to center the genotype -  I used options.normalizeGenotype to 
      # force the removal of missing genotypes as opposed to replacing them with MAF.
      if not options.normalizeGenotype:
         xs = (xs - xs.mean()) / np.sqrt(xs.var())
      Ys = Y[keeps]
      X0s = X0[keeps,:]
      Ks = K[keeps,:][:,keeps]
      if options.kfile2:
         K2s = K2[keeps,:][:,keeps]
         Ls = LMM_withK2(Ys,Ks,X0=X0s,verbose=options.verbose,K2=K2s)
      else:
         Ls = LMM(Ys,Ks,X0=X0s,verbose=options.verbose)
      if options.refit:
        Ls.fit(X=xs,REML=options.REML)
      else:
         #try:
         Ls.fit(REML=options.REML)
         #except: pdb.set_trace()
      ts,ps,beta,betaVar = Ls.association(xs,REML=options.REML,returnBeta=True)
   else:
      if x.var() == 0: 
         # PS.append(np.nan)
         # TS.append(np.nan)
         # result.append(formatResult(id,np.nan,np.nan,np.nan,np.nan)) # writes nan values
         return formatResult(id,np.nan,np.nan,np.nan,np.nan)
         # continue

      if options.refit:
         L.fit(X=x,REML=options.REML)
      # This is where it happens
      ts,ps,beta,betaVar = L.association(x,REML=options.REML,returnBeta=True)
   
   return formatResult(id,beta,np.sqrt(betaVar).sum(),ts,ps)
Exemplo n.º 2
0
def compute_snp(j, snp_ids, q=None):
    # print(j,len(snp_ids),"\n")
    result = []
    for snp_id in snp_ids:
        # j,snp_id = collect
        snp, id = snp_id
        # id = collect[1]
        # result = []
        # Check SNPs for missing values
        x = snp[keep].reshape((n, 1))  # all the SNPs
        v = np.isnan(x).reshape((-1, ))
        if v.sum():
            # NOTE: this code appears to be unreachable!
            if options.verbose:
                sys.stderr.write("Found missing values in " + str(x))
            keeps = True - v
            xs = x[keeps, :]
            if keeps.sum() <= 1 or xs.var() <= 1e-6:
                # PS.append(np.nan)
                # TS.append(np.nan)
                # result.append(formatResult(id,np.nan,np.nan,np.nan,np.nan))
                # continue
                result.append(formatResult(id, np.nan, np.nan, np.nan, np.nan))
                continue

            # Its ok to center the genotype -  I used options.normalizeGenotype to
            # force the removal of missing genotypes as opposed to replacing them with MAF.
            if not options.normalizeGenotype:
                xs = (xs - xs.mean()) / np.sqrt(xs.var())
            Ys = Y[keeps]
            X0s = X0[keeps, :]
            Ks = K[keeps, :][:, keeps]
            if options.kfile2:
                K2s = K2[keeps, :][:, keeps]
                Ls = LMM_withK2(Ys,
                                Ks,
                                X0=X0s,
                                verbose=options.verbose,
                                K2=K2s)
            else:
                Ls = LMM(Ys, Ks, X0=X0s, verbose=options.verbose)
            if options.refit:
                Ls.fit(X=xs, REML=options.REML)
            else:
                #try:
                Ls.fit(REML=options.REML)
                #except: pdb.set_trace()
            ts, ps, beta, betaVar = Ls.association(xs,
                                                   REML=options.REML,
                                                   returnBeta=True)
        else:
            if x.var() == 0:
                # Note: this code appears to be unreachable!

                # PS.append(np.nan)
                # TS.append(np.nan)
                # result.append(formatResult(id,np.nan,np.nan,np.nan,np.nan)) # writes nan values
                result.append(formatResult(id, np.nan, np.nan, np.nan, np.nan))
                continue

            if options.refit:
                L.fit(X=x, REML=options.REML)
            # This is where it happens
            ts, ps, beta, betaVar = L.association(x,
                                                  REML=options.REML,
                                                  returnBeta=True)
        result.append(formatResult(id, beta, np.sqrt(betaVar).sum(), ts, ps))
        # compute_snp.q.put([j,formatResult(id,beta,np.sqrt(betaVar).sum(),ts,ps)])
    # print [j,result[0]]," in result queue\n"
    if not q:
        q = compute_snp.q
    q.put([j, result])
    return j
Exemplo n.º 3
0
      # Its ok to center the genotype -  I used options.normalizeGenotype to 
      # force the removal of missing genotypes as opposed to replacing them with MAF.
      if not options.normalizeGenotype: xs = (xs - xs.mean()) / np.sqrt(xs.var())
      Ys = Y[keeps]
      X0s = X0[keeps,:]
      Ks = K[keeps,:][:,keeps]
      if options.kfile2: K2s = K2[keeps,:][:,keeps]
      if options.kfile2: Ls = LMM_withK2(Ys,Ks,X0=X0s,verbose=options.verbose,K2=K2s)
      else: Ls = LMM(Ys,Ks,X0=X0s,verbose=options.verbose)
      if options.refit: Ls.fit(X=xs,REML=options.REML)
      else: 
	 #try:
	 Ls.fit(REML=options.REML)
	 #except: pdb.set_trace()
      ts,ps,beta,betaVar = Ls.association(xs,REML=options.REML,returnBeta=True)
   else: 
      if x.var() == 0: 
	 PS.append(np.nan)
	 TS.append(np.nan)
	 outputResult(id,np.nan,np.nan,np.nan,np.nan)
	 continue

      if options.refit: L.fit(X=x,REML=options.REML)
      ts,ps,beta,betaVar = L.association(x,REML=options.REML,returnBeta=True)
	    
   outputResult(id,beta,np.sqrt(betaVar).sum(),ts,ps)
   PS.append(ps)
   TS.append(ts)

Exemplo n.º 4
0
def compute_snp(j,snp_ids,q = None):
   # print(j,len(snp_ids),"\n")
   result = []
   for snp_id in snp_ids:
      # j,snp_id = collect
      snp,id = snp_id
      # id = collect[1]
      # result = []
      # Check SNPs for missing values
      x = snp[keep].reshape((n,1))  # all the SNPs
      v = np.isnan(x).reshape((-1,))
      if v.sum():
         # NOTE: this code appears to be unreachable!
         if options.verbose:
            sys.stderr.write("Found missing values in "+str(x))
         keeps = True - v
         xs = x[keeps,:]
         if keeps.sum() <= 1 or xs.var() <= 1e-6: 
            # PS.append(np.nan)
            # TS.append(np.nan)
            # result.append(formatResult(id,np.nan,np.nan,np.nan,np.nan))
            # continue
            result.append(formatResult(id,np.nan,np.nan,np.nan,np.nan))
            continue

         # Its ok to center the genotype -  I used options.normalizeGenotype to 
         # force the removal of missing genotypes as opposed to replacing them with MAF.
         if not options.normalizeGenotype:
            xs = (xs - xs.mean()) / np.sqrt(xs.var())
         Ys = Y[keeps]
         X0s = X0[keeps,:]
         Ks = K[keeps,:][:,keeps]
         if options.kfile2:
            K2s = K2[keeps,:][:,keeps]
            Ls = LMM_withK2(Ys,Ks,X0=X0s,verbose=options.verbose,K2=K2s)
         else:
            Ls = LMM(Ys,Ks,X0=X0s,verbose=options.verbose)
         if options.refit:
           Ls.fit(X=xs,REML=options.REML)
         else:
            #try:
            Ls.fit(REML=options.REML)
            #except: pdb.set_trace()
         ts,ps,beta,betaVar = Ls.association(xs,REML=options.REML,returnBeta=True)
      else:
         if x.var() == 0:
            # Note: this code appears to be unreachable!

            # PS.append(np.nan)
            # TS.append(np.nan)
            # result.append(formatResult(id,np.nan,np.nan,np.nan,np.nan)) # writes nan values
            result.append(formatResult(id,np.nan,np.nan,np.nan,np.nan))
            continue

         if options.refit:
            L.fit(X=x,REML=options.REML)
         # This is where it happens
         ts,ps,beta,betaVar = L.association(x,REML=options.REML,returnBeta=True)
      result.append(formatResult(id,beta,np.sqrt(betaVar).sum(),ts,ps))
      # compute_snp.q.put([j,formatResult(id,beta,np.sqrt(betaVar).sum(),ts,ps)])
   # print [j,result[0]]," in result queue\n"
   if not q:
      q = compute_snp.q
   q.put([j,result])
   return j
Exemplo n.º 5
0
	      # Its ok to center the genotype -  I used options.normalizeGenotype to 
	      # force the removal of missing genotypes as opposed to replacing them with MAF.
	      if not options.normalizeGenotype: xs = (xs - xs.mean()) / np.sqrt(xs.var())
	      Ys = Y[keeps]
	      X0s = X0[keeps,:]
	      Ks = K[keeps,:][:,keeps]
	      if options.kfile2: K2s = K2[keeps,:][:,keeps]
	      if options.kfile2: Ls = LMM_withK2(Ys,Ks,X0=X0s,verbose=options.verbose,K2=K2s)
	      else: Ls = LMM(Ys,Ks,X0=X0s,verbose=options.verbose)
	      if options.refit: Ls.fit(X=xs,REML=options.REML)
	      else: 
		 #try:
		 Ls.fit(REML=options.REML)
		 #except: pdb.set_trace()
	      ts,ps,beta,betaVar = Ls.association(xs,REML=options.REML,returnBeta=True)
	   else: 
	      if x.var() == 0: 
		 PS.append(np.nan)
		 TS.append(np.nan)
		 outputResult(id,np.nan,np.nan,np.nan,np.nan)
		 continue

	      if options.refit: L.fit(X=x,REML=options.REML)
	      ts,ps,beta,betaVar = L.association(x,REML=options.REML,returnBeta=True)
	    
	   outputResult(id,beta,np.sqrt(betaVar).sum(),ts,ps)
	   PS.append(ps)
	   TS.append(ts)