Skip to content

Commit

Permalink
add database checks
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwengers committed Jun 25, 2019
1 parent b52cec3 commit 4ac8fc7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
52 changes: 52 additions & 0 deletions platon/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,58 @@ def setup_configuration():
return config


def test_database( config ):
"""Test if database directory exists, is accessible and contains necessary files."""

if( 'db' not in config ):
sys.exit( 'ERROR: database directory not detected! Please provide a valid path to the database directory.' )

if( not os.access(config['db'], os.R_OK & os.X_OK) ):
sys.exit( 'ERROR: database directory ('+config['db']+') not readable/accessible!' )

file_names = [
'conjugation.h3f',
'conjugation.h3i',
'conjugation.h3m',
'conjugation.h3p',
'mobilization.h3f',
'mobilization.h3i',
'mobilization.h3m',
'mobilization.h3p',
'replication.h3f',
'replication.h3i',
'replication.h3m',
'replication.h3p',
'ncbifam-amr.h3f',
'ncbifam-amr.h3i',
'ncbifam-amr.h3m',
'ncbifam-amr.h3p',
'ncbifam-amr.tsv',
'rRNA.i1f',
'rRNA.i1i',
'rRNA.i1m',
'rRNA.i1p',
'protein-scores.tsv',
'refseq-plasmids.tsv',
'inc-types.fasta',
'refseq-plasmids.nhr',
'refseq-plasmids.nin',
'refseq-plasmids.nsq',
'refseq-bacteria-nrpc-reps.inf',
'refseq-bacteria-nrpc-reps_0.inf',
'refseq-bacteria-nrpc-reps_0.nam',
'refseq-bacteria-nrpc-reps_0.off',
'refseq-bacteria-nrpc-reps_0.seq',
'refseq-bacteria-nrpc-reps_0.src'
]

for file_name in file_names:
path = config['db'] + '/' + file_name
if( not os.access(path, os.R_OK) or not os.path.isfile(path) ):
sys.exit( 'ERROR: database file ('+file_name+') not readable!' )
return


def test_binaries():
"""Test the proper installation of necessary 3rd party executables."""

Expand Down
9 changes: 2 additions & 7 deletions platon/platon.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ def main():

if( args.db ):
config['db'] = os.path.abspath(args.db)
elif( 'db' not in config ):
sys.exit( 'ERROR: database directory not detected nor provided! Please provide a valid path to the database directory.' )

if( not os.access( config['db'], os.R_OK & os.X_OK ) ):
sys.exit( 'ERROR: database directory ('+config['db']+') not readable/accessible!' )
test_database( config )

if( 'bundled-binaries' not in config ):
test_binaries()
Expand Down Expand Up @@ -106,8 +102,7 @@ def main():


if( len(raw_contigs) == 0 ):
print( 'Error: input file contains no valid contigs.' )
sys.exit(1)
sys.exit( 'Error: input file contains no valid contigs.' )

if( len(contigs) == 0 ):
print( HEADER )
Expand Down

0 comments on commit 4ac8fc7

Please sign in to comment.