Edits

Implements list edits, i.e. functions which take a list as input and return a changed list.

class edist.edits.Deletion(index)

Deletes node self._index.

_index

The index of the node to be deleted.

Type:int
apply(lst)

Deletes the self._indexth entry.

Parameters:lst (list) – a list
Returns:res – a copy of the list with the applied edit.
Return type:list
apply_in_place(lst)

Deletes the self._indexth entry.

Parameters:lst (list) – a list
class edist.edits.Edit

An abstract parent class for all edits.

apply(lst)

Applies this edit to the given list and returns a copy of the list with the applied changes. The original list remains unchanged.

Parameters:lst (list) – a list
Returns:res – a copy of the list with the applied edit.
Return type:list
apply_in_place(lst)

Applies this edit to the given list. Note that this changes the input argument.

Parameters:lst (list) – a list
class edist.edits.Insertion(index, label)

Inserts a new self._label entry at position self._index .

_index

The index at which this edit will be applied.

Type:int
_label

The new entry.

Type:str
apply(lst)

Inserts a new self._label entry at position self._index.

Parameters:lst (list) – a list
Returns:res – a copy of the list with the applied edit.
Return type:list
apply_in_place(lst)

Inserts a new self._label entry at position self._index.

Parameters:lst (list) – a list
class edist.edits.Replacement(index, label)

Replaces node self._index with label self._label.

_index

The index of the node to be deleted.

Type:int
_label

The new label for node self._index.

Type:str
apply(lst)

Replaces entry self._index with self._label.

Parameters:lst (list) – a list
Returns:res – a copy of the list with the applied edit.
Return type:list
apply_in_place(lst)

Replaces entry self._index with self._label.

Parameters:lst (list) – a list
class edist.edits.Script(lst=[])

A list of Edits.

apply(lst)

Applies all edits in this script.

Parameters:lst (list) – a list
Returns:res – a copy of the list with the applied edits of this script.
Return type:list
apply_in_place(lst)

Applies all edits in this script in place.

Parameters:lst (list) – a list
edist.edits.alignment_to_script(alignment, x, y)

Converts the given alignment into an edit script which maps the given list x to the given list y such that all entries of the alignment are translated one to one into edits.

Note that the order of operations does change because the script will first apply replacements (in input order), then deletions (in descending order), and finally insertions (in ascending order), which simplifies conversion.

Parameters:
  • alignment (class alignment.Alignment) – an Alignment object which maps between the given lists x and y.
  • x (list) – a list.
  • y (list) – another list.
Returns:

script – A Script object script such that script.apply(x) = y and where every tuple in the alignment has one corresponding edit.

Return type:

class edits.Script