Skip to content

Commit

Permalink
Use the local database if available when internet is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Beghini committed Dec 9, 2020
1 parent d57327c commit f4e814a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions metaphlan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,20 @@ def check_and_install_database(index, bowtie2_db, bowtie2_build, nproc, force_re
return index

use_zenodo = False
if urllib.request.urlopen("http://cmprod1.cibio.unitn.it/biobakery3/metaphlan_databases/mpa_latest").getcode() != 200:
use_zenodo = True
try:
if urllib.request.urlopen("http://cmprod1.cibio.unitn.it/biobakery3/metaphlan_databases/mpa_latest").getcode() != 200:
use_zenodo = True
except:
print('WARNING: It seems that you do not have Internet access.')
if os.path.exists(os.path.join(bowtie2_db,'mpa_latest')):
print('WARNING: Cannot connect to the database server. The latest available local database will be used.')
with open(os.path.join(bowtie2_db,'mpa_latest')) as mpa_latest:
latest_db_version = [line.strip() for line in mpa_latest if not line.startswith('#')]
else:
print("""ERROR: Cannot find a local database. Please run MetaPhlAn using option "-x <database_name>".
You can download the MetaPhlAn database from \n {} \n {} \n {}
""".format('http://cmprod1.cibio.unitn.it/biobakery3/metaphlan_databases',ZENODO_DATABASE_DOWNLOAD, DROPBOX_DATABASE_DOWNLOAD))
sys.exit()

#try downloading from the segatalab website. If fails, use zenodo
if index == 'latest':
Expand Down
4 changes: 2 additions & 2 deletions metaphlan/metaphlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
'Nicola Segata ([email protected]), '
'Duy Tin Truong, '
'Francesco Asnicar ([email protected])')
__version__ = '3.0.6'
__date__ = '24s Nov 2020'
__version__ = '3.0.7'
__date__ = '09 Dec 2020'

import sys
try:
Expand Down

0 comments on commit f4e814a

Please sign in to comment.