bx-python / scripts / nib_intervals_to_fasta.py

#!/usr/bin/env python

Read a set of ranges and a nib file, print portions of nib overlapping
those ranges to stdout

usage: %prog range_file nib_file

from bx.cookbook import doc_optparse
import bx.seq.nib
import string
import sys

def __main__():

    options, args = doc_optparse.parse( __doc__ )

        range_file = file( args[0] )
        nib_file = file( args[1] )

    nib = bx.seq.nib.NibFile( nib_file )

    for line in range_file: 
        fields = line.split()
        start, end = int( fields[0] ), int( fields[1] ) 
        print ">", start, end 
        print_wrapped( nib.get( start, end - start ) )

def print_wrapped( s ):
    l = len( s )        
    c = 0
    while c < l:
        b = min( c + 50, l )
        print s[c:b]
        c = b

if __name__ == "__main__": __main__()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.