-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho-trim
executable file
·61 lines (44 loc) · 1.99 KB
/
o-trim
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
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2010 - 2012, A. Murat Eren
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
import sys
import Oligotyping.lib.fastalib as u
from Oligotyping.utils.utils import pretty_print as pp
def main(input_fasta, trim_from = 0, trim_to = sys.maxsize, min_length = 0, output = None):
if not output:
output = input_fasta + '.TRIMMED.fa'
fasta = u.SequenceSource(input_fasta)
output = u.FastaOutput(output)
while next(fasta):
if fasta.pos % 1000 == 0:
sys.stderr.write('\rreads processed so far: %s' % (pp(fasta.pos)))
sys.stderr.flush()
if len(fasta.seq) < min_length:
continue
output.write_id(fasta.id)
output.write_seq(fasta.seq[trim_from:trim_to])
fasta.close()
output.close()
sys.stderr.write('\n')
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Trim FASTA file')
parser.add_argument('input_fasta', metavar = 'FILE',
help = 'FASTA file to subsample')
parser.add_argument('--trim-from', metavar = 'INTEGER', type = int, default = 0,
help = 'Start position')
parser.add_argument('--trim-to', metavar = 'INTEGER', type = int, default = sys.maxsize,
help = 'End position')
parser.add_argument('--min-length', metavar = 'INTEGER', type = int, default = 0,
help = 'Minimum lenght of a read to be kept')
parser.add_argument('-o', '--output', metavar = 'FILE_FILE_PATH', default = None,
help = 'Output file name.')
args = parser.parse_args()
sys.exit(main(args.input_fasta, args.trim_from, args.trim_to, args.min_length, args.output))