-
Notifications
You must be signed in to change notification settings - Fork 1
phylogenetic: generic pattern for additional inputs #91
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
713be21
git subrepo pull (merge) shared/vendored
joverlee521 d899fdb
phylogenetic: include shared *.smk files
joverlee521 66cca7e
phylogenetic: copy `merge_inputs.smk` from zika
joverlee521 9dc453f
merge_inputs: generalize docs
joverlee521 e9f3cb7
merge_inputs: generalize input_* functions for wildcards
joverlee521 adbf1af
merge_inputs: add docs for compression support
joverlee521 1bc57a0
phylogenetic: include `merge_inputs` rules file
joverlee521 42b74e6
phylogenetic/ci: update config to use `inputs` param
joverlee521 60e2fae
phylo/merge_inputs: verify at least one metadata and sequences
joverlee521 fed74be
phylo/merge_inputs: decompress single inputs through `augur read-file`
joverlee521 17b7dab
phylo/merge_inputs: Produce the same output files for single or multi…
joverlee521 8b25198
phylo/merge_inputs: small docs & error message edits
joverlee521 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
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 |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| # This configuration file contains the custom configurations parameters | ||
| # for the CI workflow to run with the example data. | ||
|
|
||
| # Custom rules to run as part of the CI automated workflow | ||
| # The paths should be relative to the phylogenetic directory. | ||
| custom_rules: | ||
| - build-configs/ci/copy_example_data.smk | ||
| inputs: | ||
| - name: example_data | ||
| metadata: "example_data/metadata.tsv" | ||
| sequences: "example_data/sequences.fasta" |
This file was deleted.
Oops, something went wrong.
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
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
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
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,184 @@ | ||
| """ | ||
| This part of the workflow merges inputs based on what is defined in the config. | ||
|
|
||
| OUTPUTS: | ||
|
|
||
| metadata = results/metadata.tsv | ||
| sequences = results/sequences.fasta | ||
|
|
||
| The config dict is expected to have a top-level `inputs` list that defines the | ||
| separate inputs' name, metadata, and sequences. Optionally, the config can have | ||
| a top-level `additional-inputs` list that is used to define additional data that | ||
| are combined with the default inputs: | ||
|
|
||
| ```yaml | ||
| inputs: | ||
| - name: default | ||
| metadata: <path-or-url> | ||
| sequences: <path-or-url> | ||
|
|
||
| additional_inputs: | ||
| - name: private | ||
| metadata: <path-or-url> | ||
| sequences: <path-or-url> | ||
| ``` | ||
|
|
||
| Supports any of the compression formats that are supported by `augur read-file`, | ||
| see <https://docs.nextstrain.org/projects/augur/page/usage/cli/read-file.html> | ||
|
|
||
| NOTE: The included rules are written for workflows that do not use wildcards | ||
| for defining inputs such as zika. You will need to edit the rules to support wildcards | ||
|
|
||
| 1. If your workflow needs wildcards for both metadata and sequences, | ||
| e.g. serotypes for dengue, then you will need to edit the `output`, `log`, and | ||
| `benchmark` paths of the metadata and sequences rules. | ||
| The wildcards can then be directly used in the config for inputs: | ||
|
|
||
| ```yaml | ||
| inputs: | ||
| - name: default | ||
| metadata: https://data.nextstrain.org/files/workflows/dengue/metadata_{serotype}.tsv.zst | ||
| sequences: https://data.nextstrain.org/files/workflows/dengue/sequences_{serotype}.fasta.zst | ||
|
|
||
| ``` | ||
|
|
||
| 2. If your workflow only needs wildcards for sequences, e.g. segments for influenza, | ||
| then you will only need to edit the paths for the sequences rules. | ||
| The wildcards can then be directly used in the config for inputs: | ||
|
|
||
| ```yaml | ||
| inputs: | ||
| - name: default | ||
| metadata: s3://nextstrain-data-private/files/workflows/avian-flu/metadata.tsv.zst | ||
| sequences: s3://nextstrain-data-private/files/workflows/avian-flu/{segment}/sequences.fasta.zst | ||
| ``` | ||
| """ | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def _gather_inputs(): | ||
| all_inputs = [*config['inputs'], *config.get('additional_inputs', [])] | ||
|
|
||
| if len(all_inputs)==0: | ||
| raise InvalidConfigError("Config must define at least one element in config.inputs or config.additional_inputs lists") | ||
| if not all([isinstance(i, dict) for i in all_inputs]): | ||
| raise InvalidConfigError("All of the elements in config.inputs and config.additional_inputs lists must be dictionaries. " | ||
| "If you've used a command line '--config' double check your quoting.") | ||
| if len({i['name'] for i in all_inputs})!=len(all_inputs): | ||
| raise InvalidConfigError("Names of inputs (config.inputs and config.additional_inputs) must be unique") | ||
| if not all(['name' in i and ('sequences' in i or 'metadata' in i) for i in all_inputs]): | ||
| raise InvalidConfigError("Each input (config.inputs and config.additional_inputs) must have a 'name' and 'metadata' and/or 'sequences'") | ||
| if not any(['metadata' in i for i in all_inputs]): | ||
| raise InvalidConfigError("At least one input must have 'metadata'") | ||
| if not any (['sequences' in i for i in all_inputs]): | ||
| raise InvalidConfigError("At least one input must have 'sequences'") | ||
|
|
||
| available_keys = set(['name', 'metadata', 'sequences']) | ||
| if any([len(set(el.keys())-available_keys)>0 for el in all_inputs]): | ||
| raise InvalidConfigError(f"Each input (config.inputs and config.additional_inputs) can only include keys of {', '.join(available_keys)}") | ||
|
|
||
| return {el['name']: {k:(v if k=='name' else path_or_url(v)) for k,v in el.items()} for el in all_inputs} | ||
|
|
||
| input_sources = _gather_inputs() | ||
| _input_metadata = [info['metadata'] for info in input_sources.values() if info.get('metadata', None)] | ||
| _input_sequences = [info['sequences'] for info in input_sources.values() if info.get('sequences', None)] | ||
|
|
||
|
|
||
| if len(_input_metadata) == 1: | ||
|
|
||
| rule decompress_metadata: | ||
| """ | ||
| This rule is invoked when there is a single metadata input to | ||
| ensure that we have a decompressed input for downstream rules to match | ||
| the output of rule.merge_metadata. | ||
| """ | ||
| input: | ||
| metadata = _input_metadata[0], | ||
| output: | ||
| metadata = "results/metadata.tsv", | ||
| log: | ||
| "logs/decompress_metadata.txt", | ||
| benchmark: | ||
| "benchmarks/decompress_metadata.txt", | ||
| shell: | ||
| r""" | ||
| exec &> >(tee {log:q}) | ||
|
|
||
| augur read-file {input.metadata:q} > {output.metadata:q} | ||
| """ | ||
|
|
||
| else: | ||
|
|
||
| rule merge_metadata: | ||
| """ | ||
| This rule is invoked when there are multiple defined metadata inputs | ||
| (config.inputs + config.additional_inputs) | ||
| """ | ||
| input: | ||
| **{name: info['metadata'] for name,info in input_sources.items() if info.get('metadata', None)} | ||
| params: | ||
| metadata = lambda w, input: list(map("=".join, input.items())), | ||
| id_field = config['strain_id_field'], | ||
| output: | ||
| metadata = "results/metadata.tsv" | ||
| log: | ||
| "logs/merge_metadata.txt", | ||
| benchmark: | ||
| "benchmarks/merge_metadata.txt" | ||
| shell: | ||
| r""" | ||
| exec &> >(tee {log:q}) | ||
|
|
||
| augur merge \ | ||
| --metadata {params.metadata:q} \ | ||
| --metadata-id-columns {params.id_field:q} \ | ||
| --output-metadata {output.metadata:q} | ||
| """ | ||
|
|
||
|
|
||
| if len(_input_sequences) == 1: | ||
|
|
||
| rule decompress_sequences: | ||
| """ | ||
| This rule is invoked when there is a single sequences input to | ||
| ensure that we have a decompressed input for downstream rules to match | ||
| the output of rule.merge_sequences. | ||
| """ | ||
| input: | ||
| sequences = _input_sequences[0], | ||
| output: | ||
| sequences = "results/sequences.fasta", | ||
| log: | ||
| "logs/decompress_sequences.txt", | ||
| benchmark: | ||
| "benchmarks/decompress_sequences.txt", | ||
| shell: | ||
| r""" | ||
| exec &> >(tee {log:q}) | ||
|
|
||
| augur read-file {input.sequences:q} > {output.sequences:q} | ||
| """ | ||
|
|
||
| else: | ||
|
|
||
| rule merge_sequences: | ||
| """ | ||
| This rule is invoked when there are multiple defined sequences inputs | ||
| (config.inputs + config.additional_inputs) | ||
| """ | ||
| input: | ||
| **{name: info['sequences'] for name,info in input_sources.items() if info.get('sequences', None)} | ||
| output: | ||
| sequences = "results/sequences.fasta", | ||
| log: | ||
| "logs/merge_sequences.txt", | ||
| benchmark: | ||
| "benchmarks/merge_sequences.txt" | ||
| shell: | ||
| r""" | ||
| exec &> >(tee {log:q}) | ||
|
|
||
| augur merge \ | ||
| --sequences {input:q} \ | ||
| --output-sequences {output.sequences:q} | ||
| """ |
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.