3
|
1 import argparse
|
|
2
|
|
3 #docs.python.org/dev/library/argparse.html
|
|
4 parser = argparse.ArgumentParser()
|
4
|
5 parser.add_argument("--input", help="Input fasta")
|
|
6 parser.add_argument("--output", help="Output fasta")
|
3
|
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
|
4
|
14 if end <= 0 and start <= 0:
|
3
|
15 import shutil
|
|
16 shutil.copy(args.input, args.output)
|
|
17 import sys
|
|
18 sys.exit()
|
4
|
19
|
|
20
|
3
|
21
|
|
22 currentSeq = ""
|
|
23 currentId = ""
|
|
24
|
4
|
25 if end is 0:
|
|
26 with open(args.input, 'r') as i:
|
|
27 with open(args.output, 'w') as o:
|
|
28 for line in i.readlines():
|
|
29 if line[0] is ">":
|
|
30 currentSeq = currentSeq[start:]
|
|
31 if currentSeq is not "" and currentId is not "":
|
|
32 o.write(currentId)
|
|
33 o.write(currentSeq + "\n")
|
|
34 currentId = line
|
|
35 currentSeq = ""
|
|
36 else:
|
|
37 currentSeq += line.rstrip()
|
|
38 o.write(currentId)
|
|
39 o.write(currentSeq[start:] + "\n")
|
|
40 else:
|
|
41 with open(args.input, 'r') as i:
|
|
42 with open(args.output, 'w') as o:
|
|
43 for line in i.readlines():
|
|
44 if line[0] is ">":
|
|
45 currentSeq = currentSeq[start:-end]
|
|
46 if currentSeq is not "" and currentId is not "":
|
|
47 o.write(currentId)
|
|
48 o.write(currentSeq + "\n")
|
|
49 currentId = line
|
|
50 currentSeq = ""
|
|
51 else:
|
|
52 currentSeq += line.rstrip()
|
|
53 o.write(currentId)
|
|
54 o.write(currentSeq[start:-end] + "\n")
|