Skip to content

API reference

pydustmasker.DustMasker

Identify and mask low-complexity nucleotide regions using the SDUST algorithm.

Parameters:

Name Type Description Default

sequence

str

The nucleotide sequence to be processed. ASCII characters other than 'A', 'C', 'G', 'T', 'a', 'c', 'g', and 't' are considered ambiguous bases. Non-ASCII characters are rejected. The minimum allowed sequence length is 4 bases.

required

window_size

int

The length of the window used by symmetric DUST algorithm. The minimum allowed value is 4.

64

score_threshold

int

Score threshold for identifying low-complexity regions. Higher values result in fewer regions being masked.

20

Attributes:

Name Type Description
sequence str

The nucleotide sequence that was provided as input.

window_size int

The length of the window used by symmetric DUST algorithm.

score_threshold int

Score threshold for identifying low-complexity regions.

intervals tuple of tuples

A tuple of tuples representing the start and end positions of the low-complexity regions identified in the sequence.

n_masked_bases int

The total number of bases that were masked.

Methods:

Name Description
mask

Returns the sequence with low-complexity regions masked.

Raises:

Type Description
ValueError

If the input parameters violate the following constraints:

  • sequence contains a non-ASCII character
  • sequence length < 4
  • window_size < 4
TypeError

If the input parameters are not of the expected type.

OverflowError

If window_size or score_threshold cannot be represented by its unsigned integer type, including negative or excessively large values.

Methods:

mask

mask(hard: bool = False) -> str

Return the sequence with low-complexity regions masked.

Parameters:

Name Type Description Default
hard
bool

If True, low-complexity regions will be masked with 'N' (for nucleotide sequences) or 'X' (for protein sequences). Otherwise, residues within low-complexity regions are converted to lowercase (i.e., soft-masking).

False

Returns:

Type Description
str

The masked sequence.

pydustmasker.LongdustMasker

Identify and mask low-complexity nucleotide regions using the Longdust algorithm.

Parameters:

Name Type Description Default

sequence

str

Nucleotide sequence to process. ASCII characters other than 'A', 'C', 'G', 'T', 'a', 'c', 'g', and 't' are treated as ambiguous bases. Non-ASCII characters are rejected. Must contain at least kmer + 1 bases.

required

window_size

int

Maximum sliding-window size. Larger windows can detect longer repeats but use more memory. Must be in the range [kmer + 1, 65535].

5000

score_threshold

float

Score threshold for identifying low-complexity regions. Higher values result in fewer regions being masked. Must be finite and greater than 0.0.

0.6

kmer

int

The k-mer length used by the Longdust algorithm. Must be in the range [1, 12].

7

gc

(None, 'auto')

GC content for bias correction. If None (default), assume a uniform base composition. If 'auto', compute the GC content from the unambiguous bases ('A', 'C', 'G', and 'T', case-insensitive) of the input sequence, or use 0.0 if there are none. If a float, it must be between 0.0 and 1.0.

None

xdrop

int or None

Maximum allowable score drop for X-drop extension termination. During backward scanning, extension continues while (max_score - current_score) does not exceed (score_threshold * xdrop). Once the score drops by more than this amount from the peak score observed during the scan, extension stops immediately. Lower values enforce stricter extensions and tighter boundaries, potentially truncating part of the low-complexity region, whereas higher values allow more permissive extensions and looser boundaries, which may include non-low-complexity regions. If set to None, X-drop is disabled.

50

min_start_cnt

int

Minimum k-mer frequency to start a backward scan. Must be in [2, 65535]. Lower values are more sensitive but slower.

3

approx

bool

If True, use approximate mode for guaranteed O(L*w) time complexity. In this mode, only the first candidate starting position is examined during backward scanning, rather than checking all candidates to find the optimal one.

False

forward_only

bool

If True, only process the forward strand. Otherwise, both strands are processed.

False

Attributes:

Name Type Description
sequence str

The nucleotide sequence that was provided as input.

window_size int

The size of the sliding window used to scan for low-complexity regions.

score_threshold float

Score threshold for determining low-complexity regions.

kmer int

k-mer length.

gc {None, 'auto'} or float

Option used for GC bias correction. Can be None (a uniform base composition was assumed), 'auto' (GC was computed from the unambiguous bases of the input sequence), or a float between 0.0 and 1.0 (provided by the user).

xdrop int or None

Multiplier used to derive the X-drop extension threshold.

min_start_cnt int

Minimum k-mer frequency to trigger backward scan.

approx bool

Whether approximate mode was enabled.

forward_only bool

Whether only the forward strand was processed.

intervals tuple of tuples

A tuple of tuples representing the start and end positions of the low-complexity regions identified in the sequence.

n_masked_bases int

The total number of bases that were masked.

Methods:

Name Description
mask

Returns the sequence with low-complexity regions masked.

Raises:

Type Description
ValueError

If the input parameters violate the following constraints:

  • sequence contains a non-ASCII character
  • sequence length < kmer + 1
  • window_size is not in [kmer + 1, 65535]
  • kmer is not in [1, 12]
  • score_threshold is non-finite or not greater than 0.0
  • min_start_cnt < 2
  • xdrop is 0
  • gc is invalid (not 'auto', None, or float between 0.0 and 1.0)
TypeError

If the input parameters are not of the expected type.

OverflowError

If an integer cannot be represented by its parameter type, including a negative value or min_start_cnt above 65535.

Methods:

mask

mask(hard: bool = False) -> str

Return the sequence with low-complexity regions masked.

Parameters:

Name Type Description Default
hard
bool

If True, low-complexity regions will be masked with 'N' (for nucleotide sequences) or 'X' (for protein sequences). Otherwise, residues within low-complexity regions are converted to lowercase (i.e., soft-masking).

False

Returns:

Type Description
str

The masked sequence.

pydustmasker.TantanMasker

Identify and mask low-complexity and short-period tandem repeats using tantan.

Parameters:

Name Type Description Default

sequence

str

The nucleotide or protein sequence to be processed. When protein is False, ASCII characters other than 'A', 'C', 'G', and 'T' (case-insensitive) are treated as ambiguous residues. When protein is True, ASCII characters other than the standard 20 amino acids (case-insensitive) are considered ambiguous. Non-ASCII characters are rejected in either mode. Must contain at least one character.

required

protein

bool

Determines whether the input is treated as a protein sequence (True) or as a nucleotide sequence (False).

False

repeat_start

float

Probability of transitioning from the background state to a repeat state. Must be in the range [0.0, 1.0).

0.005

repeat_end

float

Probability of ending a repeat (transitioning from a repeat state back to the background). Must be in the range [0.0, 1.0].

0.05

decay

float

Probability decay from one period offset to the next. Must be in the range (0.0, 1.0] and be a normal finite number.

0.9

max_period

int or None

Maximum repeat period (cycle length) to consider. If None (default), it resolves to 50 for protein sequences and 100 for nucleotide sequences. Must be in the range [1, 2147483647].

None

gap_open

int

Cost of opening a gap within a repeat.

0

gap_extend

int or None

Cost of extending a gap by one more letter. If None (default), gaps within repeats are disabled. If set, must be greater than 0.

None

score_threshold

float

Posterior probability threshold at or above which a position is considered part of a repeat. Used by intervals and mask. Has no effect on probabilities or repeat_units. Must be in the range [0.0, 1.0].

0.5

min_copy_number

float

Minimum copy-number estimate from the Viterbi path for a tandem repeat tract to be reported by repeat_units. Selecting a period does not recompute this estimate from the selected unit. Must be finite and non-negative. Has no effect on intervals, mask, and probabilities.

2.0

Attributes:

Name Type Description
sequence str

The sequence that was provided as input.

protein bool

Whether the sequence was treated as a protein sequence.

repeat_start float

Probability of a repeat starting per position.

repeat_end float

Probability of a repeat ending per position.

decay float

Probability decay per unit increase in repeat period.

max_period int

Maximum tandem repeat period (in letters) considered. Resolved from None to 50 (protein) or 100 (nucleotide) when not provided explicitly.

gap_open int

Cost of opening a gap within a repeat.

gap_extend int or None

Cost of extending a gap by one more letter, or None if gaps within repeats are disabled.

score_threshold float

Posterior probability threshold at or above which a position is considered part of a repeat by intervals and mask. Has no effect on probabilities or repeat_units.

min_copy_number float

Minimum copy number used to filter the tracts returned by repeat_units.

intervals tuple of tuples

An immutable tuple of tuples representing the start and end positions of the tandem repeat regions identified in the sequence, based on per-position posterior probabilities.

n_masked_bases int

The total number of bases/residues that were masked.

probabilities tuple of float

The per-position posterior probability of being part of a tandem repeat, one value per character of sequence, in order. Computed once at construction time.

Methods:

Name Description
mask

Returns the sequence with tandem repeat regions masked.

repeat_units

Returns the consensus tandem repeat unit(s), optionally for a selected period, identified via a Viterbi decode independent of intervals.

Raises:

Type Description
ValueError

If the input parameters violate the following constraints:

  • sequence is empty
  • sequence contains a non-ASCII character
  • repeat_start is not in [0.0, 1.0)
  • repeat_end is not in [0.0, 1.0]
  • decay is not a normal finite number in (0.0, 1.0]
  • score_threshold is not in [0.0, 1.0]
  • max_period is not in [1, 2147483647]
  • gap_extend is 0
  • the combined repeat/gap probabilities form an invalid distribution (i.e. repeat_end + 2 * first_gap_prob > 1.0, where the gap probabilities are derived from gap_open and gap_extend). Raising gap_open or gap_extend lowers first_gap_prob, so this is resolved by increasing them or by lowering repeat_end.
  • min_copy_number is not finite, or is negative
TypeError

If the input parameters are not of the expected type.

OverflowError

If max_period, gap_open, or gap_extend cannot be represented by its unsigned integer type, including negative or excessively large values.

Methods:

mask

mask(hard: bool = False) -> str

Return the sequence with low-complexity regions masked.

Parameters:

Name Type Description Default
hard
bool

If True, low-complexity regions will be masked with 'N' (for nucleotide sequences) or 'X' (for protein sequences). Otherwise, residues within low-complexity regions are converted to lowercase (i.e., soft-masking).

False

Returns:

Type Description
str

The masked sequence.

repeat_units

repeat_units(period: int | None = None) -> tuple[tuple[str, int, int, float], ...]

Return consensus tandem repeat units from an independent Viterbi decode.

The decoded tract boundaries can differ from intervals.

Parameters:

Name Type Description Default
period
int or None

Repeat period to select from the candidates on the decoded Viterbi path. If None (default), the most frequent period in each tract is selected. Must be in the range [1, max_period]. Tracts without candidates of the requested period are omitted.

None

Returns:

Type Description
tuple of (str, int, int, float)

One (unit, start, end, copy_number) tuple per tract, sorted by start. Gaps can make copy_number differ from tract length divided by unit length. Tracts below min_copy_number are omitted. Ambiguous letters in units are reported as 'N' ('X' for protein).

Raises:

Type Description
ValueError

If period is not in the range [1, max_period].

TypeError

If period is not an integer or None.

OverflowError

If period is negative or too large to fit in an unsigned integer.