Back to index

python-biopython  1.60
Public Member Functions | Private Member Functions
Bio.SeqFeature.OneOfPosition Class Reference
Inheritance diagram for Bio.SeqFeature.OneOfPosition:
Inheritance graph
[legend]
Collaboration diagram for Bio.SeqFeature.OneOfPosition:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __new__
def position
def extension
def __repr__
def __str__

Private Member Functions

def _shift
def _flip

Detailed Description

Specify a position where the location can be multiple positions.

This models the GenBank 'one-of(1888,1901)' function, and tries
to make this fit within the Biopython Position models. If this was
a start position it should act like 1888, but as an end position 1901.

>>> p = OneOfPosition(1888, [ExactPosition(1888), ExactPosition(1901)])
>>> p
OneOfPosition(1888, choices=[ExactPosition(1888), ExactPosition(1901)])
>>> int(p)
1888

Interget comparisons and operators act like using int(p),

>>> p == 1888
True
>>> p <= 1888
True
>>> p > 1888
False
>>> p + 100
1988

>>> isinstance(p, OneOfPosition)
True
>>> isinstance(p, AbstractPosition)
True
>>> isinstance(p, int)
True

The old legacy properties of position and extension give the
starting/lowest/left-most position as an integer, and the
distance to the ending/highest/right-most position as an integer.
Note that the position object will act like one of the list of
possible locations depending on how it was created:

>>> p2 = OneOfPosition(1901, [ExactPosition(1888), ExactPosition(1901)])
>>> p.position == p2.position == 1888
True
>>> p.extension == p2.extension == 13
True
>>> int(p) == int(p2)
False
>>> p == 1888
True
>>> p2 == 1901
True

Definition at line 1231 of file SeqFeature.py.


Member Function Documentation

def Bio.SeqFeature.OneOfPosition.__new__ (   cls,
  position,
  choices 
)
Initialize with a set of posssible positions.

position_list is a list of AbstractPosition derived objects,
specifying possible locations.

position is an integer specifying the default behaviour.

Definition at line 1281 of file SeqFeature.py.

01281 
01282     def __new__(cls, position, choices):
01283         """Initialize with a set of posssible positions.
01284 
01285         position_list is a list of AbstractPosition derived objects,
01286         specifying possible locations.
01287 
01288         position is an integer specifying the default behaviour.
01289         """
01290         assert position in choices
01291         obj = int.__new__(cls, position)
01292         obj.position_choices = choices
01293         return obj

String representation of the OneOfPosition location for debugging.

Reimplemented from Bio.SeqFeature.AbstractPosition.

Definition at line 1305 of file SeqFeature.py.

01305 
01306     def __repr__(self):
01307         """String representation of the OneOfPosition location for debugging."""
01308         return "%s(%i, choices=%r)" % (self.__class__.__name__, \
01309                                        int(self), self.position_choices)

Definition at line 1310 of file SeqFeature.py.

01310 
01311     def __str__(self):
01312         out = "one-of("
01313         for position in self.position_choices:
01314             out += "%s," % position
01315         # replace the last comma with the closing parenthesis
01316         out = out[:-1] + ")"
01317         return out

def Bio.SeqFeature.OneOfPosition._flip (   self,
  length 
) [private]

Definition at line 1322 of file SeqFeature.py.

01322 
01323     def _flip(self, length):
01324         return self.__class__(length - int(self),
01325                               [p._flip(length) for p in self.position_choices[::-1]])
01326 

def Bio.SeqFeature.OneOfPosition._shift (   self,
  offset 
) [private]

Definition at line 1318 of file SeqFeature.py.

01318 
01319     def _shift(self, offset):
01320         return self.__class__(int(self) + offset,
01321                               [p._shift(offset) for p in self.position_choices])

Legacy attribute to get extension as integer (OBSOLETE).

Definition at line 1300 of file SeqFeature.py.

01300 
01301     def extension(self):
01302         """Legacy attribute to get extension as integer (OBSOLETE)."""
01303         positions = [int(pos) for pos in self.position_choices]
01304         return max(positions) - min(positions)

Legacy attribute to get (left) position as integer (OBSOLETE).

Definition at line 1295 of file SeqFeature.py.

01295 
01296     def position(self):
01297         """Legacy attribute to get (left) position as integer (OBSOLETE)."""
01298         return min(int(pos) for pos in self.position_choices)

Here is the caller graph for this function:


The documentation for this class was generated from the following file: