buttle 0.3.0__tar.gz → 0.4.0__tar.gz

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 (35) hide show
  1. {buttle-0.3.0 → buttle-0.4.0}/PKG-INFO +52 -28
  2. {buttle-0.3.0 → buttle-0.4.0}/README.md +50 -26
  3. {buttle-0.3.0 → buttle-0.4.0}/pyproject.toml +3 -3
  4. {buttle-0.3.0 → buttle-0.4.0}/rust/Cargo.lock +1 -1
  5. {buttle-0.3.0 → buttle-0.4.0}/rust/Cargo.toml +1 -1
  6. {buttle-0.3.0 → buttle-0.4.0}/rust/src/constants.rs +5 -0
  7. {buttle-0.3.0 → buttle-0.4.0}/rust/src/lib.rs +8 -7
  8. {buttle-0.3.0 → buttle-0.4.0}/rust/src/merge.rs +37 -7
  9. {buttle-0.3.0 → buttle-0.4.0}/rust/src/pairwise.rs +26 -7
  10. buttle-0.4.0/src/buttle/__init__.py +17 -0
  11. buttle-0.4.0/src/buttle/buttle_rust.pyi +46 -0
  12. {buttle-0.3.0 → buttle-0.4.0}/src/buttle/cli.py +141 -66
  13. {buttle-0.3.0 → buttle-0.4.0}/src/buttle/comparisons.py +13 -12
  14. {buttle-0.3.0 → buttle-0.4.0}/src/buttle/constants.py +26 -6
  15. buttle-0.4.0/src/buttle/models/alignments.py +90 -0
  16. buttle-0.4.0/src/buttle/models/molecules.py +239 -0
  17. buttle-0.3.0/src/buttle/msa.py → buttle-0.4.0/src/buttle/multiple_alignment.py +147 -110
  18. buttle-0.4.0/src/buttle/pairwise.py +171 -0
  19. buttle-0.4.0/src/buttle/parsers.py +148 -0
  20. {buttle-0.3.0 → buttle-0.4.0}/src/buttle/renderers.py +97 -143
  21. buttle-0.4.0/src/buttle/sequences.py +27 -0
  22. buttle-0.4.0/src/buttle/validation.py +14 -0
  23. buttle-0.3.0/src/buttle/buttle_rust.pyi +0 -38
  24. buttle-0.3.0/src/buttle/decorators.py +0 -30
  25. buttle-0.3.0/src/buttle/models.py +0 -266
  26. buttle-0.3.0/src/buttle/pairwise_align.py +0 -219
  27. buttle-0.3.0/src/buttle/parsers.py +0 -86
  28. buttle-0.3.0/src/buttle/sequences.py +0 -128
  29. {buttle-0.3.0 → buttle-0.4.0}/LICENSE +0 -0
  30. {buttle-0.3.0 → buttle-0.4.0}/rust/src/main.rs +0 -0
  31. {buttle-0.3.0 → buttle-0.4.0}/src/buttle/__main__.py +0 -0
  32. {buttle-0.3.0 → buttle-0.4.0}/src/buttle/dialogs.py +0 -0
  33. {buttle-0.3.0 → buttle-0.4.0}/src/buttle/fonts/JetBrainsMono-Regular.ttf +0 -0
  34. {buttle-0.3.0 → buttle-0.4.0}/src/buttle/fonts/OFL.txt +0 -0
  35. {buttle-0.3.0/src/buttle → buttle-0.4.0/src/buttle/models}/__init__.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: buttle
3
- Version: 0.3.0
4
- Requires-Dist: pillow>=12.3.0
3
+ Version: 0.4.0
4
+ Requires-Dist: pillow>=13.0.0
5
5
  License-File: LICENSE
6
6
  Summary: Command-line utilities for DNA and protein sequence analysis. At your service.
7
7
  License-Expression: BSD-3-Clause
@@ -11,7 +11,7 @@ Project-URL: Homepage, https://github.com/DJV512/Buttle
11
11
  Project-URL: Issues, https://github.com/DJV512/Buttle/issues
12
12
  Project-URL: Repository, https://github.com/DJV512/Buttle
13
13
 
14
- ![Logo](https://raw.githubusercontent.com/DJV512/Buttle/v0.3.0/docs/images/buttle_logo_with_tag.png)
14
+ ![Logo](https://raw.githubusercontent.com/DJV512/Buttle/main/docs/images/buttle_logo_with_tag.png)
15
15
  Buttle was developed as a lightweight collection of bioinformatics utilities for common sequence-analysis tasks, with an emphasis on convenient command-line use. It provides tools for working with DNA and protein sequences, including sequence manipulation, peptide properties, motif searching, pairwise alignment, and multiple sequence alignment.
16
16
 
17
17
  Buttle is currently under active development.
@@ -26,11 +26,14 @@ Buttle is currently under active development.
26
26
 
27
27
  ### DNA sequences
28
28
 
29
- - Transcribe DNA to RNA
30
- - Translate DNA in three reading frames
29
+ - Transcribe to RNA
30
+ - Translate in three reading frames
31
31
  - Generate reverse complements
32
32
  - Calculate GC content
33
- - Pairwise DNA sequence alignment
33
+ - Pairwise sequence alignment from two raw sequence arguments
34
+ - Rust backend by default, with a Python backend available
35
+ - Multiple sequence alignment (MSA) from FASTA files or FASTA-formatted strings
36
+ - Rust backend by default, with a Python backend available
34
37
 
35
38
  ### Protein sequence tools
36
39
  - Calculate protein net charge
@@ -45,14 +48,16 @@ Buttle is currently under active development.
45
48
 
46
49
 
47
50
  ### Rendering
48
- - Display alignments in the terminal (when no `--save` argument provided)
51
+ - Print alignments in the terminal (when no `--save` argument provided)
49
52
  - Generate publication-quality PNG and TIFF alignment images
50
- - Save Pairwise DNA and protein alignments
51
- - Save multiple protein sequence alignments
53
+ - Pairwise DNA and Protein alignments
54
+ - Multiple DNA and Protein sequence alignments
52
55
  - Alignment row length can be tuned with `--wrap`
53
56
  - Argument `--real-ruler` displays residue number based on the first sequence, skipping gaps
54
- - Argument `--diff` displays alignment differences relative to a reference sequence
55
- - MSA optionally adds a consensus sequence with `--consensus`
57
+ - Optionally add a number at which the ruler numbering will start (defaults to 1)
58
+ - Argument `--diff` displays alignment differences relative to a reference sequence (first sequence in FASTA file)
59
+ - Argument `--consensus` optionally adds a consensus sequence to the bottom of an MSA
60
+ - Argument `--tree` displays an average-linkage clustering of pairwise sequence distances, not a phylogenetic reconstruction
56
61
 
57
62
 
58
63
  ## Installation/Requirements
@@ -95,11 +100,20 @@ Or install it into your active Python environment:
95
100
  pip install buttle
96
101
  ```
97
102
 
98
- Buttle's Python modules can then be imported and used directly.
103
+ Buttle's Python modules can also be imported and used directly.
99
104
  ```python
100
105
  from buttle import sequences
101
106
 
102
- # Use functions from the sequences module
107
+ # Access functions from the sequences module
108
+ output = sequences.find_position(sequence, search_string)
109
+ ```
110
+
111
+ For convenience, commonly used classes and functions are also exposed at the package's top level:
112
+ ```python
113
+ from buttle import find_position
114
+
115
+ # Call functions directly without referencing their modules
116
+ output = find_position(sequence, search_string)
103
117
  ```
104
118
 
105
119
  ### Building from source
@@ -219,28 +233,42 @@ GC Content: 46.30
219
233
  $ buttle props adlsykfehyaskgascwedasdkflsdad
220
234
  Charge = -4
221
235
  Molecular Weight = 3357.6
222
- Extinction Coefficient = 8370
236
+ Extinction Coefficient = 8370
223
237
  ```
224
238
 
225
239
  #### Pairwise Alignment of DNA or Protein
226
240
  ```console
227
- $ buttle dna_align atctcatgcgtcgtacgtacgt tgcatgcgtacgtagtcgatgtc
241
+ $ buttle dna_align atctcatgcgtcgtacgtacgt tgcatgcgtacgtagtcgatgtc --diff
228
242
  ```
229
- ![Pairwise DNA Alignment](https://raw.githubusercontent.com/DJV512/Buttle/v0.3.0/docs/images/dna_pairwise_align.png)
243
+ ![Pairwise DNA Alignment](https://raw.githubusercontent.com/DJV512/Buttle/main/docs/images/dna_pairwise_align.png)
230
244
 
231
- #### Multiple Protein Sequence Alignment
232
- Buttle implements a custom progressive multiple protein sequence alignment algorithm using an average-linkage guide tree, BLOSUM62-based scoring, and tunable affine gap open and extension penalties. Optional "X" residues can be used as alignment anchors. Computationally intensive operations are accelerated using a Rust extension.
245
+ #### Multiple Sequence Alignment
246
+ Buttle implements a custom progressive multiple sequence alignment algorithm using an average-linkage guide tree with tunable affine gap open and extension penalties. For Proteins, Buttle uses BLOSUM62-based scoring. Optional "X" residues can be used as alignment anchors. For DNA, Buttle uses fixed base match and mismatch scoring. Computationally intensive operations are accelerated using a Rust extension.
233
247
 
234
248
 
235
249
  ```console
236
- $ buttle msa docs/examples/synthetic_example_proteins.fasta --save docs/images/synthetic_alignment.png --diff --wrap 100
250
+ $ buttle msa docs/examples/synthetic_example_proteins.fasta --save docs/images/synthetic_alignment_protein.png --diff --wrap 100
237
251
  ```
238
- ![Multiple Protein Sequence Alignment](https://raw.githubusercontent.com/DJV512/Buttle/v0.3.0/docs/images/synthetic_alignment.png)
252
+ ![Multiple Protein Sequence Alignment](https://raw.githubusercontent.com/DJV512/Buttle/main/docs/images/synthetic_alignment_protein.png)
253
+
254
+ Conservative substitutions are shown in purple, non-conservative substitutions in red, and gaps as black dashes. When `--diff` is enabled, identities to the reference sequence are shown as dots. For DNA, conservative substitutions are disabled.
239
255
 
240
- Conservative substitutions are shown in purple, non-conservative substitutions in red, and gaps as black dashes. When `--diff` is enabled, identities to the reference sequence are shown as dots.
256
+ The Protein sequences used in this example are available in
257
+ [synthetic_example_proteins.fasta](docs/examples/synthetic_example_proteins.fasta). A similar set of synthetic DNA sequences is available in [synthetic_example_dna.fasta](docs/examples/synthetic_example_dna.fasta).
241
258
 
242
- The sequences used in this example are available in
243
- [synthetic_example_proteins.fasta](docs/examples/synthetic_example_proteins.fasta).
259
+ If the `--tree` argument is supplied, the average-linkage guide tree that was used to construct the multiple sequence alignment is printed to the terminal in a readable, hierarchical format. `*` represents internal `Cluster` nodes.
260
+
261
+ ```text
262
+ root
263
+ ├── *
264
+ │ ├── *
265
+ │ │ ├── *
266
+ │ │ │ ├── Synthetic_Alpha
267
+ │ │ │ └── Synthetic_Beta
268
+ │ │ └── Synthetic_Delta
269
+ │ └── Synthetic_Gamma
270
+ └── Synthetic_Epsilon
271
+ ```
244
272
 
245
273
  #### Rust vs Python
246
274
  The computationally intensive sequence alignment algorithms in Buttle were originally implemented in Python and subsequently ported to Rust to improve performance.
@@ -257,11 +285,7 @@ Omitting `--backend` uses the Rust implementation.
257
285
 
258
286
  ## Development status
259
287
 
260
- Buttle is currently in development. Interfaces and command-line options may change before version 1.0. Known limitations include:
261
-
262
- - Multiple sequence alignment currently supports proteins only.
263
- - DNA alignment image output currently limited to PNG, and does not support some arguments.
264
- - Guide tree visualization is still experimental.
288
+ Buttle is currently in development. Interfaces and command-line options may change before version 1.0. If you find any issues, please report them [here](https://github.com/DJV512/Buttle/issues).
265
289
 
266
290
  ## License
267
291
 
@@ -1,4 +1,4 @@
1
- ![Logo](https://raw.githubusercontent.com/DJV512/Buttle/v0.3.0/docs/images/buttle_logo_with_tag.png)
1
+ ![Logo](https://raw.githubusercontent.com/DJV512/Buttle/main/docs/images/buttle_logo_with_tag.png)
2
2
  Buttle was developed as a lightweight collection of bioinformatics utilities for common sequence-analysis tasks, with an emphasis on convenient command-line use. It provides tools for working with DNA and protein sequences, including sequence manipulation, peptide properties, motif searching, pairwise alignment, and multiple sequence alignment.
3
3
 
4
4
  Buttle is currently under active development.
@@ -13,11 +13,14 @@ Buttle is currently under active development.
13
13
 
14
14
  ### DNA sequences
15
15
 
16
- - Transcribe DNA to RNA
17
- - Translate DNA in three reading frames
16
+ - Transcribe to RNA
17
+ - Translate in three reading frames
18
18
  - Generate reverse complements
19
19
  - Calculate GC content
20
- - Pairwise DNA sequence alignment
20
+ - Pairwise sequence alignment from two raw sequence arguments
21
+ - Rust backend by default, with a Python backend available
22
+ - Multiple sequence alignment (MSA) from FASTA files or FASTA-formatted strings
23
+ - Rust backend by default, with a Python backend available
21
24
 
22
25
  ### Protein sequence tools
23
26
  - Calculate protein net charge
@@ -32,14 +35,16 @@ Buttle is currently under active development.
32
35
 
33
36
 
34
37
  ### Rendering
35
- - Display alignments in the terminal (when no `--save` argument provided)
38
+ - Print alignments in the terminal (when no `--save` argument provided)
36
39
  - Generate publication-quality PNG and TIFF alignment images
37
- - Save Pairwise DNA and protein alignments
38
- - Save multiple protein sequence alignments
40
+ - Pairwise DNA and Protein alignments
41
+ - Multiple DNA and Protein sequence alignments
39
42
  - Alignment row length can be tuned with `--wrap`
40
43
  - Argument `--real-ruler` displays residue number based on the first sequence, skipping gaps
41
- - Argument `--diff` displays alignment differences relative to a reference sequence
42
- - MSA optionally adds a consensus sequence with `--consensus`
44
+ - Optionally add a number at which the ruler numbering will start (defaults to 1)
45
+ - Argument `--diff` displays alignment differences relative to a reference sequence (first sequence in FASTA file)
46
+ - Argument `--consensus` optionally adds a consensus sequence to the bottom of an MSA
47
+ - Argument `--tree` displays an average-linkage clustering of pairwise sequence distances, not a phylogenetic reconstruction
43
48
 
44
49
 
45
50
  ## Installation/Requirements
@@ -82,11 +87,20 @@ Or install it into your active Python environment:
82
87
  pip install buttle
83
88
  ```
84
89
 
85
- Buttle's Python modules can then be imported and used directly.
90
+ Buttle's Python modules can also be imported and used directly.
86
91
  ```python
87
92
  from buttle import sequences
88
93
 
89
- # Use functions from the sequences module
94
+ # Access functions from the sequences module
95
+ output = sequences.find_position(sequence, search_string)
96
+ ```
97
+
98
+ For convenience, commonly used classes and functions are also exposed at the package's top level:
99
+ ```python
100
+ from buttle import find_position
101
+
102
+ # Call functions directly without referencing their modules
103
+ output = find_position(sequence, search_string)
90
104
  ```
91
105
 
92
106
  ### Building from source
@@ -206,28 +220,42 @@ GC Content: 46.30
206
220
  $ buttle props adlsykfehyaskgascwedasdkflsdad
207
221
  Charge = -4
208
222
  Molecular Weight = 3357.6
209
- Extinction Coefficient = 8370
223
+ Extinction Coefficient = 8370
210
224
  ```
211
225
 
212
226
  #### Pairwise Alignment of DNA or Protein
213
227
  ```console
214
- $ buttle dna_align atctcatgcgtcgtacgtacgt tgcatgcgtacgtagtcgatgtc
228
+ $ buttle dna_align atctcatgcgtcgtacgtacgt tgcatgcgtacgtagtcgatgtc --diff
215
229
  ```
216
- ![Pairwise DNA Alignment](https://raw.githubusercontent.com/DJV512/Buttle/v0.3.0/docs/images/dna_pairwise_align.png)
230
+ ![Pairwise DNA Alignment](https://raw.githubusercontent.com/DJV512/Buttle/main/docs/images/dna_pairwise_align.png)
217
231
 
218
- #### Multiple Protein Sequence Alignment
219
- Buttle implements a custom progressive multiple protein sequence alignment algorithm using an average-linkage guide tree, BLOSUM62-based scoring, and tunable affine gap open and extension penalties. Optional "X" residues can be used as alignment anchors. Computationally intensive operations are accelerated using a Rust extension.
232
+ #### Multiple Sequence Alignment
233
+ Buttle implements a custom progressive multiple sequence alignment algorithm using an average-linkage guide tree with tunable affine gap open and extension penalties. For Proteins, Buttle uses BLOSUM62-based scoring. Optional "X" residues can be used as alignment anchors. For DNA, Buttle uses fixed base match and mismatch scoring. Computationally intensive operations are accelerated using a Rust extension.
220
234
 
221
235
 
222
236
  ```console
223
- $ buttle msa docs/examples/synthetic_example_proteins.fasta --save docs/images/synthetic_alignment.png --diff --wrap 100
237
+ $ buttle msa docs/examples/synthetic_example_proteins.fasta --save docs/images/synthetic_alignment_protein.png --diff --wrap 100
224
238
  ```
225
- ![Multiple Protein Sequence Alignment](https://raw.githubusercontent.com/DJV512/Buttle/v0.3.0/docs/images/synthetic_alignment.png)
239
+ ![Multiple Protein Sequence Alignment](https://raw.githubusercontent.com/DJV512/Buttle/main/docs/images/synthetic_alignment_protein.png)
240
+
241
+ Conservative substitutions are shown in purple, non-conservative substitutions in red, and gaps as black dashes. When `--diff` is enabled, identities to the reference sequence are shown as dots. For DNA, conservative substitutions are disabled.
226
242
 
227
- Conservative substitutions are shown in purple, non-conservative substitutions in red, and gaps as black dashes. When `--diff` is enabled, identities to the reference sequence are shown as dots.
243
+ The Protein sequences used in this example are available in
244
+ [synthetic_example_proteins.fasta](docs/examples/synthetic_example_proteins.fasta). A similar set of synthetic DNA sequences is available in [synthetic_example_dna.fasta](docs/examples/synthetic_example_dna.fasta).
228
245
 
229
- The sequences used in this example are available in
230
- [synthetic_example_proteins.fasta](docs/examples/synthetic_example_proteins.fasta).
246
+ If the `--tree` argument is supplied, the average-linkage guide tree that was used to construct the multiple sequence alignment is printed to the terminal in a readable, hierarchical format. `*` represents internal `Cluster` nodes.
247
+
248
+ ```text
249
+ root
250
+ ├── *
251
+ │ ├── *
252
+ │ │ ├── *
253
+ │ │ │ ├── Synthetic_Alpha
254
+ │ │ │ └── Synthetic_Beta
255
+ │ │ └── Synthetic_Delta
256
+ │ └── Synthetic_Gamma
257
+ └── Synthetic_Epsilon
258
+ ```
231
259
 
232
260
  #### Rust vs Python
233
261
  The computationally intensive sequence alignment algorithms in Buttle were originally implemented in Python and subsequently ported to Rust to improve performance.
@@ -244,11 +272,7 @@ Omitting `--backend` uses the Rust implementation.
244
272
 
245
273
  ## Development status
246
274
 
247
- Buttle is currently in development. Interfaces and command-line options may change before version 1.0. Known limitations include:
248
-
249
- - Multiple sequence alignment currently supports proteins only.
250
- - DNA alignment image output currently limited to PNG, and does not support some arguments.
251
- - Guide tree visualization is still experimental.
275
+ Buttle is currently in development. Interfaces and command-line options may change before version 1.0. If you find any issues, please report them [here](https://github.com/DJV512/Buttle/issues).
252
276
 
253
277
  ## License
254
278
 
@@ -1,12 +1,12 @@
1
1
  [project]
2
2
  name = "buttle"
3
- version = "0.3.0"
3
+ version = "0.4.0"
4
4
  description = "Command-line utilities for DNA and protein sequence analysis. At your service."
5
5
  readme = "README.md"
6
6
  license = "BSD-3-Clause"
7
7
  requires-python = ">=3.15"
8
8
  dependencies = [
9
- "pillow>=12.3.0",
9
+ "pillow>=13.0.0",
10
10
  ]
11
11
 
12
12
  [project.scripts]
@@ -43,4 +43,4 @@ addopts = [
43
43
  [project.urls]
44
44
  Homepage = "https://github.com/DJV512/Buttle"
45
45
  Repository = "https://github.com/DJV512/Buttle"
46
- Issues = "https://github.com/DJV512/Buttle/issues"
46
+ Issues = "https://github.com/DJV512/Buttle/issues"
@@ -4,7 +4,7 @@ version = 4
4
4
 
5
5
  [[package]]
6
6
  name = "buttle_rust"
7
- version = "0.3.0"
7
+ version = "0.4.0"
8
8
  dependencies = [
9
9
  "pyo3",
10
10
  ]
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "buttle_rust"
3
- version = "0.3.0"
3
+ version = "0.4.0"
4
4
  edition = "2024"
5
5
 
6
6
  [lib]
@@ -59,6 +59,11 @@ pub enum Direction {
59
59
  Impossible,
60
60
  }
61
61
 
62
+ pub enum Molecule {
63
+ DNA,
64
+ Protein,
65
+ }
66
+
62
67
  #[derive(Debug, Clone)]
63
68
  pub struct Profile {
64
69
  pub names: Vec<String>,
@@ -2,23 +2,23 @@ mod constants;
2
2
  mod pairwise;
3
3
  mod merge;
4
4
 
5
- pub use pairwise::pairwise_protein;
5
+ pub use pairwise::pairwise_align;
6
6
  pub use merge::merge;
7
7
  pub use constants::Profile;
8
8
 
9
9
  #[cfg(feature = "python")]
10
10
  use pyo3::prelude::*;
11
11
 
12
- /// Globally align two protein sequences using affine gap penalties.
12
+ /// Globally align two sequences using affine gap penalties.
13
13
  ///
14
- /// Inputs must be normalized sequences from validated Protein objects.
14
+ /// Inputs must be normalized sequences from validated Protein or DNA objects.
15
15
  /// This internal function does not perform input validation.
16
16
  ///
17
17
  /// Returns the two aligned sequences, with '-' characters marking gaps.
18
18
  #[cfg(feature = "python")]
19
19
  #[pyfunction]
20
- fn _align_protein(seq1: &str, seq2: &str) -> (String, String) {
21
- pairwise_protein(seq1, seq2)
20
+ fn _align(seq1: &str, seq2: &str, molecule_type: &str) -> (String, String) {
21
+ pairwise_align(seq1, seq2, molecule_type)
22
22
  }
23
23
 
24
24
  /// Globally align two profiles, made up of already aligned sequences, using affine gap penalties.
@@ -34,6 +34,7 @@ fn _merge(
34
34
  left_sequences: Vec<String>,
35
35
  right_names: Vec<String>,
36
36
  right_sequences: Vec<String>,
37
+ molecule_type: &str,
37
38
  gap_open: f64,
38
39
  gap_extend: f64,
39
40
  ) -> (Vec<String>, Vec<String>) {
@@ -53,7 +54,7 @@ fn _merge(
53
54
  .collect(),
54
55
  };
55
56
 
56
- let result = merge(&left, &right, gap_open, gap_extend);
57
+ let result = merge(&left, &right, molecule_type, gap_open, gap_extend);
57
58
 
58
59
  (
59
60
  result.names,
@@ -67,7 +68,7 @@ fn _merge(
67
68
  #[cfg(feature = "python")]
68
69
  #[pymodule]
69
70
  fn buttle_rust(m: &Bound<'_, PyModule>) -> PyResult<()> {
70
- m.add_function(wrap_pyfunction!(_align_protein, m)?)?;
71
+ m.add_function(wrap_pyfunction!(_align, m)?)?;
71
72
  m.add_function(wrap_pyfunction!(_merge, m)?)?;
72
73
  Ok(())
73
74
  }
@@ -1,7 +1,16 @@
1
1
  use crate::constants::{BLOSUMX,aa_index,Direction,Profile};
2
2
 
3
3
 
4
- pub fn merge(left: &Profile, right: &Profile, gap_open: f64, gap_extend: f64) -> Profile {
4
+ pub fn merge(left: &Profile, right: &Profile, molecule_type: &str, gap_open: f64, gap_extend: f64) -> Profile {
5
+
6
+ let msa_score: fn(&[char], &[char]) -> f64 = if molecule_type == "protein" {
7
+ _msa_sigma_protein
8
+ } else if molecule_type == "dna" {
9
+ _msa_sigma_dna
10
+ } else {
11
+ panic!("Invalid molecule type.");
12
+ };
13
+
5
14
 
6
15
  const NEG_INF:f64 = f64::NEG_INFINITY;
7
16
 
@@ -78,13 +87,13 @@ pub fn merge(left: &Profile, right: &Profile, gap_open: f64, gap_extend: f64) ->
78
87
  .collect();
79
88
 
80
89
 
81
- // Current pair is a residue column vs residue column
82
- let column_v_column_blosum_score = _msa_sigma(&left_column, &right_column);
90
+ // Current pair is a residue or base column vs residue or base column
91
+ let column_v_column_score = msa_score(&left_column, &right_column);
83
92
 
84
93
  let (best_score, direction) = [
85
- (score_vert[(i-1) * cols + (j-1)] + column_v_column_blosum_score, Direction::Vert),
86
- (score_hori[(i-1) * cols + (j-1)] + column_v_column_blosum_score, Direction::Hori),
87
- (score_diag[(i-1) * cols + (j-1)] + column_v_column_blosum_score, Direction::Diag),
94
+ (score_vert[(i-1) * cols + (j-1)] + column_v_column_score, Direction::Vert),
95
+ (score_hori[(i-1) * cols + (j-1)] + column_v_column_score, Direction::Hori),
96
+ (score_diag[(i-1) * cols + (j-1)] + column_v_column_score, Direction::Diag),
88
97
  ].into_iter().max_by(|a, b| a.0.total_cmp(&b.0)).unwrap();
89
98
  score_diag[i * cols + j] = best_score;
90
99
  trace_diag[i * cols + j] = direction;
@@ -119,7 +128,7 @@ pub fn merge(left: &Profile, right: &Profile, gap_open: f64, gap_extend: f64) ->
119
128
  }
120
129
 
121
130
 
122
- fn _msa_sigma(
131
+ fn _msa_sigma_protein(
123
132
  left_residues: &[char],
124
133
  right_residues: &[char],
125
134
  ) -> f64 {
@@ -146,6 +155,27 @@ fn _msa_sigma(
146
155
  }
147
156
 
148
157
 
158
+ fn _msa_sigma_dna(
159
+ left_residues: &[char],
160
+ right_residues: &[char],
161
+ ) -> f64 {
162
+ let comparisons = left_residues.len() * right_residues.len();
163
+ let mut score = 0;
164
+ for &left_residue in left_residues {
165
+ for &right_residue in right_residues {
166
+ if left_residue == '-' && right_residue == '-' {
167
+ continue;
168
+ } else if left_residue == '-' || right_residue == '-' {
169
+ score -= 8;
170
+ } else if left_residue == right_residue && left_residue != 'N' {
171
+ score += 8
172
+ } else {
173
+ score -= 5
174
+ }
175
+ }
176
+ }
177
+ score as f64 / comparisons as f64
178
+ }
149
179
 
150
180
  fn msa_traceback(
151
181
  _left:&Profile,
@@ -1,10 +1,19 @@
1
1
  use crate::constants::BLOSUMX;
2
2
  use crate::constants::aa_index;
3
3
  use crate::constants::Direction;
4
+ use crate::constants::Molecule;
4
5
 
5
- pub fn pairwise_protein(seq1: &str, seq2: &str) -> (String, String) {
6
+
7
+ pub fn pairwise_align(seq1: &str, seq2: &str, molecule_type: &str) -> (String, String) {
6
8
 
7
9
  // Set Gap penalty constants, and a highly negative number for the impossible boundaries
10
+
11
+ let molecule = match molecule_type {
12
+ "protein" => Molecule::Protein,
13
+ "dna" => Molecule::DNA,
14
+ _ => unreachable!("Invalid molecule type"),
15
+ };
16
+
8
17
  const GAP_OPEN:i32 = -10;
9
18
  const GAP_EXTEND:i32 = -1;
10
19
  const NEG_INF:i32 = i32::MIN / 2;
@@ -70,16 +79,26 @@ pub fn pairwise_protein(seq1: &str, seq2: &str) -> (String, String) {
70
79
  }
71
80
  }
72
81
 
73
- // Populate the entire scoring and traceback matrix based on maximum BLOSUM62 based scoring
74
- // BLOSUMX is a modified BLOSUM62 whcih uses an "X" amino acid as an alignment anchor
82
+ // Populate scoring and traceback matrices using molecule-specific substitution scores.
83
+ // Protein scoring uses BLOSUMX; DNA scoring uses fixed match/mismatch penalties.
75
84
  for i in 1..rows {
76
85
  for j in 1..cols {
77
- let residue_blosum_score = BLOSUMX[aa_index(&s1[i..i+1])][aa_index(&s2[j..j+1])];
86
+
87
+ let score = match molecule {
88
+ Molecule::Protein => BLOSUMX[aa_index(&s1[i..i+1])][aa_index(&s2[j..j+1])],
89
+ Molecule::DNA => {
90
+ if &s1[i..i+1] == &s2[j..j+1] && &s1[i..i+1] != "N" {
91
+ 8
92
+ } else {
93
+ -5
94
+ }
95
+ }
96
+ };
78
97
 
79
98
  let (best_score, direction) = [
80
- (score_vert[(i-1)*cols + (j-1)] + residue_blosum_score, Direction::Vert),
81
- (score_hori[(i-1)*cols + (j-1)] + residue_blosum_score, Direction::Hori),
82
- (score_diag[(i-1)*cols + (j-1)] + residue_blosum_score, Direction::Diag),
99
+ (score_vert[(i-1)*cols + (j-1)] + score, Direction::Vert),
100
+ (score_hori[(i-1)*cols + (j-1)] + score, Direction::Hori),
101
+ (score_diag[(i-1)*cols + (j-1)] + score, Direction::Diag),
83
102
  ].into_iter().max_by_key(|(score, _)| *score).unwrap();
84
103
 
85
104
  score_diag[i*cols + j] = best_score;
@@ -0,0 +1,17 @@
1
+ lazy from .models.molecules import Protein, DNA
2
+ lazy from .multiple_alignment import msa
3
+ lazy from .pairwise import pairwise_align
4
+ lazy from .comparisons import motifs, identity
5
+ lazy from .parsers import parse_fasta
6
+ lazy from .sequences import find_position
7
+
8
+ __all__ = [
9
+ "Protein",
10
+ "DNA",
11
+ "msa",
12
+ "pairwise_align",
13
+ "motifs",
14
+ "identity",
15
+ "parse_fasta",
16
+ "find_position",
17
+ ]
@@ -0,0 +1,46 @@
1
+ def _align(
2
+ seq1: str,
3
+ seq2: str,
4
+ molecule_type: str
5
+ ) -> tuple[str, str]:
6
+ """
7
+ Perform a global pairwise alignment using affine gap penalties.
8
+
9
+ Both inputs must be of the same type (Protein sequence or DNA sequence).
10
+ Protein alignments use BLOSUM62 substitution scores, while DNA
11
+ alignments use fixed match and mismatch scores. Gap penalties
12
+ are determined by the molecule type.
13
+
14
+ Args:
15
+ seq1: First Protein or DNA sequence to align.
16
+ seq2: Second Protein or DNA sequence to align.
17
+
18
+ Returns:
19
+ A tuple containing two lists of aligned residues or bases,
20
+ including '-' characters representing gaps.
21
+
22
+ Warning:
23
+ This function does not validate that the input sequences match
24
+ the specified molecule type. Callers must perform this validation
25
+ before invoking the function.
26
+ """
27
+ ...
28
+
29
+ def _merge(
30
+ left_names:list[str],
31
+ left_sequences: list[str],
32
+ right_names:list[str],
33
+ right_sequences: list[str],
34
+ molecule_type: str,
35
+ gap_open:float,
36
+ gap_extend:float,
37
+ ) -> tuple[list[str], list[str]]:
38
+ '''
39
+ Globally align two profiles, made up of already aligned sequences, using affine gap penalties.
40
+
41
+ Inputs are two Profiles to merge (separated out into their constituent lists of names and sequences to pass to rust),
42
+ as well as the gap open and gap extend penalties to use. This internal function does not perform input validation.
43
+
44
+ Returns a tuple of a list of sequence names, and a list of sequence alignments.
45
+ '''
46
+ ...