-
Notifications
You must be signed in to change notification settings - Fork 6
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
Update Nextclade metadata merge to use augur curate rename
and augur merge
#52
Conversation
Preserving the line-breaks makes the command much more readable in Snakemake output¹, which is important since I'm changing this rule right now. The \n previously interpreted by Python is now interpreted by `tr`, which is preferable. ¹ <https://docs.nextstrain.org/en/latest/reference/snakemake-style-guide.html#use-triple-quoted-command-definitions>
This construction reads much clearer and cleaner. Moves the Nextclade field map directly and more conveniently into the YAML config instead of referencing a separate TSV file. Putting the field map into a separate file seemed to be only for the sake of the --kv-file (-k) interface provided by `cvstk rename2`, which we're no longer using here. For backwards compatibility, configs that reference a TSV file are still supported and will be handled on-the-fly. Note that `augur curate` commands currently emit CSV-like TSVs that are limited to be IANA-like¹ such that parsing them with tsv-utils is most appropriate, hence the switch from `csvtk cut` to `tsv-select`. ¹ See <nextstrain/augur#1566>.
To run this with the unreleased
or run in an ambient runtime with Augur installed from source
|
CI is failing because it requires an unreleased Augur feature at the moment. |
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.
Thanks for using measles as an example! This is so much cleaner 🌟
@@ -124,5 +124,32 @@ curate: | |||
genotype_field: "virus_name" | |||
nextclade: | |||
dataset_name: "nextstrain/measles/N450/WHO-2012" | |||
field_map: "defaults/nextclade_field_map.tsv" | |||
field_map: |
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.
Putting the field map into a separate file seemed to be only for the sake of the --kv-file (-k) interface provided by
cvstk rename2
, which we're no longer using here.
Yup, this is much cleaner to keep all the field mappings in the central config.yaml 🙌
--id-column {params.nextclade_id_field:q} \ | ||
--field-map {params.nextclade_field_map:q} \ | ||
--output-metadata - \ | ||
| tsv-select --header --fields {params.nextclade_fields:q} \ |
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.
tangent
I was thinking of revisiting nextstrain/augur#1526 to remove the need to use tsv-select
here, but now tsv-select
looks so much cleaner than having to list out the columns to drop 😅
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.
tsv-select
will be less clean if we were properly using csv2tsv --csv-delim $'\t' | tsv-select …
. 😬
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.
Oh, hmm. Depending on the type of TSV that Nextclade outputs, we could flip it to tsv-select ... | augur curate rename
?
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.
following up
Nextclade outputs CSV-like TSV, so we will still need the csv2tsv …
to use tsv-utils.
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.
I'm going to leave the precise TSV flavors and correct handling of them as future work for nextstrain/augur#1566. Lots of tsv-utils and csvtk usages will have to change if we want them to be correct (and I think we do).
This construction reads a bit clearer and cleaner. It's also a good example of how to use `augur merge`. The limitation on non-seekable streams means the workflow now uses additional transient disk space, but it typically shouldn't be an issue. The way Augur's slow start up time impacts `augur merge` also contributes to a longer rule execution time, but it should be negligible in the context of the larger workflow and presumably we'll fix the slow start up eventually.¹ The output is semantically identical but has some syntactic changes re: quoting. It's worth noting that the pre-existing TSV format was _not_ IANA TSV, despite it (still) being treated as such in a few places, but was (and remains) a CSV-like TSV with some quoted fields (and some mangled quotes², e.g. the "institution" column for accession KJ556895). We really need to sort out our TSV formats³, but that's for a larger project. ¹ <nextstrain/augur#1628> ² <nextstrain/augur#1565> ³ <nextstrain/augur#1566>
4212c40
to
4d73b7f
Compare
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.
Nice!
input: | ||
nextclade="results/nextclade.tsv", | ||
output: | ||
nextclade_metadata=temp("results/nextclade_metadata.tsv"), | ||
params: |
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.
Missing log
and benchmark
, which I think we're trying to include everywhere?
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.
These were missing in the rule prior to my changes. None of the rules in this file have those stanzas. I'm going to punt on changing that here and now.
input: | ||
nextclade="results/nextclade.tsv", | ||
output: | ||
nextclade_metadata=temp("results/nextclade_metadata.tsv"), |
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.
why temp()
here?
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.
It's a subset of the data that's only needed transiently and unlikely to be useful on its own. It may also be large for some pathogens, so don't want it to stick around unnecessarily.
""" | ||
|
||
|
||
rule join_metadata_and_nextclade: |
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.
Also missing log
and benchmark
here.
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.
Preserving the line-breaks makes the command much more readable in Snakemake output¹, which is important since I'm changing this rule right now. The \n previously interpreted by Python is now interpreted by `tr`, which is preferable. ¹ <https://docs.nextstrain.org/en/latest/reference/snakemake-style-guide.html#use-triple-quoted-command-definitions> Ported-from: <nextstrain/measles@762acdb> Related-to: <nextstrain/measles#52> Related-to: <#65>
This construction reads much clearer and cleaner. Moves the Nextclade field map directly and more conveniently into the YAML config instead of referencing a separate TSV file. Putting the field map into a separate file seemed to be only for the sake of the --kv-file (-k) interface provided by `cvstk rename2`, which we're no longer using here. Backwards compatibility with configs that name a TSV file is not preserved since this pathogen-repo-guide is expected to be used to stamp out new repos, and we don't have any particular process/plan for how to update previously stamped out repos. Note that `augur curate` commands currently emit CSV-like TSVs that are limited to be IANA-like¹ such that parsing them with tsv-utils is most appropriate, hence the switch from `csvtk cut` to `tsv-select`. ¹ See <nextstrain/augur#1566>. Ported-from: <nextstrain/measles@faebd64> Related-to: <nextstrain/measles#52> Related-to: <#65>
This construction reads a bit clearer and cleaner. It's also a good example of how to use `augur merge`. The limitation on non-seekable streams means the workflow now uses additional transient disk space, but it typically shouldn't be an issue. The way Augur's slow start up time impacts `augur merge` also contributes to a longer rule execution time, but it should be negligible in the context of the larger workflow and presumably we'll fix the slow start up eventually.¹ The output is semantically identical but has some syntactic changes re: quoting. It's worth noting that the pre-existing TSV format was _not_ IANA TSV, despite it (still) being treated as such in a few places, but was (and remains) a CSV-like TSV with some quoted fields. We really need to sort out our TSV formats³, but that's for a larger project. ¹ <nextstrain/augur#1628> ² <nextstrain/augur#1565> ³ <nextstrain/augur#1566> Ported-from: <nextstrain/measles@4d73b7f> Related-to: <nextstrain/measles#52> Related-to: <#65>
See individual commit messages for all the details.
Marking this PR as draft (for now) because it's primarily meant (for now) to solicit feedback on this approach. Once we're happy with the implementation and come to a consensus, we can merge it and then port it to nextstrain/pathogen-repo-guide.
Checklist