-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextract_subseq.py
More file actions
executable file
·41 lines (33 loc) · 1.33 KB
/
extract_subseq.py
File metadata and controls
executable file
·41 lines (33 loc) · 1.33 KB
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
#!/usr/bin/env python
"""A simple python script template.
"""
import os
import sys
import argparse
def main(arguments):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-i', '--infile', required='True', help="Input file",dest='infile')
parser.add_argument("-s", "--start_pos",
dest="start",
default = 1,
type = int,
help="Starting position [0 indexing]")
parser.add_argument("-e", "--end_pos",
dest="end",
default = -1,
type = int,
help="End position [1 indexing]")
parser.add_argument('-o', '--outfile', help="Output file",dest='outfile',
default=sys.stdout, type=argparse.FileType('w'))
args = parser.parse_args(arguments)
from Bio import SeqIO
from Bio.SeqRecord import SeqRecord
if args.infile == '-':
h = sys.stdin
else:
h = open(args.infile, 'rU')
record = list(SeqIO.parse(args.infile, "fasta"))[0]
qrecord = SeqRecord(record.seq[args.start:args.end], record.id + ':'+ str(args.start) + '-' + str(args.end), description= "")
SeqIO.write(qrecord, args.outfile, "fasta")
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))