-
Notifications
You must be signed in to change notification settings - Fork 0
/
blast_scraps.py
28 lines (26 loc) · 1007 Bytes
/
blast_scraps.py
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
def batch_make_DBs():
"""Make Blast DBs from FastA files in a directory.
This lists all files present in a directory, detects which are valid
FastA files and creates Blast databases from their contents.
"""
# get directory contents
fas_dir = dirs['mfas_contigs_dir']
db_dir = dirs['blast_db_dir']
contents = listdir(fas_dir)
g_names = []
for item in contents:
try:
records = load_multifasta(item)
assert len(records) > 0
except IOError: print "\t"+item, "rejected (error opening file)"
except AssertionError: print "\t"+item, "rejected (no FastA records)"
except Exception: raise Exception
else:
print "\t"+item, "...",
pattern = re.compile('^(.+)_.+')
match = re.match(pattern, item)
g_name = match.group(1)
make_blastDB(db_dir+g_name, fas_dir+item, 'nucl')
print "DB ready"
g_names.append(g_name)
return g_names