Skip to content

Adding feature "serde_feature" to enable support. #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions .github/workflow/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
Formatting:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt

- name: Check format
run: cargo fmt -- --check

Linting:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: clippy

- name: Lint with clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

Testing:
needs: Formatting
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build: [beta, stable, windows, macos]
include:
- build: macos
os: macos-latest
rust: stable
- build: windows
os: windows-latest
rust: stable
- build: beta
os: ubuntu-latest
rust: beta
- build: stable
os: ubuntu-latest
rust: stable
steps:
- name: Checkout repository
uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true

- name: Install ${{ matrix.rust }} toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true

- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --all --no-fail-fast

Coverage:
needs: Formatting
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true

- name: Install cargo-tarpaulin
uses: actions-rs/[email protected]
with:
crate: cargo-tarpaulin
version: latest
use-tool-cache: true

- name: Coverage with tarpaulin
run: cargo tarpaulin --all --all-features --timeout 600 --out Lcov -- --test-threads 1

- name: Upload coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./lcov.info
37 changes: 0 additions & 37 deletions .travis.yml

This file was deleted.

11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [next]
- BREAKING: Adding serialization with `serde` as a feature: `serde_feature`.
- Adding `Debug` and `Serialize`/`Deserialize` traits to a couple of more types.
- Moving from Travis CI to Github Actions for CI.

## [0.7.0] - 2020-07-02
No changelog is kept up to and including this version.
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ homepage = "https://rust-bio.github.io"
repository = "https://github.com/rust-bio/rust-bio"
documentation = "https://docs.rs/bio"
readme = "README.md"
license = "MIT"
license-file = "LICENSE.md"

[features]
serde_feature = ["serde", "serde_derive"]

[dependencies]
serde = "1.0"
serde_derive = "1.0"
quick-error = "1.2"
regex = "1.0"
lazy_static = "1.1"
derive-new = "0.5"

serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
9 changes: 6 additions & 3 deletions src/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pub type TextSlice<'a> = &'a [u8];
/// value associated with the clipping operations are the lengths clipped. In case
/// of standard modes like Global, Semi-Global and Local alignment, the clip operations
/// are filtered out
#[derive(Eq, PartialEq, Debug, Copy, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub enum AlignmentOperation {
Match,
Subst,
Expand All @@ -33,7 +34,8 @@ pub enum AlignmentOperation {
/// appropriately set.
///
/// The default alignment mode is Global.
#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum AlignmentMode {
Local,
Semiglobal,
Expand All @@ -53,7 +55,8 @@ impl Default for AlignmentMode {
/// lengths of sequences x and y, and the alignment edit operations. The start position
/// and end position of the alignment does not include the clipped regions. The length
/// of clipped regions are already encapsulated in the Alignment Operation.
#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Eq, PartialEq, Clone, Default)]
pub struct Alignment {
/// Smith-Waterman alignment score
pub score: i32,
Expand Down
1 change: 1 addition & 0 deletions src/annot/contig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use strand::*;
/// # }
/// # fn main() { try_main().unwrap(); }
/// ```
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Contig<R, S> {
refid: R,
Expand Down
2 changes: 2 additions & 0 deletions src/annot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub mod spliced;

// Errors that arise in parsing annotations.
quick_error! {
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub enum ParseAnnotError {
BadAnnot {
Expand All @@ -76,6 +77,7 @@ quick_error! {

// Errors that arise in maniuplating annotations
quick_error! {
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub enum AnnotError {
NoStrand {
Expand Down
1 change: 1 addition & 0 deletions src/annot/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use strand::*;
/// # }
/// # fn main() { try_main().unwrap(); }
/// ```
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Pos<R, S> {
refid: R,
Expand Down
2 changes: 2 additions & 0 deletions src/annot/refids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ use std::ops::Deref;
/// assert_eq!(Rc::strong_count(&chr_i), 7);
/// }
/// ```
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
pub struct RefIDSet<R> {
refids: HashMap<String, R>,
}
Expand Down
10 changes: 10 additions & 0 deletions src/annot/spliced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mod inex {

use super::SplicingError;

#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct InEx {
intron_length: usize,
Expand Down Expand Up @@ -69,6 +70,7 @@ mod inex {

// Represent just the start (relative to the start of the location) and length of exons
// Useful for internal coordinate math
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Ex {
start: usize,
Expand All @@ -88,12 +90,15 @@ mod inex {
}

// Iterator over the Ex exons from lowest to highest coordinate
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
pub struct Exes<'a> {
state: ExesState,
curr_start: usize,
rest: Iter<'a, InEx>,
}

#[derive(Debug)]
enum ExesState {
FirstExon(usize),
LaterExon,
Expand Down Expand Up @@ -140,6 +145,7 @@ mod inex {

// Represent just the start (relative to the start of the location) and length of introns
// Useful for internal coordinate math
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct In {
start: usize,
Expand All @@ -160,6 +166,8 @@ mod inex {
}

// Iterator over the Ex introns from lowest to highest coordinate
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
pub struct Ins<'a> {
curr_start: usize,
rest: Iter<'a, InEx>,
Expand Down Expand Up @@ -223,6 +231,7 @@ mod inex {
/// # }
/// # fn main() { try_main().unwrap(); }
/// ```
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Spliced<R, S> {
refid: R,
Expand Down Expand Up @@ -687,6 +696,7 @@ pub type SeqSplicedStranded = Spliced<String, ReqStrand>;
pub type SeqSplicedUnstranded = Spliced<String, NoStrand>;

quick_error! {
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub enum SplicingError {
IntronLength {
Expand Down
6 changes: 4 additions & 2 deletions src/genome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub trait AbstractInterval {
}
}

#[derive(new, Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(new, Debug, PartialEq, Eq, Clone, Hash)]
pub struct Interval {
contig: String,
range: Range<Position>,
Expand Down Expand Up @@ -67,7 +68,8 @@ pub trait AbstractLocus {
fn pos(&self) -> Position;
}

#[derive(new, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(new, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub struct Locus {
contig: String,
pos: Position,
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#[macro_use]
#[cfg_attr(feature = "serde_feature", macro_use)]
#[cfg(feature = "serde_feature")]
extern crate serde_derive;
#[macro_use]
extern crate quick_error;
Expand Down
4 changes: 4 additions & 0 deletions src/strand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::ops::Neg;
use std::str::FromStr;

/// Strand information.
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy)]
pub enum Strand {
Forward,
Expand Down Expand Up @@ -134,6 +135,7 @@ impl From<NoStrand> for Strand {
}

/// Strand information for annotations that require a strand.
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq, Ord, PartialOrd, Copy)]
pub enum ReqStrand {
Forward,
Expand Down Expand Up @@ -243,6 +245,7 @@ impl Neg for ReqStrand {

/// Strand information for annotations that definitively have no
/// strand information.
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Hash, PartialEq, Eq, Ord, PartialOrd, Copy)]
pub enum NoStrand {
Unknown,
Expand Down Expand Up @@ -302,6 +305,7 @@ where
}

quick_error! {
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub enum StrandError {
InvalidChar(invalid_char: char) {
Expand Down
3 changes: 2 additions & 1 deletion src/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pub trait AbstractVariant: genome::AbstractLocus {
}

/// Possible genomic variants.
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub enum Kind {
SNV(Base),
MNV(Sequence),
Expand Down