File: maf_randomize.py

package info (click to toggle)
python-bx 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,000 kB
  • sloc: python: 17,136; ansic: 2,326; makefile: 24; sh: 8
file content (37 lines) | stat: -rwxr-xr-x 690 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python3

"""
Randomize the order of blocks in a MAF file. If `sample_size` is specified,
that many random blocks will be kept from the original maf

usage: %prog [sample_size] < maf > maf
"""

import random
import sys

from bx.align import maf


def __main__():
    if len(sys.argv) > 1:
        sample_size = int(sys.argv[1])

    maf_reader = maf.Reader(sys.stdin)
    maf_writer = maf.Writer(sys.stdout)

    mafs = list(maf_reader)

    # for m in maf_reader: mafs.append( m )

    random.shuffle(mafs)

    if not sample_size:
        sample_size = len(mafs)

    for i in range(0, sample_size):
        maf_writer.write(mafs[i])


if __name__ == "__main__":
    __main__()