biotite.sequence.Annotation¶

class biotite.sequence.Annotation(features=None)[source]

Bases: biotite.copyable.Copyable

An Annotation is a set of features belonging to one sequence.

Its advantage over a simple list is the base/residue position based indexing: When using slice indices in Annotation objects, a subannotation is created, containing copies of all Feature objects whose first and last base/residue are in range of the slice. If the slice starts after the first base/residue or/and the slice ends before the last residue, the position out of range is set to the boundaries of the slice (the Feature is truncated). In this case the Feature obtains the MISS_LEFT and/or MISS_RIGHT defect. The third case occurs when a Feature starts after the slice ends or a Feature ends before the slice starts. In this case the Feature will not appear in the subannotation.

The start or stop position in the slice indices can be omitted, then the subannotation will include all features from the start or up to the stop, respectively. Step values are ignored. The stop values are still exclusive, i.e. the subannotation will contain a not truncated Feature only if its last base/residue is smaller than the stop value of the slice.

Integers or other index types are not supported. If you want to obtain the Feature instances from the Annotation you need to iterate over it. The iteration has no defined order. Alternatively, you can obtain a copy of the internal Feature set via get_features().

Multiple Annotation objects can be concatenated to one Annotation object using the ‘+’ operator. Single Feature instances can be added this way, too. If a feature is present in both Annotation objects, the resulting Annotation will contain this feature twice.

Parameters: features : iterable object of Feature, optional The features to create the Annotation from. if not provided, an empty Annotation is created.

Examples

Creating an annotation from a feature list

>>> feature1 = Feature("CDS", [Location(-10, 30 )], qual={"gene" : "test1"})
>>> feature2 = Feature("CDS", [Location(20,  50 )], qual={"gene" : "test2"})
>>> annotation1 = Annotation([feature1, feature2])
>>> for f in sorted(list(annotation1)):
...     print(f.qual["gene"], "".join([str(loc) for loc in f.locs]))
test1 -10-30 >
test2 20-50 >


Merging two annotations and a feature

>>> feature3 = Feature("CDS", [Location(100, 130 )], qual={"gene" : "test3"})
>>> feature4 = Feature("CDS", [Location(150, 250 )], qual={"gene" : "test4"})
>>> annotation2 = Annotation([feature3, feature4])
>>> feature5 = Feature("CDS", [Location(-50, 200 )], qual={"gene" : "test5"})
>>> annotation3 = annotation1 + annotation2 + feature5
>>> for f in sorted(list(annotation3)):
...     print(f.qual["gene"], "".join([str(loc) for loc in f.locs]))
test5 -50-200 >
test1 -10-30 >
test2 20-50 >
test3 100-130 >
test4 150-250 >


Location based indexing, note the defects

>>> annotation4 = annotation3[40:150]
>>> for f in sorted(list(annotation4)):
...     print(f.qual["gene"], "".join([str(loc) for loc in f.locs]))
test2 40-50 >
test5 40-149 >
test3 100-130 >

get_features()[source]

Get a copy of the internal feature set.

Returns: feature_list : list of Feature A copy of the internal feature set.
add_feature(feature)[source]

Add a feature to the annotation.

Parameters: feature : Feature Feature to be added.
get_location_range()[source]

Get the range of feature locations, i.e. the first and exclusive last base/residue.

Returns: int : start Start location. int : stop Exclusive stop location.
del_feature(feature)[source]

Delete a feature from the annotation.

Parameters: feature : Feature Feature to be removed. KeyError If the feature is not in the annotation
copy()

Create a deep copy of this object.

Returns: copy A copy of this object.