diff --git a/content/news/2023-06-from-single-files-to-collections/figs/empty_collection.png b/content/news/2023-06-from-single-files-to-collections/figs/empty_collection.png new file mode 100644 index 0000000000..44a27106e3 Binary files /dev/null and b/content/news/2023-06-from-single-files-to-collections/figs/empty_collection.png differ diff --git a/content/news/2023-06-from-single-files-to-collections/figs/failed_collection.png b/content/news/2023-06-from-single-files-to-collections/figs/failed_collection.png new file mode 100644 index 0000000000..3f3b4f938c Binary files /dev/null and b/content/news/2023-06-from-single-files-to-collections/figs/failed_collection.png differ diff --git a/content/news/2023-06-from-single-files-to-collections/figs/genebasedWF_collection_marked.png b/content/news/2023-06-from-single-files-to-collections/figs/genebasedWF_collection_marked.png new file mode 100644 index 0000000000..03124d0a2d Binary files /dev/null and b/content/news/2023-06-from-single-files-to-collections/figs/genebasedWF_collection_marked.png differ diff --git a/content/news/2023-06-from-single-files-to-collections/figs/genebasedWF_single_marked.png b/content/news/2023-06-from-single-files-to-collections/figs/genebasedWF_single_marked.png new file mode 100644 index 0000000000..0bfbd2ab44 Binary files /dev/null and b/content/news/2023-06-from-single-files-to-collections/figs/genebasedWF_single_marked.png differ diff --git a/content/news/2023-06-from-single-files-to-collections/figs/implicit_datatype_coversion.png b/content/news/2023-06-from-single-files-to-collections/figs/implicit_datatype_coversion.png new file mode 100644 index 0000000000..b41c630b6e Binary files /dev/null and b/content/news/2023-06-from-single-files-to-collections/figs/implicit_datatype_coversion.png differ diff --git a/content/news/2023-06-from-single-files-to-collections/figs/preprocessing_WFpart_collection_marked.png b/content/news/2023-06-from-single-files-to-collections/figs/preprocessing_WFpart_collection_marked.png new file mode 100644 index 0000000000..a15c251774 Binary files /dev/null and b/content/news/2023-06-from-single-files-to-collections/figs/preprocessing_WFpart_collection_marked.png differ diff --git a/content/news/2023-06-from-single-files-to-collections/figs/reindex_collection.png b/content/news/2023-06-from-single-files-to-collections/figs/reindex_collection.png new file mode 100644 index 0000000000..73e756cdde Binary files /dev/null and b/content/news/2023-06-from-single-files-to-collections/figs/reindex_collection.png differ diff --git a/content/news/2023-06-from-single-files-to-collections/figs/rerun.png b/content/news/2023-06-from-single-files-to-collections/figs/rerun.png new file mode 100644 index 0000000000..5ed75ce4a4 Binary files /dev/null and b/content/news/2023-06-from-single-files-to-collections/figs/rerun.png differ diff --git a/content/news/2023-06-from-single-files-to-collections/index.md b/content/news/2023-06-from-single-files-to-collections/index.md new file mode 100644 index 0000000000..2454d7930c --- /dev/null +++ b/content/news/2023-06-from-single-files-to-collections/index.md @@ -0,0 +1,150 @@ +--- +title: "Moving workflows from single files to collections - a case study" +date: "2023-06-20" +tease: "Allowing a complex workflow to be used on multiple datasets using collections." +hide_tease: false +authors: 'Paul Zierep, Engy Nasr' +authors_structured: +- github: paulzierep +- github: EngyNasr +tags: [EU] +subsites: [all-eu] +main_subsite: eu +--- + + +Collections are a great way to bundle multiple dataset into single entities (as shown in the history) that can be +processed collectively. In fact, when the amount of datasets rises up to 1000+ it becomes essential to use collections. +Galaxy can also use collections in tools that are not specifically designed to process +collections using the mapping-over strategy (run the tool for each of the elements in a collection). +Therefore, it should be a peace of cake to port complete workflows that +were based on processing single files to use collections as well. + +However, when applying this idea on our latest metagenomics workflow [Foodborne Pathogen detection](https://training.galaxyproject.org/training-material/topics/metagenomics/tutorials/pathogen-detection-from-nanopore-foodborne-data/tutorial.html) we encountered some problems +that arise when switching from single files to collections. +In the following we would like to present some of those issues and how we solved them, in the hopes that these strategies can help +others to port their workflows to collections as well. + +# Case 1 - Simple inputs for workflow logic + +It is often useful to add simple inputs to a workflow such as integers or text to specify specific parameters of tools. Galaxy can also use the output of a tool as input +parameter for another tool. Details are described in the tutorial [Using Workflow Parameters](https://training.galaxyproject.org/training-material/topics/galaxy-interface/tutorials/workflow-parameters/tutorial.html). In the case of the *Single File Foodborne Pathogen Detection Workflow* a text input `Sample ID` is used downstream by multiple tools as input. + +The figure below shows 1 out of 5 sub-workflows, which form together the complete pathogen detection workflow. This sub-workflow is the *Gene based pathogenic identification workflow*, which takes as an input the pre-processed sample reads and the `Sample ID` both marked in green, and detects possible pathogens by identifying virulence factors (VFs) for all contigs of the input sample. + +![Gene Based Pathogenic Identification For Single Sample Workflow](./figs/genebasedWF_single_marked.png) + + +
+ Gene based pathogenic identification workflow for single files: Green boxes identifies the single sample input sequences file and the text Sample ID. These inputs needed to be changed to allow processing of collections. +
+ + + +This workflow could not be transformed straight forward into a collection logic, since the input in this case would need to be a list with matching `Sample IDs`. +The problem was solved by using the name of the collection elements as `Sample IDs` and transforming them into workflow parameters using the following set of tools marked in Green, which are [Extract element identifiers](https://usegalaxy.eu/?tool_id=toolshed.g2.bx.psu.edu%2Frepos%2Fiuc%2Fcollection_element_identifiers%2Fcollection_element_identifiers%2F0.0.2&version=0.0.2), [Split file](https://usegalaxy.eu/?tool_id=toolshed.g2.bx.psu.edu%2Frepos%2Fbgruening%2Fsplit_file_to_collection%2Fsplit_file_to_collection%2F0.5.0&version=0.5.0) and `Parse parameter value` (only available in the workflow editor). A [PR](https://github.com/galaxyproject/iwc/pull/182) to add the workflow to IWC is currently pending in progress. + +![Gene Based Pathogenic Identification For Collection of Samples Workflow](./figs/genebasedWF_collection_marked.png) + + +
+ Gene based pathogenic identification workflow for collections: Green boxes identifies the collection of sample sequences files as the main input and the tools used to replace the input text `Sample ID`. Using this approach the user doesn't have to worry about manually entering the `Sample IDs` rather the tools will extract them from the collection element names. +
+ + +In case the `Sample IDs` do not match the element identifies a list with matching IDs could +be provided by the user that is then processed similarly to the described approach. + +# Case 2 - Failing or empty elements in a collection + +Even if a workflow is well designed, in some cases in can happen that only few elements of a collection fail. This happened to us rather randomly in case of Kraken2, since +it requires large amounts of memory (>70 GB), which were not assigned to every run of the tool by the server. That issue was solved by increasing the minimum memory required by the tool on the EU server. But there are various other scenarios where the failure of the tool can be attributed for example to specific input data. In other cases only a few elements of a collection are empty (e.g. if an assembly can not be made due to not overlapping reads). + +If a collection is used in the tool [Collapse Collection +into single dataset in order of the collection](https://usegalaxy.eu/root?tool_id=toolshed.g2.bx.psu.edu/repos/nml/collapse_collections/collapse_dataset/5.1.0) but an element of the collection is failed or empty the entire downstream processing is stopped, which can be rather annoying if one aims to process a large amount of data and got stuck due to a few elements. Two solutions are proposed to handle such cases. + +## Intermediate workflow specific solution + +### Filter the collection + +Collections can be filtered for failed or empty datasets using collection tools such as [filter empty datasets](https://usegalaxy.eu/?tool_id=__FILTER_EMPTY_DATASETS__&version=1.0.0) and [filter failed datasets](https://usegalaxy.eu/?tool_id=__FILTER_FAILED_DATASETS__&version=1.0.0). + +
+
+ +![Empty collection](./figs/empty_collection.png) + +
+
+ Filter failed collection elements +
+
+ +
+
+ +![Empty collection](./figs/failed_collection.png) + +
+
+ Filter empty collection elements +
+
+ + +Although this can solve the issue in some cases immediately, further considerations need to be made. +First, often one cannot really know at which step the collection will be affected. +To cover all cases one would need to add the filter steps for every produced collection, which will increase the workflow steps unreasonably. +Secondly, the filtering will change the size of the collection. If downstream tools depend on a specific collection size, which is always the case if a tool +takes two or more collections as input, the tool will also fail. That's basically a follow up problem of the first problem. +This case can still be solved by a intermediate step where the second collection is basically reindexed by the same element identifiers then the collection with +missing elements. + +
+
+ +![Empty collection](./figs/reindex_collection.png) + +
+
+ Proposed solution to reindexed second collection using elements of the first collection. +
+
+ +However, if this logic needs to be applied to multiple collections or again for multiple steps, the workflow becomes even more unreasonably large and complex. + +Furthermore it needs to be considered, that filtering empty or failed elements from a collection +can hide the root cause of the problem. The question why some tool runs fail or produce empty output should always be further investigated. + +### Rerun the workflow with rerun activated + +In some cases a rerun of the workflow can also solve the issue, for example in our use case where the failure was rather randomly. +For this strategy it is beneficial to activate the rerun option of galaxy (User/Preferences/Manage Information) on instance with version > 23.0. +This allows to only rerun failed elements, which saves computing resources and time. + +
+
+ +![Empty collection](./figs/rerun.png) + +
+
+ Rerun option of galaxy using cached files. +
+
+ + +## Global tool dependent solution + +Since this issue cannot be solved satisfactory on the workflow level, one can still aim to improve the problem for the community by solving it on the tool level. +In general the aim should be that the tool neither fails nor produces empty output. This is much more work, but will ultimately have a benefit for all users. +Two things need to be considered here. + +* Why does the tool fail, can it be solved? In our case we had to increase the memory of kraken2 for the server. In other cases it could be necessary to inspect the tool wrapper and find individual solutions. +* Why does the tool produce empty elements? If the tool produces empty elements when in fact it has an output but the output is an empty file (e.g. if a detection tools detects nothing), it might be as simple as adding an empty table or fasta file for this tool, to allow follow up tools to work. E.g. an assembly tool than cannot create any contig should return an empty fasta file instead of failing. + +# Outlook + +We hope that this post can help others to also move from single file workflows to collections and motivate to improve the overall experience for the community by creating +PRs and raising issues for tools that need a little more help to fully comply with the wonders of collections as well. +