changeset 0:b56071bdecad draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_plasmidfinder commit f6d40bf94e015c2690e97c4b3533517b812f3bfb
author iuc
date Thu, 15 Jun 2023 09:14:08 +0000
parents
children 3542cd220bc3
files data_manager/macro.xml data_manager/plasmidfinder_fetch_database.py data_manager/plasmidfinder_fetch_database.xml data_manager_conf.xml plasmidfinder_database.loc test-data/plasmidfinder.loc.test test-data/plasmidfinder_test_data_manager_2.1.json tool-data/plasmidfinder_database.loc tool_data_table_conf.xml.sample tool_data_table_conf.xml.test
diffstat 10 files changed, 266 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/macro.xml	Thu Jun 15 09:14:08 2023 +0000
@@ -0,0 +1,16 @@
+<macros>
+    <token name="@TOOL_VERSION@">2.1.6</token>
+    <token name="@GIT_PYTHON_VERSION@">3.1.31</token>
+    <token name="@GIT_VERSION@">2.34.1</token>
+    <token name="@GIT_DB@">4.0.10</token>
+    <token name="@PYTHON_VERSION@">3.11.3</token>
+    <token name="@VERSION_SUFFIX@">0</token>
+    <token name="@PROFILE@">21.05</token>
+    <xml name="requirements">
+        <requirements>
+            <requirement type="package" version="@PYTHON_VERSION@">python</requirement>
+            <requirement type="package" version="@GIT_PYTHON_VERSION@">gitpython</requirement>
+            <requirement type="package" version="@GIT_VERSION@">git</requirement>
+        </requirements>
+    </xml>
+</macros>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/plasmidfinder_fetch_database.py	Thu Jun 15 09:14:08 2023 +0000
@@ -0,0 +1,154 @@
+import argparse
+import json
+import os
+import time
+from pathlib import Path
+
+
+import git
+
+
+class GetPlasmidfinderDataManager:
+    """
+    Create the json file with database information for galaxy data manager
+    """
+
+    def __init__(self,
+                 plasmidfinder_database="plasmidfinder_database",
+                 db_name="plasmidfinder_database",
+                 plasmidfinder_version="latest"):
+        self.data_table_name = plasmidfinder_database
+        self._db_name = db_name
+        self._plasmidfinder_version = plasmidfinder_version
+        self._plasmidfinder_date_version = None
+        self.data_table_entry = None
+        self.plasmidfinder_table_list = None
+        self._commit_number = None
+
+    def get_data_table_format(self):
+        """
+        Skeleton of a data_table format
+        return: a data table formatted for json output
+        """
+        self.data_table_entry = {
+            "data_tables": {
+                self.data_table_name: {}
+            }
+        }
+        return self.data_table_entry
+
+    def get_data_manager(self):
+        """
+        Create the empty data table format and add all the information into
+        Commit number is added if latest is required instead of version number
+        return: The data table with database information
+        """
+        self.plasmidfinder_table_list = self.get_data_table_format()
+        if self._plasmidfinder_version == "latest":
+            version_value = self._commit_number
+        else:
+            version_value = self._plasmidfinder_version
+        plasmidfinder_value = f"plasmidfinder_{self._commit_number}" \
+                              f"_{self._plasmidfinder_date_version}"
+        plasmidfinder_name = f"{version_value}" \
+                             f"_{self._plasmidfinder_date_version}"
+        data_info = dict(value=plasmidfinder_value,
+                         name=plasmidfinder_name,
+                         date=self._plasmidfinder_date_version,
+                         path=self._db_name)
+        self.plasmidfinder_table_list["data_tables"][self.data_table_name] = [data_info]
+        return self.plasmidfinder_table_list
+
+
+class DownloadPlasmidfinderDatabase(GetPlasmidfinderDataManager):
+    """
+    Download the plasmidfinder database from the bitbucket repository.
+    Build the data manager info for galaxy
+    """
+
+    def __init__(self,
+                 output_dir=Path.cwd(),
+                 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=None):
+
+        super().__init__()
+        self.json_file_path = json_file_path
+        self._output_dir = output_dir
+        self._plasmidfinder_url = plasmidfinder_url
+        self._temporary_folder = db_tmp
+        self._db_name = db_name
+        self._db_name_tar = f'{db_name}.gz'
+        self._plasmidfinder_version = plasmidfinder_version
+        self._plasmidfinder_date_version = date_version
+        self._commit_number = None
+
+    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 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 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 git lib
+        Extract commit and commit date
+        """
+        self._output_dir = Path(self._output_dir)
+        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):
+        """
+        Import the json file
+        """
+        with open(self.json_file_path) as fh:
+            params = json.load(fh)
+        target_dir = params['output_data'][0]['extra_files_path']
+        os.makedirs(target_dir)
+        self._output_dir = target_dir
+
+    def write_json_infos(self):
+        """
+        Write in the imported json file
+        """
+        with open(self.json_file_path, 'w') as fh:
+            json.dump(self.get_data_manager(), fh, sort_keys=True)
+
+
+def parse_arguments():
+    """
+    List of arguments provided by the user
+    return: parsed arguments
+    """
+    # parse options and arguments
+    arg_parser = argparse.ArgumentParser()
+    arg_parser.add_argument("data_manager_json",
+                            help="json file from galaxy")
+    arg_parser.add_argument("-v", "--db_version",
+                            help="version of the plasmidfinder (latest or 2.1)")
+    return arg_parser.parse_args()
+
+
+def main():
+    all_args = parse_arguments()
+    plasmidfinder_download = DownloadPlasmidfinderDatabase(json_file_path=all_args.data_manager_json, plasmidfinder_version=all_args.db_version)
+    plasmidfinder_download.read_json_input_file()
+    plasmidfinder_download.download_database()
+    plasmidfinder_download.write_json_infos()
+
+
+if __name__ == '__main__':
+    main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager/plasmidfinder_fetch_database.xml	Thu Jun 15 09:14:08 2023 +0000
@@ -0,0 +1,39 @@
+<tool id="data_manager_fetch_plasmidfinder" name="plasmidfinder_datamanager" tool_type="manage_data" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
+    <description>plasmidfinder database builder</description>
+    <macros>
+        <import>macro.xml</import>
+    </macros>
+    <expand macro="requirements"/>
+    <command detect_errors="exit_code">
+      <![CDATA[
+        python '$__tool_directory__/plasmidfinder_fetch_database.py'
+        --db_version '$database_select'
+        '$output_file'
+      ]]></command>
+    <inputs>
+        <param name="database_select" type="select" label="Database version" help="Choose a database version to download (default latest version)">
+            <option value="latest" selected="true">Latest available version</option>
+            <option value="2.1">V2.1_2019-08-28</option>
+        </param>
+    </inputs>
+    <outputs>
+        <data name="output_file" format="data_manager_json"/>
+    </outputs>
+    <tests>
+        <!-- Test_2 DB 2.1 -->
+        <test expect_num_outputs="1">
+           <param name="database_select" value="2.1"/>
+           <output name="output_file" value="plasmidfinder_test_data_manager_2.1.json">
+               <assert_contents>
+                   <has_text text="2019_08_28"/>
+               </assert_contents>
+           </output>
+        </test>
+    </tests>
+    <help><![CDATA[
+        Download plasmidfinder database from the bitbucket repository: https://bitbucket.org/genomicepidemiology/plasmidfinder_db/src/master/
+    ]]></help>
+    <citations>
+        <citation type="doi">10.1007/978-1-4939-9877-7_20</citation>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_manager_conf.xml	Thu Jun 15 09:14:08 2023 +0000
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<data_managers>
+    <data_manager tool_file="data_manager/plasmidfinder_fetch_database.xml" id="plasmidfinder_fetch_database">
+        <data_table name="plasmidfinder_database">
+            <output>
+                <column name="value" />
+                <column name="name" />
+                <column name="date" />
+                <column name="path" output_ref="output_file">
+                    <move type="directory" relativize_symlinks="True">
+                        <source>${path}</source>
+                        <target base="${GALAXY_DATA_MANAGER_DATA_PATH}">plasmidfinder-db/${name}</target>
+                    </move>
+                    <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/plasmidfinder-db/${name}</value_translation>
+                    <value_translation type="function">abspath</value_translation>
+                </column>
+            </output>
+        </data_table>
+    </data_manager>
+</data_managers>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plasmidfinder_database.loc	Thu Jun 15 09:14:08 2023 +0000
@@ -0,0 +1,8 @@
+# this is a tab separated file describing the location of plasmidfinder database
+# The name was obtained by merging date of download and commit number
+# the columns are:
+# value, name, date, path
+#
+# for example
+#plasmidfinder_9002e7282dd0_2022-12-20	9002e7282dd0_2022-12-20	2022-12-20	plasmidfinder-db
+#plasmidfinder_1307168b1ce7_2022-12-20	2.1_2022-12-20	2022-12-20	plasmidfinder-db
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/plasmidfinder.loc.test	Thu Jun 15 09:14:08 2023 +0000
@@ -0,0 +1,5 @@
+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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/plasmidfinder_test_data_manager_2.1.json	Thu Jun 15 09:14:08 2023 +0000
@@ -0,0 +1,1 @@
+{"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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool-data/plasmidfinder_database.loc	Thu Jun 15 09:14:08 2023 +0000
@@ -0,0 +1,8 @@
+# this is a tab separated file describing the location of plasmidfinder database
+# The name was obtained by merging date of download and commit number
+# the columns are:
+# value, name, date, path
+#
+# for example
+#plasmidfinder_9002e7282dd0_2022-12-20	9002e7282dd0_2022-12-20	2022-12-20	plasmidfinder-db
+#plasmidfinder_1307168b1ce7_2022-12-20	2.1_2022-12-20	2022-12-20	plasmidfinder-db
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_data_table_conf.xml.sample	Thu Jun 15 09:14:08 2023 +0000
@@ -0,0 +1,8 @@
+
+<tables>
+    <!-- Locations of plasmidfinder database in the required format -->
+    <table name="plasmidfinder_database" comment_char="#">
+        <columns>value, name, date, path</columns>
+        <file path="tool-data/plasmidfinder.loc" />
+    </table>
+</tables>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_data_table_conf.xml.test	Thu Jun 15 09:14:08 2023 +0000
@@ -0,0 +1,7 @@
+<tables>
+    <!-- Locations of plasmidfinder database in the required format -->
+    <table name="plasmidfinder_database" comment_char="#">
+        <columns>value, name, date,  path</columns>
+        <file path="${__HERE__}/test-data/plasmidfinder.loc.test"/>
+    </table>
+</tables>