amplifyp 1.24.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. amplifyp/__init__.py +37 -0
  2. amplifyp/__main__.py +27 -0
  3. amplifyp/amplicon.py +310 -0
  4. amplifyp/assets/favicon.png +0 -0
  5. amplifyp/assets/fonts/RobotoMono-Regular.ttf +0 -0
  6. amplifyp/assets/icon.ico +0 -0
  7. amplifyp/assets/icon.png +0 -0
  8. amplifyp/assets/images/favicon.png +0 -0
  9. amplifyp/assets/images/icon.png +0 -0
  10. amplifyp/dimer.py +331 -0
  11. amplifyp/dir_idx.py +230 -0
  12. amplifyp/dna.py +515 -0
  13. amplifyp/errors.py +293 -0
  14. amplifyp/gui/__init__.py +20 -0
  15. amplifyp/gui/app.py +133 -0
  16. amplifyp/gui/colours.py +581 -0
  17. amplifyp/gui/controller.py +606 -0
  18. amplifyp/gui/controllers/__init__.py +22 -0
  19. amplifyp/gui/controllers/navigation.py +273 -0
  20. amplifyp/gui/controllers/theme.py +87 -0
  21. amplifyp/gui/controllers/updater.py +74 -0
  22. amplifyp/gui/logger.py +461 -0
  23. amplifyp/gui/os_paths.py +65 -0
  24. amplifyp/gui/settings.py +588 -0
  25. amplifyp/gui/user_data.py +85 -0
  26. amplifyp/gui/util.py +86 -0
  27. amplifyp/gui/utils/__init__.py +16 -0
  28. amplifyp/gui/utils/data_helpers.py +518 -0
  29. amplifyp/gui/utils/gui_helpers.py +492 -0
  30. amplifyp/gui/utils/system.py +438 -0
  31. amplifyp/gui/views/__init__.py +39 -0
  32. amplifyp/gui/views/about/__init__.py +20 -0
  33. amplifyp/gui/views/about/about_view.py +208 -0
  34. amplifyp/gui/views/designer/__init__.py +38 -0
  35. amplifyp/gui/views/designer/designer_card_helpers.py +167 -0
  36. amplifyp/gui/views/designer/designer_form_base.py +397 -0
  37. amplifyp/gui/views/designer/designer_view_base.py +335 -0
  38. amplifyp/gui/views/designer/progress_tracker.py +198 -0
  39. amplifyp/gui/views/designer_1d/__init__.py +26 -0
  40. amplifyp/gui/views/designer_1d/designer_1d_form.py +240 -0
  41. amplifyp/gui/views/designer_1d/designer_1d_view.py +773 -0
  42. amplifyp/gui/views/designer_1d/dismissible_self_dimer_card.py +127 -0
  43. amplifyp/gui/views/designer_1d/primer_item_card.py +158 -0
  44. amplifyp/gui/views/designer_1d/quality_bar_chart.py +115 -0
  45. amplifyp/gui/views/designer_2d/__init__.py +28 -0
  46. amplifyp/gui/views/designer_2d/designer_2d_form.py +378 -0
  47. amplifyp/gui/views/designer_2d/designer_2d_view.py +434 -0
  48. amplifyp/gui/views/designer_2d/dismissible_2d_card.py +318 -0
  49. amplifyp/gui/views/designer_2d/grid_2d_results.py +487 -0
  50. amplifyp/gui/views/dimer/__init__.py +20 -0
  51. amplifyp/gui/views/dimer/dimer_card.py +202 -0
  52. amplifyp/gui/views/dimer/dimer_view.py +141 -0
  53. amplifyp/gui/views/header.py +319 -0
  54. amplifyp/gui/views/input/__init__.py +20 -0
  55. amplifyp/gui/views/input/events.py +261 -0
  56. amplifyp/gui/views/input/input_view.py +408 -0
  57. amplifyp/gui/views/input/layout.py +87 -0
  58. amplifyp/gui/views/input/primer/__init__.py +20 -0
  59. amplifyp/gui/views/input/primer/action_controller.py +504 -0
  60. amplifyp/gui/views/input/primer/clipboard.py +161 -0
  61. amplifyp/gui/views/input/primer/coordinator.py +156 -0
  62. amplifyp/gui/views/input/primer/file_manager.py +208 -0
  63. amplifyp/gui/views/input/primer/header.py +205 -0
  64. amplifyp/gui/views/input/primer/info_panel.py +261 -0
  65. amplifyp/gui/views/input/primer/input.py +500 -0
  66. amplifyp/gui/views/input/primer/layout_manager.py +162 -0
  67. amplifyp/gui/views/input/primer/list.py +204 -0
  68. amplifyp/gui/views/input/primer/row.py +509 -0
  69. amplifyp/gui/views/input/primer/toolbar.py +121 -0
  70. amplifyp/gui/views/input/primer/validation.py +181 -0
  71. amplifyp/gui/views/input/template/__init__.py +20 -0
  72. amplifyp/gui/views/input/template/casing.py +69 -0
  73. amplifyp/gui/views/input/template/file_manager.py +69 -0
  74. amplifyp/gui/views/input/template/formatter.py +220 -0
  75. amplifyp/gui/views/input/template/input.py +633 -0
  76. amplifyp/gui/views/pcr/__init__.py +20 -0
  77. amplifyp/gui/views/pcr/amplicon_drawing.py +367 -0
  78. amplifyp/gui/views/pcr/dismissible_detail_card.py +90 -0
  79. amplifyp/gui/views/pcr/pcr_diagram_panel.py +492 -0
  80. amplifyp/gui/views/pcr/pcr_layout.py +239 -0
  81. amplifyp/gui/views/pcr/pcr_view.py +370 -0
  82. amplifyp/gui/views/pcr/primer_drawing.py +589 -0
  83. amplifyp/gui/views/settings/__init__.py +40 -0
  84. amplifyp/gui/views/settings/appearance_tile.py +217 -0
  85. amplifyp/gui/views/settings/designer_1d_tile.py +103 -0
  86. amplifyp/gui/views/settings/designer_2d_tile.py +114 -0
  87. amplifyp/gui/views/settings/diagnostics_tile.py +295 -0
  88. amplifyp/gui/views/settings/dimer_tile.py +132 -0
  89. amplifyp/gui/views/settings/general_tile.py +385 -0
  90. amplifyp/gui/views/settings/primer_list_tile.py +128 -0
  91. amplifyp/gui/views/settings/replication_tile.py +166 -0
  92. amplifyp/gui/views/settings/score_table.py +196 -0
  93. amplifyp/gui/views/settings/settings_view.py +477 -0
  94. amplifyp/gui/views/settings/tm_tile.py +129 -0
  95. amplifyp/main.py +154 -0
  96. amplifyp/melting.py +345 -0
  97. amplifyp/origin.py +246 -0
  98. amplifyp/pcr.py +158 -0
  99. amplifyp/primer_designer_1d.py +314 -0
  100. amplifyp/primer_designer_2d.py +469 -0
  101. amplifyp/py.typed +0 -0
  102. amplifyp/repliconf.py +418 -0
  103. amplifyp/settings.py +559 -0
  104. amplifyp-1.24.1.dist-info/METADATA +264 -0
  105. amplifyp-1.24.1.dist-info/RECORD +108 -0
  106. amplifyp-1.24.1.dist-info/WHEEL +4 -0
  107. amplifyp-1.24.1.dist-info/entry_points.txt +2 -0
  108. amplifyp-1.24.1.dist-info/licenses/LICENSE +674 -0
amplifyp/__init__.py ADDED
@@ -0,0 +1,37 @@
1
+ # Copyright (C) 2026 AmplifyP Contributors
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ """AmplifyP - A Python package for simulating DNA amplification (PCR).
17
+
18
+ This package provides tools to simulate Polymerase Chain Reaction (PCR)
19
+ experiments. It includes classes for handling DNA sequences, primers,
20
+ replication configurations, and calculating binding statistics such as
21
+ primability and stability.
22
+ """
23
+
24
+ __version__ = "1.24.1"
25
+
26
+ from .amplicon import Amplicon
27
+ from .dna import DNA, DNAType, Primer
28
+ from .pcr import PCR
29
+
30
+ __all__ = [
31
+ "DNA",
32
+ "PCR",
33
+ "Amplicon",
34
+ "DNAType",
35
+ "Primer",
36
+ "__version__",
37
+ ]
amplifyp/__main__.py ADDED
@@ -0,0 +1,27 @@
1
+ # Copyright (C) 2026 AmplifyP Contributors
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+ """Entry point for python -m amplifyp."""
16
+
17
+ import sys
18
+ import traceback
19
+
20
+ from amplifyp.main import cli
21
+
22
+ if __name__ == "__main__": # pragma: no cover
23
+ try:
24
+ cli()
25
+ except Exception:
26
+ traceback.print_exc()
27
+ sys.exit(1)
amplifyp/amplicon.py ADDED
@@ -0,0 +1,310 @@
1
+ # Copyright (C) 2026 AmplifyP Contributors
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ """Amplicon-related classes for AmplifyP."""
17
+
18
+ from dataclasses import dataclass
19
+ from typing import ClassVar
20
+
21
+ from .dna import DNA, DNADirection, DNAType, Primer
22
+ from .errors import (
23
+ DuplicateRepliconfError,
24
+ InvalidAmpliconRangeError,
25
+ InvalidEndDirectionError,
26
+ InvalidIndexOrderError,
27
+ InvalidStartDirectionError,
28
+ TemplateMismatchError,
29
+ )
30
+ from .repliconf import DirIdx, Repliconf
31
+
32
+
33
+ @dataclass(slots=True, frozen=True)
34
+ class Amplicon:
35
+ """A class representing a DNA amplification product (Amplicon).
36
+
37
+ An amplicon is defined by the DNA sequence resulting from a PCR reaction,
38
+ bounded by the forward and reverse primers. It stores metadata about
39
+ the primers involved and the genomic location of the product.
40
+
41
+ Attributes:
42
+ product (DNA): The full DNA sequence of the amplicon.
43
+ fwd_origin (Primer): The primer that initiated the forward strand
44
+ synthesis.
45
+ rev_origin (Primer): The primer that initiated the reverse strand
46
+ synthesis.
47
+ start (DirIdx): The starting index of the amplicon on the template DNA.
48
+ end (DirIdx): The ending index of the amplicon on the template DNA.
49
+ q_score (float): A calculated quality score for the amplicon.
50
+ circular (bool): Whether the amplicon is circular.
51
+ """
52
+
53
+ _Q_SCORE_THRESHOLDS: ClassVar = (
54
+ (300, "good", " amplification"),
55
+ (700, "okay", " amplification"),
56
+ (1500, "moderate", " amplification"),
57
+ (
58
+ 4000,
59
+ "weak",
60
+ " amplification — might be visible on an agarose gel",
61
+ ),
62
+ (
63
+ float("inf"),
64
+ "very weak",
65
+ " amplification — probably not visible on an agarose gel",
66
+ ),
67
+ )
68
+
69
+ product: DNA
70
+ fwd_origin: Primer
71
+ rev_origin: Primer
72
+ start: DirIdx
73
+ end: DirIdx
74
+ q_score: float
75
+ circular: bool
76
+
77
+ def __post_init__(self) -> None:
78
+ """Validate the consistency of the amplicon indices.
79
+
80
+ Raises:
81
+ ValueError: If `start` is not forward, `end` is not reverse, or
82
+ if `end` index precedes or equals `start` index on linear DNA.
83
+ """
84
+ if self.start.direction != DNADirection.FWD:
85
+ raise InvalidStartDirectionError()
86
+ if self.end.direction != DNADirection.REV:
87
+ raise InvalidEndDirectionError()
88
+ if (self.start.index >= self.end.index) and not self.circular:
89
+ raise InvalidIndexOrderError()
90
+
91
+ def q_score_report_str(self, verbose: bool = False) -> str:
92
+ """Generate textual report based on the amplicon q-score.
93
+
94
+ Uses a set of predefined thresholds to categorise the quality score
95
+ into descriptive strings ranging from "good" to "very weak".
96
+
97
+ Args:
98
+ verbose (bool): Whether to return verbose description of the
99
+ q-score.
100
+
101
+ Returns:
102
+ str: The textual report describing the amplification quality.
103
+ """
104
+ for limit, desc, verbose_suffix in self._Q_SCORE_THRESHOLDS:
105
+ if self.q_score < limit:
106
+ suffix = verbose_suffix if verbose else ""
107
+ circ = " (Circular)" if self.circular else ""
108
+ return f"{desc}{suffix}{circ}"
109
+
110
+ return "" # pragma: no cover
111
+
112
+
113
+ class AmpliconGenerator:
114
+ """A generator for predicting PCR amplicons from a template.
115
+
116
+ This class manages a list of replication configurations (Repliconfs)
117
+ associated with a single DNA template. It simulates the PCR process by
118
+ finding valid combinations of forward and reverse priming sites that could
119
+ produce an amplicon.
120
+
121
+ Attributes:
122
+ template (DNA): The DNA sequence used as the template for amplification.
123
+ repliconfs (list[Repliconf]): A list of `Repliconf` objects, each
124
+ representing a primer and its binding properties on the template.
125
+ """
126
+
127
+ def __init__(self, template: DNA) -> None:
128
+ """Initialise an AmpliconGenerator.
129
+
130
+ Args:
131
+ template (DNA): The template DNA sequence.
132
+ """
133
+ self.template = template
134
+ self.repliconfs: list[Repliconf] = []
135
+ self._repliconf_set: set[Repliconf] = set()
136
+
137
+ def add_repliconf(self, repliconf: Repliconf) -> None:
138
+ """Add a replication configuration to the generator.
139
+
140
+ Args:
141
+ repliconf (Repliconf): The configuration to add.
142
+
143
+ Raises:
144
+ ValueError: If the `repliconf` uses a different template than the
145
+ generator.
146
+ DuplicateRepliconfError: If the `repliconf` has already been added.
147
+ """
148
+ if self.template != repliconf.template:
149
+ raise TemplateMismatchError()
150
+
151
+ if repliconf in self._repliconf_set:
152
+ raise DuplicateRepliconfError()
153
+
154
+ self.repliconfs.append(repliconf)
155
+ self._repliconf_set.add(repliconf)
156
+
157
+ def remove_repliconf(self, repliconf: Repliconf) -> None:
158
+ """Remove a replication configuration from the generator.
159
+
160
+ Args:
161
+ repliconf (Repliconf): The configuration to remove.
162
+
163
+ Raises:
164
+ ValueError: If the `repliconf` is not present in the generator.
165
+ """
166
+ self.repliconfs.remove(repliconf)
167
+ self._repliconf_set.remove(repliconf)
168
+
169
+ def get_amplicon_quality_score(
170
+ self,
171
+ fwd_conf: Repliconf,
172
+ rev_conf: Repliconf,
173
+ start: DirIdx,
174
+ end: DirIdx,
175
+ length: int,
176
+ ) -> float:
177
+ """Calculate a quality score for a potential amplicon.
178
+
179
+ The score is derived from the length of the amplicon and the quality
180
+ scores of the forward and reverse priming events.
181
+
182
+ Args:
183
+ fwd_conf (Repliconf): The configuration providing the forward
184
+ primer.
185
+ rev_conf (Repliconf): The configuration providing the reverse
186
+ primer.
187
+ start (DirIdx): The start index of the forward primer.
188
+ end (DirIdx): The end index of the reverse primer.
189
+ length (int): The length of the amplicon.
190
+
191
+ Returns:
192
+ float: The calculated quality score.
193
+ """
194
+ fwd_quality = fwd_conf.origin(start).quality
195
+ rev_quality = rev_conf.origin(end).quality
196
+ return length / (fwd_quality * rev_quality) ** 2
197
+
198
+ def _construct_amplicon_sequence(
199
+ self,
200
+ fwd_conf: Repliconf,
201
+ rev_conf: Repliconf,
202
+ start: DirIdx,
203
+ end: DirIdx,
204
+ ) -> tuple[DNA | None, bool]:
205
+ """Construct the amplicon sequence from start and end points.
206
+
207
+ Handles both linear and circular DNA templates. For linear DNA, ensures
208
+ start < end. For circular DNA, handles wrapping around the origin if
209
+ end < start.
210
+
211
+ Args:
212
+ fwd_conf (Repliconf): Configuration for the forward primer.
213
+ rev_conf (Repliconf): Configuration for the reverse primer.
214
+ start (DirIdx): Start index.
215
+ end (DirIdx): End index.
216
+
217
+ Returns:
218
+ tuple[DNA | None, bool]: A tuple containing the constructed DNA
219
+ sequence (or None if the range is invalid for linear DNA) and
220
+ a boolean indicating if the product is circular.
221
+
222
+ Raises:
223
+ InvalidAmpliconRangeError: If the start index equals the end
224
+ index on a linear DNA template.
225
+ """
226
+ if start < end:
227
+ # Linear DNA template branch
228
+ seq = (
229
+ fwd_conf.primer
230
+ + self.template[start:end]
231
+ + rev_conf.rev_comp_primer
232
+ )
233
+ return seq, False
234
+
235
+ if self.template.type == DNAType.CIRCULAR:
236
+ # Circular DNA handling
237
+ seq = (
238
+ fwd_conf.primer
239
+ + self.template[start:]
240
+ + self.template[:end]
241
+ + rev_conf.rev_comp_primer
242
+ )
243
+ return seq, True
244
+
245
+ if (start > end) and (self.template.type == DNAType.LINEAR):
246
+ # Not possible on linear DNA
247
+ return None, False
248
+
249
+ raise InvalidAmpliconRangeError()
250
+
251
+ def get_amplicons(self) -> list[Amplicon]:
252
+ """Generate all possible amplicons based on added configurations.
253
+
254
+ Triggers the search for origins in all added `Repliconf` objects (if
255
+ not already searched). Then, collects all forward and reverse origins
256
+ and iterates through their Cartesian product to identify valid
257
+ amplicon combinations.
258
+
259
+ Returns:
260
+ list[Amplicon]: A list of all generated `Amplicon` objects sorted
261
+ by discovery order.
262
+ """
263
+ amplicons: list[Amplicon] = []
264
+
265
+ # Ensure all repliconfs are searched and collect origins
266
+ all_fwd_origins: list[tuple[Repliconf, DirIdx]] = []
267
+ all_rev_origins: list[tuple[Repliconf, DirIdx]] = []
268
+
269
+ for repliconf in self.repliconfs:
270
+ if not repliconf.searched:
271
+ repliconf.search()
272
+ # Collect (conf, index) pairs
273
+ for start in repliconf.origin_db.fwd:
274
+ all_fwd_origins.append((repliconf, start))
275
+ for end in repliconf.origin_db.rev:
276
+ all_rev_origins.append((repliconf, end))
277
+
278
+ # Iterate over combinations
279
+ is_circular = self.template.type == DNAType.CIRCULAR
280
+ for fwd_conf, start in all_fwd_origins:
281
+ for rev_conf, end in all_rev_origins:
282
+ if not is_circular and start.index >= end.index:
283
+ continue
284
+
285
+ seq, circular = self._construct_amplicon_sequence(
286
+ fwd_conf, rev_conf, start, end
287
+ )
288
+
289
+ if seq is None: # pragma: no cover
290
+ continue
291
+
292
+ q_score = self.get_amplicon_quality_score(
293
+ fwd_conf,
294
+ rev_conf,
295
+ start,
296
+ end,
297
+ (len(seq) - len(fwd_conf.primer) - len(rev_conf.primer)),
298
+ )
299
+ amplicons.append(
300
+ Amplicon(
301
+ seq,
302
+ fwd_conf.primer,
303
+ rev_conf.primer,
304
+ start,
305
+ end,
306
+ q_score,
307
+ circular,
308
+ )
309
+ )
310
+ return amplicons
Binary file
Binary file
Binary file
Binary file
Binary file