rstoolbox.components.Selection

class rstoolbox.components.Selection(selection=None)

Complex management of residue selection from a sequence.

It can be used in any function that accepts the key_residue parameter.

It accepts both numerical and string data. Thus, a Selection can be declared in multiple ways.

In [1]: from rstoolbox.components import Selection
   ...: # From an array of numbers
   ...: sn = Selection([3, 4, 5, 13, 14, 15, 21, 25])
   ...: # From a string representation of numbers
   ...: ss = Selection("3-5,13-15,21,25")
   ...: # From a string representation of PDB numbering.
   ...: sp = Selection("4A-6A,14A-16A,22A,26A")
   ...: 

If a Series is provided, Selection will try to extract the appropiate content.

If regular numbering is provided, it will assume that it refers to direct sequence positions.

Note

Selection works with sequence positioning; that means that it expects the first position to be 1, not 0.

If a PDB numbering schema is provided, Selection will consider that the shift of the original PDB is already taken into account and will correct accordingly when applied to the different functons and data containers.

Note

PDB numbering cannot combine selections from multiple chains.

Parameters:

selection (Union[str, list(), Series]) – Residue positions that define the sequence selection.

Raises:
AttributeError:if the provided selection object cannot be processed.
ValueError:if values provided cannot be properly converted to an integer list.

Multiple operations are available for Selection.

In [2]: sele = Selection([3, 4, 5, 13, 14, 15, 21, 25])
   ...: # Negate selection: will call 'select all except'
   ...: not_sele = ~sele
   ...: sele.to_list()
   ...: 
Out[2]: [3, 4, 5, 13, 14, 15, 21, 25]

In [3]: not_sele.to_list(25)
Out[3]: [1, 2, 6, 7, 8, 9, 10, 11, 12, 16, 17, 18, 19, 20, 22, 23, 24]

In [4]: # Addition and substract will join or find the difference between
   ...: # two selections.
   ...: sele1 = Selection([3, 4, 5, 13, 14])
   ...: sele2 = Selection([14, 15, 21, 25])
   ...: sele1 - sele2  # Res in sele1 not in sele2
   ...: 
Out[4]: 3-5,13

In [5]: sele1 + sele2  # Res in both sele1 and sele2
Out[5]: 3-5,13-15,21,25

In [6]: # Logical operations
   ...: sele1 & sele2  # Res in sele1 that are also in sele2
   ...: 
Out[6]: 14

In [7]: new_sele = sele1 | sele2  # Res in both sele1 and sele2

In [8]: # Shift
   ...: sele << 2  # Shift all residue selection by -2
   ...: 
Out[8]: 1-3,11-13,19,23

In [9]: sele >> 2  # Shift all residue selection by +2
Out[9]: 5-7,15-17,23,27

Warning

Shifted and Unshifted Selection cannot operate between them.

Methods

is_empty() Evaluate if Selection is empty.
is_shifted() Evaluate if Selection is shifted.
map_to_sequences(sequence_map) Generator for parse_rosetta_file().
seqID() Identifier of the sequence to which Selection is assigned.
shift(seqID, shift) Shifts the Selection according to a value and sets up the chain to which it is associated.
to_list([length]) Provide the values of the Selection as a list of integers.
to_string() Provide the values of the Selection as a string.
unshift(seqID, shift) Unhifts the Selection according to a value.