18
18
19
19
import sys
20
20
import os
21
+ import errno
21
22
import argparse
22
23
from os import listdir
23
24
from os .path import isfile , join
@@ -175,25 +176,29 @@ def run_check_fasta(checkDir, replace, delete, concat):
175
176
176
177
def check_blastdb (args ):
177
178
""" Check for outdated blastdb """
178
- (query , taxon , coreTaxa_dir ) = args
179
+ (query , taxon , coreTaxa_dir , searchTaxa_dir ) = args
179
180
blast_db = '%s/%s/%s' % (coreTaxa_dir , taxon , taxon )
180
181
try :
181
182
blastp_cline = NcbiblastpCommandline (query = query , db = blast_db )
182
183
stdout , stderr = blastp_cline ()
183
184
except :
184
185
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 )
189
194
190
195
191
- def run_check_blastdb (coreTaxa_dir , fdogPath ):
196
+ def run_check_blastdb (coreTaxa_dir , searchTaxa_dir , fdogPath ):
192
197
""" Run check_blastdb fn """
193
198
query = '%s/data/infile.fa' % fdogPath
194
199
jobs = []
195
200
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 ])
197
202
cpus = mp .cpu_count ()- 1
198
203
pool = mp .Pool (cpus )
199
204
out = []
@@ -216,10 +221,10 @@ def create_blastdb(args):
216
221
shutil .rmtree (blast_path )
217
222
### Redo blastdb
218
223
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 ])
220
225
### 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 )
223
228
fa_in_blast = "%s/%s.fa" % (blast_path , taxon )
224
229
fai_in_blast = "%s/%s.fa.fai" % (blast_path , taxon )
225
230
if not os .path .exists (fa_in_blast ):
@@ -326,6 +331,7 @@ def main():
326
331
parser .add_argument ('--delete' , help = 'Delete special characters in sequences' , action = 'store_true' , default = False )
327
332
parser .add_argument ('--concat' , help = 'Concatenate multiple-line sequences into single-line' , action = 'store_true' , default = False )
328
333
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)
329
335
330
336
### get arguments
331
337
args = parser .parse_args ()
@@ -337,6 +343,7 @@ def main():
337
343
delete = args .delete
338
344
concat = args .concat
339
345
reblast = args .reblast
346
+ # updateJson = args.updateJson
340
347
341
348
checkOptConflict (concat , replace , delete )
342
349
caution = 0
@@ -374,7 +381,7 @@ def main():
374
381
print ('All old BlastDBs have been updated!' )
375
382
print ('=> Checking %s...' % coreTaxa_dir )
376
383
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 )
378
385
379
386
if not check_blast [0 ] == 1 :
380
387
print ('*** ERROR: Version incompatible between BlastDB and BLAST program!' )
@@ -391,6 +398,8 @@ def main():
391
398
print ('NOTE: You still can run fdog without FAS using the option "-fasoff"' )
392
399
caution = 1
393
400
run_check_complete_anno (annotation_dir , searchTaxa_dir )
401
+ # if updateJson:
402
+ # run_update_anno(annotation_dir, searchTaxa_dir)
394
403
395
404
# ### check ncbi IDs
396
405
print ('=> Checking NCBI taxonomy IDs...' )
0 commit comments