+def reverse_complement(seq):
+ """
+ This function takes a read in plain or bracket notation and returns the
+ reverse complement of it.
+ I.e.
+
+ est = cgt[ac][tg]a
+
+ leads to
+
+ rev_comp = t[ac][tg]acg
+ """
+
+ bpos = seq.find('[')
+ rc = lambda x: {'a':'t','c':'g','g':'c','t':'a'}[x]
+
+ # check first whether seq contains no brackets at all
+ if bpos == -1:
+ ret_val = map(rc,seq)
+ ret_val.reverse()
+ ret_val = "".join(ret_val)
+ else:
+ brc = lambda x: {'a':'t','c':'g','g':'c','t':'a','[':'[',']':']'}[x]
+
+ # first_part is the part of the seq up to the first occurrence of a
+ # bracket
+ first_part = seq[:bpos]
+ first_part = map(rc,first_part)
+ first_part.reverse()
+ first_part = "".join(first_part)
+
+ # inside brackets has to be complemented but NOT reversed
+ inside_brackets = seq[bpos+1:bpos+3]
+ inside_brackets = "".join(map(rc,inside_brackets))
+
+ ret_val = '%s[%s]%s'%(reverse_complement(seq[bpos+4:]),inside_brackets,first_part)
+
+ return ret_val
+
+
+def unbracket_est(est):
+ """
+ This function takes a read in bracket notation and restores the read sequence from it.
+ I.e.
+
+ est = cgt[ac][tg]aa
+
+ leads to
+
+ result = cgtcgaa
+
+ so the second entry within brackets is the base on the read whereas the first
+ entry is the base from the dna.
+ """
+
+ new_est = ''
+ e = 0
+
+ while True:
+ if e >= len(est):
+ break
+
+ if est[e] == '[':
+ new_est += est[e+2]
+ e += 4
+ else:
+ new_est += est[e]
+ e += 1
+
+ return "".join(new_est).lower()
+
+
+def create_bracket_seq(dna_seq,read_seq):
+ """
+ This function takes a dna sequence and a read sequence and returns the
+ bracket format of the match/mismatches i.e.
+
+ dna : aaa
+ read: aac
+ is written in bracket notation: aa[ac]
+ """
+ assert len(dna_seq) == len(read_seq)
+ return "".join(map(lambda x,y: ['[%s%s]'%(x,y),x][x==y],dna_seq,read_seq))
+
+
+def getSpliceScores(chr,strand,intervalBegin,intervalEnd,total_size=0):