Example #1
0
def define_gp(Y, Xr, Sg, Ug, type):
    P = Y.shape[1]
    _A = sp.eye(P)
    if type in 'rank1': _Cr = limix.core.covar.LowRankCov(P, 1)
    elif type == 'block': _Cr = limix.core.covar.FixedCov(sp.ones((P, P)))
    elif type == 'full': _Cr = limix.core.covar.FreeFormCov(P)
    elif type == 'null': pass
    else: print('poppo')
    _Cn = limix.core.covar.FreeFormCov(P)
    _Cg = limix.core.covar.FreeFormCov(P)
    if type == 'null': _gp = GP2KronSum(Y=Y, Cg=_Cg, Cn=_Cn, S_R=Sg, U_R=Ug)
    else: _gp = GP3KronSumLR(Y=Y, G=Xr, Cr=_Cr, Cg=_Cg, Cn=_Cn, S_R=Sg, U_R=Ug)
    return _gp
Example #2
0
    def setUp(self):
        np.random.seed(1)

        # define phenotype
        N = 200
        P = 2
        Y = sp.randn(N, P)
        # define row caoriance
        f = 10
        G = 1. * (sp.rand(N, f) < 0.2)
        X = 1. * (sp.rand(N, f) < 0.2)
        R = covar_rescale(sp.dot(X, X.T))
        R += 1e-4 * sp.eye(N)
        # define col covariances
        Cg = FreeFormCov(P)
        self._Cg = Cg
        Cn = FreeFormCov(P)
        Cg.setCovariance(0.5 * sp.cov(Y.T))
        Cn.setCovariance(0.5 * sp.cov(Y.T))
        # define gp
        self.gp = GP3KronSumLR(Y=Y, Cg=Cg, Cn=Cn, R=R, G=G, rank=1)
Example #3
0
from limix.core.gp import GP3KronSumLR
from limix.core.gp import GP
from limix.utils.preprocess import covar_rescale
import time
import copy
import pdb

if __name__ == '__main__':

    # define region and bg terms
    N = 500
    f = 10
    P = 3
    G = 1. * (sp.rand(N, f) < 0.2)
    X = 1. * (sp.rand(N, f) < 0.2)
    R = covar_rescale(sp.dot(X, X.T))
    R += 1e-4 * sp.eye(N)

    # define col covariances
    Cg = FreeFormCov(P)
    Cn = FreeFormCov(P)
    Cg.setRandomParams()
    Cn.setRandomParams()

    # define pheno
    Y = sp.randn(N, P)

    # define GP and optimize
    gp = GP3KronSumLR(Y=Y, Cg=Cg, Cn=Cn, R=R, G=G, rank=1)
    gp.optimize()
Example #4
0
 def __init__(self,
              Y=None,
              R=None,
              S_R=None,
              U_R=None,
              traitID=None,
              F=None,
              rank=1):
     """
     Args:
         Y:          [N, P] phenotype matrix
         F:          [N, K] matrix of fixed effect design.
                     K is the number of per-trait covariates.
         R:          [N, N] genetic relatedness matrix between individuals.
                     In alternative to R, S_R and U_R can be provided.
                     If not specified a model without relatedness component is considered.
         S_R:        N vector of eigenvalues of R
         U_R:        [N, N] eigenvector matrix of R
         traiID:     P vector of the IDs of the phenotypes to analyze (optional)
         rank:       rank of the trait covariance matrix of the variance component to be tested (default is 1)
     """
     # data
     noneNone = S_R is not None and U_R is not None
     self.bgRE = R is not None or noneNone
     # fixed effect
     msg = 'The current implementation of the full rank mtSet'
     msg += ' does not support covariates.'
     msg += ' We reccommend to regress out covariates and'
     msg += ' subsequently quantile normalize the phenotypes'
     msg += ' to a normal distribution prior to use mtSet.'
     msg += ' This can be done within the LIMIX framework using'
     msg += ' the methods limix.utils.preprocess.regressOut and'
     msg += ' limix.utils.preprocess.gaussianize'
     assert not (F is not None and self.bgRE), msg
     if F is not None:
         F = remove_dependent_cols(F)
         A = sp.eye(Y.shape[1])
     else:
         A = None
     #traitID
     if traitID is None:
         traitID = sp.array(['trait %d' % p for p in range(Y.shape[1])])
     self.setTraitID(traitID)
     #init covariance matrices and gp
     Cg = FreeFormCov(Y.shape[1])
     Cn = FreeFormCov(Y.shape[1])
     G = 1. * (sp.rand(Y.shape[0], 1) < 0.2)
     if self.bgRE:
         self._gp = GP3KronSumLR(Y=Y,
                                 Cg=Cg,
                                 Cn=Cn,
                                 R=R,
                                 S_R=S_R,
                                 U_R=U_R,
                                 G=G,
                                 rank=1)
     else:
         self._gp = GP2KronSumLR(Y=Y, Cn=Cn, G=G, F=F, A=A)
     # null model params
     self.null = None
     # calls itself for column-by-column trait analysis
     self.stSet = None
     self.nullST = None
     self.infoOpt = None
     self.infoOptST = None
     pass
Example #5
0
    if not os.path.exists(out_file) or 'recalc' in sys.argv:
        Ns = sp.array(
            [100, 150, 200, 300, 500, 800, 1200, 1600, 2000, 3000, 4000, 5000])
        n_rips = 5
        t = sp.zeros((Ns.shape[0], n_rips))
        t0 = sp.zeros((Ns.shape[0], n_rips))
        r = sp.zeros((Ns.shape[0], n_rips))
        for ni, n in enumerate(Ns):
            for ri in range(n_rips):
                print '.. %d individuals - rip %d' % (n, ri)
                print '   .. generating data'
                Y, S, U, G = gen_data(N=n, P=P)

                # define GPs
                gp = GP3KronSumLR(Y=Y, Cg=Cg, Cn=Cn, S_R=S, U_R=U, G=G, rank=1)
                gp0 = gp3ks0(mean(Y),
                             covariance.freeform(P),
                             covariance.freeform(P),
                             S_XX=S,
                             U_XX=U,
                             rank=1)
                gp0.set_Xr(G)
                gp._reset_profiler()

                if 1:
                    gp.covar.setRandomParams()
                else:
                    n_params = gp.covar.Cr.getNumberParams()
                    n_params += gp.covar.Cg.getNumberParams()
                    n_params += gp.covar.Cn.getNumberParams()