Add support for terminal_columns in Alignment formatting, issue 5035#5070
Add support for terminal_columns in Alignment formatting, issue 5035#5070data2code wants to merge 10 commits intobiopython:masterfrom
Conversation
Fix the syntax for assert in test_Align_Alignment_format.py
|
@data2code Can you have a look at the failing checks? |
|
I don't know what's wrong. I ran "pytest Tests/test_Align_Alignment_format.py" and it was clean. |
|
@data2code Have a look at the failing checks as shown on this web page. |
|
I believe I have fixed the style issue in the test script. The error currently is in the main code. I don't feel comfortable to add this new attribute to the Alignment class, as I am unfamiliar with the BioPython code base. |
|
The errors look like a problem not creating an attribute when the object is created? eg Black is still not happy - this could be the version of black: We still use black 24.10.0 for trailing whitespace in doctests. |
The |
|
Not sure what I can do here. The Pre-commit.ci gives failures without providing me the accurate feedback. |
|
@data2code Check the failing tests as shown on this web page, where it says "4 failing checks" |
|
@mdehoon I only see failure flags without details. I am not a biopython developer; instead, I am a user who made a feature request. I am afraid I have done what I can with the issue. Could someone from the developer team help take over? Thanks. |
There is no developer team. We are all just volunteers. What happens if you click on the first failure (where it says "CI / style (pull_request)") ? |
|
Two files are not following the automated style checking using the tool |
|
The main tests are looking better though, from AppVeyor which runs the tests on Windows: |
Bio/Align/__init__.py
Outdated
| import sys | ||
| import types | ||
| import warnings | ||
| import shutil |
There was a problem hiding this comment.
This would ideally be a few lines up (alphabetical sorting of standard library imports).
Bio/Align/__init__.py
Outdated
| position_width = 10 | ||
| line_width = 80 | ||
|
|
||
| # support custom column size, see issue 5035 |
There was a problem hiding this comment.
I think the comment is redundant and could be removed.
Tests/test_Align_Alignment_format.py
Outdated
| @@ -0,0 +1,40 @@ | |||
| """Tests for controling the number of terminal columns | |||
| Issue #5035 | |||
| """ | |||
There was a problem hiding this comment.
This is not formatted in the expected style, but there are bigger issues with your test.
Tests/test_Align_Alignment_format.py
Outdated
| # 0 -||||||...||||--|...|--|...||..|-|....|..|.|--|--|||.||.|-------|--------------|.||.|---|-||---------||-------------||.|.|.|.||-. 129 | ||
| # query 0 DVQLQESGPGLVKP--SQSQSLTCTVTGYSITSDYAWNWIRQFP--GNKLEWMGYMS-------Y--------------SGSTRY---NPSLRSRISITRDTSKNQFFLQLKSVTTEDTATYFCARG-W 100 | ||
| # | ||
| assert (len(str(best_alignment).split("\n")) == 4), "Expecting alignment to be output as one group." |
There was a problem hiding this comment.
You have not defined any tests using the unittest framework, thus the error No tests found in test_Align_Alignment_format.
See https://biopython.org/docs/latest/Tutorial/chapter_testing.html
Also I think this need not be an entire new file.
|
@peterjc Thank you, that's very helpful. |
|
@peterjc The test looks good on my local: $ python Tests/test_Align_Alignment_format.py Ran 1 test in 0.001s OK Any pointers for what to work on next? Thank you! |
|
Fix the black style. Move the test into an appropriate existing [I have not considered the value of the change itself yet, as others seem to have.] |
|
I believe the test error was not due to the code I added to the test file. The error was triggered by other tests in the same file. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5070 +/- ##
==========================================
- Coverage 85.44% 77.93% -7.52%
==========================================
Files 286 282 -4
Lines 59908 59430 -478
==========================================
- Hits 51189 46316 -4873
- Misses 8719 13114 +4395 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bio/Align/__init__.py
Outdated
| position_width = 10 | ||
| line_width = 80 | ||
|
|
||
| if not hasattr(self, "terminal_columns") or self.terminal_columns is None: |
There was a problem hiding this comment.
It is better to have a class variable terminal_columns on the Alignment class.
|
@mdehoon Updated. Thanks for the suggestion. |
|
Okay, move it to a class attribute. Thanks. |
| # 120 .|.|.||-. 129 | ||
| # query 92 TYFCARG-W 100 | ||
| # | ||
| self.assertEqual(len(str(best_alignment).split("\n")), 12) |
There was a problem hiding this comment.
Why not just test str(best_alignment) explicitly (using triple quotes)?
There was a problem hiding this comment.
IMHO, this test should not be checking the exact alignment itself, but instead focus on the row count. The exact alginment might be altered in the future due small changes in alignment algorithm or the naming of the "target", "query" or other small formatting changes. The exact alignment should be checked by other test cases, while this test focuses on row counts. I hope it makes sense.
There was a problem hiding this comment.
If at some point some bug is introduced that causes the printed alignment to be incorrect, then your test may not capture it, if it only checks the number of lines.
The algorithm by definition generates the optimal alignment. Even if there are any changes to the algorithm, the generated optimal alignment will still be the same.
|
@mdehoon You have a valid point in believing the algorithm won't change, however, the formatting itself can change. E.g., someone may decided instead of using query and target, print Q and T instead. Then this test will break. Anyway, this test is to check the alignment layout, not the exact content of the alignment itself. There are other tests that change the validity of the content of the alignment. I think it's best for this test to focus on the formatting not the content. If it is okay with everyone, we should close this thread. I have learned a lot from this PR, thank you and Peter for your patience! Really appreciate all the guidance and feedback. |

[ X] I hereby agree to dual licence this and any previous contributions under both
the Biopython License Agreement AND the BSD 3-Clause License.
[ X] I have read the
CONTRIBUTING.rstfile, have runpre-commitlocally, and understand that continuous integration checks will be used to
confirm the Biopython unit tests and style checks pass with these changes.
I have added my name to the alphabetical contributors listings in the files
NEWS.rstandCONTRIB.rstas part of this pull request, am listedalready, or do not wish to be listed. (This acknowledgement is optional.)
Closes #5035
Modify Bio.Align.init.py to support terminal_columns. If not specified, use all available terminal columns to show the alignment, otherwise, use user-specified value. Add Tests/test_Align_Alignment_format.py.