Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nh13 committed Jun 30, 2022
1 parent 2b47d10 commit 81013f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/bam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ CCCCCCCCCCCCCCCCCCC"[..],
where
F: Fn(&record::Record) -> Option<bool>,
{
let mut bam_reader = Reader::from_path(bamfile).unwrap(); // internal functions, just unwarp
let mut bam_reader = Reader::from_path(bamfile).unwrap(); // internal functions, just unwrap
let header = header::Header::from_template(bam_reader.header());
let mut sam_writer = Writer::from_path(samfile, &header, Format::Sam).unwrap();
for record in bam_reader.records() {
Expand Down Expand Up @@ -2826,7 +2826,9 @@ CCCCCCCCCCCCCCCCCCC"[..],
.prefix("rust-htslib")
.tempdir()
.expect("Cannot create temp dir");
let bampath = tmp.path().join("test.bam");
//let bampath = tmp.path().join("test.bam");
//let bampath = "/tmp/test.bam";
let bampath = "/tmp/test.sam";

// write an unmapped BAM record (uBAM)
{
Expand All @@ -2841,16 +2843,14 @@ CCCCCCCCCCCCCCCCCCC"[..],
);

// Build the writer
let mut writer = Writer::from_path(&bampath, &header, Format::Bam).unwrap();
//let mut writer = Writer::from_path(&bampath, &header, Format::Bam).unwrap();
let mut writer = Writer::from_path(&bampath, &header, Format::Sam).unwrap();

// Build an empty record
let mut record = Record::new();

// By default the read is mapped, so unset it.
record.set_unmapped();

// Write the record (this previously seg-faulted)
writer.write(&record);
assert!(writer.write(&record).is_ok());
}

// Read the record
Expand All @@ -2862,7 +2862,7 @@ CCCCCCCCCCCCCCCCCCC"[..],
let mut rec = Record::new();
match reader.read(&mut rec) {
Some(r) => r.expect("Failed to read record."),
None => {}
None => panic!("No record read."),
};

// Check a few things
Expand Down
4 changes: 4 additions & 0 deletions src/bam/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ impl Record {
cigar: None,
header: None,
};
// The read/query name needs to be set as empty to properly initialize
// the record
record.set_qname(b"");
// Developer note: these are needed so the returned record is properly
// initialized as unmapped.
record.set_unmapped();
record.set_tid(-1);
record.set_pos(-1);
record.set_mpos(-1);
Expand Down

0 comments on commit 81013f9

Please sign in to comment.