Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rust-bio/rust-htslib
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskoester committed Feb 22, 2018
2 parents c0e0ce9 + 66face4 commit ed2b565
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/bam/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use bam::Read;
/// The buffer is implemented as a ringbuffer, such that extension or movement to the right has
/// linear complexity. The buffer makes use of indexed random access. Hence, when fetching a
/// region at the very end of the BAM, everything before is omitted without cost.
#[derive(Debug)]
pub struct RecordBuffer {
reader: bam::IndexedReader,
inner: VecDeque<bam::Record>,
Expand Down Expand Up @@ -124,7 +125,7 @@ impl RecordBuffer {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum RecordBufferError {
UnknownSequence(chrom: String) {
description("unknown sequence")
Expand Down
2 changes: 2 additions & 0 deletions src/bam/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bam::HeaderView;


/// A BAM header.
#[derive(Debug, Clone)]
pub struct Header {
records: Vec<Vec<u8>>
}
Expand Down Expand Up @@ -53,6 +54,7 @@ impl Header {


/// Header record.
#[derive(Debug, Clone)]
pub struct HeaderRecord<'a> {
rec_type: Vec<u8>,
tags: Vec<(&'a [u8], Vec<u8>)>,
Expand Down
27 changes: 16 additions & 11 deletions src/bam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub trait Read: Sized {


/// A BAM reader.
#[derive(Debug)]
pub struct Reader {
bgzf: *mut htslib::BGZF,
header: HeaderView,
Expand Down Expand Up @@ -174,6 +175,7 @@ impl Drop for Reader {
}


#[derive(Debug)]
pub struct IndexedReader {
bgzf: *mut htslib::BGZF,
header: HeaderView,
Expand Down Expand Up @@ -311,6 +313,7 @@ impl Drop for IndexedReader {


/// A BAM writer.
#[derive(Debug)]
pub struct Writer {
f: *mut htslib::BGZF,
header: HeaderView,
Expand Down Expand Up @@ -429,6 +432,7 @@ impl Drop for Writer {


/// Iterator over the records of a BAM.
#[derive(Debug)]
pub struct Records<'a, R: 'a + Read> {
reader: &'a mut R
}
Expand All @@ -449,7 +453,7 @@ impl<'a, R: Read> Iterator for Records<'a, R> {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum ReadError {
Truncated {
description("truncated record")
Expand All @@ -476,7 +480,7 @@ impl ReadError {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum IndexedReaderError {
InvalidIndex {
description("invalid index")
Expand All @@ -489,7 +493,7 @@ quick_error! {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum WriterPathError {
InvalidPath {
description("invalid path")
Expand All @@ -502,7 +506,7 @@ quick_error! {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum IndexedReaderPathError {
InvalidPath {
description("invalid path")
Expand All @@ -515,7 +519,7 @@ quick_error! {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum BGZFError {
Some {
description("error reading BGZF file")
Expand All @@ -525,7 +529,7 @@ quick_error! {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum ReaderPathError {
InvalidPath {
description("invalid path")
Expand All @@ -538,7 +542,7 @@ quick_error! {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum ThreadingError {
Some {
description("error setting threads for multi-threaded writing")
Expand All @@ -547,7 +551,7 @@ quick_error! {
}

quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum WriteError {
Some {
description("error writing record")
Expand All @@ -557,7 +561,7 @@ quick_error! {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum FetchError {
Some {
description("error fetching a locus")
Expand All @@ -567,7 +571,7 @@ quick_error! {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum SeekError {
Some {
description("error seeking to voffset")
Expand All @@ -577,7 +581,7 @@ quick_error! {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum AuxWriteError {
Some {
description("error pushing aux data to record")
Expand Down Expand Up @@ -615,6 +619,7 @@ fn itr_next(bgzf: *mut htslib::BGZF, itr: *mut htslib:: hts_itr_t, record: *mut
}


#[derive(Debug)]
pub struct HeaderView {
inner: *mut htslib::bam_hdr_t,
owned: bool,
Expand Down
15 changes: 12 additions & 3 deletions src/bam/pileup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use std::slice;
use std::iter;
use std::fmt;

use htslib;

Expand All @@ -20,6 +21,7 @@ pub type Alignments<'a> = iter::Map<


/// A pileup over one genomic position.
#[derive(Debug)]
pub struct Pileup {
inner: *const htslib::bam_pileup1_t,
depth: u32,
Expand Down Expand Up @@ -57,6 +59,13 @@ pub struct Alignment<'a> {
}


impl<'a> fmt::Debug for Alignment<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Alignment")
}
}


impl<'a> Alignment<'a> {
pub fn new(inner: &'a htslib::bam_pileup1_t) -> Self {
Alignment { inner: inner }
Expand Down Expand Up @@ -108,8 +117,7 @@ impl<'a> Alignment<'a> {
}


#[derive(PartialEq)]
#[derive(Debug)]
#[derive(PartialEq, Eq, Debug, Copy, Clone, Hash)]
pub enum Indel {
Ins(u32),
Del(u32),
Expand All @@ -118,6 +126,7 @@ pub enum Indel {


/// Iterator over pileups.
#[derive(Debug)]
pub struct Pileups<'a, R: 'a + bam::Read> {
#[allow(dead_code)]
reader: &'a mut R,
Expand Down Expand Up @@ -172,7 +181,7 @@ impl<'a, R: bam::Read> Drop for Pileups<'a, R> {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum PileupError {
Some {
description("error generating pileup")
Expand Down
11 changes: 6 additions & 5 deletions src/bam/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ macro_rules! flag {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum CigarError {
UnsupportedOperation(msg: String) {
description("Unsupported CIGAR operation")
Expand Down Expand Up @@ -498,8 +498,7 @@ impl Drop for Record {
}

/// Auxiliary record data.
#[derive(Debug)]
#[derive(PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Aux<'a> {
Integer(i64),
String(&'a [u8]),
Expand Down Expand Up @@ -566,6 +565,7 @@ static ENCODE_BASE: [u8; 256] = [


/// The sequence of a record.
#[derive(Debug, Copy, Clone)]
pub struct Seq<'a> {
pub encoded: &'a [u8],
len: usize
Expand Down Expand Up @@ -605,7 +605,7 @@ unsafe impl<'a> Send for Seq<'a> {}
unsafe impl<'a> Sync for Seq<'a> {}


#[derive(PartialEq, Eq, Debug, Clone)]
#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash)]
pub enum Cigar {
Match(u32), // M
Ins(u32), // I
Expand Down Expand Up @@ -707,7 +707,8 @@ custom_derive! {
PartialEq,
Eq,
NewtypeDebug,
Clone
Clone,
Hash
)]
pub struct CigarString(pub Vec<Cigar>);
}
Expand Down
1 change: 1 addition & 0 deletions src/bcf/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use bcf;
/// linear complexity. The buffer does not use any indexed random access. Hence, for getting a
/// region at the very end of the BCF, you will have to wait until all records before have
/// been read.
#[derive(Debug)]
pub struct RecordBuffer {
reader: bcf::Reader,
ringbuffer: VecDeque<bcf::Record>,
Expand Down
11 changes: 7 additions & 4 deletions src/bcf/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub type SampleSubset = Vec<i32>;


/// A BCF header.
#[derive(Debug)]
pub struct Header {
pub inner: *mut htslib::bcf_hdr_t,
pub subset: Option<SampleSubset>,
Expand Down Expand Up @@ -92,7 +93,7 @@ impl Drop for Header {
}



#[derive(Debug)]
pub struct HeaderView {
pub inner: *mut htslib::bcf_hdr_t,
}
Expand Down Expand Up @@ -200,6 +201,7 @@ impl Drop for HeaderView {
}


#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum TagType {
Flag,
Integer,
Expand All @@ -208,6 +210,7 @@ pub enum TagType {
}


#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum TagLength {
Fixed,
AltAlleles,
Expand All @@ -218,7 +221,7 @@ pub enum TagLength {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum RidError {
UnknownSequence(name: String) {
description("unknown sequence")
Expand All @@ -229,7 +232,7 @@ quick_error! {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum SubsetError {
DuplicateSampleName {
description("duplicate sample name when subsetting header")
Expand All @@ -239,7 +242,7 @@ quick_error! {


quick_error! {
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum TagTypeError {
UnexpectedTagType {
description("unexpected tag type in header")
Expand Down
Loading

0 comments on commit ed2b565

Please sign in to comment.