def scan(bfile, Y, cov, null, wnds, minSnps, i0, i1, perm_i, resfile, F, colCovarType_r='lowrank', rank_r=1): if perm_i is not None: print 'Generating permutation (permutation %d)' % perm_i np.random.seed(perm_i) perm = np.random.permutation(Y.shape[0]) mtSet = limix.MTSet(Y=Y, S_R=cov['eval'], U_R=cov['evec'], F=F, rank=rank_r) mtSet.setNull(null) bim = plink_reader.readBIM(bfile, usecols=(0, 1, 2, 3)) fam = plink_reader.readFAM(bfile, usecols=(0, 1)) print 'fitting model' wnd_file = csv.writer(open(resfile, 'wb'), delimiter='\t') for wnd_i in range(i0, i1): print '.. window %d - (%d, %d-%d) - %d snps' % ( wnd_i, int(wnds[wnd_i, 1]), int(wnds[wnd_i, 2]), int( wnds[wnd_i, 3]), int(wnds[wnd_i, -1])) if int(wnds[wnd_i, -1]) < minSnps: print 'SKIPPED: number of snps lower than minSnps' continue #RV = bed.read(PositionRange(int(wnds[wnd_i,-2]),int(wnds[wnd_i,-1]))) RV = plink_reader.readBED(bfile, useMAFencoding=True, blocksize=1, start=int(wnds[wnd_i, 4]), nSNPs=int(wnds[wnd_i, 5]), order='F', standardizeSNPs=False, ipos=2, bim=bim, fam=fam) Xr = RV['snps'] if perm_i is not None: Xr = Xr[perm, :] rv = mtSet.optimize(Xr) line = np.concatenate([wnds[wnd_i, :], rv['LLR']]) wnd_file.writerow(line) pass