Skip to content
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

Merged
merged 3 commits into from
Sep 19, 2024

Conversation

tsibley
Copy link
Member

@tsibley tsibley commented Sep 10, 2024

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

  • Checks pass

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>.
@tsibley
Copy link
Member Author

tsibley commented Sep 10, 2024

To run this with the unreleased --no-source-columns option to augur merge, use the Docker runtime with a local Augur overlay, e.g.

nextstrain build --docker --augur ../augur/ ingest -f results/metadata.tsv

or run in an ambient runtime with Augur installed from source

nextstrain build --ambient ingest -f results/metadata.tsv

@tsibley
Copy link
Member Author

tsibley commented Sep 10, 2024

CI is failing because it requires an unreleased Augur feature at the moment.

Copy link
Contributor

@joverlee521 joverlee521 left a 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:
Copy link
Contributor

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 🙌

ingest/rules/nextclade.smk Outdated Show resolved Hide resolved
--id-column {params.nextclade_id_field:q} \
--field-map {params.nextclade_field_map:q} \
--output-metadata - \
| tsv-select --header --fields {params.nextclade_fields:q} \
Copy link
Contributor

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 😅

Copy link
Member Author

@tsibley tsibley Sep 10, 2024

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 …. 😬

Copy link
Contributor

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?

Copy link
Member Author

@tsibley tsibley Sep 16, 2024

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.

Copy link
Member Author

@tsibley tsibley Sep 16, 2024

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>
Copy link
Contributor

@j23414 j23414 left a 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:
Copy link
Contributor

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?

Copy link
Member Author

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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why temp() here?

Copy link
Member Author

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:
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsibley tsibley merged commit e416110 into main Sep 19, 2024
4 checks passed
@tsibley tsibley deleted the trs/nextclade-merge branch September 19, 2024 20:44
tsibley added a commit to nextstrain/pathogen-repo-guide that referenced this pull request Oct 3, 2024
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>
tsibley added a commit to nextstrain/pathogen-repo-guide that referenced this pull request Oct 3, 2024
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>
tsibley added a commit to nextstrain/pathogen-repo-guide that referenced this pull request Oct 3, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants