def run(args): logging.basicConfig(level=logging.DEBUG) fin=IO.fopen(args.input,"r") out=IO.fopen(args.output,"w") bam=DBI.init(args.bam,"bam"); beds=[i for i in TableIO.parse(fin,"bed12")] beds.sort() bp=args.bp print("mapped:{}".format(bam.mapped)) print("unmapped:{}".format(bam.unmapped)) data={} for i,x in enumerate(iter_cluster(beds)): print("{}\t{}:{}-{}".format(i+1,x["chr"],x["start"]+1,x["stop"])) ''' cds=[z.cds() for z in x["beds"] if z.cds()] utr3=[z.utr3() for z in x["beds"] if z.utr3()] utr5=[z.utr5() for z in x["beds"] if z.utr5()] ''' coords = [ up_down_coordinate(gene,args.bp,args.bp) for gene in x["beds"] ] for j,y in enumerate(coords): data[y.id]={} data[y.id]["coord"]=y data[y.id]["values"]=[0.0 for l in range(y.cdna_length())]; coord_beds = [ _translate(coord,bed) for coord,bed in itertools.izip(coords,x["beds"])] for j,read in enumerate(bam.query(method="bam1",chr=x["chr"],start=x["start"]-args.bp,stop=x["stop"]+args.bp,strand=args.strand)): NM=getNM(read) # number of hits NC=0 # number of compatible c_coords=[] for k,coord in enumerate(coords): if overlap(read,coord) and compatible(read,coord): # don't consider the reads extend out of coords. NC+=1 c_coords.append(k) for k,c in enumerate(c_coords): coord=coords[c] if read.start < coord.start or read.stop > coord.stop: start=max(read.start,coord.start) stop=min(read.stop,coord.stop) read=read._slice(start,stop) read_in_coord = _translate(coord,read) for l in xrange(read_in_coord.start,read_in_coord.stop): data[coord.id]["values"][l]+=1.0/NC/NM for j,y in enumerate(coords): print(data[y.id]["coord"]) print(data[y.id]["values"]) '''
def compatible_with_group(i,group): for j in group: if not compatible(i,j): return False return True