1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Randomize the order of blocks in a MAF file. If `sample_size` is specified, |
---|
5 | that many random blocks will be kept from the original maf |
---|
6 | |
---|
7 | usage: %prog [sample_size] < maf > maf |
---|
8 | """ |
---|
9 | |
---|
10 | import sys |
---|
11 | |
---|
12 | import sys, random |
---|
13 | from bx.align import maf |
---|
14 | from math import * |
---|
15 | from optparse import OptionParser |
---|
16 | |
---|
17 | def __main__(): |
---|
18 | |
---|
19 | #if len( sys.argv ) > 1: fraction = float( sys.argv[1] ) |
---|
20 | if len( sys.argv ) > 1: sample_size = int( sys.argv[1] ) |
---|
21 | |
---|
22 | maf_reader = maf.Reader( sys.stdin ) |
---|
23 | maf_writer = maf.Writer( sys.stdout ) |
---|
24 | |
---|
25 | mafs = list( maf_reader ) |
---|
26 | |
---|
27 | # for m in maf_reader: mafs.append( m ) |
---|
28 | |
---|
29 | random.shuffle( mafs ) |
---|
30 | |
---|
31 | if not sample_size: sample_size = len( mafs ) |
---|
32 | |
---|
33 | for i in range( 0, sample_size ): maf_writer.write( mafs[ i ] ) |
---|
34 | |
---|
35 | if __name__ == "__main__": __main__() |
---|