Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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