Skip to content

Commit da5206f

Browse files
make serde optional (#23)
Co-authored-by: Johannes Köster <[email protected]>
1 parent 27c0e7d commit da5206f

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bio-types"
3-
version = "0.7.1-alpha.0"
3+
version = "0.8.0-alpha.0"
44
authors = ["Johannes Köster <[email protected]>"]
55
description = "A collection of common biomedical types for use in rust-bio and rust-htslib."
66
homepage = "https://rust-bio.github.io"
@@ -11,8 +11,7 @@ license = "MIT"
1111

1212

1313
[dependencies]
14-
serde = "1.0"
15-
serde_derive = "1.0"
14+
serde = { version = "^1", optional = true, features=["derive"] }
1615
quick-error = "1.2"
1716
regex = "1.0"
1817
lazy_static = "1.1"

src/alignment.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
//! Types for representing pairwise sequence alignments
77
8+
#[cfg(feature = "serde")]
9+
use serde::{Deserialize, Serialize};
10+
811
pub type TextSlice<'a> = &'a [u8];
912

1013
/// Alignment operations supported are match, substitution, insertion, deletion
@@ -15,7 +18,8 @@ pub type TextSlice<'a> = &'a [u8];
1518
/// value associated with the clipping operations are the lengths clipped. In case
1619
/// of standard modes like Global, Semi-Global and Local alignment, the clip operations
1720
/// are filtered out
18-
#[derive(Eq, PartialEq, Debug, Copy, Clone, Serialize, Deserialize)]
21+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
22+
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
1923
pub enum AlignmentOperation {
2024
Match,
2125
Subst,
@@ -33,7 +37,8 @@ pub enum AlignmentOperation {
3337
/// appropriately set.
3438
///
3539
/// The default alignment mode is Global.
36-
#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
40+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
41+
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
3742
pub enum AlignmentMode {
3843
Local,
3944
Semiglobal,
@@ -53,7 +58,8 @@ impl Default for AlignmentMode {
5358
/// lengths of sequences x and y, and the alignment edit operations. The start position
5459
/// and end position of the alignment does not include the clipped regions. The length
5560
/// of clipped regions are already encapsulated in the Alignment Operation.
56-
#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize, Default)]
61+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
62+
#[derive(Debug, Eq, PartialEq, Clone, Default)]
5763
pub struct Alignment {
5864
/// Smith-Waterman alignment score
5965
pub score: i32,

src/genome.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::cmp;
22
use std::ops::Range;
33

4+
#[cfg(feature = "serde")]
5+
use serde::{Deserialize, Serialize};
6+
47
pub type Position = u64;
58
pub type Length = u64;
69

@@ -19,8 +22,8 @@ pub trait AbstractInterval {
1922
&& locus.pos() < self.range().end
2023
}
2124
}
22-
23-
#[derive(new, Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)]
25+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
26+
#[derive(new, Debug, PartialEq, Eq, Clone, Hash)]
2427
pub struct Interval {
2528
contig: String,
2629
range: Range<Position>,
@@ -67,7 +70,8 @@ pub trait AbstractLocus {
6770
fn pos(&self) -> Position;
6871
}
6972

70-
#[derive(new, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize)]
73+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
74+
#[derive(new, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
7175
pub struct Locus {
7276
contig: String,
7377
pos: Position,

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#[macro_use]
2-
extern crate serde_derive;
1+
#[cfg(feature = "serde")]
2+
extern crate serde;
33
#[macro_use]
44
extern crate quick_error;
55
#[macro_use]

src/variant.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
use genome;
22
use sequence::{Base, Sequence};
33

4+
#[cfg(feature = "serde")]
5+
use serde::{Deserialize, Serialize};
6+
47
/// A trait for providing variant information. This can e.g. be implemented by file readers.
58
pub trait AbstractVariant: genome::AbstractLocus {
69
fn kind(&self) -> &Kind;
710
}
811

912
/// Possible genomic variants.
10-
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)]
13+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14+
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
1115
pub enum Kind {
1216
SNV(Base),
1317
MNV(Sequence),

0 commit comments

Comments
 (0)