1pub mod alphabet;
16pub mod collection;
17pub mod digest;
18pub mod encoder;
19pub mod fasta;
20pub mod store;
21
22mod hashkeyable;
24mod utils;
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 use std::time::Instant;
31 use store::RefgetStore;
32 use tempfile::tempdir;
33 #[test]
34 #[ignore]
35 fn test_loading_large_fasta_file() {
36 let fasta_path =
39 std::env::var("FASTA_PATH").expect("FASTA_PATH environment variable not set");
40 println!("Loading large FASTA file: {}", &fasta_path);
43
44 println!("Adding sequences from FASTA file...");
46 let start = Instant::now();
47 let mut store = RefgetStore::in_memory();
48 store.add_sequence_collection_from_fasta(&fasta_path).unwrap();
49 let duration = start.elapsed();
50 println!("⏱️ Time taken to load: {:.2?}", duration);
51
52 let mut store2 = RefgetStore::in_memory();
53 store2.disable_encoding(); store2.add_sequence_collection_from_fasta(&fasta_path).unwrap();
55
56 let sequences: Vec<_> = store.sequence_digests().collect();
58 assert!(!sequences.is_empty(), "No sequences found in the store");
59
60 println!("Look up a sequence by digest...");
62 let digest = &sequences[0];
63 let digest_str = String::from_utf8(digest.to_vec()).expect("Invalid ASCII data");
64 println!("Retrieving a substring of sequence named: {:?}", digest_str);
70 let start_basic = 0;
71 let end_basic = 3;
72 let substring = store.get_substring(digest, start_basic, end_basic);
73 assert!(
74 substring.is_ok(),
75 "Failed to retrieve substring with name: {:?}",
76 digest_str
77 );
78 println!("Retrieved substring: {:?}", substring.unwrap());
79
80 let start = 148 * 70;
82 let end = 148 * 70 + 70;
83 let substring2 = store.get_substring(digest, start, end);
84 assert!(
85 substring2.is_ok(),
86 "Failed to retrieve substring with name: {:?}",
87 digest_str
88 );
89
90 let substring3 = store2.get_substring(digest, start, end);
91 assert_eq!(substring2.as_ref().unwrap(), substring3.as_ref().unwrap());
92 println!("Retrieved substring: {:?}", substring2.unwrap());
93 println!("Retrieved substring: {:?}", substring3.unwrap());
94 }
95
96 #[test]
97 fn test_get_sequence_encoded() {
98 let temp_dir = tempdir().expect("Failed to create temporary directory");
99 let temp_path = temp_dir.path();
100 let mut store = RefgetStore::in_memory();
102 let fasta_path = "../tests/data/fasta/base.fa.gz";
104 let temp_fasta = temp_path.join("base.fa.gz");
105 std::fs::copy(fasta_path, &temp_fasta).expect("Failed to copy base.fa.gz to tempdir");
106
107 store.add_sequence_collection_from_fasta(temp_fasta).unwrap();
109 println!("Listing sequences in the store...");
110 let digest = "iYtREV555dUFKg2_agSJW6suquUyPpMw"; let digest_str = String::from_utf8(digest.as_bytes().to_vec()).expect("Invalid ASCII data");
116
117 println!("Retrieving a substring of sequence named: {:?}", digest_str);
119 let start = 2;
120 let end = start + 5;
121 let substring = store.get_substring(digest, start, end);
122 assert!(
123 substring.is_ok(),
124 "Failed to retrieve substring with name: {:?}",
125 digest_str
126 );
127 println!("Retrieved substring: {:?}", substring.as_ref().unwrap());
128 assert_eq!(substring.unwrap(), "GGGGA");
129 println!("Retrieving a substring of sequence named: {:?}", digest_str);
132 let start = 3;
133 let end = start + 2;
134 let substring = store.get_substring(digest, start, end);
135 assert!(
136 substring.is_ok(),
137 "Failed to retrieve substring with name: {:?}",
138 digest_str
139 );
140 println!("Retrieved substring: {:?}", substring.as_ref().unwrap());
141 assert_eq!(substring.unwrap(), "GG");
142 }
144}