def testImpute(snpData, Ls): """ Function that slides the window(s) and calculates accuracy of imputation on all called values. """ global corrects global count L = max(Ls) vectors = snpData.vectors snps = snpData.snps numSNPs = len(snps) print "Running imputation window test with %d window sizes..." % len(Ls), count = 0 corrects = zeros(len(Ls)) vectorLength = len(vectors.values()[0]) vectorQueue = CircularQueue(Ls, vectorLength) acc = zeros((len(Ls), vectorLength), uint16) # Initialize queue for i in xrange(L): snpVector = vectors[snps[i]] vectorQueue.queue[i] = snpVector for j in xrange(len(Ls)): if i < Ls[j]: add(acc[j], snpVector, acc[j]) # Begin impute for i in xrange(numSNPs): if i + L < numSNPs: vectorQueue.enqueue(vectors[snps[i + L]]) else: vectorQueue.enqueue(zeros(vectorLength, uint16)) mid = vectorQueue.getMid() snp = snps[i] for j in xrange(len(Ls)): top, bottom = vectorQueue.getEnds(j) add(acc[j], top, acc[j]) subtract(acc[j], bottom, acc[j]) imputeSNPT(snpData, i, acc[j] - mid, snp, j) print "Done" return count, corrects
def testImpute(snpData, Ls): ''' Function that slides the window(s) and calculates accuracy of imputation on all called values. ''' global corrects global count L = max(Ls) vectors = snpData.vectors snps = snpData.snps numSNPs = len(snps) print 'Running imputation window test with %d window sizes...' % len(Ls), count = 0 corrects = zeros(len(Ls)) vectorLength = len(vectors.values()[0]) vectorQueue = CircularQueue(Ls, vectorLength) acc = zeros((len(Ls), vectorLength), uint16) # Initialize queue for i in xrange(L): snpVector = vectors[snps[i]] vectorQueue.queue[i] = snpVector for j in xrange(len(Ls)): if i < Ls[j]: add(acc[j], snpVector, acc[j]) # Begin impute for i in xrange(numSNPs): if i + L < numSNPs: vectorQueue.enqueue(vectors[snps[i + L]]) else: vectorQueue.enqueue(zeros(vectorLength, uint16)) mid = vectorQueue.getMid() snp = snps[i] for j in xrange(len(Ls)): top, bottom = vectorQueue.getEnds(j) add(acc[j], top, acc[j]) subtract(acc[j], bottom, acc[j]) imputeSNPT(snpData, i, acc[j] - mid, snp, j) print 'Done' return count, corrects
def impute(snpData, L): """ Function that slides the window and calls other functions to do the actual imputation. """ global count snpData.changes = dict() count = 0 snps = snpData.snps vectors = snpData.vectors numSNPs = len(snps) sys.stderr.write("Imputing with window size " + str(L) + "...") vectorLength = len(vectors.values()[0]) vectorQueue = CircularQueue([L], vectorLength) acc = zeros(vectorLength, uint16) # Initialize queue for i in xrange(L): snpVector = vectors[snps[i]] vectorQueue.queue[i] = snpVector add(acc, snpVector, acc) # Begin impute for i in xrange(numSNPs): if i + L < numSNPs: snpVector = vectors[snps[i + L]] vectorQueue.enqueue(snpVector) else: vectorQueue.enqueue(zeros(vectorLength, uint16)) top, bottom = vectorQueue.getEnds(0) add(acc, top, acc) subtract(acc, bottom, acc) snp = snps[i] if "?" in snp: imputeSNP(snpData, i, acc, snp) sys.stderr.write("Done.\n") return count
def impute(snpData, L): ''' Function that slides the window and calls other functions to do the actual imputation. ''' global count snpData.changes = dict() count = 0 snps = snpData.snps vectors = snpData.vectors numSNPs = len(snps) print "Imputing with window size " + str(L) + "...", vectorLength = len(vectors.values()[0]) vectorQueue = CircularQueue([L], vectorLength) acc = zeros(vectorLength, uint16) # Initialize queue for i in xrange(L): snpVector = vectors[snps[i]] vectorQueue.queue[i] = snpVector add(acc, snpVector, acc) # Begin impute for i in xrange(numSNPs): if i + L < numSNPs: snpVector = vectors[snps[i + L]] vectorQueue.enqueue(snpVector) else: vectorQueue.enqueue(zeros(vectorLength, uint16)) top, bottom = vectorQueue.getEnds(0) add(acc, top, acc) subtract(acc, bottom, acc) snp = snps[i] if '?' in snp: imputeSNP(snpData, i, acc, snp) print "Done" return count