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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
use std::{
fmt::{self, Display},
path::{Path, PathBuf},
};
use log::debug;
use serde::{Deserialize, Serialize};
use crate::{
EntryError, ValidationError,
downloads::check_url,
validate::{UnvalidatedFile, ValidatedFile, hash_valid_download},
};
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum DownloadStatus {
NotYetDownloaded(String),
Downloaded(ValidatedFile),
}
impl Default for DownloadStatus {
fn default() -> Self {
DownloadStatus::NotYetDownloaded(String::new())
}
}
impl Display for DownloadStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DownloadStatus::NotYetDownloaded(undownloaded) => {
write!(f, "NotYetDownloaded: {undownloaded}")
},
DownloadStatus::Downloaded(validated_file) => {
write!(f, "Downloaded: {validated_file}")
},
}
}
}
impl DownloadStatus {
#[must_use]
pub fn new(file: String) -> Self {
DownloadStatus::NotYetDownloaded(file)
}
#[must_use]
pub fn new_downloaded(file: ValidatedFile) -> Self {
Self::Downloaded(file)
}
#[must_use]
pub fn url(&self) -> &str {
match self {
DownloadStatus::NotYetDownloaded(url) => url,
DownloadStatus::Downloaded(validated_file) => &validated_file.uri,
}
}
#[must_use]
pub fn url_owned(&self) -> String {
match self {
DownloadStatus::NotYetDownloaded(url) => url.to_owned(),
DownloadStatus::Downloaded(validated_file) => validated_file.uri.clone(),
}
}
#[must_use]
pub fn is_downloaded(&self) -> bool {
match self {
DownloadStatus::NotYetDownloaded(_) => false,
DownloadStatus::Downloaded(_) => true,
}
}
#[must_use]
pub fn is_validated(&self) -> bool {
match self {
DownloadStatus::NotYetDownloaded(_) => false,
DownloadStatus::Downloaded(validated_file) => validated_file.validated,
}
}
}
/// A structure that manages various types of data associated with a single biological reference dataset.
/// A reference dataset typically consists of sequence files (like FASTA or Genbank)
/// and optional annotation files (like GFF, GTF, or BED) that provide additional layers of genomic
/// information.
///
/// The structure enforces important data integrity rules:
/// - Every dataset must have a unique label for identification
/// - At least one file must be associated with a label
/// - Annotation files (GFF, GTF, BED) can only be included if there's an associated sequence file
/// (FASTA or Genbank) present
///
/// Each field represents a different file format commonly used in bioinformatics:
/// - FASTA: Raw sequence data
/// - Genbank: Annotated sequence data
/// - GFA: Genome/gene assembly graphs
/// - GFF: General Feature Format for genomic features
/// - GTF: Gene Transfer Format (a refined version of GFF)
/// - BED: Browser Extensible Data format for genomic intervals
/// - TAR: A tar-archive ("tarball") of arbitrary files
///
/// Files are stored as optional strings, typically representing paths or identifiers to the actual
/// data. This allows for flexible dataset configurations while maintaining data integrity through
/// the `try_new()` constructor.
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct RefDataset {
pub label: String,
// TODO: Replace the strings with the `DownloadStatus` enum
pub fasta: Option<DownloadStatus>,
pub genbank: Option<DownloadStatus>,
pub gfa: Option<DownloadStatus>,
pub gff: Option<DownloadStatus>,
pub gtf: Option<DownloadStatus>,
pub bed: Option<DownloadStatus>,
pub tar: Option<DownloadStatus>,
}
impl RefDataset {
/// Create a new reference dataset while enforcing data integrity rules.
///
/// This method creates a new [`RefDataset`] instance after validating that certain
/// critical invariants are maintained:
/// - Every dataset must have a non-empty label for identification
/// - At least one file (FASTA, Genbank, GFA, GFF, GTF, or BED) must be associated with a label
/// - Annotation files (GFF, GTF, BED) can only be included if there's an associated sequence file
/// (FASTA or Genbank) present
/// - All provided file URLs must be valid and accessible
///
/// # Arguments
///
/// * `label` - A unique identifier for this reference dataset
/// * `fasta` - Optional URL to a FASTA format sequence file
/// * `genbank` - Optional URL to a Genbank format sequence file
/// * `gfa` - Optional URL to a GFA format assembly graph file
/// * `gff` - Optional URL to a GFF format annotation file
/// * `gtf` - Optional URL to a GTF format annotation file
/// * `bed` - Optional URL to a BED format annotation file
/// # `tar` - Optional URL to a tar archive of arbitrary files
///
/// # Returns
///
/// Returns a `Result<RefDataset, EntryError>` which is:
/// - `Ok(RefDataset)` if all validation passes
/// - `Err(EntryError)` if any validation fails
///
/// # Errors
///
/// This function will return an error if:
/// - No files are provided with the label (`EntryError::LabelButNoFiles`)
/// - Annotation files are provided without sequence files (`EntryError::AnnotationsButNoSequence`)
/// - Any provided URL is invalid or inaccessible
///
/// # Examples
///
/// ```no_run
/// use your_crate::RefDataset;
///
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let dataset = RefDataset::try_new(
/// "hg38".to_string(),
/// Some("https://example.com/hg38.fa".to_string()),
/// None,
/// None,
/// Some("https://example.com/hg38.gff".to_string()),
/// None,
/// None,
/// None
/// ).await?;
/// # Ok(())
/// # }
/// ```
#[allow(clippy::similar_names, clippy::too_many_arguments)]
pub async fn try_new(
label: String,
fasta: Option<String>,
genbank: Option<String>,
gfa: Option<String>,
gff: Option<String>,
gtf: Option<String>,
bed: Option<String>,
tar: Option<String>,
) -> Result<Self, EntryError> {
match (&fasta, &genbank, &gfa, &gff, >f, &bed, &tar) {
// This is the case when no files are provided, but a label is (label is the only argument to this function
// that is not an Option<String>)
(None, None, None, None, None, None, None) => Err(EntryError::LabelButNoFiles),
// If none of the above conditions are met, we're all good! Return an instance of the `RefDataset` struct
// with validated combinations of fields.
_ => {
// check each of the possible files, if provided by the user. If all are successful, initialize each
// file name wrapped in a `DownloadStatus` `NotYetDownloaded` variant, which preserves backwards
// compatibility with the `refman.toml` format and controls the valid ways state can be updated in the
// `refman` register-download-validate workflow. We'll just use variable shadowing here instead of
// binding new variables.
let fasta = if let Some(url_to_check) = fasta {
let _ = check_url(&url_to_check).await?;
let status = DownloadStatus::new(url_to_check);
Some(status)
} else {
None
};
let genbank = if let Some(url_to_check) = genbank {
let _ = check_url(&url_to_check).await?;
let status = DownloadStatus::new(url_to_check);
Some(status)
} else {
None
};
let gfa = if let Some(url_to_check) = gfa {
let _ = check_url(&url_to_check).await?;
let status = DownloadStatus::new(url_to_check);
Some(status)
} else {
None
};
let gff = if let Some(url_to_check) = gff {
let _ = check_url(&url_to_check).await?;
let status = DownloadStatus::new(url_to_check);
Some(status)
} else {
None
};
let gtf = if let Some(url_to_check) = gtf {
let _ = check_url(&url_to_check).await?;
let status = DownloadStatus::new(url_to_check);
Some(status)
} else {
None
};
let bed = if let Some(url_to_check) = bed {
let _ = check_url(&url_to_check).await?;
let status = DownloadStatus::new(url_to_check);
Some(status)
} else {
None
};
let tar = if let Some(url_to_check) = tar {
let _ = check_url(&url_to_check).await?;
let status = DownloadStatus::new(url_to_check);
Some(status)
} else {
None
};
// If all provided URLs are valid, set up an instance of a registry
Ok(Self {
label,
fasta,
genbank,
gfa,
gff,
gtf,
bed,
tar,
})
},
}
}
pub(crate) fn get_fasta_download(&self, target_dir: &Path) -> Option<UnvalidatedFile> {
// resolve state for each of the files
match &self.fasta {
Some(file) => match file {
DownloadStatus::NotYetDownloaded(uri) => {
let unvalidated = UnvalidatedFile::Fasta {
uri: uri.clone(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
DownloadStatus::Downloaded(validated_file) => {
debug!(
"Deciding whether to re-download the previously downloaded file at {:?}...",
validated_file
);
// pull in the previously downloaded file path
let old_path = &validated_file.local_path;
// make sure the old file still exists or is in the requested destination. If not, it should
// be downloaded.
if !old_path.exists() || !old_path.starts_with(target_dir) {
return Some(UnvalidatedFile::Fasta {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
});
}
// make sure there's a hash we can use to checksum
let Some(old_hash) = &validated_file.hash else {
debug!("The file was never hashed, so it will be re-downloaded");
return None;
};
// make sure the file exists and still matches the hash. Otherwise, re-download.
let Ok(new_hash) = hash_valid_download(old_path) else {
debug!(
"The checksum failed because the file could not be accessed, so it will be redownloaded"
);
return None;
};
if old_path.exists() && old_hash.eq(&new_hash) {
debug!(
"The path previously recorded for the download, {:?}, existed and it passed the checksum, so it will not be re-downloaded",
old_path,
);
return None;
}
// if we've made it this far, the file should be redownloaded. Clear the
// local path and fill the URI into an UnvalidatedFile variant
let unvalidated = UnvalidatedFile::Fasta {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
},
None => None,
}
}
pub(crate) fn get_genbank_download(&self, target_dir: &Path) -> Option<UnvalidatedFile> {
match &self.genbank {
Some(file) => match file {
DownloadStatus::NotYetDownloaded(uri) => {
let unvalidated = UnvalidatedFile::Genbank {
uri: uri.to_string(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
DownloadStatus::Downloaded(validated_file) => {
debug!(
"Deciding whether to re-download the previously downloaded file at {:?}...",
validated_file
);
// pull in the previously downloaded file path
let old_path = &validated_file.local_path;
// make sure the old file still exists. If not, it should be downloaded.
if !old_path.exists() || !old_path.starts_with(target_dir) {
return Some(UnvalidatedFile::Genbank {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
});
}
// make sure there's a hash we can use to checksum
let Some(old_hash) = &validated_file.hash else {
debug!("The file was never hashed, so it will be re-downloaded");
return None;
};
// make sure the file exists and still matches the hash. Otherwise, re-download.
let Ok(new_hash) = hash_valid_download(old_path) else {
debug!(
"The checksum failed because the file could not be accessed, so it will be redownloaded"
);
return None;
};
if old_path.exists() && old_hash.eq(&new_hash) {
debug!(
"The path previously recorded for the download, {:?}, existed and it passed the checksum, so it will not be re-downloaded",
old_path,
);
return None;
}
// if we've made it this far, the file should be redownloaded. Clear the
// local path and fill the URI into an UnvalidatedFile variant
let unvalidated = UnvalidatedFile::Genbank {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
},
None => None,
}
}
pub(crate) fn get_gfa_download(&self, target_dir: &Path) -> Option<UnvalidatedFile> {
match &self.gfa {
Some(file) => match file {
DownloadStatus::NotYetDownloaded(uri) => {
let unvalidated = UnvalidatedFile::Gfa {
uri: uri.to_string(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
DownloadStatus::Downloaded(validated_file) => {
debug!(
"Deciding whether to re-download the previously downloaded file at {:?}...",
validated_file
);
// pull in the previously downloaded file path
let old_path = &validated_file.local_path;
// make sure the old file still exists. If not, it should be downloaded.
if !old_path.exists() || !old_path.starts_with(target_dir) {
return Some(UnvalidatedFile::Gfa {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
});
}
// make sure there's a hash we can use to checksum
let Some(old_hash) = &validated_file.hash else {
debug!("The file was never hashed, so it will be re-downloaded");
return None;
};
// make sure the file exists and still matches the hash. Otherwise, re-download.
let Ok(new_hash) = hash_valid_download(old_path) else {
debug!(
"The checksum failed because the file could not be accessed, so it will be redownloaded"
);
return None;
};
if old_path.exists() && old_hash.eq(&new_hash) {
debug!(
"The path previously recorded for the download, {:?}, existed and it passed the checksum, so it will not be re-downloaded",
old_path,
);
return None;
}
// if we've made it this far, the file should be redownloaded. Clear the
// local path and fill the URI into an UnvalidatedFile variant
let unvalidated = UnvalidatedFile::Gfa {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
},
None => None,
}
}
pub(crate) fn get_gff_download(&self, target_dir: &Path) -> Option<UnvalidatedFile> {
match &self.gff {
Some(file) => match file {
DownloadStatus::NotYetDownloaded(uri) => {
let unvalidated = UnvalidatedFile::Gff {
uri: uri.to_string(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
DownloadStatus::Downloaded(validated_file) => {
debug!(
"Deciding whether to re-download the previously downloaded file at {:?}...",
validated_file
);
// pull in the previously downloaded file path
let old_path = &validated_file.local_path;
// make sure the old file still exists. If not, it should be downloaded.
if !old_path.exists() || !old_path.starts_with(target_dir) {
return Some(UnvalidatedFile::Gff {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
});
}
// make sure there's a hash we can use to checksum
let Some(old_hash) = &validated_file.hash else {
debug!("The file was never hashed, so it will be re-downloaded");
return None;
};
// make sure the file exists and still matches the hash. Otherwise, re-download.
let Ok(new_hash) = hash_valid_download(old_path) else {
debug!(
"The checksum failed because the file could not be accessed, so it will be redownloaded"
);
return None;
};
if old_path.exists() && old_hash.eq(&new_hash) {
debug!(
"The path previously recorded for the download, {:?}, existed and it passed the checksum, so it will not be re-downloaded",
old_path,
);
return None;
}
// if we've made it this far, the file should be redownloaded. Clear the
// local path and fill the URI into an UnvalidatedFile variant
let unvalidated = UnvalidatedFile::Gff {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
},
None => None,
}
}
pub(crate) fn get_gtf_download(&self, target_dir: &Path) -> Option<UnvalidatedFile> {
match &self.gtf {
Some(file) => match file {
DownloadStatus::NotYetDownloaded(uri) => {
let unvalidated = UnvalidatedFile::Gtf {
uri: uri.to_string(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
DownloadStatus::Downloaded(validated_file) => {
debug!(
"Deciding whether to re-download the previously downloaded file at {:?}...",
validated_file
);
// pull in the previously downloaded file path
let old_path = &validated_file.local_path;
// make sure the old file still exists. If not, it should be downloaded.
if !old_path.exists() || !old_path.starts_with(target_dir) {
return Some(UnvalidatedFile::Gtf {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
});
}
// make sure there's a hash we can use to checksum
let Some(old_hash) = &validated_file.hash else {
debug!("The file was never hashed, so it will be re-downloaded");
return None;
};
// make sure the file exists and still matches the hash. Otherwise, re-download.
let Ok(new_hash) = hash_valid_download(old_path) else {
debug!(
"The checksum failed because the file could not be accessed, so it will be redownloaded"
);
return None;
};
if old_path.exists() && old_hash.eq(&new_hash) {
debug!(
"The path previously recorded for the download, {:?}, existed and it passed the checksum, so it will not be re-downloaded",
old_path,
);
return None;
}
// if we've made it this far, the file should be redownloaded. Clear the
// local path and fill the URI into an UnvalidatedFile variant
let unvalidated = UnvalidatedFile::Gtf {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
},
None => None,
}
}
pub(crate) fn get_bed_download(&self, target_dir: &Path) -> Option<UnvalidatedFile> {
match &self.bed {
Some(file) => match file {
DownloadStatus::NotYetDownloaded(uri) => {
let unvalidated = UnvalidatedFile::Bed {
uri: uri.to_string(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
DownloadStatus::Downloaded(validated_file) => {
debug!(
"Deciding whether to re-download the previously downloaded file at {:?}...",
validated_file
);
// pull in the previously downloaded file path
let old_path = &validated_file.local_path;
// make sure the old file still exists. If not, it should be downloaded.
if !old_path.exists() || !old_path.starts_with(target_dir) {
return Some(UnvalidatedFile::Bed {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
});
}
// make sure there's a hash we can use to checksum
let Some(old_hash) = &validated_file.hash else {
debug!("The file was never hashed, so it will be re-downloaded");
return None;
};
// make sure the file exists and still matches the hash. Otherwise, re-download.
let Ok(new_hash) = hash_valid_download(old_path) else {
debug!(
"The checksum failed because the file could not be accessed, so it will be redownloaded"
);
return None;
};
if old_path.exists() && old_hash.eq(&new_hash) {
debug!(
"The path previously recorded for the download, {:?}, existed and it passed the checksum, so it will not be re-downloaded",
old_path,
);
return None;
}
// if we've made it this far, the file should be redownloaded. Clear the
// local path and fill the URI into an UnvalidatedFile variant
let unvalidated = UnvalidatedFile::Bed {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
},
None => None,
}
}
pub(crate) fn get_tar_download(&self, target_dir: &Path) -> Option<UnvalidatedFile> {
match &self.tar {
Some(file) => match file {
DownloadStatus::NotYetDownloaded(uri) => {
let unvalidated = UnvalidatedFile::Tar {
uri: uri.to_string(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
DownloadStatus::Downloaded(validated_file) => {
debug!(
"Deciding whether to re-download the previously downloaded file at {:?}...",
validated_file
);
// pull in the previously downloaded file path
let old_path = &validated_file.local_path;
// make sure the old file still exists. If not, it should be downloaded.
if !old_path.exists() || !old_path.starts_with(target_dir) {
return Some(UnvalidatedFile::Tar {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
});
}
// make sure there's a hash we can use to checksum
let Some(old_hash) = &validated_file.hash else {
debug!("The file was never hashed, so it will be re-downloaded");
return None;
};
// make sure the file exists and still matches the hash. Otherwise, re-download.
let Ok(new_hash) = hash_valid_download(old_path) else {
debug!(
"The checksum failed because the file could not be accessed, so it will be redownloaded"
);
return None;
};
if old_path.exists() && old_hash.eq(&new_hash) {
debug!(
"The path previously recorded for the download, {:?}, existed and it passed the checksum, so it will not be re-downloaded",
old_path,
);
return None;
}
// if we've made it this far, the file should be redownloaded. Clear the
// local path and fill the URI into an UnvalidatedFile variant
let unvalidated = UnvalidatedFile::Tar {
uri: validated_file.uri.clone(),
local_path: PathBuf::new(),
};
Some(unvalidated)
},
},
None => None,
}
}
/// Updates the state of the dataset with newly downloaded and validated file's information.
///
/// This method takes an `UnvalidatedFile` that has been downloaded and validates it,
/// updating the corresponding field in the dataset with the new download status. This
/// is a key part of the refman register-download-validate workflow, transitioning files
/// from the `NotYetDownloaded` to `Downloaded` state.
///
/// The method handles all supported file types (FASTA, Genbank, GFA, GFF, GTF, BED)
/// and updates the respective field in the dataset with validated file information,
/// including hash values and local paths.
///
/// # Arguments
///
/// * `downloaded_file` - An `UnvalidatedFile` containing the downloaded file's information,
/// including its URI and local path
///
/// # Returns
///
/// Returns `Ok(())` if validation and update succeeds, otherwise returns a `ValidationError`
///
/// # Errors
///
/// Returns a `ValidationError` if:
/// - The file fails validation checks
/// - The file hash cannot be computed
/// - The file type is invalid or corrupted
///
/// # Examples
///
/// ```rust,no_run
/// use your_crate::{RefDataset, UnvalidatedFile};
/// use std::path::PathBuf;
///
/// let mut dataset = RefDataset::default();
/// let downloaded = UnvalidatedFile::Fasta {
/// uri: "https://example.com/file.fa".to_string(),
/// local_path: PathBuf::from("/tmp/file.fa"),
/// };
/// dataset.update_with_download(&downloaded).unwrap();
/// ```
pub fn update_with_download(
&mut self,
downloaded_file: &UnvalidatedFile,
) -> Result<(), ValidationError> {
match downloaded_file {
UnvalidatedFile::Fasta { .. } => {
let validated = downloaded_file.try_validate()?;
let updated_status = DownloadStatus::new_downloaded(validated);
self.fasta = Some(updated_status);
},
UnvalidatedFile::Genbank { .. } => {
let validated = downloaded_file.try_validate()?;
let updated_status = DownloadStatus::new_downloaded(validated);
self.genbank = Some(updated_status);
},
UnvalidatedFile::Gfa { .. } => {
let validated = downloaded_file.try_validate()?;
let updated_status = DownloadStatus::new_downloaded(validated);
self.gfa = Some(updated_status);
},
UnvalidatedFile::Gff { .. } => {
let validated = downloaded_file.try_validate()?;
let updated_status = DownloadStatus::new_downloaded(validated);
self.gff = Some(updated_status);
},
UnvalidatedFile::Gtf { .. } => {
let validated = downloaded_file.try_validate()?;
let updated_status = DownloadStatus::new_downloaded(validated);
self.gtf = Some(updated_status);
},
UnvalidatedFile::Bed { .. } => {
let validated = downloaded_file.try_validate()?;
let updated_status = DownloadStatus::new_downloaded(validated);
self.bed = Some(updated_status);
},
UnvalidatedFile::Tar { .. } => {
let validated = downloaded_file.try_validate()?;
let updated_status = DownloadStatus::new_downloaded(validated);
self.tar = Some(updated_status);
},
}
Ok(())
}
}