ssw.alignmentmgr

Alignment Manager Cython wrapper for ssw library code.

NOTE: See this link for a info on the CIGAR format: What is a CIGAR?

Refer to Wiki Smith–Waterman_algorithm to understand Smith-Waterman scoring

class ssw.alignmentmgr.AlignmentMgr

Class to manage SSW-based alignment

read

Read sequence python string or bytes-string

reference

Reference sequence python string or bytes-string

match_score

0 to 255 value for scoring matches

mismatch_penalty

0 to 255 value penalty for mismatches

align(gap_open, gap_extension, start_idx, end_idx, bitwise_flag, distance_cutoff, score_cutoff)

Align a read to the reference with optional index offseting

Returns a dictionary no matter what as align_c can’t return NULL

Parameters:
  • gap_open (int) – Penalty for gap_open. default 3

  • gap_extension (int) – Penalty for gap_extension. default 1

  • start_idx (int) – Index to start search. Default 0

  • end_idx (int) – Index to end search (trying to avoid a target region). Default 0 means use whole reference length

  • bitwise_flag (int) – Flag using a member of BitwiseAlignmentFlag

  • distance_cutoff (int) – Filter by index start to end distances less than this value. see BitwiseAlignmentFlag docs for details bitwise_flag=BitwiseAlignmentFlag.distance_filter

  • score_cutoff (int) – Filter by fits with a score greater score value cutoff see BitwiseAlignmentFlag docs for details bitwise_flag=BitwiseAlignmentFlag.score_filter

Return type:

Alignment

Returns:

ssw.alignmenttuple.Alignment instance

Raises:
  • ValueError – Negative indexing not supported

  • ValueErrorstart_idx or end_idx error

  • ValueError – Call set_reference() first

build_dna_score_matrix()

Mismatch_penalty should be positive

The score matrix looks like:

A, C, G, T, N

score_matrix = { 2, -2, -2, -2, 0, // A

-2, 2, -2, -2, 0, // C -2, -2, 2, -2, 0, // G -2, -2, -2, 2, 0, // T

0, 0, 0, 0, 0 // N

}

Hard coded to a 5 x 5 matrix so this should not be called externally as of now

Uses:

match_score: Match score mismatch_penalty: Mismatch penalty score_matrix: Pointer to matrix to populate

match_score

0 to 255 value for scoring matches

mismatch_penalty

0 to 255 penalty value for scoring mismatches

printResult(result, start_idx)

Deprecated since version 1.0.0.: Choose print_result() method instead

print_result(result, start_idx)

Rebuild an s_align struct from a result dictionary so as to be able to call ssw terminal print functions

Parameters:
Raises:

OSError – Memory allocation issue

setRead(read)

Deprecated since version 1.0.0.: Choose set_read() method instead

setReference(reference)

Deprecated since version 1.0.0.: Choose set_reference() method instead

set_read(read)

Set the query read string

Parameters:

read (Union[str, bytes]) – String-like (str or bytestring) that represents the read. Must be set for a call to align()

set_reference(reference)

Set the query reference string.

Parameters:

reference (Union[str, bytes]) – String-like (str or bytestring) that represents the reference sequence. Must be set a call to align()

class ssw.alignmentmgr.BitwiseAlignmentFlag

bitwise_flag (from high- to low-bit) for AlignmentMgr.align()

best_idxs_no_cigar

Bit 5. When set as 1, ssw_align will return the best alignment beginning position; NOTE: this is setting bitwise_flag == 8

distance_filter

Bit 6. When set as 1:

if (
    ((reference_end - reference_start) < distance_filter) and
    ((read_end - read_start) < distance_filter)
)

(whatever bit 5 is set) the function will return the best alignment beginning position and cigar; NOTE: this is setting bitwise_flag == 4

score_filter

Bit 7. When set as 1, if the best alignment_score >= score_filter, (whatever bit 5 is set as) the function will return the best alignment beginning position and cigar; NOTE: this is setting bitwise_flag == 2

best_idxs

Bit 8. When set as 1, (whatever bit 5, 6 or 7 are set as) the function will always return the best alignment beginning position and cigar. NOTE: this is setting bitwise_flag = 1

end_idxs_only_no_cigar

When bitwise_flag == 0, only the optimal and sub-optimal scores and the optimal alignment ending position will be returned.

ssw.alignmentmgr.force_align(read, reference, force_overhang=False, aligner=None)

Enforces no gaps by raising the gap_open penalty

Parameters:
  • read (Union[str, bytes]) – Read sequence python string or bytes-string

  • reference (Union[str, bytes]) – Reference sequence python string or bytes-string

  • force_overhang (bool) – Make sure only one end overhangs

  • aligner (Optional[AlignmentMgr]) – pass an existing AlignmentMgr object

Return type:

Alignment

Returns:

ssw.alignmenttuple.Alignment result

Raises:
  • ValueError – No solution found

  • ValueError – Read does not align to one overhang

ssw.alignmentmgr.format_force_align(read, reference, alignment, do_print=False)

Does not truncate strings. Optionally prints these formatted strings

Parameters:
  • read (Union[str, bytes]) – Read sequence python string or bytes-string

  • reference (Union[str, bytes]) – Reference sequence python string or bytes-string

  • alignment (Alignment) – ssw.alignmenttuple.Alignment named tuple

  • do_print (bool) – Default is False. If True, print output

Return type:

Tuple[str, str]

Returns:

(<reference output>, <read output>)