Exemplo n.º 1
0
def findSamAlignments(samfile,start,end):
	ret = [0 for x in range(end-start+1)]
	
	def lineCheck(line):
			if line[0] == "@":
				return #header line
			pieces = line.split()
			seqname = pieces[0]
			pos = int(pieces[3])
			testnumber = int(pieces[1])
	
			if testnumber&0x4 == 0x4:
				pass
			else:
				ret[pos-start]+=1
				
	efficientFileRead(samfile,lineCheck)
	return ret
Exemplo n.º 2
0
def findBamAlignments(bamfile,chrom,start,end):
	
	samtoolsViewRegion(bamfile,chrom,start,end,"temp")
	alignRange = [start,end]
	def rangeCheck(line):
		if line[0] == "@":
				return #header line
		pieces = line.split()
		seqname = pieces[0]
		ch = pieces[2]
		pos = int(pieces[3])
		testnumber = int(pieces[1])

		if testnumber&0x4 == 0x4:
			pass
		else:
			if pos < alignRange[0]:
				alignRange[0] = pos
			if pos > alignRange[1]:
				alignRange[1] = pos
	efficientFileRead("temp",rangeCheck)
	
	def lineCheck(line):
		if line[0] == "@":
			return #header line
		pieces = line.split()
		seqname = pieces[0]
		ch = pieces[2]
		pos = int(pieces[3])
		testnumber = int(pieces[1])

		if testnumber&0x4 == 0x4:
			pass
		elif ch == chrom:
			ret[pos-start]+=1

	ret = [0 for x in range(alignRange[1]-alignRange[0]+1)]
	efficientFileRead("temp",lineCheck)
	runCommand("rm temp")	
	return ret
Exemplo n.º 3
0
		sys.exit()
	
	filename = args[0]
	try:
		length = int(args[1])
	except ValueError:
		print "expandBed.py filename length"
		print "expecting int value for length"
		sys.exit()
	
	def lineParse(line):
		split = line.split("\t")
		sc = 1
		try:
			int(split[3])
			sc = split[3]
			line = bedtools.BEDLine(split[0],split[1],split[2],score = sc)
		except:
			sc = split[4]
			line = bedtools.BEDLine(split[0],split[1],split[2],split[3],score = sc)
		
		print line.chrom + "\t" + str(line.start) + "\t" + str(line.end+length) + "\t" + line.name + "\t" + str(line.score) + "\t" + line.strand
	
	efficientFileRead(filename,lineParse)
	
	#lines = bedtools.BEDFile(filename).lines
	
	#for line in lines:
	#	for i in range(line.start,line.end+1):
	#		print line.chrom + "\t" + str(i) + "\t" + str(i+length) + "\t" + line.name + "\t" + line.score + "\t" + line.strand