use std::fmt;
use std::path::{Path, PathBuf};
use crate::dim::{Dimension, Dimensions};
use crate::hash::ContentHash;
use crate::note::Note;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DataKind {
Reads,
Reference,
Alignment,
Variants,
Intervals,
ResistanceReport,
EntitySet,
RankedList,
}
impl DataKind {
pub const ALL: [Self; 8] = [
Self::Reads,
Self::Reference,
Self::Alignment,
Self::Variants,
Self::Intervals,
Self::ResistanceReport,
Self::EntitySet,
Self::RankedList,
];
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::Reads => "Reads",
Self::Reference => "Reference",
Self::Alignment => "Alignment",
Self::Variants => "Variants",
Self::Intervals => "Intervals",
Self::ResistanceReport => "ResistanceReport",
Self::EntitySet => "EntitySet",
Self::RankedList => "RankedList",
}
}
#[must_use]
pub fn from_name(name: &str) -> Option<Self> {
Self::ALL.into_iter().find(|kind| kind.name() == name)
}
#[must_use]
pub const fn applies(self, dimension: Dimension) -> bool {
match (self, dimension) {
(_, Dimension::Organism) => true,
(Self::Reads, Dimension::SampleSet | Dimension::Pairing) => true,
(Self::Reads, Dimension::QualityEncoding) => true,
(Self::Reads, _) => false,
(Self::Reference, Dimension::Reference | Dimension::ContigNaming) => true,
(Self::Reference, Dimension::Release) => true,
(Self::Reference, _) => false,
(
Self::Alignment,
Dimension::Reference
| Dimension::ContigNaming
| Dimension::Coordinates
| Dimension::SampleSet
| Dimension::Pairing,
) => true,
(Self::Alignment, _) => false,
(
Self::Variants,
Dimension::Reference
| Dimension::ContigNaming
| Dimension::Coordinates
| Dimension::SampleSet,
) => true,
(Self::Variants, _) => false,
(
Self::Intervals,
Dimension::Reference | Dimension::ContigNaming | Dimension::Coordinates,
) => true,
(Self::Intervals, _) => false,
(Self::ResistanceReport, Dimension::SampleSet) => true,
(Self::ResistanceReport, _) => false,
(
Self::EntitySet | Self::RankedList,
Dimension::IdentifierNamespace | Dimension::Subject | Dimension::Release,
) => true,
(Self::EntitySet | Self::RankedList, _) => false,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum RemoteVerdict {
Pinned,
Replayed,
Live,
}
impl fmt::Display for RemoteVerdict {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Pinned => "pinned",
Self::Replayed => "replayed",
Self::Live => "live",
})
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Origin {
pub locator: String,
pub digest: ContentHash,
pub bytes: ContentHash,
pub fetched_at: i64,
pub verdict: RemoteVerdict,
}
#[derive(Clone, Debug)]
pub struct Dataset {
kind: DataKind,
origin: Option<Origin>,
path: Option<PathBuf>,
mates: Vec<PathBuf>,
dimensions: Dimensions,
notes: Vec<Note>,
}
impl Dataset {
#[must_use]
pub const fn new(kind: DataKind, path: Option<PathBuf>, dimensions: Dimensions) -> Self {
Self {
kind,
origin: None,
path,
mates: Vec::new(),
dimensions,
notes: Vec::new(),
}
}
#[must_use]
pub fn with_notes(mut self, notes: Vec<Note>) -> Self {
self.notes = notes;
self
}
#[must_use]
pub fn with_origin(mut self, origin: Origin) -> Self {
self.origin = Some(origin);
self
}
#[must_use]
pub const fn origin(&self) -> Option<&Origin> {
self.origin.as_ref()
}
#[must_use]
pub fn with_mate(mut self, mate: PathBuf) -> Self {
self.mates.push(mate);
self
}
#[must_use]
pub const fn kind(&self) -> DataKind {
self.kind
}
#[must_use]
pub fn path(&self) -> Option<&Path> {
self.path.as_deref()
}
#[must_use]
pub fn files(&self) -> Vec<PathBuf> {
self.path.iter().chain(self.mates.iter()).cloned().collect()
}
#[must_use]
pub const fn dimensions(&self) -> &Dimensions {
&self.dimensions
}
#[must_use]
pub fn notes(&self) -> &[Note] {
&self.notes
}
}