orphos 0.2.0__tar.gz → 0.3.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 (59) hide show
  1. {orphos-0.2.0 → orphos-0.3.0}/PKG-INFO +1 -1
  2. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/Cargo.toml +6 -5
  3. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/README.md +1 -1
  4. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/engine.rs +47 -38
  5. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/output/formats/bed.rs +11 -16
  6. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/sequence/mod.rs +364 -267
  7. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/sequence/processing.rs +57 -33
  8. {orphos-0.2.0 → orphos-0.3.0}/orphos-python/Cargo.lock +224 -156
  9. {orphos-0.2.0 → orphos-0.3.0}/orphos-python/Cargo.toml +4 -3
  10. {orphos-0.2.0 → orphos-0.3.0}/orphos-python/src/lib.rs +6 -3
  11. {orphos-0.2.0 → orphos-0.3.0}/pyproject.toml +1 -1
  12. {orphos-0.2.0 → orphos-0.3.0}/Cargo.toml +0 -0
  13. {orphos-0.2.0 → orphos-0.3.0}/README.md +0 -0
  14. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/dynamic_programming/gene_prediction.rs +0 -0
  15. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/dynamic_programming/mod.rs +0 -0
  16. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/dynamic_programming/overlap_resolution.rs +0 -0
  17. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/dynamic_programming/path_optimization.rs +0 -0
  18. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/dynamic_programming/scoring/connection_types.rs +0 -0
  19. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/dynamic_programming/scoring/handlers.rs +0 -0
  20. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/dynamic_programming/scoring/mod.rs +0 -0
  21. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/gene_finding/annotation.rs +0 -0
  22. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/gene_finding/creation.rs +0 -0
  23. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/gene_finding/mod.rs +0 -0
  24. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/gene_finding/optimization.rs +0 -0
  25. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/gene_finding/scoring.rs +0 -0
  26. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/algorithms/mod.rs +0 -0
  27. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/bitmap/mod.rs +0 -0
  28. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/config.rs +0 -0
  29. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/constants.rs +0 -0
  30. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/lib.rs +0 -0
  31. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/metagenomic/mod.rs +0 -0
  32. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/metagenomic/presets.rs +0 -0
  33. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/node/creation.rs +0 -0
  34. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/node/dicodon.rs +0 -0
  35. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/node/management.rs +0 -0
  36. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/node/mod.rs +0 -0
  37. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/node/motifs.rs +0 -0
  38. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/node/overlaps.rs +0 -0
  39. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/node/record_gc_bias.rs +0 -0
  40. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/node/scoring.rs +0 -0
  41. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/node/utilities.rs +0 -0
  42. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/node/validation.rs +0 -0
  43. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/output/formats/gbk.rs +0 -0
  44. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/output/formats/gca.rs +0 -0
  45. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/output/formats/gff.rs +0 -0
  46. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/output/formats/sco.rs +0 -0
  47. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/output/mod.rs +0 -0
  48. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/results.rs +0 -0
  49. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/sequence/encoded.rs +0 -0
  50. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/sequence/io.rs +0 -0
  51. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/training/common.rs +0 -0
  52. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/training/mod.rs +0 -0
  53. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/training/non_sd_training.rs +0 -0
  54. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/training/sd_training.rs +0 -0
  55. {orphos-0.2.0 → orphos-0.3.0}/orphos-core/src/types.rs +0 -0
  56. {orphos-0.2.0 → orphos-0.3.0}/orphos-python/.gitignore +0 -0
  57. {orphos-0.2.0 → orphos-0.3.0}/orphos-python/README.md +0 -0
  58. {orphos-0.2.0 → orphos-0.3.0}/orphos-python/test_bindings.py +0 -0
  59. {orphos-0.2.0 → orphos-0.3.0}/python/orphos/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orphos
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Intended Audience :: Science/Research
6
6
  Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
@@ -1,7 +1,8 @@
1
1
  [package]
2
2
  name = "orphos-core"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  edition = "2024"
5
+ rust-version = "1.89"
5
6
  description = "Core library for Orphos, a tool for finding protein-coding genes in microbial genomes."
6
7
  license = "GPL-3.0-or-later"
7
8
  repository = "https://github.com/FullHuman/orphos"
@@ -20,9 +21,9 @@ all-features = true
20
21
  rustdoc-args = ["--cfg", "docsrs"]
21
22
 
22
23
  [dependencies]
23
- bio = "2.3.0"
24
- rayon = "1.10.0"
25
- thiserror = "2.0.12"
26
- wide = "0.7.33"
24
+ bio = "4.0.1"
25
+ rayon = "1.12.0"
26
+ thiserror = "2.0.19"
27
+ wide = "1.5.0"
27
28
 
28
29
  [dev-dependencies]
@@ -25,7 +25,7 @@ Add to your `Cargo.toml`:
25
25
 
26
26
  ```toml
27
27
  [dependencies]
28
- orphos-core = "0.1.0"
28
+ orphos-core = "0.3.0"
29
29
  ```
30
30
 
31
31
  ## Quick Start
@@ -1,5 +1,6 @@
1
1
  use std::marker::PhantomData;
2
2
  use std::path::Path;
3
+ use std::sync::OnceLock;
3
4
 
4
5
  use crate::algorithms::dynamic_programming::eliminate_bad_genes;
5
6
  use crate::algorithms::dynamic_programming::predict_genes;
@@ -22,6 +23,9 @@ use crate::training::should_use_sd;
22
23
  use crate::types::Gene;
23
24
  use crate::types::{CodonType, Node, OrphosError, Training};
24
25
  use bio::bio_types::strand::Strand;
26
+ use rayon::prelude::*;
27
+
28
+ static RAYON_POOL_INIT: OnceLock<()> = OnceLock::new();
25
29
 
26
30
  /// Marker trait for Orphos training state.
27
31
  ///
@@ -158,12 +162,12 @@ impl UntrainedOrphos {
158
162
  };
159
163
 
160
164
  if let Some(num_threads) = orphos.config.num_threads {
161
- rayon::ThreadPoolBuilder::new()
162
- .num_threads(num_threads)
163
- .build_global()
164
- .map_err(|e| {
165
- OrphosError::InvalidSequence(format!("Failed to configure thread pool: {}", e))
166
- })?;
165
+ RAYON_POOL_INIT.get_or_init(|| {
166
+ // Ignore error if pool was already initialized by a previous call
167
+ let _ = rayon::ThreadPoolBuilder::new()
168
+ .num_threads(num_threads)
169
+ .build_global();
170
+ });
167
171
  }
168
172
 
169
173
  Ok(orphos)
@@ -576,11 +580,15 @@ fn update_display_scores(genes: &mut [Gene], nodes: &[Node]) {
576
580
  gene.coordinates.end.saturating_sub(1)
577
581
  };
578
582
 
579
- if let Some(start_node) = nodes.iter().find(|n| {
580
- n.position.index == target_pos
581
- && n.position.strand == gene.coordinates.strand
582
- && n.position.codon_type != CodonType::Stop
583
- }) {
583
+ let lo = nodes.partition_point(|n| n.position.index < target_pos);
584
+ if let Some(start_node) = nodes[lo..]
585
+ .iter()
586
+ .take_while(|n| n.position.index == target_pos)
587
+ .find(|n| {
588
+ n.position.strand == gene.coordinates.strand
589
+ && n.position.codon_type != CodonType::Stop
590
+ })
591
+ {
584
592
  gene.display_score =
585
593
  Some(start_node.scores.coding_score + start_node.scores.start_score);
586
594
  }
@@ -625,7 +633,7 @@ fn update_display_scores(genes: &mut [Gene], nodes: &[Node]) {
625
633
  /// ```rust,no_run
626
634
  /// use orphos_core::{OrphosAnalyzer, config::OrphosConfig};
627
635
  ///
628
- /// let mut analyzer = OrphosAnalyzer::new(OrphosConfig::default());
636
+ /// let analyzer = OrphosAnalyzer::new(OrphosConfig::default());
629
637
  /// let results = analyzer.analyze_fasta_file("genome.fasta")?;
630
638
  ///
631
639
  /// for result in results {
@@ -649,7 +657,7 @@ fn update_display_scores(genes: &mut [Gene], nodes: &[Node]) {
649
657
  /// ..Default::default()
650
658
  /// };
651
659
  ///
652
- /// let mut analyzer = OrphosAnalyzer::new(config);
660
+ /// let analyzer = OrphosAnalyzer::new(config);
653
661
  /// # Ok::<(), orphos_core::types::OrphosError>(())
654
662
  /// ```
655
663
  #[derive(Debug)]
@@ -701,7 +709,7 @@ impl OrphosAnalyzer {
701
709
  /// ```rust,no_run
702
710
  /// use orphos_core::{OrphosAnalyzer, config::OrphosConfig};
703
711
  ///
704
- /// let mut analyzer = OrphosAnalyzer::new(OrphosConfig::default());
712
+ /// let analyzer = OrphosAnalyzer::new(OrphosConfig::default());
705
713
  /// let results = analyzer.analyze_fasta_file("genomes.fasta")?;
706
714
  ///
707
715
  /// for (i, result) in results.iter().enumerate() {
@@ -710,17 +718,17 @@ impl OrphosAnalyzer {
710
718
  /// # Ok::<(), orphos_core::types::OrphosError>(())
711
719
  /// ```
712
720
  pub fn analyze_fasta_file<P: AsRef<Path>>(
713
- &mut self,
721
+ &self,
714
722
  path: P,
715
723
  ) -> Result<Vec<OrphosResults>, OrphosError> {
716
724
  let sequences = read_fasta_sequences(path.as_ref().to_str().unwrap())?;
717
725
 
718
- let mut results = Vec::new();
719
- for (header, description, seq_bytes) in sequences {
720
- let result = self.analyze_sequence_bytes(&seq_bytes, header, description)?;
721
- results.push(result);
722
- }
723
- Ok(results)
726
+ sequences
727
+ .into_par_iter()
728
+ .map(|(header, description, seq_bytes)| {
729
+ self.analyze_sequence_bytes(&seq_bytes, header, description)
730
+ })
731
+ .collect()
724
732
  }
725
733
 
726
734
  /// Analyzes a single sequence from a string.
@@ -750,7 +758,7 @@ impl OrphosAnalyzer {
750
758
  /// ```rust,no_run
751
759
  /// use orphos_core::{OrphosAnalyzer, config::OrphosConfig};
752
760
  ///
753
- /// let mut analyzer = OrphosAnalyzer::new(OrphosConfig::default());
761
+ /// let analyzer = OrphosAnalyzer::new(OrphosConfig::default());
754
762
  ///
755
763
  /// let sequence = "ATGAAACGCATTAGCACCACCATT...";
756
764
  /// let results = analyzer.analyze_sequence(sequence, Some("E. coli K12".to_string()))?;
@@ -761,7 +769,7 @@ impl OrphosAnalyzer {
761
769
  /// # Ok::<(), orphos_core::types::OrphosError>(())
762
770
  /// ```
763
771
  pub fn analyze_sequence(
764
- &mut self,
772
+ &self,
765
773
  sequence: &str,
766
774
  header: Option<String>,
767
775
  ) -> Result<OrphosResults, OrphosError> {
@@ -801,7 +809,7 @@ impl OrphosAnalyzer {
801
809
  /// ```rust,no_run
802
810
  /// use orphos_core::{OrphosAnalyzer, config::OrphosConfig};
803
811
  ///
804
- /// let mut analyzer = OrphosAnalyzer::new(OrphosConfig::default());
812
+ /// let analyzer = OrphosAnalyzer::new(OrphosConfig::default());
805
813
  ///
806
814
  /// let sequence = b"ATGAAACGCATTAGCACCACCATT...";
807
815
  /// let results = analyzer.analyze_sequence_bytes(
@@ -814,7 +822,7 @@ impl OrphosAnalyzer {
814
822
  /// # Ok::<(), orphos_core::types::OrphosError>(())
815
823
  /// ```
816
824
  pub fn analyze_sequence_bytes(
817
- &mut self,
825
+ &self,
818
826
  sequence: &[u8],
819
827
  header: String,
820
828
  description: Option<String>,
@@ -848,13 +856,14 @@ impl OrphosAnalyzer {
848
856
  (genes, None, training)
849
857
  };
850
858
 
859
+ let num_genes = genes.len();
851
860
  Ok(OrphosResults {
852
- genes: genes.clone(),
861
+ genes,
853
862
  training_used: best_training,
854
863
  sequence_info: SequenceInfo {
855
864
  length: sequence_length,
856
865
  gc_content: encoded_sequence.gc_content,
857
- num_genes: genes.len(),
866
+ num_genes,
858
867
  header,
859
868
  description,
860
869
  },
@@ -1115,7 +1124,7 @@ mod tests {
1115
1124
  #[test]
1116
1125
  fn test_analyze_sequence_basic() {
1117
1126
  let config = OrphosConfig::default();
1118
- let mut analyzer = OrphosAnalyzer::new(config);
1127
+ let analyzer = OrphosAnalyzer::new(config);
1119
1128
 
1120
1129
  let sequence =
1121
1130
  "ATGAAACGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTAAATAG".repeat(300);
@@ -1135,7 +1144,7 @@ mod tests {
1135
1144
  #[test]
1136
1145
  fn test_analyze_sequence_with_header() {
1137
1146
  let config = OrphosConfig::default();
1138
- let mut analyzer = OrphosAnalyzer::new(config);
1147
+ let analyzer = OrphosAnalyzer::new(config);
1139
1148
 
1140
1149
  let sequence =
1141
1150
  "ATGAAACGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTAAATAG".repeat(300);
@@ -1151,7 +1160,7 @@ mod tests {
1151
1160
  #[test]
1152
1161
  fn test_analyze_sequence_bytes() {
1153
1162
  let config = OrphosConfig::default();
1154
- let mut analyzer = OrphosAnalyzer::new(config);
1163
+ let analyzer = OrphosAnalyzer::new(config);
1155
1164
 
1156
1165
  let sequence =
1157
1166
  "ATGAAACGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTAAATAG".repeat(300);
@@ -1175,7 +1184,7 @@ mod tests {
1175
1184
  metagenomic: true,
1176
1185
  ..OrphosConfig::default()
1177
1186
  };
1178
- let mut analyzer = OrphosAnalyzer::new(config);
1187
+ let analyzer = OrphosAnalyzer::new(config);
1179
1188
 
1180
1189
  let sequence =
1181
1190
  "ATGAAACGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTAAATAG".repeat(300);
@@ -1233,7 +1242,7 @@ mod tests {
1233
1242
  #[test]
1234
1243
  fn test_analyze_fasta_file_not_found() {
1235
1244
  let config = OrphosConfig::default();
1236
- let mut analyzer = OrphosAnalyzer::new(config);
1245
+ let analyzer = OrphosAnalyzer::new(config);
1237
1246
 
1238
1247
  let result = analyzer.analyze_fasta_file("nonexistent_file.fa");
1239
1248
  assert!(result.is_err());
@@ -1245,7 +1254,7 @@ mod tests {
1245
1254
  metagenomic: true,
1246
1255
  ..OrphosConfig::default()
1247
1256
  };
1248
- let mut analyzer = OrphosAnalyzer::new(config);
1257
+ let analyzer = OrphosAnalyzer::new(config);
1249
1258
 
1250
1259
  // Create a temporary FASTA file
1251
1260
  let fasta_content = ">test_seq\nATCG\n";
@@ -1266,7 +1275,7 @@ mod tests {
1266
1275
  #[test]
1267
1276
  fn test_analyze_fasta_file_single_genome() {
1268
1277
  let config = OrphosConfig::default();
1269
- let mut analyzer = OrphosAnalyzer::new(config);
1278
+ let analyzer = OrphosAnalyzer::new(config);
1270
1279
 
1271
1280
  // Create a temporary FASTA file with a longer sequence for training
1272
1281
  let sequence =
@@ -1289,7 +1298,7 @@ mod tests {
1289
1298
  #[test]
1290
1299
  fn test_analyze_empty_sequence() {
1291
1300
  let config = OrphosConfig::default();
1292
- let mut analyzer = OrphosAnalyzer::new(config);
1301
+ let analyzer = OrphosAnalyzer::new(config);
1293
1302
 
1294
1303
  let sequence = "";
1295
1304
  let result = analyzer.analyze_sequence(sequence, None);
@@ -1309,7 +1318,7 @@ mod tests {
1309
1318
  #[test]
1310
1319
  fn test_analyze_very_short_sequence() {
1311
1320
  let config = OrphosConfig::default();
1312
- let mut analyzer = OrphosAnalyzer::new(config);
1321
+ let analyzer = OrphosAnalyzer::new(config);
1313
1322
 
1314
1323
  let sequence = "ATG"; // Very short sequence (3 bp)
1315
1324
  let result = analyzer.analyze_sequence(sequence, None);
@@ -1377,7 +1386,7 @@ mod tests {
1377
1386
  #[test]
1378
1387
  fn test_analyzer_multiple_sequences() {
1379
1388
  let config = OrphosConfig::default();
1380
- let mut analyzer = OrphosAnalyzer::new(config);
1389
+ let analyzer = OrphosAnalyzer::new(config);
1381
1390
 
1382
1391
  let sequence1 =
1383
1392
  "ATGAAACGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTCGTAAATAG".repeat(150);
@@ -1404,7 +1413,7 @@ mod tests {
1404
1413
  #[test]
1405
1414
  fn test_error_handling_edge_cases() {
1406
1415
  let config = OrphosConfig::default();
1407
- let mut analyzer = OrphosAnalyzer::new(config);
1416
+ let analyzer = OrphosAnalyzer::new(config);
1408
1417
 
1409
1418
  // Test with sequence containing invalid characters
1410
1419
  let invalid_sequence = "ATCGXYZ123";
@@ -1,6 +1,6 @@
1
1
  use std::io::Write;
2
2
 
3
- use bio::bio_types::strand::Strand;
3
+ use bio::io::bed;
4
4
 
5
5
  use crate::{OrphosError, results::OrphosResults};
6
6
 
@@ -19,17 +19,14 @@ pub fn write_bed_format<W: Write>(
19
19
  writer: &mut W,
20
20
  results: &OrphosResults,
21
21
  ) -> Result<(), OrphosError> {
22
+ let mut bed_writer = bed::Writer::new(&mut *writer as &mut dyn Write);
22
23
  for (i, gene) in results.genes.iter().enumerate() {
23
24
  if gene.coordinates.begin > gene.coordinates.end {
24
25
  // BED6 has no native circular wrap representation.
25
26
  continue;
26
27
  }
27
28
 
28
- let strand = match gene.coordinates.strand {
29
- Strand::Forward => '+',
30
- Strand::Reverse => '-',
31
- Strand::Unknown => '.',
32
- };
29
+ let strand = gene.coordinates.strand;
33
30
 
34
31
  let name = if gene.annotation.identifier.is_empty() {
35
32
  format!("{}_{}", results.sequence_info.header, i + 1)
@@ -37,16 +34,14 @@ pub fn write_bed_format<W: Write>(
37
34
  gene.annotation.identifier.clone()
38
35
  };
39
36
 
40
- writeln!(
41
- writer,
42
- "{}\t{}\t{}\t{}\t{}\t{}",
43
- results.sequence_info.header,
44
- gene.coordinates.begin,
45
- gene.coordinates.end + 1,
46
- name,
47
- confidence_to_bed_score(gene.score.confidence),
48
- strand
49
- )?;
37
+ let mut record = bed::Record::new();
38
+ record.set_chrom(&results.sequence_info.header);
39
+ record.set_start(gene.coordinates.begin as u64);
40
+ record.set_end((gene.coordinates.end + 1) as u64);
41
+ record.set_name(&name);
42
+ record.set_score(&confidence_to_bed_score(gene.score.confidence).to_string());
43
+ record.set_strand(strand);
44
+ bed_writer.write(&record).map_err(std::io::Error::other)?;
50
45
  }
51
46
  Ok(())
52
47
  }