def getRegionCoveringAll(self, annotations): spans = [] annotation_types = [] for annot in annotations: spans.extend(annot.map.spans) if annot.type not in annotation_types: annotation_types.append(annot.type) map = Map(spans=spans, parent_length=len(self)) map = map.covered() # No overlaps Name = ','.join(annotation_types) return _Feature(self, map, type='region', Name=Name)
def Feature(parent, type, Name, spans, value=None): if isinstance(spans, Map): map = spans assert map.parent_length == len(parent), (map, len(parent)) else: map = Map(locations=spans, parent_length=len(parent)) return AnnotatableFeature(parent, map, type=type, Name=Name)
def _shiftedAnnotations(self, new, shift): result = [] if self.annotations: newmap = Map([(shift, shift + len(self))], parent_length=len(new)) for annot in self.annotations: annot = annot.remappedTo(new, newmap) result.append(annot) return result
def Variable(parent, type, Name, xxy_list): """A variable that has 2 x-components (start, end) and a single y component. Currently used by Vestige - BMC Bioinformatics, 6:130, 2005.""" start = min([min(x1, x2) for ((x1, x2), y) in xxy_list]) end = max([max(x1, x2) for ((x1, x2), y) in xxy_list]) if start != 0: xxy_list = [((x1-start, x2-start), y) for ((x1, x2), y) in xxy_list] end -= start #values = [location.Span(x1-start, x2-start, True, True, y) for ((x1, x2), y) in xxy] map = Map([(start, end)], parent_length=len(parent)) return _Variable(parent, map, type=type, Name=Name, xxy_list=xxy_list)
def _as_map(self, index): """Can take a slice, integer, map or feature, or even a list/tuple of those""" if type(index) in [list, tuple]: spans = [] for i in index: spans.extend(self._as_map(i).spans) map = Map(spans=spans, parent_length=len(self)) elif isinstance(index, _Feature): feature = index map = feature.map base = feature.parent containers = [] while feature and base is not self and hasattr(base, 'parent'): containers.append(base) base = base.parent if base is not self: raise ValueError("Can't map %s onto %s via %s" % (index, repr(self), containers)) for base in containers: feature = feature.remappedTo(base, base.map) index = map else: map = as_map(index, len(self)) return map
def SimpleVariable(parent, type, Name, data): """A simple variable type of annotation, such as a computed property of a sequence that varies spatially.""" assert len(data) == len(parent), (len(data), len(parent)) map = Map([(0, len(data))], parent_length=len(parent)) return _SimpleVariable(parent, map, type=type, Name=Name, data=data)