def locations_to_biopython_features( self, feature_type="misc_feature", color="red", label_prefix="", merge_overlapping=False, ): """Return a list of locations (of breach/suboptimality) as annotations. Parameters ---------- feature_type Genbank type of the annotations color Color property attached to the annotations label_prefix The locations will be labelled of the form "prefix NameOfSpecification()" merge_overlapping If true, then overlapping locations (0-5, 2-9) will be merged into a single one (0-9). """ locations = self.locations if merge_overlapping: locations = Location.merge_overlapping_locations(locations) return [ SeqFeature( location.to_biopython_location(), type=feature_type, qualifiers=dict( label=label_prefix + " " + str(self.specification), color=color, ), ) for location in locations ]
def locations_as_features( self, features_type="misc_feature", with_specifications=True, label_prefix="From", colors="cycle", merge_overlapping=False, locations_filter=None, ): """Return all locations from all evaluations as biopython features. Parameters ---------- features_type The Genbank feature type with_specifications If True, features are added to the list to indicate the scope of the different specifications. If false, only the specification breaches are returned. label_prefix Each breach may be labeled "prefix NameOfSpec(props)", for instance, "From AvoidPattern(100-200)", to indicate where the breach belongs. colors Either a list of colors (one for each specification), e.g. ['red', '#7aab71', ...] or "cycle" for cycling through predefined colors. The colors are applied to all breaches. locations_filter A function (location => True/False) deciding whether """ if colors == "cycle": cycle = colors_cycle( lightness_factor=self.color_lightness, color_shift=self.color_shift, ) colors = [next(cycle) for ev in self.evaluations] features = [ location.to_biopython_feature( feature_type="misc_feature", label=" ".join([ label_prefix, ev.specification.label(use_short_form=True, with_location=False), ]), color=color, ApEinfo_fwdcolor=color, ApEinfo_revcolor=color, ) for (ev, color) in zip(self.evaluations_with_locations(), colors) for location in (Location.merge_overlapping_locations(ev.locations) if merge_overlapping else ev.locations) if (locations_filter is None) or locations_filter(location) ] if with_specifications: features += [ ev.specification.to_biopython_feature( feature_type="misc_feature", label=ev.specification.label(use_short_form=True, with_location=False), role=self.specifications_role, color=color, ApEinfo_fwdcolor=color, ApEinfo_revcolor=color, ) for ev, color in zip(self.evaluations, colors) if ev.specification.__dict__.get("location", False) ] return features