Commit be780604 authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Add diamond database creation\nFix bug\nImprove logging

parent c4d8ffab
......@@ -45,7 +45,7 @@ def create_metadata(name,
def save_metadata(metadata, path="./metadata.json"):
with open(path, "w") as metadata_file:
logging.info("Writing metadata " + json.dumps(metadata))
logging.debug("Writing metadata to '%s'", os.path.abspath(path))
json.dump(metadata, metadata_file)
def load_metadata(path="./metadata.json"):
......
......@@ -8,6 +8,7 @@ import pathlib
import prettytable
import shutil
import pkg_resources
import shutil
import dbman.helper as h
def main():
......@@ -91,7 +92,7 @@ def prepare(args):
if not transform_recipe:
logging.warn("Recipe '%s - %s' does not exits", args.tool, args.tool)
return
db_info = _getdb(_local_databases(args), args.database, args.tool)
db_info = _getdb(_local_databases(args), args.database, 'download')
if not db_info or args.force_download:
logging.info("Database '%s' not found. Downloading it.", args.database)
db_info = run_in_tempdir(func = lambda: h.run_external_tool(download_recipe['script'], download_recipe['params'] if 'params' in download_recipe else None),
......@@ -136,10 +137,10 @@ def _rename_directory_after_metadata(path):
oldpath = pathlib.Path(path)
newpath = oldpath.parent.parent.joinpath(newname)
if newpath.exists():
import shutil
shutil.rmtree(str(newpath))
logging.debug("Renaming '%s' to '%s'", oldpath, newpath)
oldpath.rename(newpath)
metadata['location'] = str(newpath.absolute())
return metadata
def run_in_tempdir(func=None, success=None, fail=None):
......@@ -163,10 +164,12 @@ def run_in_tempdir(func=None, success=None, fail=None):
def _recipes(args):
recipes = {
'card': {'download': {'script': _pkgres('recipes/download_card.py')},
'blast': {'script': _pkgres('recipes/create_blast_dbs.py')}
'blast': {'script': _pkgres('recipes/create_blast_dbs.py')},
'diamond': {'script': _pkgres('recipes/create_diamond_dbs.py')},
},
'swissprot': {'download': {'script': _pkgres('recipes/download_uniprotkb.py'), 'params': ['--database', 'swissprot', '--type', 'fasta']},
'blast': {'script': _pkgres('recipes/create_blast_dbs.py')},
'diamond': {'script': _pkgres('recipes/create_diamond_dbs.py')},
}
}
return recipes
......
#!/usr/bin/env python
import dbman.helper as h
import subprocess
import sys
import os
import json
from pathlib import Path
metadata = h.load_metadata('./.source_metadata.json')
fasta_parts = [p for p in metadata['parts'] if 'fasta' in p['tags'] and 'protein' in p['tags']]
new_parts = []
for part in fasta_parts:
type = None
for file in part['files']:
name = Path(file).stem
command = 'diamond makedb --db {} --in {}'.format(name, file)
cp = subprocess.run(command, shell=True)
if (cp.returncode != 0):
sys.exit(cp)
files = [f.name for f in os.scandir('.') if f.name.startswith(name + '.') and not f.name.endswith('.fasta')]
tags = ['diamond_db']
tags.extend(part['tags'])
tags.remove('fasta')
new_parts.append({'files': files, 'tags': tags})
h.create_metadata(metadata['name'], 'diamond', metadata['description'], metadata['version'], other={'parts': new_parts})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment