Protein.
to_regex
(within_capture=False)[source]¶Return regular expression object that accounts for degenerate chars.
State: Stable as of 0.4.1.
within_capture (bool) – If True
, format the regex pattern for the sequence into a
single capture group. If False
, compile the regex pattern as-is
with no capture groups.
Pre-compiled regular expression object (as from re.compile
)
that matches all definite versions of this sequence, and nothing
else.
regex
Examples
>>> from skbio import DNA
>>> seq = DNA('TRG')
>>> regex = seq.to_regex()
>>> regex.match('TAG').string
'TAG'
>>> regex.match('TGG').string
'TGG'
>>> regex.match('TCG') is None
True
>>> regex = seq.to_regex(within_capture=True)
>>> regex.match('TAG').groups(0)
('TAG',)