Skip to content

Addresses #1497: FeatureLocation invalid input exception - #1499

Merged
peterjc merged 7 commits into
biopython:masterfrom
JamesJeffryes:#1497
Jan 31, 2018
Merged

peterjc merged 7 commits into
biopython:masterfrom
JamesJeffryes:#1497

Conversation

@JamesJeffryes

Copy link
Copy Markdown
Contributor

FeatureLocation will now raise a value error if supplied an start location greater than the specified end location

This pull request addresses issue #1497

I hereby agree to dual licence this and any previous contributions under both
the Biopython License Agreement AND the BSD 3-Clause License.

I have read the CONTRIBUTING.rst file and understand that AppVeyor and
TravisCI will be used to confirm the Biopython unit tests and flake8 style
checks pass with these changes.

I am happy be thanked by name in the NEWS.rst and CONTRIB.rst files,
and have added myself to those files as part of this pull request. (This
acknowledgement is optional. Note we list the names sorted alphabetically.
)

FeatureLocation will now raise a value error if supplied an start location greater than the specified end location
@JamesJeffryes
JamesJeffryes requested a review from peterjc as a code owner January 9, 2018 14:19
@JamesJeffryes

Copy link
Copy Markdown
Contributor Author

When testing I discovered my change must support a feature location with an UnknownPosition like FeatureLocation(42, UnknownPosition()). However the len of a feature location with an UnknownPosition is invalid.

Traceback (most recent call last):
  File "/Users/jjeffryes/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-22-d5f7e1d31af9>", line 1, in <module>
    len(FeatureLocation(UnknownPosition(), 42))
  File "/Users/jjeffryes/anaconda3/lib/python3.6/site-packages/Bio/SeqFeature.py", line 787, in __len__
    return int(self._end) - int(self._start)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'UnknownPosition'

I think it's right to have an exception raised in this case but would you like me to add a more informative error message to this PR?

@peterjc

peterjc commented Jan 9, 2018

Copy link
Copy Markdown
Member

Good point - I'd forgotten about the annoying special case, yes, if either start or end is UnknownPosition the order check will fail.

As to the exception with __len__ in this case, I think the current TypeError exception is reasonably clear as is - these locations are fairly rare so I wouldn't worry too much about making that exception more informative.

(Note now that I've merged #1500 the NumPy doctest failures on the master branch should be solved #1496; you were probably ignoring them anyway)

Comment thread Bio/SeqFeature.py Outdated
else:
raise TypeError("end=%r %s" % (end, type(end)))
if self._start > self._end:
if self.start.position and self.end.position and self.start > self.end:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sadly zero is a valid start or end position, so I think this would miss some corner cases

Comment thread Tests/test_SeqFeature.py Outdated
from Bio import SeqIO
from Bio.SeqFeature import FeatureLocation, AfterPosition, BeforePosition, CompoundLocation
from Bio.SeqFeature import FeatureLocation, AfterPosition, BeforePosition, \
CompoundLocation, UnknownPosition

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you use two import lines, rather than the slash continuation here.

Comment thread Tests/test_SeqFeature.py
# Features with UnknownPositions should pass test
FeatureLocation(42, UnknownPosition())
FeatureLocation(UnknownPosition(), 42)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Include some zero positions, and also special case where start and end are equal (e.g. location of digest enzyme cutting site between two bases)?

@codecov

codecov Bot commented Jan 9, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #1499 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1499      +/-   ##
=========================================
+ Coverage   84.79%   84.8%   +0.01%     
=========================================
  Files         323     323              
  Lines       49393   49395       +2     
=========================================
+ Hits        41884   41891       +7     
+ Misses       7509    7504       -5
Impacted Files Coverage Δ
Bio/SeqFeature.py 86.06% <100%> (+0.25%) ⬆️
Bio/GA/Evolver.py 72.72% <0%> (+18.18%) ⬆️

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 3628959...de0edaa. Read the comment docs.

@JamesJeffryes

Copy link
Copy Markdown
Contributor Author

So the travis build seems to have failed on a network error. I can't make much sense of why one of the appveyor builds failed it's tests

@peterjc

peterjc commented Jan 10, 2018 •

Copy link
Copy Markdown
Member

As you say, the tests look to have failed due to a network issue. Sadly they would have failed anyway on AppVeyor due to #1496 which I am working on now, #1502

Update: Travis seems happy now after I restarted the stuck test...

@peterjc

peterjc commented Jan 11, 2018

Copy link
Copy Markdown
Member

@bow - does this seem fine to you too?

@JamesJeffryes

Copy link
Copy Markdown
Contributor Author

@peterjc Any further feedback on this?

@peterjc

peterjc commented Jan 30, 2018

Copy link
Copy Markdown
Member

I'm happy. @bow if this looks OK to you, either of us could go ahead and rebase-merge this.

@bow bow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@peterjc ~ sorry for the last ping (I missed that). This changeset looks ok ~ thank you @JamesJeffryes!

@peterjc

peterjc commented Jan 31, 2018

Copy link
Copy Markdown
Member

Thanks Bow, merging. Thank you James!

peterjc added a commit to peterjc/biopython that referenced this pull request Nov 8, 2019
peterjc added a commit to peterjc/biopython that referenced this pull request Dec 20, 2019
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.

3 participants