Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import argparse
import json
import subprocess
from datetime import date
from pathlib import Path
from urllib.parse import urlparse

HUMANN_REFERENCE_DATA = {
"chocophlan": {
Expand Down Expand Up @@ -113,6 +113,22 @@ def add_data_table_entry(d, table, entry):
raise Exception("add_data_table_entry: no table '%s'" % table)


def get_database_source_id(database, build):
"""Return the versioned artifact name advertised by HUMAnN."""
available = subprocess.check_output(
["humann_databases", "--available"], text=True
)
prefix = f"{database} : {build} = "
for line in available.splitlines():
if line.startswith(prefix):
filename = Path(urlparse(line[len(prefix):]).path).name
for suffix in (".tar.gz", ".tar.bz2", ".tgz", ".zip"):
if filename.endswith(suffix):
return filename[:-len(suffix)]
return filename
raise RuntimeError(f"Unable to determine source for {database} {build}")


def download_humann_db(data_tables, table_name, database, build, version, target_dp):
"""Download HUMAnN database

Expand All @@ -134,12 +150,18 @@ def download_humann_db(data_tables, table_name, database, build, version, target
db_target_dp = target_dp / Path(database)
db_dp = db_target_dp / Path(database)
build_target_dp = db_target_dp / Path(build)
source_id = get_database_source_id(database, build)
# launch tool to get db
cmd = "humann_databases --download %s %s %s --update-config no" % (
cmd = [
"humann_databases",
"--download",
database,
build,
db_target_dp)
subprocess.check_call(cmd, shell=True)
str(db_target_dp),
"--update-config",
"no",
]
subprocess.check_call(cmd)
# move db
db_dp.rename(build_target_dp)
# add details to data table
Expand All @@ -148,7 +170,7 @@ def download_humann_db(data_tables, table_name, database, build, version, target
data_tables,
table_name,
dict(
value="%s-%s-%s-%s" % (database, build, version, date.today().strftime("%d%m%Y")),
value=f"{database}-{build}-{source_id}",
name=HUMANN_REFERENCE_DATA[database][build],
dbkey=version,
path=str(build_target_dp)))
Expand All @@ -159,7 +181,7 @@ def download_humann_db(data_tables, table_name, database, build, version, target
data_tables,
table_name,
dict(
value="%s-%s-%s-%s-%s%s" % (database, build, name, version, date.today().strftime("%d%m%Y"), x.suffix),
value=f"{database}-{build}-{name}-{source_id}{x.suffix}",
name=HUMANN_REFERENCE_DATA["utility_mapping"][build][name],
dbkey=version,
path=str(x)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<description>Download HUMAnN database</description>
<macros>
<token name="@TOOL_VERSION@">3.9</token>
<token name="@VERSION_SUFFIX@">0</token>
<token name="@VERSION_SUFFIX@">1</token>
<token name="@PROFILE@">22.01</token>
</macros>
<requirements>
Expand Down Expand Up @@ -58,7 +58,7 @@ python '$__tool_directory__/data_manager_humann_download.py'
<has_text text="humann_nucleotide_database"/>
<has_text text="Demo ChocoPhlAn for HUManN"/>
<has_text text="chocophlan/DEMO"/>
<has_text text="chocophlan-DEMO-"/>
<has_text text="chocophlan-DEMO-DEMO_chocophlan.v201901_v31"/>
</assert_contents>
</output>
</test>
Expand All @@ -69,10 +69,9 @@ python '$__tool_directory__/data_manager_humann_download.py'
</conditional>
<output name="out_file">
<assert_contents>
<has_text text="DEMO_diamond"/>
<has_text text="Demo UniRef for HUManN"/>
<has_text text="uniref/DEMO_diamond"/>
<has_text text="uniref-DEMO_diamond-"/>
<has_text text="uniref-DEMO_diamond-uniref90_DEMO_diamond_v201901b"/>
</assert_contents>
</output>
</test>
Expand All @@ -83,7 +82,6 @@ python '$__tool_directory__/data_manager_humann_download.py'
</conditional>
<output name="out_file">
<assert_contents>
<has_text text="utility_mapping"/>
<has_text text="Mapping (full)"/>
<has_text text="utility_mapping/full"/>
<has_text text="map_uniref50_uniref90"/>
Expand All @@ -106,6 +104,7 @@ python '$__tool_directory__/data_manager_humann_download.py'
<has_text text="map_uniref50_name"/>
<has_text text="map_ec_name"/>
<has_text text="map_pfam_name"/>
<has_text text="full_mapping_v201901b"/>
<has_text text=".gz"/>
<has_text text=".bz2"/>
</assert_contents>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#This is a sample file distributed with Galaxy that enables tools
#to use a directory of metagenomics files.
#file has this format (white space characters are TAB characters)
#db-build-version-date db-name build /path/to/data
#db-build-source db-name build /path/to/data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#This is a sample file distributed with Galaxy that enables tools
#to use a directory of metagenomics files.
#file has this format (white space characters are TAB characters)
#db-build-version-date db-name build /path/to/data
#db-build-source db-name build /path/to/data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#This is a sample file distributed with Galaxy that enables tools
#to use a directory of metagenomics files.
#file has this format (white space characters are TAB characters)
#db-build-version-date db-name build /path/to/data
#db-build-source db-name build /path/to/data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#This is a sample file distributed with Galaxy that enables tools
#to use a directory of metagenomics files.
#file has this format (white space characters are TAB characters)
#db-build-version-date db-name build /path/to/data
#db-build-source db-name build /path/to/data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#This is a sample file distributed with Galaxy that enables tools
#to use a directory of metagenomics files.
#file has this format (white space characters are TAB characters)
#db-build-version-date db-name build /path/to/data
#db-build-source db-name build /path/to/data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#This is a sample file distributed with Galaxy that enables tools
#to use a directory of metagenomics files.
#file has this format (white space characters are TAB characters)
#db-build-version-date db-name build /path/to/data
#db-build-source db-name build /path/to/data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind to add the new reference data from 2026 listed here: https://bioinformatics-centre.github.io/kaiju/downloads.html? But we can also do this separately.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<description>builder</description>
<macros>
<token name="@TOOL_VERSION@">1.10.1</token>
<token name="@VERSION_SUFFIX@">0</token>
<token name="@VERSION_SUFFIX@">1</token>
</macros>
<requirements>
<requirement type="package" version="@TOOL_VERSION@">kaiju</requirement>
Expand All @@ -20,49 +20,38 @@
mv \$(find . -name "*nodes.dmp") '${out_file.extra_files_path}'/nodes.dmp &&
mv \$(find . -name "*names.dmp") '${out_file.extra_files_path}'/names.dmp &&
mv \$(find . -name "*.fmi") '${out_file.extra_files_path}'/database.fmi &&
cp '$dmjson' '$out_file'
#if str($type.date) == "today"
database_digest=\$(
for database_file in database.fmi names.dmp nodes.dmp; do
printf '%s\0' "\$database_file";
cat '${out_file.extra_files_path}'/"\$database_file";
printf '\0';
done | sha256sum | cut -d ' ' -f 1
) &&
download_date=\$(date -u +%F) &&
sed
-e "s/__DATABASE_DIGEST__/\$database_digest/g"
-e "s/__DOWNLOAD_DATE__/\$download_date/g"
'$dmjson' > '$out_file'
#else
cp '$dmjson' '$out_file'
#end if
]]></command>
<configfiles>
<configfile name="dmjson"><![CDATA[#slurp
#import datetime
#if $type.date == "today"
#set date = datetime.datetime.utcnow().strftime("%Y-%m-%d")
#import json
#set $database_names = {"refseq": "(refseq) bacterial, archaeal and viral genomes in the NCBI RefSeq database with assembly status Complete", "refseq_nr": "(refseq_nr) proteins from bacteria, Archaea, viruses, fungi and microbial eukaryotes from the NCBI RefSeq non-redundant proteins collection", "refseq_ref": "(refseq_ref) proteins from bacteria, Archaea from the NCBI RefSeq representative assemblies + viral proteins from NCBI RefSeq", "progenomes": "(progenomes) proteins in the set of representative genomes from the proGenomes v3 database and viral proteins from NCBI RefSeq", "nr": "(nr) NCBI BLAST non-redundant protein database 'nr', only Archaea, bacteria, and viruses", "nr_euk": "(nr_euk) nr and additionally including fungi and microbial eukaryotes", "fungi": "(fungi) all fungi genomes from NCBI RefSeq (any assembly status)", "viruses": "(viruses) viral genomes from NCBI RefSeq", "plasmids": "(plasmids) plasmid genomes from NCBI RefSeq", "rvdb": "(rvdb) viral proteins from RVDB-prot"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you format this more human readable?

#set $database = str($type.select)
#set $source_date = str($type.date)
#if $source_date == "today"
#set $display_date = "__DOWNLOAD_DATE__"
#set $value = $database + "_sha256___DATABASE_DIGEST__"
#else
#set date = $type.date
#end if
#if $type.select == "refseq"
#set name = "(refseq) bacterial, archaeal and viral genomes in the NCBI RefSeq database with assembly status Complete"
#elif $type.select == "refseq_nr"
#set name = "(refseq_nr) proteins from bacteria, Archaea, viruses, fungi and microbial eukaryotes from the NCBI RefSeq non-redundant proteins collection"
#elif $type.select == "refseq_ref"
#set name = "(refseq_ref) proteins from bacteria, Archaea from the NCBI RefSeq representative assemblies + viral proteins from NCBI RefSeq"
#elif $type.select == "progenomes"
#set name = "(progenomes) proteins in the set of representative genomes from the proGenomes v3 database and viral proteins from NCBI RefSeq"
#elif $type.select == "nr"
#set name = "(nr) NCBI BLAST non-redundant protein database 'nr', only Archaea, bacteria, and viruses"
#elif $type.select == "nr_euk"
#set name = "(nr_euk) nr and additionally including fungi and microbial eukaryotes"
#elif $type.select == "fungi"
#set name = "(fungi) all fungi genomes from NCBI RefSeq (any assembly status)"
#elif $type.select == "viruses"
#set name = "(viruses) viral genomes from NCBI RefSeq"
#elif $type.select == "plasmids"
#set name = "(plasmids) plasmid genomes from NCBI RefSeq"
#elif $type.select == "rvdb"
#set name = "(tvdb) viral proteins from RVDB-prot"
#set $display_date = $source_date
#set $value = $source_date + "_" + $database
#end if
{
"data_tables":{
"kaiju":[
{
"value": "${date}_${$type.select}",
"name": "${date} $name",
"path": "output/",
"version": "@TOOL_VERSION@"
}
]
}
}
#set $entry = {"value": $value, "name": $display_date + " " + $database_names[$database], "path": "output/", "version": "@TOOL_VERSION@"}
${json.dumps({"data_tables": {"kaiju": [$entry]}}, sort_keys=True)}
]]></configfile>
</configfiles>
<inputs>
Expand Down Expand Up @@ -150,14 +139,7 @@
<param name="select" value="viruses"/>
<param name="date" value="2024-08-15"/>
</conditional>
<output name="out_file">
<assert_contents>
<has_text text="kaiju"/>
<has_text text="(viruses)"/>
<has_text text="2024-08-15"/>
<has_text text="@TOOL_VERSION@"/>
</assert_contents>
</output>
<output name="out_file" file="kaiju-viruses-2024-08-15.json"/>
</test>
<test>
<conditional name="type">
Expand All @@ -168,6 +150,9 @@
<assert_contents>
<has_text text="kaiju"/>
<has_text text="(viruses)"/>
<has_text text="viruses_sha256_"/>
<has_text negate="true" text="__DATABASE_DIGEST__"/>
<has_text negate="true" text="__DOWNLOAD_DATE__"/>
<has_text negate="true" text="2024-05-10"/>
<has_text text="@TOOL_VERSION@"/>
</assert_contents>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data_tables": {"kaiju": [{"name": "2024-08-15 (viruses) viral genomes from NCBI RefSeq", "path": "output/", "value": "2024-08-15_viruses", "version": "1.10.1"}]}}
4 changes: 2 additions & 2 deletions data_managers/data_manager_kaiju/tool-data/kaiju.loc.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# id: db name + date
# id: source snapshot + db name, or db name + content digest for current builds
# name: what is shown to the user in the select
# path: of the reference data must contain database.fmi, names.dmp and nodes.dmp
# version: version used for constructing the DB (or just the current version at the time when pre-computed indices were downloaded)
#id name path version
#id name path version
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import os
import shutil
import tarfile
from datetime import datetime
from datetime import date
from pathlib import Path

import wget

Expand Down Expand Up @@ -36,6 +37,14 @@
}


def source_id(url):
filename = Path(url).name
for suffix in (".tar.gz", ".tar.bz2", ".tgz", ".zip"):
if filename.endswith(suffix):
return filename.removesuffix(suffix)
return filename


def download_untar_store(url, tmp_path, dest_path):
"""
Download a tar.gz file containing one folder,
Expand Down Expand Up @@ -104,8 +113,8 @@ def main():
workdir = params["output_data"][0]["extra_files_path"]
os.mkdir(workdir)

time = datetime.utcnow().strftime("%Y-%m-%d")
db_value = f"{args.db_type}_from_{time}"
download_date = date.today().isoformat()
db_value = f"{args.db_type}_{source_id(DB_paths[args.db_type])}"

# output paths
db_path = os.path.join(workdir, db_value)
Expand All @@ -126,7 +135,7 @@ def main():
"data_tables": {
"mapseq_db": {
"value": db_value,
"name": f"{db_name} downloaded at {time}",
"name": f"{db_name} downloaded at {download_date}",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can drop the downloaded at ...?

"version": args.version,
"path": db_path,
}
Expand Down
2 changes: 1 addition & 1 deletion data_managers/data_manager_mapseq/data_manager/macros.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<macros>
<token name="@TOOL_VERSION@">1.1</token>
<token name="@VERSION_SUFFIX@">4</token>
<token name="@VERSION_SUFFIX@">5</token>
<token name="@PROFILE@">25.0</token>
<xml name="requirements">
<requirements>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</conditional>
<output name="out_file">
<assert_contents>
<has_text text="mgnify_v5_lsu"/>
<has_text text="mgnify_v5_lsu_silva_lsu-20200130"/>
<has_text text="5.0.7"/>
</assert_contents>
</output>
Expand Down
Loading