1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Read a MAF from standard input and print the score of each block. It can |
---|
5 | optionally recalculate each score using the hox70 matrix, and normalize the |
---|
6 | score by the number of columns in the alignment. |
---|
7 | |
---|
8 | TODO: Should be able to read an arbitrary scoring matrix. |
---|
9 | |
---|
10 | usage: %prog [options] |
---|
11 | -r, --recalculate: don't use the score from the maf, recalculate (using hox70 matrix) |
---|
12 | -l, --lnorm: divide (normalize) score by alignment text length |
---|
13 | """ |
---|
14 | |
---|
15 | from __future__ import division |
---|
16 | |
---|
17 | import sys |
---|
18 | from bx.cookbook import doc_optparse |
---|
19 | from bx.align import maf |
---|
20 | from bx.align import score |
---|
21 | from optparse import OptionParser |
---|
22 | |
---|
23 | def main(): |
---|
24 | |
---|
25 | # Parse command line arguments |
---|
26 | options, args = doc_optparse.parse( __doc__ ) |
---|
27 | |
---|
28 | try: |
---|
29 | lnorm = bool( options.lnorm ) |
---|
30 | recalculate = bool( options.recalculate ) |
---|
31 | except: |
---|
32 | doc_optparse.exit() |
---|
33 | |
---|
34 | hox70 = score.build_scoring_scheme( """ A C G T |
---|
35 | 91 -114 -31 -123 |
---|
36 | -114 100 -125 -31 |
---|
37 | -31 -125 100 -114 |
---|
38 | -123 -31 -114 91 """, 400, 30, default=0 ) |
---|
39 | |
---|
40 | maf_reader = maf.Reader( sys.stdin ) |
---|
41 | |
---|
42 | for m in maf_reader: |
---|
43 | if m.text_size == 0: |
---|
44 | print "NA" |
---|
45 | continue |
---|
46 | s = m.score |
---|
47 | # Recalculate? |
---|
48 | if recalculate: |
---|
49 | s = hox70.score_alignment( m ) |
---|
50 | # Normalize? |
---|
51 | if lnorm: |
---|
52 | s = s / m.text_size |
---|
53 | # Print |
---|
54 | print s |
---|
55 | |
---|
56 | if __name__ == "__main__": |
---|
57 | main() |
---|