gffutils.interface.FeatureDB.merge

FeatureDB.merge(features, merge_criteria=(<function seqid>, <function overlap_end_inclusive>, <function strand>, <function feature_type>), multiline=False)[source]

Merge features matching criteria together

Returned Features have a special property called ‘children’ that is a list of the component features. This only exists for the lifetime of the Feature instance.

Parameters:
  • features (iterable) – Iterable of Feature instances to merge

  • merge_criteria (list) – List of merge criteria callbacks. All must evaluate to True in order for a feature to be merged. See notes below on callback signature.

  • multiline (bool) – True to emit multiple features with the same ID attribute, False otherwise.

Return type:

Generator yielding merged Features

Notes

See the gffutils.merge_criteria module (imported here as mc) for existing callback functions. For writing custom callbacks, functions must have the following signature:

callback(
    acc: gffutils.Feature,
    cur: gffutils.Feature,
    components: [gffutils.Feature]
) -> bool

Where:

  • acc: current accumulated feature

  • cur: candidate feature to merge

  • components: list of features that compose acc

The function should return True to merge cur into acc, False to set cur to acc (that is, start a new merged feature).

If merge criteria allows different feature types then the merged features’ feature types should have their featuretype property reassigned to a more specific ontology value.