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 forgap_open
. default 3gap_extension (
int
) – Penalty forgap_extension
. default 1start_idx (
int
) – Index to start search. Default 0end_idx (
int
) – Index to end search (trying to avoid a target region). Default 0 means use whole reference lengthbitwise_flag (
int
) – Flag using a member ofBitwiseAlignmentFlag
distance_cutoff (
int
) – Filter by index start to end distances less than this value. seeBitwiseAlignmentFlag
docs for detailsbitwise_flag=BitwiseAlignmentFlag.distance_filter
score_cutoff (
int
) – Filter by fits with a score greater score value cutoff seeBitwiseAlignmentFlag
docs for detailsbitwise_flag=BitwiseAlignmentFlag.score_filter
- Return type:
- Returns:
ssw.alignmenttuple.Alignment
instance- Raises:
ValueError – Negative indexing not supported
ValueError –
start_idx
orend_idx
errorValueError – 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 scoremismatch_penalty
: Mismatch penaltyscore_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:
result (
Alignment
) –ssw.alignmenttuple.Alignment
containing the result from a call toalign()
start_idx (
int
) – index to start printing from. defaults to 0
- 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
- class ssw.alignmentmgr.BitwiseAlignmentFlag
bitwise_flag
(from high- to low-bit) forAlignmentMgr.align()
- best_idxs_no_cigar
Bit 5. When set as 1,
ssw_align
will return the best alignment beginning position; NOTE: this is settingbitwise_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 settingbitwise_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-stringreference (
Union
[str
,bytes
]) – Reference sequence python string or bytes-stringforce_overhang (
bool
) – Make sure only one end overhangsaligner (
Optional
[AlignmentMgr
]) – pass an existingAlignmentMgr
object
- Return type:
- 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-stringreference (
Union
[str
,bytes
]) – Reference sequence python string or bytes-stringalignment (
Alignment
) –ssw.alignmenttuple.Alignment
named tupledo_print (
bool
) – Default isFalse
. IfTrue
, print output
- Return type:
Tuple
[str
,str
]- Returns:
(<reference output>, <read output>)