5 print 'psyco not running'
10 from commoncode import readDataset
16 usage = "usage: python %s rdsfile outfilename [--cache pages]"
18 parser = optparse.OptionParser(usage=usage)
19 parser.add_option("--cache", type="int", dest="numCachePages",
20 help="number of cache pages to use [default: 100000]")
21 parser.set_defaults(numCachePages=None)
22 (options, args) = parser.parse_args(argv[1:])
31 if options.numCachePages is not None:
33 cachePages = options.numCachePages
38 altSpliceCounts(hitfile, outfilename, doCache, cachePages)
41 def altSpliceCounts(hitfile, outfilename, doCache=False, cachePages=100000):
46 hitRDS = readDataset(hitfile, verbose = True, cache=doCache)
47 if cachePages > hitRDS.getDefaultCacheSize():
48 hitRDS.setDBcache(cachePages)
50 readlen = hitRDS.getReadSize()
51 hitDict = hitRDS.getSplicesDict(noSense=True)
52 outfile = open(outfilename,'w')
57 resultDict[chrom] = []
61 for (tagStart, lstop, rstart, tagStop) in hitDict[chrom]:
63 length = tagStop - tagStart
64 if length < readlen + 5:
67 startDict[chrom].append((tagStart, length))
68 stopDict[chrom].append((tagStop, length))
70 startDict[chrom].sort()
71 stopDict[chrom].sort()
76 for chrom in startDict:
78 maxIndex = len(startDict[chrom])
79 while firstIndex < maxIndex:
80 (fstart, flen) = startDict[chrom][firstIndex]
81 (start, length) = (fstart, flen)
82 secondIndex = firstIndex
84 while (start - fstart) < readlen:
85 if secondIndex >= maxIndex:
88 (start, length) = startDict[chrom][secondIndex]
89 if (start - fstart) < readlen and abs(length - flen) > readlen:
90 line = (chrom, fstart, fstart + flen, chrom, start, start + length)
92 for slength in secondLengths:
93 if abs(slength - length) < readlen:
96 if len(resultDict[chrom]) == 0:
97 resultDict[chrom].append(line)
98 elif line != resultDict[chrom][-1] and not alreadySeen:
99 resultDict[chrom].append(line)
100 secondLengths.append(length)
106 firstIndex = secondIndex
110 maxIndex = len(stopDict[chrom])
111 while firstIndex < maxIndex:
112 (fstop, flen) = stopDict[chrom][firstIndex]
113 (stop, length) = (fstop, flen)
114 secondIndex = firstIndex
116 while (stop - fstop) < readlen:
117 if secondIndex >= maxIndex:
119 (stop, length) = stopDict[chrom][secondIndex]
120 if (stop - fstop) < readlen and abs(length - flen) > readlen:
121 line = (chrom, fstop - flen, fstop, chrom, stop - length, stop)
123 for slength in secondLengths:
124 if abs(slength - length) < readlen:
127 if len(resultDict[chrom]) == 0:
128 resultDict[chrom].append(line)
130 if line != resultDict[chrom][-1] and not alreadySeen:
131 resultDict[chrom].append(line)
132 secondLengths.append(length)
138 firstIndex = secondIndex
141 resultDict[chrom].sort()
142 for line in resultDict[chrom]:
143 outfile.write('alt%d' % alternative + '\tchr%s\t%d\t%d\tchr%s\t%d\t%d\n' % line)
146 print chrom, maxIndex, spliceEvent, altSpliceEvent
148 print spliceEvent, altSpliceEvent
151 if __name__ == "__main__":