from bedtools import findBedAlignmentsByName from rpkm import rpkm if __name__ == "__main__": opts,args = getopt(sys.argv[1:],'') if len(args) < 3: print "bedRPKM.py alignment.bed uniqueLocations.bed totalAlignments" sys.exit() alignmentFile = args[0] uniqueFile = args[1] total = int(args[2]) alignments = findBedAlignmentsByName(alignmentFile) pseudogenes = findBedAlignmentsByName(uniqueFile) for gene in alignments.keys(): if gene in alignments and gene in pseudogenes: alignLine = alignments[gene][0] #find the beginning and end of the gene minStart,maxEnd = 987654321,0 for line in alignments[gene]: if line.start < minStart: minStart = line.start if line.end > maxEnd: maxEnd = line.end chrom = alignLine.chrom count = sum([line.thickStart for line in alignments[gene]])#alignments[gene][0].thickStart
opts,args = getopt.getopt(sys.argv[1:],'') for opt,arg in opts: if opt == "-r": rpgenes = True geneFile = args[0] alignmentFile = args[1] genes = [] """ if not rpgenes: genes = pseudogenes.load_all() else: genes = rpgenes.load_all() """ genes = bedtools.findBedAlignmentsByName(geneFile) for k in genes.keys(): total = 0 mn = 987654321 mx = 0 for gene in genes[k]: if gene.start < mn: mn = gene.start if gene.end > mx: mx = gene.end alignments = samtools.findBamAlignments(alignmentFile,gene.chrom,gene.start,gene.end) for alignment in alignments: if alignment > 0: total+=1