Package Bio :: Module SeqFeature :: Class FeatureLocation
[hide private]
[frames] | no frames]

Class FeatureLocation

source code

object --+
         |
        FeatureLocation

Specify the location of a feature along a sequence.

This attempts to deal with fuzziness of position ends, but also make it easy to get the start and end in the 'normal' case (no fuzziness).

You should access the start and end attributes with your_location.start and your_location.end. If the start and end are exact, this will return the positions, if not, we'll return the approriate Fuzzy class with info about the position and fuzziness.

Note that the start and end location numbering follow Python's scheme, thus a GenBank entry of 123..150 (one based counting) becomes a location of [122:150] (zero based counting).

Instance Methods [hide private]
 
__init__(self, start, end)
Specify the start and end of a sequence feature.
source code
 
__str__(self)
Returns a representation of the location (with python counting).
source code
 
__repr__(self)
A string representation of the location for debugging.
source code
 
__nonzero__(self)
Returns True regardless of the length of the feature.
source code
 
__len__(self)
Returns the length of the region described by the FeatureLocation.
source code
 
__contains__(self, value)
Check if an integer position is within the FeatureLocation.
source code
 
__iter__(self)
Iterate over the parent positions within the FeatureLocation.
source code
 
_shift(self, offset)
Returns a copy of the location shifted by the offset (PRIVATE).
source code
 
_flip(self, length)
Returns a copy of the location after the parent is reversed (PRIVATE).
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]
  start
Start location (possibly a fuzzy position, read only).
  end
End location (possibly a fuzzy position, read only).
  nofuzzy_start
Start position (integer, approximated if fuzzy, read only).
  nofuzzy_end
End position (integer, approximated if fuzzy, read only).

Inherited from object: __class__

Method Details [hide private]

__init__(self, start, end)
(Constructor)

source code 

Specify the start and end of a sequence feature.

start and end arguments specify the values where the feature begins and ends. These can either by any of the *Position objects that inherit from AbstractPosition, or can just be integers specifying the position. In the case of integers, the values are assumed to be exact and are converted in ExactPosition arguments. This is meant to make it easy to deal with non-fuzzy ends.

i.e. Short form:

>>> from Bio.SeqFeature import FeatureLocation
>>> loc = FeatureLocation(5,10)

Explicit form:

>>> from Bio.SeqFeature import FeatureLocation, ExactPosition
>>> loc = FeatureLocation(ExactPosition(5),ExactPosition(10))

Other fuzzy positions are used similarly,

>>> from Bio.SeqFeature import FeatureLocation
>>> from Bio.SeqFeature import BeforePosition, AfterPosition
>>> loc2 = FeatureLocation(BeforePosition(5),AfterPosition(10))
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

Returns a representation of the location (with python counting).

For the simple case this uses the python splicing syntax, [122:150] (zero based counting) which GenBank would call 123..150 (one based counting).

Overrides: object.__str__

__repr__(self)
(Representation operator)

source code 

A string representation of the location for debugging.

Overrides: object.__repr__

__nonzero__(self)
(Boolean test operator)

source code 

Returns True regardless of the length of the feature.

This behaviour is for backwards compatibility, since until the __len__ method was added, a FeatureLocation always evaluated as True.

Note that in comparison, Seq objects, strings, lists, etc, will all evaluate to False if they have length zero.

WARNING: The FeatureLocation may in future evaluate to False when its length is zero (in order to better match normal python behaviour)!

__len__(self)
(Length operator)

source code 

Returns the length of the region described by the FeatureLocation.

Note that extra care may be needed for fuzzy locations, e.g.

>>> from Bio.SeqFeature import FeatureLocation
>>> from Bio.SeqFeature import BeforePosition, AfterPosition
>>> loc = FeatureLocation(BeforePosition(5),AfterPosition(10))
>>> len(loc)
5

__contains__(self, value)
(In operator)

source code 

Check if an integer position is within the FeatureLocation.

Note that extra care may be needed for fuzzy locations, e.g.

>>> from Bio.SeqFeature import FeatureLocation
>>> from Bio.SeqFeature import BeforePosition, AfterPosition
>>> loc = FeatureLocation(BeforePosition(5),AfterPosition(10))
>>> len(loc)
5
>>> [i for i in range(15) if i in loc]
[5, 6, 7, 8, 9]

__iter__(self)

source code 

Iterate over the parent positions within the FeatureLocation.

>>> from Bio.SeqFeature import FeatureLocation
>>> from Bio.SeqFeature import BeforePosition, AfterPosition
>>> loc = FeatureLocation(BeforePosition(5),AfterPosition(10))
>>> len(loc)
5
>>> for i in loc: print i
5
6
7
8
9
>>> list(loc)
[5, 6, 7, 8, 9]
>>> [i for i in range(15) if i in loc]
[5, 6, 7, 8, 9]

Property Details [hide private]

start

Start location (possibly a fuzzy position, read only).

Get Method:
unreachable(self)

end

End location (possibly a fuzzy position, read only).

Get Method:
unreachable(self)

nofuzzy_start

Start position (integer, approximated if fuzzy, read only).

To get non-fuzzy attributes (ie. the position only) ask for 'location.nofuzzy_start', 'location.nofuzzy_end'. These should return the largest range of the fuzzy position. So something like: (10.20)..(30.40) should return 10 for start, and 40 for end.

Get Method:
unreachable(self)

nofuzzy_end

End position (integer, approximated if fuzzy, read only).

To get non-fuzzy attributes (ie. the position only) ask for 'location.nofuzzy_start', 'location.nofuzzy_end'. These should return the largest range of the fuzzy position. So something like: (10.20)..(30.40) should return 10 for start, and 40 for end.

Get Method:
unreachable(self)