-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_scaffold.py
More file actions
38 lines (33 loc) · 928 Bytes
/
get_scaffold.py
File metadata and controls
38 lines (33 loc) · 928 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
31
32
33
34
35
36
37
38
import argparse
import re
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", required=True,
help="name of the fasta file")
ap.add_argument("-s", "--scaffold", required=True,
help="name of the scaffold to fetch")
ap.add_argument("-o", "--output", required=True,
help="name of output fasta file")
args = vars(ap.parse_args())
def get_scaffold(file_read, file_write, scaf):
fh1 = open(file_read, 'r')
i=0
fh2=open(file_write, 'w')
tmp=''; chk=0
for line in fh1:
if re.search('>', line):
chk=0
if re.search(scaf, line):
chk=1
if chk==1:
tmp=tmp+line
fh2.write(tmp)
#######
if args['scaffold']:
print('Outputting the scaffold.')
get_scaffold(args['input'], args['output'], args['scaffold'])
else :
print('ERROR : Check options')
#seq_reverse(fh, 'out.fa')
#seq_complement(fh, 'out2.fa')
#seq_complement(args['input'], args['output'])