# HG changeset patch
# User pimarin
# Date 1690192833 0
# Node ID 60cfd33bc2fba16bdbd46b52dda47d958849c78d
# Parent e05fd47bcca6822ae95bec9ab233ce26c979aaee
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_plasmidfinder commit 0a3992c5be846fc9f18b7ca18f0adcd78f5b9396-dirty
diff -r e05fd47bcca6 -r 60cfd33bc2fb data_manager/macro.xml
--- a/data_manager/macro.xml Fri Feb 17 14:07:54 2023 +0000
+++ b/data_manager/macro.xml Mon Jul 24 10:00:33 2023 +0000
@@ -1,13 +1,16 @@
2.1.6
- 2.27.1
- 3.8
+ 3.1.31
+ 2.34.1
+ 4.0.10
+ 3.11.3
0
21.05
python
- requests
+ gitpython
+ git
diff -r e05fd47bcca6 -r 60cfd33bc2fb data_manager/plasmidfinder_fetch_database.py
--- a/data_manager/plasmidfinder_fetch_database.py Fri Feb 17 14:07:54 2023 +0000
+++ b/data_manager/plasmidfinder_fetch_database.py Mon Jul 24 10:00:33 2023 +0000
@@ -1,11 +1,11 @@
import argparse
import json
import os
-import tarfile
-from datetime import datetime
+import time
from pathlib import Path
-import requests
+
+import git
class GetPlasmidfinderDataManager:
@@ -15,7 +15,7 @@
def __init__(self,
plasmidfinder_database="plasmidfinder_database",
- db_name="plasmidfinder-db",
+ db_name="plasmidfinder_database",
plasmidfinder_version="latest"):
self.data_table_name = plasmidfinder_database
self._db_name = db_name
@@ -68,12 +68,12 @@
def __init__(self,
output_dir=Path.cwd(),
- plasmidfinder_url="https://bitbucket.org/genomicepidemiology/plasmidfinder_db/get/",
- db_name="plasmidfinder-db",
+ plasmidfinder_url="https://bitbucket.org/genomicepidemiology/plasmidfinder_db/src/master",
+ db_name="plasmidfinder_database",
db_tmp="tmp_database",
plasmidfinder_version="latest",
json_file_path=None,
- date_version=datetime.now().strftime("%Y-%m-%d")):
+ date_version=None):
super().__init__()
self.json_file_path = json_file_path
@@ -86,86 +86,29 @@
self._plasmidfinder_date_version = date_version
self._commit_number = None
- def extract_db_commit(self, request_header, title_name="content-disposition"):
- """
- Extract the commit if to add the information as identifier of the download
- @request_header: a request object obtained from requests.get()
- @title_name: the tag to search in the header of the requests object
- return: the value of the commit
- """
- db_info = request_header.headers[title_name]
- commit_number = db_info.split("-")[2].split(".")[0]
- return commit_number
+ def git_clone(self):
+ git.Repo.clone_from(url=self._plasmidfinder_url, to_path=self._output_dir)
+ self._plasmidfinder_repository = git.Repo(path=self._output_dir)
- def untar_files(self, file_path: Path, extracted_path_output: Path):
- """
- untar the download archive
- @file_path: input path of the tar.gz file
- @extracted_path_output: output path of the extract folder
- return: the path of the output
- """
- try:
- with file_path.open('rb') as fh_in, \
- tarfile.open(fileobj=fh_in, mode='r:gz') as tar_file:
- tar_file.extractall(path=extracted_path_output)
- print(f'Untar the database in {extracted_path_output}')
- return extracted_path_output
- except OSError:
- os.sys.exit(f'ERROR: Could not extract {file_path}')
+ def get_commit_number(self):
+ sha = self._plasmidfinder_repository.head.commit.hexsha
+ short_sha = self._plasmidfinder_repository.git.rev_parse(sha, short=7)
+ self._commit_number = short_sha
- def choose_db_version(self):
- """
- Update the url link depending on the version choosen by user.
- This method could be upgraded simply by adding the new versions
- """
- if self._plasmidfinder_version == "latest":
- self._plasmidfinder_url = f"{self._plasmidfinder_url}master.gz"
- elif self._plasmidfinder_version == "2.1":
- self._plasmidfinder_url = f"{self._plasmidfinder_url}1307168.gz"
+ def get_commit_date(self):
+ self._plasmidfinder_date_version = time.strftime("%Y_%m_%d", time.gmtime(self._plasmidfinder_repository.head.commit.committed_date))
def download_database(self):
"""
- Download the plasmidfinder database using requests lib
- Make the directory and temporary directory for download
- Untar the download files
+ Download the plasmidfinder database using git lib
+ Extract commit and commit date
"""
self._output_dir = Path(self._output_dir)
- self.choose_db_version()
- try:
- request_info = requests.get(self._plasmidfinder_url)
- request_info.raise_for_status()
- self._commit_number = self.extract_db_commit(request_info)
- output_tar_path = self._output_dir.joinpath(self._temporary_folder)
- output_tar_path_file = output_tar_path.joinpath(self._db_name_tar)
- output_path = self._output_dir.joinpath(self._db_name)
- os.makedirs(output_tar_path)
- os.makedirs(output_path)
- with open(output_tar_path_file, 'wb') as output_dir:
- output_dir.write(request_info.content)
- untar_output = self.untar_files(file_path=output_tar_path_file, extracted_path_output=output_tar_path.joinpath(self._db_name))
- self.moove_download_files(source=untar_output, destination=output_path)
- except requests.exceptions.HTTPError as http_error:
- print(f"Requests Error: {http_error}")
- print(f"Fail to import Plasmidfinder database from {self._plasmidfinder_url}")
-
- def moove_download_files(self, source, destination, expression_search="*"):
- """
- Clean downloaded data by mooving fasta files in the final folder
- @older_path: previous path where the files are located
- @new_path: final path where files will be mooved
- @expression_search: keep only file with this expression
- """
- fasta_files = Path(source).rglob(expression_search)
- file_list_paths = [file for file in fasta_files if file.is_file()]
- [self.keep_filename(pathname=path, output_path=destination) for path in file_list_paths]
-
- def keep_filename(self, pathname, output_path):
- """
- Moove files
- @pathname: previous path
- @output_path: final path
- """
- Path.replace(pathname, output_path.joinpath(pathname.name))
+ self.git_clone()
+ if self._plasmidfinder_version != "latest":
+ self._plasmidfinder_repository.git.checkout(self._plasmidfinder_version)
+ self.get_commit_number()
+ self.get_commit_date()
def read_json_input_file(self):
"""
diff -r e05fd47bcca6 -r 60cfd33bc2fb data_manager/plasmidfinder_fetch_database.xml
--- a/data_manager/plasmidfinder_fetch_database.xml Fri Feb 17 14:07:54 2023 +0000
+++ b/data_manager/plasmidfinder_fetch_database.xml Mon Jul 24 10:00:33 2023 +0000
@@ -1,4 +1,3 @@
-
plasmidfinder database builder
@@ -10,38 +9,30 @@
python '$__tool_directory__/plasmidfinder_fetch_database.py'
--db_version '$database_select'
'$output_file'
+ && cat '$output_file'
]]>
- param>
+
-
+
-
-
-
-
-
-
-
+
+
10.1007/978-1-4939-9877-7_20
diff -r e05fd47bcca6 -r 60cfd33bc2fb data_manager_conf.xml
--- a/data_manager_conf.xml Fri Feb 17 14:07:54 2023 +0000
+++ b/data_manager_conf.xml Mon Jul 24 10:00:33 2023 +0000
@@ -1,6 +1,6 @@
-
+
diff -r e05fd47bcca6 -r 60cfd33bc2fb test-data/plasmidfinder.loc.test
--- a/test-data/plasmidfinder.loc.test Fri Feb 17 14:07:54 2023 +0000
+++ b/test-data/plasmidfinder.loc.test Mon Jul 24 10:00:33 2023 +0000
@@ -1,10 +1,9 @@
-plasmidfinder_c18e08c17a59_2023-02-15 c18e08c17a59_2023-02-15 2023-02-15 plasmidfinder_database
-plasmidfinder_1307168b1ce7_2023-02-15 2.1_2023-02-15 2023-02-15 plasmidfinder_database
-plasmidfinder_c18e08c17a59_2023-02-15 c18e08c17a59_2023-02-15 2023-02-15 /tmp/tmp19jlq5v4/galaxy-dev/tool-data/plasmidfinder-db/c18e08c17a59_2023-02-15
-plasmidfinder_1307168b1ce7_2023-02-15 2.1_2023-02-15 2023-02-15 /tmp/tmp19jlq5v4/galaxy-dev/tool-data/plasmidfinder-db/2.1_2023-02-15
-plasmidfinder_c18e08c17a59_2023-02-17 c18e08c17a59_2023-02-17 2023-02-17 /tmp/tmpkf9b8oam/galaxy-dev/tool-data/plasmidfinder-db/c18e08c17a59_2023-02-17
-plasmidfinder_1307168b1ce7_2023-02-17 2.1_2023-02-17 2023-02-17 /tmp/tmpkf9b8oam/galaxy-dev/tool-data/plasmidfinder-db/2.1_2023-02-17
-plasmidfinder_c18e08c17a59_2023-02-17 c18e08c17a59_2023-02-17 2023-02-17 /tmp/tmpxhdyhsl6/galaxy-dev/tool-data/plasmidfinder-db/c18e08c17a59_2023-02-17
-plasmidfinder_1307168b1ce7_2023-02-17 2.1_2023-02-17 2023-02-17 /tmp/tmpxhdyhsl6/galaxy-dev/tool-data/plasmidfinder-db/2.1_2023-02-17
-plasmidfinder_c18e08c17a59_2023-02-17 c18e08c17a59_2023-02-17 2023-02-17 /tmp/tmpt_c58x8j/galaxy-dev/tool-data/plasmidfinder-db/c18e08c17a59_2023-02-17
-plasmidfinder_1307168b1ce7_2023-02-17 2.1_2023-02-17 2023-02-17 /tmp/tmpt_c58x8j/galaxy-dev/tool-data/plasmidfinder-db/2.1_2023-02-17
+plasmidfinder_1307168_2019_08_28 2.1_2019_08_28 2019_08_28 /tmp/tmptllq5k0r/galaxy-dev/tool-data/plasmidfinder-db/2.1_2019_08_28
+plasmidfinder_1307168_2019_08_28 2.1_2019_08_28 2019_08_28 /tmp/tmpnshbzr8f/galaxy-dev/tool-data/plasmidfinder-db/2.1_2019_08_28
+plasmidfinder_1307168_2019_08_28 2.1_2019_08_28 2019_08_28 /tmp/tmpgfqg6r8x/galaxy-dev/tool-data/plasmidfinder-db/2.1_2019_08_28
+plasmidfinder_1307168_2019_08_28 2.1_2019_08_28 2019_08_28 /tmp/tmpam2pha1m/galaxy-dev/tool-data/plasmidfinder-db/2.1_2019_08_28
+plasmidfinder_1307168_2019_08_28 2.1_2019_08_28 2019_08_28 /tmp/tmp_tzl62ye/galaxy-dev/tool-data/plasmidfinder-db/2.1_2019_08_28
+plasmidfinder_1307168_2019_08_28 2.1_2019_08_28 2019_08_28 /tmp/tmpu0batsz4/galaxy-dev/tool-data/plasmidfinder-db/2.1_2019_08_28
+plasmidfinder_1307168_2019_08_28 2.1_2019_08_28 2019_08_28 /tmp/tmp72f81ayd/galaxy-dev/tool-data/plasmidfinder-db/2.1_2019_08_28
+plasmidfinder_1307168_2019_08_28 2.1_2019_08_28 2019_08_28 /tmp/tmp73run5j6/galaxy-dev/tool-data/plasmidfinder_database/2.1_2019_08_28
+plasmidfinder_1307168_2019_08_28 2.1_2019_08_28 2019_08_28 /tmp/tmpngljkg08/galaxy-dev/tool-data/plasmidfinder_database/2.1_2019_08_28
diff -r e05fd47bcca6 -r 60cfd33bc2fb test-data/plasmidfinder_test_data_manager_2.1.json
--- a/test-data/plasmidfinder_test_data_manager_2.1.json Fri Feb 17 14:07:54 2023 +0000
+++ b/test-data/plasmidfinder_test_data_manager_2.1.json Mon Jul 24 10:00:33 2023 +0000
@@ -1,1 +1,1 @@
-{"data_tables": {"plasmidfinder_database": [{"date": "2023-02-15", "name": "2.1_2023-02-15", "path": "plasmidfinder_database", "value": "plasmidfinder_1307168b1ce7_2023-02-15"}]}}
\ No newline at end of file
+{"data_tables": {"plasmidfinder_database": [{"date": "2019_08_28", "name": "2.1_2019_08_28", "path": "plasmidfinder_database", "value": "plasmidfinder_1307168_2019_08_28"}]}}
\ No newline at end of file
diff -r e05fd47bcca6 -r 60cfd33bc2fb test-data/plasmidfinder_test_data_manager_latest.json
--- a/test-data/plasmidfinder_test_data_manager_latest.json Fri Feb 17 14:07:54 2023 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-{"data_tables": {"plasmidfinder_database": [{"date": "2023-02-15", "name": "c18e08c17a59_2023-02-15", "path": "plasmidfinder_database", "value": "plasmidfinder_c18e08c17a59_2023-02-15"}]}}
\ No newline at end of file