def _count(self, filename, idx): '''count filename against idx.''' overlapping_genes = set() genes = set() # iterate over exons infile = IOTools.openFile(filename, "r") it = Bed.bed_iterator(infile) nexons, nexons_overlapping = 0, 0 nbases, nbases_overlapping = 0, 0 for this in it: nexons += 1 nbases += this.end - this.start try: intervals = list( idx[this.contig].find(max(0, this.start), this.end)) except KeyError: continue except Exception, msg: raise Exception( "error while processing %s, msg=%s" % (filename, msg)) if len(intervals) == 0: continue nexons_overlapping += 1 start, end = this.start, this.end counts = numpy.zeros(end - start, numpy.int) for other_start, other_end, other_value in intervals: for x in range(max(start, other_start) - start, min(end, other_end) - start): counts[x] += 1 nbases_overlapping += sum([1 for x in counts if x > 0])
def _count(self, filename, idx): '''count filename against idx.''' overlapping_genes = set() genes = set() # iterate over exons infile = IOTools.openFile(filename, "r") it = Bed.bed_iterator(infile) nexons, nexons_overlapping = 0, 0 nbases, nbases_overlapping = 0, 0 for this in it: nexons += 1 nbases += this.end - this.start try: intervals = list(idx[this.contig].find(max(0, this.start), this.end)) except KeyError: continue except Exception as msg: raise Exception("error while processing %s, msg=%s" % (filename, msg)) if len(intervals) == 0: continue nexons_overlapping += 1 start, end = this.start, this.end counts = numpy.zeros(end - start, numpy.int) for other_start, other_end, other_value in intervals: for x in range( max(start, other_start) - start, min(end, other_end) - start): counts[x] += 1 nbases_overlapping += sum([1 for x in counts if x > 0]) infile.close() return nexons, nexons_overlapping, nbases, nbases_overlapping