import pysam
import optparse
from cistematic.genomes import Genome
-from commoncode import isSpliceEntry, getFeaturesByChromDict
+from commoncode import isSpliceEntry
def main(argv=None):
samfile = pysam.Samfile(BAM, "rb" )
readMultiplicityDict = getReadMultiplicity(samfile)
- counts = getReadCounts(samfile, readMultiplicityDict)
+ counts, readLength = getReadCounts(samfile, readMultiplicityDict)
outheader = buildHeader(samfile.header, counts)
if options.markGID:
genome = Genome(options.genomeName, inRAM=True)
genome.extendFeatures(options.extendGenome, replace=options.replaceModels)
print "getting gene features...."
- featuresByChromDict = getFeaturesByChromDict(genome)
outheader['CO'].append(options.genomeComment)
outfile = pysam.Samfile(outputfilename, "wb", header=outheader)
if options.markGID:
chrom = samfile.getrname(alignedread.tid)
chromNum = chrom[3:]
- geneModelFlag = "NM"
- for (start, stop, gid, featureSense, featureType) in featuresByChromDict[chromNum]:
- if start < alignedread.pos and stop > alignedread.pos:
- geneModelFlag = gid
- continue
+ #new direct query
+ geneFeatures = genome.getFeaturesIntersecting(chromNum, alignedread.pos, readLength)
+ try:
+ (name, version, chromosome, start, stop, orientation, atype) = geneFeatures[0]
+ geneModelFlag = name
+ except IndexError:
+ geneModelFlag = "NM"
ID = getReadID(alignedread)
try:
"ReadLength\t%d" % readLength
]
- return counts
+ return counts, readLength
def buildHeader(templateheader, commentList):