1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Read an alignment from stdin and for each block print the result of |
---|
5 | evaluating `template_string` (in cheetah template format). The alignment |
---|
6 | block will be placed in the template context as `a` and the list of components |
---|
7 | as `c`. |
---|
8 | |
---|
9 | usage: %prog template [options] |
---|
10 | -f, --format = maf: Input format, maf (default) or axt |
---|
11 | """ |
---|
12 | |
---|
13 | from __future__ import division |
---|
14 | |
---|
15 | import psyco_full |
---|
16 | |
---|
17 | import sys |
---|
18 | from bx.cookbook import doc_optparse |
---|
19 | from bx import align |
---|
20 | |
---|
21 | try: |
---|
22 | from Cheetah.Template import Template |
---|
23 | except: |
---|
24 | print >> sys.stderr, "This script requires the Cheetah template modules" |
---|
25 | sys.exit( -1 ) |
---|
26 | |
---|
27 | def main(): |
---|
28 | |
---|
29 | # Parse command line arguments |
---|
30 | options, args = doc_optparse.parse( __doc__ ) |
---|
31 | |
---|
32 | try: |
---|
33 | template = Template( args[0] ) |
---|
34 | format = options.format |
---|
35 | if not format: format = "maf" |
---|
36 | except: |
---|
37 | doc_optparse.exception() |
---|
38 | |
---|
39 | reader = align.get_reader( format, sys.stdin ) |
---|
40 | |
---|
41 | for a in reader: |
---|
42 | template.a = a |
---|
43 | template.c = a.components |
---|
44 | print template |
---|
45 | |
---|
46 | if __name__ == "__main__": |
---|
47 | main() |
---|