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