Permalink
Browse files

Add a parts property to FeatureLocation for ease of use

  • Loading branch information...
peterjc committed Jul 25, 2012
1 parent e89cfb1 commit ff6c999fd8a71b83d6414a6d7464501c8a9abb0a
Showing with 14 additions and 13 deletions.
  1. +2 −7 Bio/Graphics/GenomeDiagram/_Feature.py
  2. +10 −0 Bio/SeqFeature.py
  3. +2 −6 BioSQL/Loader.py
@@ -168,13 +168,8 @@ def __process_feature(self):
"""
self.locations = []
bounds = []
- try:
- #Compound location?
- parts = self._feature.location.parts
- except AttributeError:
- #No, simple location
- parts = [self._feature.location]
- for location in parts:
+ #This will be a list of length one for simple FeatureLocation:
+ for location in self._feature.location.parts:
start = location.nofuzzy_start
end = location.nofuzzy_end
#if start > end and self.strand == -1:
View
@@ -822,6 +822,16 @@ def _flip(self, length):
end = self._start._flip(length),
strand = flip_strand)
+ @property
+ def parts(self):
+ """Read only list of parts (always one, the Feature Location).
+
+ This is a convience property allowing you to write code handling
+ both simple FeatureLocation objects (with one part) and more complex
+ CompoundLocation objects (with multiple parts) interchangably.
+ """
+ return [self]
+
@property
def start(self):
"""Start location (integer like, possibly a fuzzy position, read only)."""
View
@@ -798,12 +798,8 @@ def _load_seqfeature_locations(self, feature, seqfeature_id):
from Bio import BiopythonWarning
warnings.warn("%s location operators are not fully supported"
% feature.location_operator, BiopythonWarning)
- try:
- #Is is a compound location?
- parts = feature.location.parts
- except AttributeError:
- #Simple location
- parts = [feature.location]
+ #This will be a list of length one for simple FeatureLocation:
+ parts = feature.location.parts
if parts and set(loc.strand for loc in parts)==set([-1]):
#To mimic prior behaviour of Biopython+BioSQL, reverse order
parts = parts[::-1]

0 comments on commit ff6c999

Please sign in to comment.