| 1 | #!/usr/bin/python2.6 |
|---|
| 2 | |
|---|
| 3 | """ |
|---|
| 4 | Read a maf file from stdin and write out a new maf with only blocks having all |
|---|
| 5 | of the required in species, after dropping any other species and removing |
|---|
| 6 | columns containing only gaps. |
|---|
| 7 | |
|---|
| 8 | usage: %prog species,species2,... < maf |
|---|
| 9 | """ |
|---|
| 10 | |
|---|
| 11 | import psyco_full |
|---|
| 12 | |
|---|
| 13 | import bx.align.maf |
|---|
| 14 | import copy |
|---|
| 15 | import sys |
|---|
| 16 | |
|---|
| 17 | from itertools import * |
|---|
| 18 | |
|---|
| 19 | def main(): |
|---|
| 20 | |
|---|
| 21 | species = sys.argv[1].split( ',' ) |
|---|
| 22 | |
|---|
| 23 | maf_reader = bx.align.maf.Reader( sys.stdin ) |
|---|
| 24 | maf_writer = bx.align.maf.Writer( sys.stdout ) |
|---|
| 25 | |
|---|
| 26 | for m in maf_reader: |
|---|
| 27 | new_components = [] |
|---|
| 28 | for comp in m.components: |
|---|
| 29 | if comp.src.split( '.' )[0] in species: |
|---|
| 30 | new_components.append( comp ) |
|---|
| 31 | m.components = new_components |
|---|
| 32 | m.remove_all_gap_columns() |
|---|
| 33 | if len( m.components ) > 1: |
|---|
| 34 | maf_writer.write( m ) |
|---|
| 35 | |
|---|
| 36 | maf_reader.close() |
|---|
| 37 | maf_writer.close() |
|---|
| 38 | |
|---|
| 39 | if __name__ == "__main__": |
|---|
| 40 | main() |
|---|