1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# type: ignore[import]
# type: ignore[import]
=
=
"""Result of a pairwise alignment that may contain template switches.
Obtain an instance via :meth:`Aligner.align` or the module-level :func:`align`.
"""
=
"""CIGAR string of the alignment.
Template switch operations are encoded as extended CIGAR tokens.
Returns ``None`` if no valid alignment target was found.
"""
return
"""Dictionary of alignment statistics.
Keys include: ``cost``, ``cost_per_base``, ``duration_seconds``,
``opened_nodes``, ``closed_nodes``, ``template_switch_amount``, and
nested ``result`` and ``sequences`` dicts.
"""
return
"""Compact list of alignment operations.
Each entry is ``(count, op)`` where ``count`` is the repetition count and
``op`` is one of:
- :class:`SimpleAlignmentOp` — a basic edit (match, substitution,
insertion, deletion) in the primary or secondary track.
- :class:`TemplateSwitchEntranceOp` — start of a template switch.
- :class:`TemplateSwitchExitOp` — end of a template switch.
Returns ``None`` if the alignment has no valid target.
"""
=
return None
return
"""Print an ASCII visualisation of template switch jumps to stdout."""
"""Pairwise DNA sequence aligner with template switch detection.
Template switches are short-range translocations where a query region
aligns to a different part of the reference, possibly on the reverse
complement strand. The aligner uses A* search under a configurable
gap-affine cost model.
Parameters
----------
no_ts : bool
Disable template switch detection (plain gap-affine alignment).
Default: ``False``.
min_length_strategy : str
Strategy for enforcing the minimum template switch length.
One of ``"none"``, ``"lookahead"`` (default), ``"preprocess_price"``,
``"preprocess_filter"``, ``"preprocess_lookahead"``.
chaining_strategy : str
A* lower-bound chaining strategy.
One of ``"none"`` (default), ``"lower_bound"``.
total_length_strategy : str
Total template switch length strategy.
One of ``"none"``, ``"maximise"`` (default).
costs : str, optional
Cost configuration as a raw ``.tsa``-format string.
costs_file : str or Path, optional
Path to a ``.tsa`` cost configuration file.
Mutually exclusive with ``costs``.
See ``sample_tsa_config/config.tsa`` for a skeleton.
Examples
--------
Default settings::
aligner = tsalign.Aligner()
Custom cost file::
aligner = tsalign.Aligner(costs_file="sample_tsa_config/config.tsa")
"""
=
: =
=
=
"""Align two DNA sequences, accounting for template switches.
Parameters
----------
reference : str-like
Reference sequence. Any object with a string representation is
accepted (e.g. ``Bio.Seq``).
query : str-like
Query sequence.
reference_name : str
Label for the reference sequence. Default: ``"reference"``.
query_name : str
Label for the query sequence. Default: ``"query"``.
range : AlignmentRange, optional
Coordinate window to align within. When provided, overrides the
individual ``reference_start`` / ``reference_limit`` /
``query_start`` / ``query_limit`` arguments.
reference_start : int, optional
Start position in the reference (inclusive). Default: ``0``.
reference_limit : int, optional
End position in the reference (exclusive). Default: full length.
query_start : int, optional
Start position in the query (inclusive). Default: ``0``.
query_limit : int, optional
End position in the query (exclusive). Default: full length.
cost_limit : int, optional
Abandon the search and return ``None`` if the alignment cost would
exceed this value.
memory_limit : int, optional
Abandon the search and return ``None`` if the number of open A*
nodes exceeds this count.
Returns
-------
Alignment or None
``None`` if no valid alignment was found within the given limits.
"""
=
=
=
=
=
return
"""Align two DNA sequences in a single call.
A convenience wrapper that creates a temporary :class:`Aligner` and
immediately calls :meth:`~Aligner.align`.
Keyword arguments that belong to the aligner (``no_ts``,
``min_length_strategy``, ``chaining_strategy``, ``total_length_strategy``,
``costs``, ``costs_file``) are forwarded to the constructor; all remaining
keyword arguments are forwarded to :meth:`~Aligner.align`.
Returns
-------
Alignment or None
``None`` if no valid alignment was found within the given limits.
Examples
--------
::
result = tsalign.align("ACGTACGT", "ACGACGT")
print(result.cigar())
"""
=
=
return