3
|
1 import argparse
|
|
2
|
|
3 #docs.python.org/dev/library/argparse.html
|
|
4 parser = argparse.ArgumentParser()
|
|
5 parser.add_argument("--input", help="Input folder with files")
|
|
6 parser.add_argument("--output", help="Output file")
|
|
7 parser.add_argument("--start", help="How many nucleotides to trim from the start", type=int)
|
|
8 parser.add_argument("--end", help="How many nucleotides to trim from the end", type=int)
|
|
9
|
|
10 args = parser.parse_args()
|
|
11 start = int(args.start)
|
|
12 end = int(args.end)
|
|
13
|
|
14 if end <= 0:
|
|
15 import shutil
|
|
16 shutil.copy(args.input, args.output)
|
|
17 import sys
|
|
18 sys.exit()
|
|
19
|
|
20 currentSeq = ""
|
|
21 currentId = ""
|
|
22
|
|
23 with open(args.input, 'r') as i:
|
|
24 with open(args.output, 'w') as o:
|
|
25 for line in i.readlines():
|
|
26 if line[0] is ">":
|
|
27 if currentSeq is not "" or currentId is not "":
|
|
28 o.write(currentId)
|
|
29 o.write(currentSeq[start:-end] + "\n")
|
|
30 currentId = line
|
|
31 currentSeq = ""
|
|
32 else:
|
|
33 currentSeq += line.rstrip()
|
|
34 o.write(currentId)
|
|
35 o.write(currentSeq.rstrip()[start:-end] + "\n")
|