| 1 | #!/usr/bin/python2.6 |
|---|
| 2 | |
|---|
| 3 | """ |
|---|
| 4 | Read a feature file containing a 0 or 1 on each line, output |
|---|
| 5 | all mafs whose index in maf_file corresponds to a row having a 1 |
|---|
| 6 | |
|---|
| 7 | usage: %prog feature_file < maf_file |
|---|
| 8 | """ |
|---|
| 9 | |
|---|
| 10 | import psyco_full |
|---|
| 11 | |
|---|
| 12 | import sys |
|---|
| 13 | import bx.align.maf |
|---|
| 14 | |
|---|
| 15 | def __main__(): |
|---|
| 16 | |
|---|
| 17 | feature_file = sys.argv[1] |
|---|
| 18 | |
|---|
| 19 | if len( sys.argv ) > 2: |
|---|
| 20 | match = int( sys.argv[2] ) |
|---|
| 21 | else: |
|---|
| 22 | match = 1 |
|---|
| 23 | |
|---|
| 24 | feature_vector = [ int( line ) for line in file( feature_file ) ] |
|---|
| 25 | |
|---|
| 26 | maf_reader = bx.align.maf.Reader( sys.stdin ) |
|---|
| 27 | maf_writer = bx.align.maf.Writer( sys.stdout ) |
|---|
| 28 | |
|---|
| 29 | index = 0 |
|---|
| 30 | |
|---|
| 31 | for m in maf_reader: |
|---|
| 32 | if feature_vector[ index ] == match: maf_writer.write( m ) |
|---|
| 33 | index += 1 |
|---|
| 34 | |
|---|
| 35 | if __name__ == "__main__": __main__() |
|---|