GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — glide-scripts/rerun_h5.py at master · BorgwardtLab/glide-scripts Expand file tree/ Copy pathrerun_h5.pyMore file actions 81 lines (65 loc) · 2.96 KB / Copy pathrerun_h5.pyFile metadata and controls81 lines (65 loc) · 2.96 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 # rerun_h5.py --- Run linear regression again, # on a small number of SNP pairs. # Read genotypes from .h5 file (created with plink2h5.py) # contact: [email protected] import numpy as np import os import sys import tables from utils import testPair_logistic as testPair def main(args): usage = """python %s <h5 file> <bim file> <pheno> <significant pairs of SNPs> <reevaluated pairs of SNPs> Rerun linear regression evaluation on the significant pairs of SNPs. E.g.: py rerun_h5.py mydata_final_clean_pulsation.h5 mydata_final_clean.bim mydata_final_clean.phenoGlide mydata_final_clean.sortedpvals.sig mydata_final_clean.sortedpvals.rerun\n""" % args[0] if len(args) != 6: sys.stderr.write(usage) sys.exit(0) h5fname = args[1] bimF = args[2] phenoF = args[3] sigPairF = args[4] outputF = args[5] pheno = np.loadtxt(phenoF) with open(bimF) as f: snpsDict = {('%s\t%s\t%s' % \ (line.split()[1], line.split()[0], line.split()[3])):idx \ for (idx, line) in enumerate(f)} print snpsDict.keys()[0], snpsDict[snpsDict.keys()[0]] newPvalsDict = {} # pvalue, line to write with tables.openFile(h5fname) as h5f, open(sigPairF) as f: print "%d SNPs x %d samples" % (h5f.root.genotype.shape[0], h5f.root.genotype.shape[1]) f.readline() for i, line in enumerate(f): ls = line.split() try: snp1idx = snpsDict['%s\t%s\t%s' % (ls[0], ls[1], ls[2])] try: snp2idx = snpsDict['%s\t%s\t%s' % (ls[3], ls[4], ls[5])] snp1x = np.ma.masked_values(h5f.root.genotype[snp1idx], 3) snp2x = np.ma.masked_values(h5f.root.genotype[snp2idx], 3) pval, pvalStr = testPair(snp1x, snp2x, pheno) line_to_write = "%s\t%s\n" % ("\t".join(ls), pvalStr) if not newPvalsDict.has_key(pval): newPvalsDict[pval] = [line_to_write] else: newPvalsDict[pval].append(line_to_write) except KeyError: print "Didn't find %s in .bim file" % ls[3] sys.exit(-1) except KeyError: print "Didn't find %s in .bim file" % ls[0] sys.exit(-1) f.close() h5f.close() with open(outputF, 'w') as g: g.write("SNP1\tchr1\tpos1\tSNP2\tchr2\tpos2\t") g.write("t-testGLIDE\tpvalGLIDE(intercept)\tpvalGLIDE(x1)\tpvalGLIDE(x2)\tpvalGLIDE(x1:x2)") g.write("\tpval(intercept)\tpval(x1)\tpval(x2)\tpval(x1:x2)\n") sortedPvals = newPvalsDict.keys() sortedPvals.sort() for pval in sortedPvals: for line_to_write in newPvalsDict[pval]: g.write(line_to_write) g.close() if __name__ == "__main__": main(sys.argv) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |