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

Refactor filters into separate functions #745

Merged
merged 1 commit into from
Jul 16, 2021
Merged

Conversation

huddlej
Copy link
Contributor

@huddlej huddlej commented Jul 9, 2021

Description of proposed changes

Refactors filter logic into separate function with the same signature of func(metadata, **kwargs) that returns a set of strain names that pass the filter. Although this work does not reduce the complexity of the code by itself, it sets up a pattern that will allow us to move all filters into a single loop through all user-requested filters. This change should simplify the main logic and also allow us to short-cut evaluation when filters remove all possible strains (e.g., --exclude-all), avoiding unnecessary checks.

This refactoring also includes new functions for sequence-based filters. As part of these sequence-based functions, we update the sequence index data frame to be indexed by strain name to be consistent with the metadata data frame.

One side-effect of this refactoring is the addition of a functional test for both --include-where and --exclude-where filters to make sure these are properly implemented and no regressions occur during refactoring. The lack of this test initially allowed the refactoring of --exclude-where logic to introduce a bug.

Finally, we also define a new function to include strains by a query. Note that this implementation relies on the same query parser used by the --exclude-where argument which allows the negation operator and also the code that lowercases the strings before comparison. This change is backward compatible, however, and only adds functionality that is consistent with the --exclude-where functionality.

Related issue(s)

Builds on work in the pandas-metadata branch and PR #743

Testing

Adds doctests for all new filter functions. Test these functions locally by installing augur with dev dependencies (python3 -m pip install .[dev]) with ./run_tests -k filter_by.

@codecov
Copy link

codecov bot commented Jul 9, 2021

Codecov Report

Merging #745 (4545b2e) into master (00fe015) will increase coverage by 0.07%.
The diff coverage is 51.57%.

❗ Current head 4545b2e differs from pull request most recent head 0710b50. Consider uploading reports for the commit 0710b50 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #745      +/-   ##
==========================================
+ Coverage   31.51%   31.58%   +0.07%     
==========================================
  Files          41       41              
  Lines        5674     5755      +81     
  Branches     1373     1391      +18     
==========================================
+ Hits         1788     1818      +30     
- Misses       3812     3860      +48     
- Partials       74       77       +3     
Impacted Files Coverage Δ
augur/export_v2.py 11.07% <2.94%> (-0.43%) ⬇️
augur/utils.py 40.17% <40.54%> (-0.61%) ⬇️
augur/filter.py 52.44% <61.85%> (+3.81%) ⬆️
augur/__version__.py 100.00% <100.00%> (ø)
augur/distance.py 48.36% <100.00%> (+2.47%) ⬆️
augur/util_support/metadata_file.py 100.00% <100.00%> (ø)
augur/index.py 52.63% <0.00%> (-28.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 990e111...0710b50. Read the comment docs.

Copy link
Member

@tsibley tsibley left a comment

Choose a reason for hiding this comment

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

@huddlej and I talked about this offline. Summary is 👍, although this branch looks like it still needs to be rebased onto the updated #743.

Refactors filter logic into separate function with the same signature of
`func(metadata, **kwargs)` that returns a `set` of strain names that
pass the filter. Although this work does not reduce the complexity of
the code by itself, it sets up a pattern that will allow us to move all
filters into a single loop through all user-requested filters. This
change should simplify the main logic and also allow us to short-cut
evaluation when filters remove all possible strains (e.g.,
`--exclude-all`), avoiding unnecessary checks.

This refactoring also includes new functions for sequence-based filters.
As part of these sequence-based functions, we update the sequence index
data frame to be indexed by strain name to be consistent with the
metadata data frame.

One side-effect of this refactoring is the additional of a functional
test for both `--include-where` and `--exclude-where` filters to make
sure these are properly implemented and no regressions occur during
refactoring. The lack of this test initially allowed the refactoring of
`--exclude-where` logic to introduce a bug.

Finally, we also define a new function to include strains by a query.
Note that this implementation relies on the same query parser used by
the `--exclude-where` argument which allows the negation operator and
also the code that lowercases the strings before comparison. This change
is backward compatible, however, and only adds functionality that is
consistent with the `--exclude-where` functionality.
@huddlej huddlej added this to the Feature release 13.0.0 milestone Jul 16, 2021
@huddlej huddlej merged commit 2482992 into master Jul 16, 2021
@huddlej huddlej deleted the refactor-filters branch July 16, 2021 02:22
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.

2 participants