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:"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)
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:"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
logging.debug("Renaming '%s' to '%s'", oldpath, 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/')},
'blast': {'script': _pkgres('recipes/')}
'blast': {'script': _pkgres('recipes/')},
'diamond': {'script': _pkgres('recipes/')},
'swissprot': {'download': {'script': _pkgres('recipes/'), 'params': ['--database', 'swissprot', '--type', 'fasta']},
'blast': {'script': _pkgres('recipes/')},
'diamond': {'script': _pkgres('recipes/')},
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 =, shell=True)
if (cp.returncode != 0):
files = [ for f in os.scandir('.') if + '.') and not'.fasta')]
tags = ['diamond_db']
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