+ fixed some index bugs in the weights calculation
[qpalma.git] / python / computeSpliceAlign.py
index 6f0ad72..a6d4a49 100644 (file)
@@ -18,6 +18,8 @@ def  computeSpliceAlign(dna, exons):
    numberOfExons = (exons.shape)[0] # how many rows ?
    exonSizes = [-1]*numberOfExons
 
+   assert numberOfExons == 3
+
    for idx in range(numberOfExons):
       exonSizes[idx] = exons[idx,1] - exons[idx,0]
 
@@ -27,30 +29,19 @@ def  computeSpliceAlign(dna, exons):
    # 1:donorpos, 3:intron 2:acceptorpos, 0:exon, 4: dangling end
    SpliceAlign = []
 
-   if exons[0,0] > 1:
+   if exons[0,0] > 0:
       SpliceAlign.extend([4]*(exons[0,0]))
 
-   #for i=1:nr_exons
-   #  exon_length = exon_sizes(i); %exons(i,2) is begin of intron
-   #  SpliceAlign = [SpliceAlign, zeros(1,exon_length)] ;
-   #  if i~= nr_exons,
-   #    intron_length = exons(i+1,1) - exons(i,2) ;
-   #    SpliceAlign = [SpliceAlign, 1, ones(1,intron_length-2)*3, 2] ;
-   #  end
-   #end 
-
    for idx in range(numberOfExons):
       exonLength = exonSizes[idx]
       SpliceAlign.extend([0]*exonLength)
       
       if idx < numberOfExons-1:
          intronLength = exons[idx+1,0] - exons[idx,1]
-         SpliceAlign.extend([1])
-         SpliceAlign.extend([3]*((intronLength-2)))
-         SpliceAlign.extend([2])
-         
+         SpliceAlign.extend([1]+[3]*(intronLength-2)+[2])
+
    if len(dna) > exons[2,1]:
-      SpliceAlign.extend([4]*(len(dna)+1-exons[2,1]))
+      SpliceAlign.extend([4]*(len(dna)-exons[2,1]))
 
    assert len(SpliceAlign) == len(dna), pdb.set_trace()