def marginal_genecorr(pfile, gfile, startTraitIdx=0, nTraits=np.inf): """ running marginal gene-gene correlations Input: pfile : phenotype file cfile : covariance matrix file ffile : covariates file gfile : basename of output file startTraidIdx : first trait to be analyses nTraits : number of traits to be analysed """ if np.isfinite(nTraits): gfile += ".startTrait_%d" % startTraitIdx preader = phenoReaderFile.PhenoReaderFile(pfile) model = gnetlmm.GNetLMM(preader, None) corr, pv = model.marginal_gene_correlations(startTraitIdx=startTraitIdx, nTraits=nTraits) write = writer.Writer(gfile + '.pv') write.writeMatrix(pv, fmt='%.4e') write = writer.Writer(gfile + '.corr') write.writeMatrix(corr, fmt='%.4f')
def simPheno(options): assert options.bfile!=None, 'Please specify a bfile.' assert options.pfile!=None, 'Please specify a pfile.' sp.random.seed(options.seed) print 'simulating genes' if options.networkDesign=='star': sim = simulator.HotSpotSimulator(options.bfile) elif options.networkDesign=='sparse': sim = simulator.SparseSimulator(options.bfile) else: raise Exception("networkDesign '%s' is not known."%options.networkDesign) RV = sim.simulateGenes(T=options.T,varSnp=options.varSnp,varNetwork=options.varNetwork,expN=options.expN, alpha=options.alpha,nConfounder=options.nConfounder,confPerGene=options.confPerGene) print 'exporting simulated data' outdir = os.path.split(options.pfile)[0] if not(os.path.exists(outdir)): os.mkdir(outdir) np.savetxt('%s.Aconf'%options.pfile, RV['Aconf'], fmt='%d') np.savetxt('%s.Agene'%options.pfile, RV['Agene'], fmt='%d') np.savetxt('%s.conf'%options.pfile, RV['H'], fmt='%.6f') write = writer.Writer(options.pfile) write.writeColumnInfo(data={'fid':sim.genoreader.fam[:,0]}) write.writeRowInfo(data={'gene_ids':RV['gene_ids'], 'gene_chrom':RV['gene_chrom'], 'gene_start':RV['gene_start'], 'causal_rs':RV['rs']}) write.writeMatrix(RV['Y'], fmt='%.6f')
def marginal_genecorr(bfile, pfile, gfile): """ running marginal gene-gene correlations Input: bfile : binary bed file (bfile.bed, bfile.bim and bfile.fam are required) pfile : phenotype file cfile : covariance matrix file ffile : covariates file gfile : basename of output file """ preader = phenoReader.PhenoReaderFile(pfile) greader = bedReader.BedReader(bfile) model = gnetlmm.GNetLMM(preader, greader) corr, pv = model.marginal_gene_correlations() write = writer.Writer(gfile + '.pv') write.writeMatrix(pv, fmt='%.4e') write = writer.Writer(gfile + '.corr') write.writeMatrix(corr, fmt='%.4f')
def initial_scan(bfile, pfile, cfile, ffile, assoc0file, startSnpIdx=0, nSnps=np.inf, memory_efficient=False): """ running initial scan using a standard linear mixed model Input: bfile : binary bed file (bfile.bed, bfile.bim and bfile.fam are required) pfile : phenotype file cfile : covariance matrix file ffile : covariates file assoc0file : basename of output file """ K = None if cfile is not None: K = np.loadtxt(cfile) Covs = None if ffile is not None: Covs = np.loadtxt(ffile) if np.isfinite(nSnps): assoc0file += ".startSnp_%d" % startSnpIdx preader = phenoReaderFile.PhenoReaderFile(pfile) greader = bedReader.BedReader(bfile) model = gnetlmm.GNetLMM(preader, greader, K=K, Covs=Covs) beta0, pv0 = model.initial_scan(startSnpIdx, nSnps, memory_efficient) write = writer.Writer(assoc0file + '.pv') write.writeMatrix(pv0, fmt='%.4e') write = writer.Writer(assoc0file + '.beta') write.writeMatrix(beta0, fmt='%.4f')