Skip to content

Commit ec4ca17

Browse files
Make all HeaderView types cloneable.
1 parent 6439569 commit ec4ca17

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5-
## [0.14.0] - unreleased
5+
## [0.15.0] - 2017-12-05
6+
### Changed
7+
- HeaderView of bam and bcf can now be cloned.
8+
9+
10+
## [0.14.0] - 2017-12-03
611
### Added
712
- An efficient ringbuffer for accessing BCF regions
813
- An efficient ringbuffer for accessing BAM regions

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rust-htslib"
3-
version = "0.14.0"
3+
version = "0.15.0"
44
authors = ["Christopher Schröder <[email protected]>", "Johannes Köster <[email protected]>"]
55
build = "build.rs"
66
description = "This library provides HTSlib bindings and a high level Rust API for reading and writing BAM files."

src/bcf/header.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@ impl HeaderView {
172172
}
173173
}
174174

175+
176+
impl Clone for HeaderView {
177+
fn clone(&self) -> Self {
178+
HeaderView {
179+
inner: unsafe { htslib::vcf::bcf_hdr_dup(self.inner) }
180+
}
181+
}
182+
}
183+
184+
185+
impl Drop for HeaderView {
186+
fn drop(&mut self) {
187+
unsafe {
188+
htslib::vcf::bcf_hdr_destroy(self.inner);
189+
}
190+
}
191+
}
192+
193+
175194
pub enum TagType {
176195
Flag,
177196
Integer,

src/bcf/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub use bcf::buffer::RecordBuffer;
2222

2323
pub struct Reader {
2424
inner: *mut htslib::vcf::htsFile,
25-
pub header: HeaderView,
25+
header: HeaderView,
2626
}
2727

2828

@@ -56,6 +56,10 @@ impl Reader {
5656
Ok(Reader { inner: htsfile, header: HeaderView::new(header) })
5757
}
5858

59+
pub fn header(&self) -> &HeaderView {
60+
&self.header
61+
}
62+
5963
pub fn read(&mut self, record: &mut record::Record) -> Result<(), ReadError> {
6064
match unsafe { htslib::vcf::bcf_read(self.inner, self.header.inner, record.inner) } {
6165
0 => {
@@ -76,7 +80,6 @@ impl Reader {
7680
impl Drop for Reader {
7781
fn drop(&mut self) {
7882
unsafe {
79-
htslib::vcf::bcf_hdr_destroy(self.header.inner);
8083
htslib::vcf::hts_close(self.inner);
8184
}
8285
}
@@ -85,7 +88,7 @@ impl Drop for Reader {
8588

8689
pub struct Writer {
8790
inner: *mut htslib::vcf::htsFile,
88-
pub header: HeaderView,
91+
header: HeaderView,
8992
subset: Option<SampleSubset>,
9093
}
9194

@@ -127,6 +130,10 @@ impl Writer {
127130
})
128131
}
129132

133+
pub fn header(&self) -> &HeaderView {
134+
&self.header
135+
}
136+
130137
/// Translate record to header of this writer.
131138
pub fn translate(&mut self, record: &mut record::Record) {
132139
unsafe {
@@ -159,7 +166,6 @@ impl Writer {
159166
impl Drop for Writer {
160167
fn drop(&mut self) {
161168
unsafe {
162-
htslib::vcf::bcf_hdr_destroy(self.header.inner);
163169
htslib::vcf::hts_close(self.inner);
164170
}
165171
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
//! let mut bam = bam::IndexedReader::from_path(&"test/test.bam").unwrap();
6060
//!
6161
//! // seek to chr1:50000-100000
62-
//! let tid = bam.header.tid(b"CHROMOSOME_I").unwrap();
62+
//! let tid = bam.header().tid(b"CHROMOSOME_I").unwrap();
6363
//! bam.fetch(tid, 0, 20).unwrap();
6464
//! // afterwards, read or pileup in this region
6565
//! ```

0 commit comments

Comments
 (0)