| 1 | #!/usr/bin/python2.6 |
|---|
| 2 | |
|---|
| 3 | """ |
|---|
| 4 | Read a set of ranges and a nib file, print portions of nib overlapping |
|---|
| 5 | those ranges to stdout |
|---|
| 6 | |
|---|
| 7 | usage: %prog range_file nib_file |
|---|
| 8 | """ |
|---|
| 9 | |
|---|
| 10 | from bx.cookbook import doc_optparse |
|---|
| 11 | import bx.seq.nib |
|---|
| 12 | import string |
|---|
| 13 | import sys |
|---|
| 14 | |
|---|
| 15 | def __main__(): |
|---|
| 16 | |
|---|
| 17 | options, args = doc_optparse.parse( __doc__ ) |
|---|
| 18 | |
|---|
| 19 | try: |
|---|
| 20 | range_file = file( args[0] ) |
|---|
| 21 | nib_file = file( args[1] ) |
|---|
| 22 | except: |
|---|
| 23 | doc_optparse.exit() |
|---|
| 24 | |
|---|
| 25 | nib = bx.seq.nib.NibFile( nib_file ) |
|---|
| 26 | |
|---|
| 27 | for line in range_file: |
|---|
| 28 | fields = line.split() |
|---|
| 29 | start, end = int( fields[0] ), int( fields[1] ) |
|---|
| 30 | print ">", start, end |
|---|
| 31 | print_wrapped( nib.get( start, end - start ) ) |
|---|
| 32 | |
|---|
| 33 | def print_wrapped( s ): |
|---|
| 34 | l = len( s ) |
|---|
| 35 | c = 0 |
|---|
| 36 | while c < l: |
|---|
| 37 | b = min( c + 50, l ) |
|---|
| 38 | print s[c:b] |
|---|
| 39 | c = b |
|---|
| 40 | |
|---|
| 41 | if __name__ == "__main__": __main__() |
|---|