-
Notifications
You must be signed in to change notification settings - Fork 508
Add collapse_collection tool with polished UI and help #7810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nekrut
wants to merge
7
commits into
galaxyproject:main
Choose a base branch
from
nekrut:collapse_collection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6257ad7
Add collapse_collection tool with polished UI and help
nekrut afecd64
Bump version to 5.2.0 and profile to 24.2
nekrut 514617e
Fix CI lint: shed metadata, boolean conditional to select
nekrut d057e37
Address review: PNG diagram, select widget, shed metadata, citation
nekrut be1bbdf
Update .shed.yml category to Collection operations
nekrut 84cf269
Change .shed.yml owner to iuc
nekrut 8f4efc2
Fix .shed.yml category to valid Text Manipulation
nekrut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| categories: [Text Manipulation] | ||
| description: Collapse a list collection into a single dataset, with options to keep a common header and prepend dataset names. | ||
| long_description: | | ||
| Concatenates every file in a list collection into a single output dataset, | ||
| preserving collection order. Supports header deduplication and dataset name | ||
| prepending in several placement modes. | ||
| name: collapse_collections | ||
| owner: iuc | ||
| remote_repository_url: https://github.com/galaxyproject/tools-iuc/tree/main/tools/collapse_collection | ||
| homepage_url: https://github.com/galaxyproject/tools-iuc/tree/main/tools/collapse_collection | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,206 @@ | ||
| <tool id="collapse_dataset" name="Collapse Collection" version="5.2.0" profile="24.2"> | ||
| <description>into single dataset in order of the collection</description> | ||
| <macros> | ||
| <import>macros.xml</import> | ||
| </macros> | ||
| <requirements> | ||
| <requirement type="package" version="5.1.0">gawk</requirement> | ||
| </requirements> | ||
| <command> | ||
| <![CDATA[ | ||
|
|
||
| ( | ||
| #if $one_header: | ||
| #if str($filename.add_name) == "true": | ||
| awk '{if (NR==1) {print "Sample\t"$0}}' "$input_list[0]"; | ||
| #else: | ||
| awk '{if (NR==1) {print}}' "$input_list[0]"; | ||
| #end if | ||
| #end if | ||
|
|
||
| #for $f in $input_list# | ||
| #if str($filename.add_name) == "true": | ||
| #if str($filename.place_name) == "same_once": | ||
| #if $one_header: | ||
| printf "$f.element_identifier\t"; tail -q -n +2 "$f"; | ||
| #else: | ||
| printf "$f.element_identifier\t"; awk '{ print $0 } END { if (NR == 0 && NF == 0) { print "" } }' "$f"; | ||
| #end if | ||
| #elif str($filename.place_name) == "same_multiple": | ||
| #if $one_header: | ||
| awk '{if (NR!=1) {print "$f.element_identifier\t"$0}}' "$f"; | ||
| #else: | ||
| awk '{print "$f.element_identifier\t"$0} END { if (NR == 0 && NF == 0) { print "$f.element_identifier\t" } }' "$f"; | ||
| #end if | ||
| #elif str($filename.place_name) == "above": | ||
| #if $one_header: | ||
| printf "$f.element_identifier\n"; tail -q -n +2 "$f"; | ||
| #else: | ||
| printf "$f.element_identifier\n"; cat "$f"; | ||
| #end if | ||
| #end if | ||
| #else: | ||
| #if $one_header: | ||
| awk '{if (NR!=1) {print}}' "$f"; | ||
| #else: | ||
| cat "$f" ; | ||
| #end if | ||
| #end if | ||
|
|
||
| #end for# | ||
| ) | ||
| > $output | ||
|
|
||
| ]]> | ||
|
|
||
| </command> | ||
| <inputs> | ||
| <param name="input_list" type="data" format="data" label="Collection of files to collapse into single dataset" help="Select a list collection whose elements will be concatenated in order." optional="false" multiple="true" /> | ||
| <param name="one_header" type="boolean" label="Keep one header line" help="Use the first line of the first file as a single header for the output. Enable this when every file shares the same header row."/> | ||
| <conditional name="filename"> | ||
| <param name="add_name" type="select" label="Prepend dataset name" help="Add the element identifier of each dataset as a label or column in the output."> | ||
| <option value="false" selected="true">No</option> | ||
| <option value="true">Yes</option> | ||
| </param> | ||
| <when value="true"> | ||
| <param name="place_name" type="select" label="Where to add dataset name" help="Controls how the element identifier is inserted into the output."> | ||
| <option value="same_once">As a new column, first row only</option> | ||
| <option value="same_multiple">As a new column, every row</option> | ||
| <option value="above">On a separate line above each dataset</option> | ||
| </param> | ||
| </when> | ||
| <when value="false"> | ||
| </when> | ||
| </conditional> | ||
| </inputs> | ||
| <outputs> | ||
| <data name="output" format_source="input_list"/> | ||
| </outputs> | ||
| <tests> | ||
| <test> | ||
| <param name="input_list" value="input1,input2"/> | ||
| <output name="output" file="answer.txt"/> | ||
| </test> | ||
| <test> | ||
| <param name="input_list" value="strain1.tsv,strain2.tsv"/> | ||
| <param name="one_header" value="True"/> | ||
| <param name="filename|add_name" value="true"/> | ||
| <param name="filename|place_name" value="same_multiple"/> | ||
| <output name="output" file="answer2.tsv"/> | ||
| </test> | ||
| <test> | ||
| <param name="input_list" value="strain1.tsv,strain2.tsv"/> | ||
| <param name="one_header" value="True"/> | ||
| <output name="output" file="answer3.tsv"/> | ||
| </test> | ||
|
|
||
| </tests> | ||
| <help><![CDATA[ | ||
|
|
||
| =========== | ||
| Description | ||
| =========== | ||
|
|
||
| Concatenates every file in a list collection into a single output dataset, preserving the order in which they appear in the collection. | ||
|
|
||
| When the files share a common header line (e.g. a TSV with column names), enable **Keep one header line** to emit the header only once at the top of the output instead of repeating it for every file. You can also prepend the element identifier (dataset name) to each record so that the source of every line is traceable in the merged output. | ||
|
|
||
| The diagram below shows an example with header merging and dataset names prepended as a column on every row: | ||
|
|
||
| @DIAGRAM@ | ||
|
|
||
| ======== | ||
| Examples | ||
| ======== | ||
|
|
||
| **Basic collapse — simple concatenation** | ||
|
|
||
| Two text files in a collection:: | ||
|
|
||
| file1: | ||
| first file | ||
| second | ||
| third | ||
| fourth line | ||
|
|
||
| file2: | ||
| second file | ||
| second | ||
| third | ||
| fourth line | ||
|
|
||
| Output:: | ||
|
|
||
| first file | ||
| second | ||
| third | ||
| fourth line | ||
| second file | ||
| second | ||
| third | ||
| fourth line | ||
|
|
||
| ------- | ||
|
|
||
| **Header merging with dataset name on every row** | ||
|
|
||
| Two TSV files with a shared header, **Keep one header line** enabled, **Prepend dataset name** set to *As a new column, every row*:: | ||
|
|
||
| strain1.tsv: | ||
| seq_name median mean ... | ||
| mcr_1 52 52.74 ... | ||
| mcr_2 0 1.61 ... | ||
|
|
||
| strain2.tsv: | ||
| seq_name median mean ... | ||
| mcr_1 85 85.62 ... | ||
| mcr_2 0 3.05 ... | ||
|
|
||
| Output:: | ||
|
|
||
| Sample seq_name median mean ... | ||
| strain1.tsv mcr_1 52 52.74 ... | ||
| strain1.tsv mcr_2 0 1.61 ... | ||
| strain2.tsv mcr_1 85 85.62 ... | ||
| strain2.tsv mcr_2 0 3.05 ... | ||
|
|
||
| ------- | ||
|
|
||
| **Dataset name on a separate line above** | ||
|
|
||
| Same two TSV files, **Keep one header line** enabled, **Prepend dataset name** set to *On a separate line above each dataset*:: | ||
|
|
||
| seq_name median mean ... | ||
| strain1.tsv | ||
| mcr_1 52 52.74 ... | ||
| mcr_2 0 1.61 ... | ||
| strain2.tsv | ||
| mcr_1 85 85.62 ... | ||
| mcr_2 0 3.05 ... | ||
|
|
||
| ------- | ||
|
|
||
| **Header merging only (no dataset names)** | ||
|
|
||
| Same two TSV files, **Keep one header line** enabled, **Prepend dataset name** disabled:: | ||
|
|
||
| seq_name median mean ... | ||
| mcr_1 52 52.74 ... | ||
| mcr_2 0 1.61 ... | ||
| mcr_1 85 85.62 ... | ||
| mcr_2 0 3.05 ... | ||
|
|
||
| ------- | ||
|
|
||
| Originally developed by `Philip Mabon (Takadonet) <https://github.com/Takadonet>`_ at the National Microbiology Laboratory (PHAC). | ||
|
|
||
| ]]></help> | ||
| <citations> | ||
| <citation type="bibtex">@misc{phac_nml_galaxy_tools, | ||
| title={Galaxy Tools}, | ||
| author={{Public Health Agency of Canada, National Microbiology Laboratory}}, | ||
| url={https://github.com/phac-nml/galaxy_tools}, | ||
| note={Original source repository} | ||
| }</citation> | ||
| </citations> | ||
| </tool> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <macros> | ||
| <token name="@DIAGRAM@"><![CDATA[ | ||
| .. image:: $PATH_TO_IMAGES/collapse.png | ||
| :alt: Collapse a list collection into a single dataset | ||
| :width: 700 | ||
| ]]></token> | ||
| </macros> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| first file | ||
| second | ||
| third | ||
| fourth line | ||
| second file | ||
| second | ||
| third | ||
| fourth line |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Sample seq_name median mean gc% seq_length invalid_bases %_invalid non_zero_bases %_non_zero %_non_zero_corrected | ||
| strain1.tsv mcr_1 52 52.74000 0.49139 1626 0 0.00000 1600 100.00000 100.00000 | ||
| strain1.tsv mcr_2 0 1.60905 0.48114 1617 0 0.00000 56 3.51980 3.51980 | ||
| strain2.tsv mcr_1 85 85.61500 0.49139 1626 0 0.00000 1600 100.00000 100.00000 | ||
| strain2.tsv mcr_2 0 3.05343 0.48114 1617 0 0.00000 66 4.14833 4.14833 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| seq_name median mean gc% seq_length invalid_bases %_invalid non_zero_bases %_non_zero %_non_zero_corrected | ||
| mcr_1 52 52.74000 0.49139 1626 0 0.00000 1600 100.00000 100.00000 | ||
| mcr_2 0 1.60905 0.48114 1617 0 0.00000 56 3.51980 3.51980 | ||
| mcr_1 85 85.61500 0.49139 1626 0 0.00000 1600 100.00000 100.00000 | ||
| mcr_2 0 3.05343 0.48114 1617 0 0.00000 66 4.14833 4.14833 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| first file | ||
| second | ||
| third | ||
| fourth line |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| second file | ||
| second | ||
| third | ||
| fourth line |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| seq_name median mean gc% seq_length invalid_bases %_invalid non_zero_bases %_non_zero %_non_zero_corrected | ||
| mcr_1 52 52.74000 0.49139 1626 0 0.00000 1600 100.00000 100.00000 | ||
| mcr_2 0 1.60905 0.48114 1617 0 0.00000 56 3.51980 3.51980 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| seq_name median mean gc% seq_length invalid_bases %_invalid non_zero_bases %_non_zero %_non_zero_corrected | ||
| mcr_1 85 85.61500 0.49139 1626 0 0.00000 1600 100.00000 100.00000 | ||
| mcr_2 0 3.05343 0.48114 1617 0 0.00000 66 4.14833 4.14833 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mu suggestion would be
otherwise there will be two collapse_collections tools in the future. But this will only work if nml grants write access to the toolshed repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nekrut we need to solve this. We should not break the tool lineage.