Skip to content

FeatureLocation allows for swapped start and end coordinates #1497

Closed

Description

@JamesJeffryes

Setup
I am reporting a problem with Biopython version, Python version, and operating
system as follows:

2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]
CPython
Darwin-16.7.0-x86_64-i386-64bit
1.70

Expected behaviour
If given a malformed location string in a genbank file where the end location is smaller than the start location(e.g. 3000..1000) I expect Biopython to raise a warning.

Actual behaviour
In practice, the parser happily makes a feature location like this: FeatureLocation(ExactPosition(2999), ExactPosition(1000), strand=1)

Start & end violate the rule that location.end > location. start

Calling the length attribute on this feature raises an exception:

  File "<input>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/Bio/SeqFeature.py", line 383, in __len__
    return len(self.location)
ValueError: __len__() should return >= 0

Steps to reproduce
This is another corner case discovered using a mocked up genbank file:
minimal.txt

It's clearly not a proper format for the genbank location but I think it's not unreasonable to expect that manually edited files might contain errors like this one and the parse should detect that.

One can also manually generate a faulty feature location: FeatureLocation(3000,1000)

Activity

  1. peterjc commented on Jan 9, 2018

    @peterjc
    Member

    The feature positions define an order, so this could be added to the FeatureLocation.__init__ and cover both parser-created locations and user-created locations. It would be simplest to have this raise an exception there.

    However, you specifically suggested a warning when parsing problematic locations like this. Would an exception cause you problems?

    Would you like to work on this (submit a pull request)?

  2. added a commit that references this issue on Jan 9, 2018
  3. JamesJeffryes commented on Jan 9, 2018

    @JamesJeffryes
    ContributorAuthor

    An exception will be fine for my uses. Thanks!

  4. added a commit that references this issue on Jan 31, 2018
  5. peterjc commented on Jan 31, 2018

    @peterjc
    Member

    Closed via #1499, thank you James!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions