Source

bx-python / scripts / line_select.py

#!/usr/bin/env python

"""
Read a file containing a 0 or 1 on each line (`feature_file`), output 
all lines from stdin for which that value was 1

TODO: no need to read the feature_file into memory here, just iterate in
      parallel.

usage: %prog feature_file < ...
"""

import psyco_full

import sys

def __main__():

    feature_file = sys.argv[1]

    if len( sys.argv ) > 2:
        match = int( sys.argv[2] )
    else:
        match = 1
    
    feature_vector = [ int( line ) for line in file( feature_file ) ]

    for index, line in enumerate( sys.stdin ):
        if feature_vector[ index ] == match: print line,

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.