-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblast_makedb.py
43 lines (36 loc) · 1.56 KB
/
blast_makedb.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
import os
import sys
import argparse
import fnmatch
import shutil
parser = argparse.ArgumentParser(description='Check CSV file for synonymous SNP data and analyze them.')
parser.add_argument('fasta_file', default="", nargs='?', help="Fasta file with sequence data. (all for all files in dir)")
parser.add_argument('--prot', default=False, action='store_true', help="Input is a protein sequence.")
parser.add_argument('--skip_ext', default=False, action='store_true', help="Do not add the sequence type extension (aa/nn)")
parser.add_argument('--keep_name', default=False, action='store_true', help="DB name equal to filename")
args = parser.parse_args()
path = os.getcwd()
if args.fasta_file != "":
dbtype = "nucl"
ext = "_nn"
if args.prot == True:
dbtype = "prot"
ext = "_aa"
if args.skip_ext == True:
ext = ""
if args.fasta_file == "all":
for fname in os.listdir("."):
if os.path.isfile(fname):
if fnmatch.fnmatch (fname, "*.fas"):
title = fname[:-4]
if args.keep_name == False:
title = fname.split("_")[0][0]+fname.split("_")[1][:3]
os.system("makeblastdb -in "+fname+" -title "+title+ext+" -out "+title+ext+" -dbtype "+dbtype)
shutil.copyfile(fname,title+ext+".fas")
elif os.path.isfile(args.fasta_file) == True:
title = args.fasta_file[:-4]
if args.keep_name == False:
title = args.fasta_file.split("_")[0][0]+args.fasta_file.split("_")[1][:3]
os.system("makeblastdb -in "+args.fasta_file+" -title "+title+ext+" -out "+title+ext+" -dbtype "+dbtype)
shutil.copyfile(args.fasta_file,title+ext+".fas")