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

Set up Cram tests, fix fetch-from-ncbi-virus #17

Merged
merged 5 commits into from
Sep 1, 2023

Conversation

victorlin
Copy link
Member

@victorlin victorlin commented Aug 30, 2023

Description of proposed changes

Currently there's a gap in testing the scripts in this repo. Maybe Cram can help (partially) fill that gap. At the least, I've provided an example showing how it can be useful for fetch-from-ncbi-virus.

Related issue(s)

Fixing bugs surfaced by nextstrain/mpox#175

Checklist

  • If adding a script, add an entry for it in the README.
  • Added Cram tests
  • Decide what to do about different Bash versions (thread)
  • Fix outstanding bug in fetch-from-ncbi-virus to allow skipping --filter and --field on older Bash versions
  • Checks pass

@victorlin victorlin self-assigned this Aug 30, 2023
@victorlin victorlin force-pushed the victorlin/cram-tests-and-fixes branch from d6cb670 to 7e56655 Compare August 30, 2023 22:27
We definitely don't need "the system bash", which is what /bin/bash is.
We want "the bash the user wants", which will often be the system bash,
but not always.

The main motivation is that /bin/bash on macOS is stuck on an ancient
version due to licensing issues, and users might prefer another Bash in
their environments.
@victorlin victorlin force-pushed the victorlin/cram-tests-and-fixes branch from 7e56655 to 34089c4 Compare August 31, 2023 22:37
@victorlin victorlin marked this pull request as ready for review August 31, 2023 22:45
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 adding the Cram tests!

$ $TESTDIR/../../fetch-from-ncbi-virus 12637 nextstrain/ingest \
> --filters 'CreateDate_dt:([1987-11-29T00:00:00Z TO 1987-11-29T00:00:01Z])' \
> --fields 'viruslineage_ids:VirusLineageId_ss'
{"genbank_accession":"X05375","genbank_accession_rev":"X05375.1","database":"GenBank","strain":"","region":"","location":"","collected":"","submitted":"1987-11-29T00:00:00Z","updated":"2016-07-26T00:00:00Z","length":"360","host":"","isolation_source":"","bioproject_accession":"","biosample_accession":"","sra_accession":"","title":"Dengue virus type 2 genomic RNA for envelope protein E N-term","authors":"Biedrzycka,A., Cauchi,M.R., Bartholomeusz,A., Gorman,J.J., Wright,P.J.","submitting_organization":"","publications":"2952760","sequence":"GTAACTTATGGGACGTGTACCACCACAGGAGAACACAGAAGAGAAAAAAGATCAGTGGCACTCGTTCCACATGTGGGAATGGGACTGGAGACACGAACTGAAACATGGATGTCATCAGAAGGGGCCTGGAAACATGCCCAGAGAATTGAAACTTGGATCTTGAGACATCCAGGCTTTACCATAATGGCAGCAATCCTGGCATACACCATAGGAACGACACATTTCCAAAGAGCCCTGATTTTCATCTTACTGACAGCTGTCGCTCCTTCAATGACAATGCGTTGCATAGGAATATCAAATAGAGACTTTGTAGAAGGGGTTTCAGGAGGAAGCTGGGTTGACATAGTCTTAGAACATGGA","viruslineage_ids":"10239,2559587,2732396,2732406,2732462,2732545,11050,11051,12637,11060"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how we can guard against these values changing in the future, but hopefully that won't happen any time soon since this was last updated in 2016!

Copy link
Member Author

Choose a reason for hiding this comment

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

Something like jq to check only a few JSON keys would be ideal, but I don't want to add another dev dependency right now.

@victorlin victorlin force-pushed the victorlin/cram-tests-and-fixes branch from 34089c4 to 993f3ab Compare September 1, 2023 18:21
Simplify the bash script by directly passing these options to the script
that uses them.

This requires changing the order so that required arguments are
specified before options.

This also removes reliance on the Bash ≥4 feature that allows unset
arrays to be accessed by [@] with -u.
@victorlin victorlin force-pushed the victorlin/cram-tests-and-fixes branch from 993f3ab to 966ebcf Compare September 1, 2023 18:25
@victorlin victorlin merged commit c97df23 into main Sep 1, 2023
@victorlin victorlin deleted the victorlin/cram-tests-and-fixes branch September 1, 2023 20:23
tsibley added a commit to nextstrain/nextstrain.org that referenced this pull request May 13, 2024
@victorlin noted in review that the previous construct threw an "unbound
variable" error on macOS's system Bash 3.2.57.¹  This is because after
3.2.57 and at least by 4.4.20 (but maybe earlier), Bash stopped treating
the "@" and "*" parameters as unset under -u when empty.²

Use an array slice³ (i.e. substring expansion, ${parameter:offset},
applied to an array) as a workaround.  Note that testing if
"docker_args" is empty, e.g. "${docker_args:+${docker_args[@]}}", won't
work because it leaves us with an empty string argument when unset.

¹ <#857 (comment)>
² <nextstrain/ingest#17 (comment)>
³ <https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

4 participants