コード例 #1
0
ファイル: depth.py プロジェクト: SMC1/JK1
def main(inFilePath,outFilePath):

	(exnH, totalLen) = loadExonH()

	depthH = {'0':{}, '15':{}, '20':{}, '30':{}}

	exnChr = 'chr1'
	exnIdx = 0

	if inFilePath[-3:] == '.gz':
		inFile = gzip.open(inFilePath, 'rb')
	else:
		inFile = open(inFilePath)

	for line in inFile:

		tokL = line.split('\t')
		chrom, pos, cnt = tokL[0], int(tokL[1]), int(tokL[3])

		if chrom==exnChr and exnIdx==len(exnH[exnChr]):
			continue

		if chrom != exnChr:
			exnChr = chrom
			exnIdx = 0

		while exnIdx < len(exnH[exnChr]) and exnH[exnChr][exnIdx][1] < pos:
			exnIdx += 1

		if exnIdx < len(exnH[exnChr]) and exnH[exnChr][exnIdx][0] < pos <= exnH[exnChr][exnIdx][1]:
			for dt in ['0', '15', '20', '30']:
				cnt = get_cnt_by_qual(line, int(dt))
				if cnt > 1000:
					mybasic.incHash(depthH[dt], 1001, 1)
				else:
					mybasic.incHash(depthH[dt], cnt, 1)

	for dt in ['0','15','20','30']:
		depthH[dt][0] = totalLen - sum(depthH[dt].values())


	for dt in ['0','15','20','30']:
		outFile = open(outFilePath + '_mq' + dt, 'w')
#		for i in range(max(depthH[dt].keys())+1):
		for i in range(1001):
			if i in depthH[dt]:
				d = depthH[dt][i]
			else:
				d = 0
			outFile.write('%d\t%d\n' % (i,d))
		if 1001 in depthH[dt]:
			outFile.write('1001\t%d\n' % depthH[dt][1001])
		else:
			outFile.write('1001\t0\n')
		outFile.flush()
		outFile.close()

	dir = '/'.join(outFilePath.split('/')[:-1])
	sampN = outFilePath.split('/')[-1].split('.')[0]
	os.system('R --no-restore --no-save --args %s %s < %s/NGS/quality/plot_depth.R' % (dir, sampN, mysetting.SRC_HOME))
コード例 #2
0
ファイル: depth.py プロジェクト: zhangtongyikai/JK1
def main(inFilePath,outFilePath):

	exnH = loadExonH()

	depthH = {}

	exnChr = 'chr10'
	exnIdx = 0

	inFile = open(inFilePath)
	outFile = open(outFilePath,'w')

	for line in inFile:

		tokL = line.split(':')
		chrom, pos, cnt = tokL[0], int(tokL[1]), int(tokL[3])

		if chrom==exnChr and exnIdx==len(exnH[exnChr]):
			continue

		if chrom != exnChr:
			exnChr = chrom
			exnIdx = 0

		while exnH[exnChr][exnIdx][1] < pos:
			exnIdx += 1
			if exnIdx == len(exnH[exnChr]):
				break

		if exnIdx < len(exnH[exnChr]) and exnH[exnChr][exnIdx][0] < pos <= exnH[exnChr][exnIdx][1]:
			mybasic.incHash(depthH,cnt,1)

	for :
コード例 #3
0
def main(inFilePath, outFilePath):

    (exnH, totalLen) = loadExonH()

    depthH = {'0': {}, '15': {}, '20': {}, '30': {}}

    exnChr = 'chr1'
    exnIdx = 0

    if inFilePath[-3:] == '.gz':
        inFile = gzip.open(inFilePath, 'rb')
    else:
        inFile = open(inFilePath)

    for line in inFile:

        tokL = line.split('\t')
        chrom, pos, cnt = tokL[0], int(tokL[1]), int(tokL[3])

        if chrom == exnChr and exnIdx == len(exnH[exnChr]):
            continue

        if chrom != exnChr:
            exnChr = chrom
            exnIdx = 0

        while exnIdx < len(exnH[exnChr]) and exnH[exnChr][exnIdx][1] < pos:
            exnIdx += 1

        if exnIdx < len(
                exnH[exnChr]
        ) and exnH[exnChr][exnIdx][0] < pos <= exnH[exnChr][exnIdx][1]:
            for dt in ['0', '15', '20', '30']:
                cnt = get_cnt_by_qual(line, int(dt))
                if cnt > 1000:
                    mybasic.incHash(depthH[dt], 1001, 1)
                else:
                    mybasic.incHash(depthH[dt], cnt, 1)

    for dt in ['0', '15', '20', '30']:
        depthH[dt][0] = totalLen - sum(depthH[dt].values())

    for dt in ['0', '15', '20', '30']:
        outFile = open(outFilePath + '_mq' + dt, 'w')
        #		for i in range(max(depthH[dt].keys())+1):
        for i in range(1001):
            if i in depthH[dt]:
                d = depthH[dt][i]
            else:
                d = 0
            outFile.write('%d\t%d\n' % (i, d))
        if 1001 in depthH[dt]:
            outFile.write('1001\t%d\n' % depthH[dt][1001])
        else:
            outFile.write('1001\t0\n')
        outFile.flush()
        outFile.close()

    dir = '/'.join(outFilePath.split('/')[:-1])
    sampN = outFilePath.split('/')[-1].split('.')[0]
    os.system(
        'R --no-restore --no-save --args %s %s < %s/NGS/quality/plot_depth.R' %
        (dir, sampN, mysetting.SRC_HOME))