Skip to content

Commit

Permalink
build!: add features for disabling sqlite-based implementation (#74)
Browse files Browse the repository at this point in the history
Release-As: 0.7.0
  • Loading branch information
holtgrewe authored Jul 6, 2023
1 parent a84c65c commit b7fd2f2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 41 deletions.
21 changes: 16 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ readme = "README.md"
name = "seqrepo"
path = "src/lib.rs"

[features]
# By default, we enable the directory-based implementation.
default = ["impl"]
# Directory-based implementation of the interface as provided by the Python
# reference implementation. This will create a runtime dependency on
# `libsqlite3`.
impl = ["dep:chrono", "dep:noodles-bgzf", "dep:noodles-core", "dep:noodles-fasta", "dep:rusqlite"]
# Optional caching implementation that is useful in testing scenarios where
# one only wants to provide minimal data, e.g., in continuous integration.
cached = ["impl"]

[dependencies]
chrono = "0.4"
noodles-bgzf = "0.22"
noodles-core = "0.12"
noodles-fasta = "0.25"
rusqlite = "0.29"
chrono = { version = "0.4", optional = true }
noodles-bgzf = { version = "0.22", optional = true }
noodles-core = { version = "0.12", optional = true }
noodles-fasta = { version = "0.25", optional = true }
rusqlite = { version = "0.29", optional = true }
thiserror = "1.0"
tracing = "0.1"

Expand Down
11 changes: 7 additions & 4 deletions src/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ use std::{
sync::{Arc, Mutex},
};

use crate::error::Error;
use crate::repo::{self, AliasOrSeqId, SeqRepo};
use crate::repo::SeqRepo;
use crate::{
error::Error,
interface::{AliasOrSeqId, Interface},
};

/// Sequence repository reading from actual implementation and writing to a cache.
pub struct CacheWritingSeqRepo {
Expand Down Expand Up @@ -50,7 +53,7 @@ impl CacheWritingSeqRepo {
}
}

impl repo::Interface for CacheWritingSeqRepo {
impl Interface for CacheWritingSeqRepo {
fn fetch_sequence_part(
&self,
alias_or_seq_id: &AliasOrSeqId,
Expand Down Expand Up @@ -122,7 +125,7 @@ impl CacheReadingSeqRepo {
}
}

impl repo::Interface for CacheReadingSeqRepo {
impl Interface for CacheReadingSeqRepo {
fn fetch_sequence_part(
&self,
alias_or_seq_id: &AliasOrSeqId,
Expand Down
27 changes: 27 additions & 0 deletions src/interface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Implementation of the interface trait.

use crate::error::Error;

/// Trait describing the interface of a sequence repository.
pub trait Interface {
/// Fetch part sequence given an alias.
fn fetch_sequence(&self, alias_or_seq_id: &AliasOrSeqId) -> Result<String, Error> {
self.fetch_sequence_part(alias_or_seq_id, None, None)
}

/// Fetch part sequence given an alias.
fn fetch_sequence_part(
&self,
alias_or_seq_id: &AliasOrSeqId,
begin: Option<usize>,
end: Option<usize>,
) -> Result<String, Error>;
}

pub enum AliasOrSeqId {
Alias {
value: String,
namespace: Option<String>,
},
SeqId(String),
}
21 changes: 16 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
//! This is the `seqrepo` library.

mod aliases;
mod cached;
mod error;
mod fasta;
mod repo;
#[cfg(feature = "impl")]
pub(crate) mod aliases;
#[cfg(feature = "cached")]
pub(crate) mod cached;
pub(crate) mod error;
#[cfg(feature = "impl")]
pub(crate) mod fasta;
#[cfg(feature = "impl")]
pub(crate) mod interface;
#[cfg(feature = "impl")]
pub(crate) mod repo;

pub use crate::aliases::*;
#[cfg(feature = "cached")]
pub use crate::cached::*;
pub use crate::error::*;
#[cfg(feature = "impl")]
pub use crate::fasta::*;
#[cfg(feature = "impl")]
pub use crate::interface::*;
#[cfg(feature = "impl")]
pub use crate::repo::*;
31 changes: 4 additions & 27 deletions src/repo.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
//! Code providing the interface for sequence repositories and the base `SeqRepo` implementation.
//! Code providing the base `SeqRepo` implementation.

use std::path::{Path, PathBuf};

use crate::error::Error;
use crate::{AliasDb, FastaDir, Namespace, Query};

/// Trait describing the interface of a sequence repository.
pub trait Interface {
/// Fetch part sequence given an alias.
fn fetch_sequence(&self, alias_or_seq_id: &AliasOrSeqId) -> Result<String, Error> {
self.fetch_sequence_part(alias_or_seq_id, None, None)
}

/// Fetch part sequence given an alias.
fn fetch_sequence_part(
&self,
alias_or_seq_id: &AliasOrSeqId,
begin: Option<usize>,
end: Option<usize>,
) -> Result<String, Error>;
}
use crate::interface::Interface;
use crate::{AliasDb, AliasOrSeqId, FastaDir, Namespace, Query};

/// Provide (read-only) access to a `seqrepo` sequence repository.
#[derive(Debug)]
Expand All @@ -34,14 +19,6 @@ pub struct SeqRepo {
fasta_dir: FastaDir,
}

pub enum AliasOrSeqId {
Alias {
value: String,
namespace: Option<String>,
},
SeqId(String),
}

impl SeqRepo {
/// Create new `SeqRepo` at the given path.
pub fn new<P>(path: P, instance: &str) -> Result<Self, Error>
Expand Down Expand Up @@ -120,7 +97,7 @@ impl Interface for SeqRepo {

#[cfg(test)]
mod test {
use crate::{repo::Interface, AliasOrSeqId, SeqRepo};
use crate::{AliasOrSeqId, Interface, SeqRepo};
use anyhow::Error;

#[test]
Expand Down

0 comments on commit b7fd2f2

Please sign in to comment.