Skip to content
Draft
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
15 changes: 15 additions & 0 deletions src/bam/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ impl Header {
}
}

/// Creates a new Header from a HashMap. Useful if you have used `to_hashmap` and manipulated that hashmap to create a new header.
pub fn from_hashmap(hashmap: HashMap<String, Vec<LinearMap<String, String>>>) -> Self {
let mut header = Header::new();
for (key, values) in hashmap.iter() {
for value in values {
let mut record = HeaderRecord::new(key.as_bytes());
for (tag, val) in value.iter() {
record.push_tag(tag.as_bytes(), val);
}
header.push_record(&record);
}
}
header
}

/// Add a record to the header.
pub fn push_record(&mut self, record: &HeaderRecord<'_>) -> &mut Self {
self.records.push(record.to_bytes());
Expand Down
Loading