agglovar.align.score

Alignment routines.

Attributes

AFFINE_SCORE_GAP

Default affine gap scores.

AFFINE_SCORE_MATCH

Default match score.

AFFINE_SCORE_MISMATCH

Default mismatch score.

AFFINE_SCORE_TS

Default template switch score.

DEFAULT_ALIGN_SCORE_MODEL

Default alignment score model.

Classes

AffineScoreModel

Affine score model with default values modeled on minimap2 (2.26) default parameters.

ScoreModel

Score model interface.

Functions

get_affine_by_params(→ AffineScoreModel)

Parse a string to get alignment parameters from it.

get_score_model(→ ScoreModel)

Get score model from a string of alignment parameters.

Module Contents

class agglovar.align.score.AffineScoreModel(match: float = AFFINE_SCORE_MATCH, mismatch: float = AFFINE_SCORE_MISMATCH, affine_gap: Iterable[tuple[float, float]] = AFFINE_SCORE_GAP, template_switch: float = AFFINE_SCORE_TS)

Bases: ScoreModel

Affine score model with default values modeled on minimap2 (2.26) default parameters.

Variables:
  • match – Match score.

  • mismatch – Mismatch penalty.

  • affine_gap – An iterable containing tuples of two elements (gap open, gap extend).

  • template_switch – Template switch penalty. If none, defaults to 2x the penalty of a 50 bp gap.

__eq__(other: Any) bool

Determine if this scoremodel is the same as another.

Parameters:

other – Other object.

Returns:

True if this scoremodel is equivalent to other.

__repr__()

Get a string representation of this score model.

gap(n: int = 1) float

Score gap (insertion or deletion).

Compute all affine alignment gap score for each affine segment and return the highest value (least negative).

Parameters:

n – Size of gap.

Returns:

Gap score.

match(n: int = 1) float

Score match.

Parameters:

n – Number of matching bases.

Returns:

Match score.

mismatch(n: int = 1) float

Score mismatch.

Parameters:

n – Number of mismatched bases.

Returns:

Mismatch score.

mismatch_model() Self

Get a mismatch model.

Returns:

A copy of this score model that does not penalize gaps. Used for computing the score of mismatches.

model_param_string() str

Get score parameter string.

Returns:

A parameter string representing this score model.

score_operations(op_arr: numpy.ndarray) float

Sum scores for affine models using a A vectorized implementation.

Parameters:

op_arr – Array of alignment operations (op_code: first column, op_len: second column).

Returns:

Sum of scores for each CIGAR operation.

template_switch() float

Score a template switch.

Returns:

Score for a single template switch.

score_affine_gap: tuple
score_match: float
score_mismatch: float
score_template_switch: float
class agglovar.align.score.ScoreModel

Bases: abc.ABC

Score model interface.

abstractmethod __eq__(other: Any) bool

Determine if this scoremodel is the same as another.

Parameters:

other – Other object.

Returns:

True if this scoremodel is equivalent to other.

abstractmethod __repr__()

Get a string representation of this score model.

abstractmethod gap(n: int = 1) float

Score gap (insertion or deletion).

Compute all affine alignment gap score for each affine segment and return the highest value (least negative).

Parameters:

n – Size of gap.

Returns:

Gap score.

abstractmethod match(n: int = 1) float

Score match.

Parameters:

n – Number of matching bases.

Returns:

Match score.

abstractmethod mismatch(n: int = 1) float

Score mismatch.

Parameters:

n – Number of mismatched bases.

Returns:

Mismatch score.

abstractmethod mismatch_model() Self

Get a mismatch model.

Returns:

A copy of this score model that does not penalize gaps. Used for computing the score of mismatches.

abstractmethod model_param_string() str

Get score parameter string.

Returns:

A parameter string representing this score model.

score(op_code: int | str, op_len: int) float

Score an alignment operation.

Parameters:
  • op_code – Operation code. Can be a symbol (e.g. “=”, “X”, “I”, etc.) or the numeric operation code.

  • op_len – Operation length.

Returns:

Score for this operation or 0.0 if the operation is not scored (S, H, N, and P operations).

score_operations(op_arr: numpy.ndarray) float

Sum scores for affine models using a vectorized implementation.

Parameters:

op_arr – Array of alignment operations (op_code: first column, op_len: second column).

Returns:

Sum of scores for each CIGAR operation.

template_switch() float

Score a template switch.

Returns:

Score for a single template switch.

agglovar.align.score.get_affine_by_params(param_string: str) AffineScoreModel

Parse a string to get alignment parameters from it.

Parameters:

param_string – Parameter string.

Returns:

A configured AffineScoreModel.

agglovar.align.score.get_score_model(param_string: str = None) ScoreModel

Get score model from a string of alignment parameters.

Parameters:

param_string – Parameter string. Can be None or an empty string (default model is used). If the string is an instance of ScoreModel, then the ScoreModel object is returned. Otherwise, the string is parsed and a score model object is returned.

Returns:

A ScoreModel object.

agglovar.align.score.AFFINE_SCORE_GAP = ((4.0, 2.0), (24.0, 1.0))

Default affine gap scores.

agglovar.align.score.AFFINE_SCORE_MATCH = 2.0

Default match score.

agglovar.align.score.AFFINE_SCORE_MISMATCH = 4.0

Default mismatch score.

agglovar.align.score.AFFINE_SCORE_TS = None

Default template switch score.

agglovar.align.score.DEFAULT_ALIGN_SCORE_MODEL = 'affine::match=2.0,mismatch=4.0,gap='

Default alignment score model.