Commits

James Taylor committed 5b0d160

Scoring now handle alignments, including multiple. Should be exactly the
same as multiz.

Comments (0)

Files changed (2)

bx/align/score.py

             ss.set_score( ord( chars[i].upper() ), ord( chars[j].upper() ), score )
     return ss
             
-def score( scoring_scheme, text1, text2 ):
+def score_alignment( scoring_scheme, a ):
+    score = 0
+    ncomps = len( a.components )
+    for i in range( ncomps ):
+        for j in range( i+1, ncomps ):
+            score += score_texts( scoring_scheme, a.components[i].text, a.components[j].text )
+            print "."
+    return score
+    
+
+def score_texts( scoring_scheme, text1, text2 ):
     rval = 0
     last_gap = False
     for i in range( len( text1 ) ):

bx/align/score_tests.py

 import bx.align.score
+import bx.align.maf
+import StringIO
 import unittest
 
 aligns = [ ( "CCACTAGTTTTTAAATAATCTACTATCAAATAAAAGATTTGTTAATAATAAATTTTAAATCATTAACACTT",
              1690 )   
          ]
 
+mafs = """##maf
+a score=2883.0
+s hg17.chr1             6734 30 + 245522847 CTACCTCAGTGTGGAAGGTGGGCAGTTCTG
+s rheMac1.SCAFFOLD71394 9319 30 -     13789 CTACCTCAGTGTGGAAGGTGGGCAGTTCTG
+
+a score=8167.0
+s hg17.chr1             41401 40 + 245522847 TGTGTGATTAATGCCTGAGACTGTGTGAAGTAAGAGATGG
+s panTro1.chr1          49673 40 + 229575298 TGCGTGATTAATGCCTGAGATTGTGTGAAGTAAAAGATGG
+s rheMac1.SCAFFOLD45837 26063 33 -     31516 TGTGTGATTAATGCCTGAGATTGTGTGAAGTAA-------
+"""
+
 class BasicTests( unittest.TestCase ):
-    def test_scoring( self ):
+    def test_scoring_text( self ):
         ss = bx.align.score.hox70
         for t1, t2, score in aligns:
-            self.assertEquals( bx.align.score.score( ss, t1, t2 ), score )
+            self.assertEquals( bx.align.score.score_texts( ss, t1, t2 ), score )
+            
+    def test_align( self ):
+        ss = bx.align.score.hox70
+        for block in bx.align.maf.Reader( StringIO.StringIO( mafs ) ):
+            self.assertEquals( bx.align.score.score_alignment( ss, block ), float( block.score ) )
             
 test_classes = [ BasicTests ]
 suite = unittest.TestSuite( [ unittest.makeSuite( c ) for c in test_classes ] )