File: split_sequences.py

package info (click to toggle)
sepp 4.5.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 33,376 kB
  • sloc: python: 5,635; java: 4,698; sh: 2,203; makefile: 53; xml: 31
file content (51 lines) | stat: -rw-r--r-- 1,542 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3

'''
Created on May 13, 2014
@author: namphuon
'''
import argparse
import os
from sepp.alignment import MutableAlignment


def parse_args():
    parser = argparse.ArgumentParser(
        description='Performs various tools for TIPP.')
    parser.add_argument(
        '-t', '--threshold', default=None, metavar='THRESHOLD',
        help='Split based on this threshold of length',
        type=int, dest='threshold')
    parser.add_argument(
        '-i', '--input', default=None, metavar='INPUT',
        help='INPUT sequence file (default=None)', required=True,
        type=str, dest='input')
    parser.add_argument(
        '-o', '--output', default='output', metavar='OUTPUT',
        help=('OUTPUT prefix, will write fragmentary file to OUTPUT.frag.fas '
              'and full-length file to OUTPUT.full.fas (default=output)'),
        type=str, dest='output')
    args = parser.parse_args()
    return args


def main():
    args = parse_args()
    sequences = MutableAlignment()
    assert os.path.isfile(args.input) and os.access(args.input, os.R_OK), \
        "Input file %s does not exist\n" % args.input
    sequences.read_file_object(args.input)
    frag = MutableAlignment()
    full = MutableAlignment()

    for (key, seq) in sequences.items():
        if (len(seq) <= args.threshold):
            frag[key] = seq
        else:
            full[key] = seq
    frag.write_to_path("%s.frag.fas" % args.output)
    full.write_to_path("%s.full.fas" % args.output)


if __name__ == "__main__":
    main()