-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsub_fastq.py
More file actions
32 lines (24 loc) · 915 Bytes
/
sub_fastq.py
File metadata and controls
32 lines (24 loc) · 915 Bytes
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
from argparse import ArgumentParser
from Bio import SeqIO
import sys
parser = ArgumentParser()
parser.add_argument("inputfile", help="Input Files in FASTA format")
parser.add_argument("id", help="ID of read in FASTA file")
parser.add_argument("--start", type=int, help="Starting coordinate")
parser.add_argument("--end", type=int, help="End coordinate")
parser.add_argument("output", help="Output File in FASTA format")
args = parser.parse_args()
sequence = {}
for read in SeqIO.parse(args.inputfile, "fasta"):
if args.id == read.id:
sequence[args.id] = str(read.seq)
break
else:
print("id not found")
sys.exit()
start = args.start if args.start else 0
end = args.end+1 if args.end else len(sequence[args.id])+1
with open(args.output, "w") as f:
nid = ">" + args.id + "_subseq_" + str(start) + ":" + str(end)
f.write(nid + "\n")
f.write(sequence[args.id][start:end])