Skip to content

Commit 4339bad

Browse files
committed
accept old folder names
1 parent bfbc324 commit 4339bad

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

fdog/checkData.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import sys
2020
import os
21+
import errno
2122
import argparse
2223
from os import listdir
2324
from os.path import isfile, join
@@ -175,25 +176,29 @@ def run_check_fasta(checkDir, replace, delete, concat):
175176

176177
def check_blastdb(args):
177178
""" Check for outdated blastdb """
178-
(query, taxon, coreTaxa_dir) = args
179+
(query, taxon, coreTaxa_dir, searchTaxa_dir) = args
179180
blast_db = '%s/%s/%s' % (coreTaxa_dir, taxon, taxon)
180181
try:
181182
blastp_cline = NcbiblastpCommandline(query = query, db = blast_db)
182183
stdout, stderr = blastp_cline()
183184
except:
184185
return([query, blast_db])
185-
if not os.path.exists('%s/%s/%s.fa.fai' % (coreTaxa_dir, taxon, taxon)):
186-
fai_in_genome = "../../searchTaxa_dir/%s/%s.fa.fai" % (taxon, taxon)
187-
fai_in_blast = "%s/%s/%s.fa.fai" % (coreTaxa_dir, taxon, taxon)
188-
os.symlink(fai_in_genome, fai_in_blast)
186+
try:
187+
os.remove('%s/%s/%s.fa.fai' % (coreTaxa_dir, taxon, taxon))
188+
except OSError as e:
189+
if e.errno != errno.ENOENT:
190+
raise
191+
fai_in_genome = "%s/%s/%s.fa.fai" % (searchTaxa_dir, taxon, taxon)
192+
fai_in_blast = "%s/%s/%s.fa.fai" % (coreTaxa_dir, taxon, taxon)
193+
os.symlink(fai_in_genome, fai_in_blast)
189194

190195

191-
def run_check_blastdb(coreTaxa_dir, fdogPath):
196+
def run_check_blastdb(coreTaxa_dir, searchTaxa_dir, fdogPath):
192197
""" Run check_blastdb fn """
193198
query = '%s/data/infile.fa' % fdogPath
194199
jobs = []
195200
for fd in general_fn.read_dir(coreTaxa_dir):
196-
jobs.append([query, fd, coreTaxa_dir])
201+
jobs.append([query, fd, coreTaxa_dir, searchTaxa_dir])
197202
cpus = mp.cpu_count()-1
198203
pool = mp.Pool(cpus)
199204
out = []
@@ -216,10 +221,10 @@ def create_blastdb(args):
216221
shutil.rmtree(blast_path)
217222
### Redo blastdb
218223
Path(blast_path).mkdir(parents = True, exist_ok = True)
219-
blast_fn.make_blastdb([taxon, fa_file, outPath, True])
224+
blast_fn.make_blastdb([taxon, fa_file, outPath, coreTaxa_dir, searchTaxa_dir, True])
220225
### make symlink to fasta files
221-
fa_in_genome = "../../searchTaxa_dir/%s/%s.fa" % (taxon, taxon)
222-
fai_in_genome = "../../searchTaxa_dir/%s/%s.fa.fai" % (taxon, taxon)
226+
fa_in_genome = "%s/%s/%s.fa" % (searchTaxa_dir, taxon, taxon)
227+
fai_in_genome = "%s/%s/%s.fa.fai" % (searchTaxa_dir, taxon, taxon)
223228
fa_in_blast = "%s/%s.fa" % (blast_path, taxon)
224229
fai_in_blast = "%s/%s.fa.fai" % (blast_path, taxon)
225230
if not os.path.exists(fa_in_blast):
@@ -326,6 +331,7 @@ def main():
326331
parser.add_argument('--delete', help='Delete special characters in sequences', action='store_true', default=False)
327332
parser.add_argument('--concat', help='Concatenate multiple-line sequences into single-line', action='store_true', default=False)
328333
parser.add_argument('--reblast', help='Re-create blast databases', action='store_true', default=False)
334+
# parser.add_argument('--updateJson', help='Update annotation json file to FAS >=1.16', action='store_true', default=False)
329335

330336
### get arguments
331337
args = parser.parse_args()
@@ -337,6 +343,7 @@ def main():
337343
delete = args.delete
338344
concat = args.concat
339345
reblast = args.reblast
346+
# updateJson = args.updateJson
340347

341348
checkOptConflict(concat, replace, delete)
342349
caution = 0
@@ -374,7 +381,7 @@ def main():
374381
print('All old BlastDBs have been updated!')
375382
print('=> Checking %s...' % coreTaxa_dir)
376383
blastTaxa = run_check_fasta(coreTaxa_dir, replace, delete, concat)
377-
check_blast = run_check_blastdb(coreTaxa_dir, fdogPath)
384+
check_blast = run_check_blastdb(coreTaxa_dir, searchTaxa_dir, fdogPath)
378385

379386
if not check_blast[0] == 1:
380387
print('*** ERROR: Version incompatible between BlastDB and BLAST program!')
@@ -391,6 +398,8 @@ def main():
391398
print('NOTE: You still can run fdog without FAS using the option "-fasoff"')
392399
caution = 1
393400
run_check_complete_anno(annotation_dir, searchTaxa_dir)
401+
# if updateJson:
402+
# run_update_anno(annotation_dir, searchTaxa_dir)
394403

395404
# ### check ncbi IDs
396405
print('=> Checking NCBI taxonomy IDs...')

fdog/libs/addtaxon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def create_blastdb(args):
140140
(outPath, spec_name, genome_file, force, silent) = args
141141
blast_path = '%s/coreTaxa_dir/%s' % (outPath, spec_name)
142142
if (not os.path.exists(os.path.abspath('%s/%s.phr' % (blast_path, spec_name)))) or force:
143-
blast_fn.make_blastdb([spec_name, genome_file, outPath, silent])
143+
blast_fn.make_blastdb([spec_name, genome_file, outPath, '', '', silent])
144144
### make symlink to fasta files
145145
fa_in_genome = "../../searchTaxa_dir/%s/%s.fa" % (spec_name, spec_name)
146146
fai_in_genome = "../../searchTaxa_dir/%s/%s.fa.fai" % (spec_name, spec_name)

fdog/libs/blast.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,22 @@ def parse_blast_xml(blast_output):
7272

7373

7474
def make_blastdb(args):
75-
""" Make blastDB in coreTaxa_dir (for fdog.addTaxon and fdog.addTaxa) """
76-
(specName, specFile, outPath, silent) = args
77-
blastCmd = 'makeblastdb -dbtype prot -in %s -out %s/coreTaxa_dir/%s/%s' % (specFile, outPath, specName, specName)
75+
""" Make blastDB in coreTaxa_dir
76+
for fdog.addTaxon, fdog.addTaxa and fdog.checkData
77+
"""
78+
(specName, specFile, outPath, coreTaxa_dir, searchTaxa_dir, silent) = args
79+
if not coreTaxa_dir:
80+
coreTaxa_dir = '%s/coreTaxa_dir' % outPath
81+
if not searchTaxa_dir:
82+
searchTaxa_dir = '%s/searchTaxa_dir' % outPath
83+
blastCmd = 'makeblastdb -dbtype prot -in %s -out %s/%s/%s' % (specFile, coreTaxa_dir, specName, specName)
7884
if silent == True:
7985
blastCmd = blastCmd + '> /dev/null 2>&1'
8086
try:
8187
subprocess.call([blastCmd], shell = True)
8288
except:
8389
sys.exit('Problem with running %s' % blastCmd)
84-
fileInGenome = "../../searchTaxa_dir/%s/%s.fa" % (specName, specName)
85-
fileInBlast = "%s/coreTaxa_dir/%s/%s.fa" % (outPath, specName, specName)
90+
fileInGenome = "%s/%s/%s.fa" % (searchTaxa_dir, specName, specName)
91+
fileInBlast = "%s/%s/%s.fa" % (coreTaxa_dir, specName, specName)
8692
if not os.path.exists(fileInBlast):
8793
os.symlink(fileInGenome, fileInBlast)

0 commit comments

Comments
 (0)