Skip to content
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

fix: added code to ignore commented lines in a bed file #474

Merged
merged 4 commits into from Jan 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/io/bed.rs
Expand Up @@ -54,6 +54,7 @@ impl<R: io::Read> Reader<R> {
inner: csv::ReaderBuilder::new()
.delimiter(b'\t')
.has_headers(false)
.comment(Some(b'#'))
.from_reader(reader),
}
}
Expand Down Expand Up @@ -391,6 +392,12 @@ mod tests {

const BED_FILE: &[u8] = b"1\t5\t5000\tname1\tup
2\t3\t5005\tname2\tup
";
const BED_FILE_COMMENT: &[u8] = b"\
# this line should be ignored
1\t5\t5000\tname1\tup
# and this one as well
2\t3\t5005\tname2\tup
";
const BED_FILE_COMPACT: &[u8] = b"1\t5\t5000\n2\t3\t5005\n";

Expand All @@ -413,6 +420,25 @@ mod tests {
}
}

#[test]
fn test_reader_with_comment() {
let chroms = ["1", "2"];
let starts = [5, 3];
let ends = [5000, 5005];
let names = ["name1", "name2"];
let scores = ["up", "up"];

let mut reader = Reader::new(BED_FILE_COMMENT);
for (i, r) in reader.records().enumerate() {
let record = r.expect("Error reading record");
assert_eq!(record.chrom(), chroms[i]);
assert_eq!(record.start(), starts[i]);
assert_eq!(record.end(), ends[i]);
assert_eq!(record.name().expect("Error reading name"), names[i]);
assert_eq!(record.score().expect("Error reading score"), scores[i]);
}
}

#[test]
fn test_reader_compact() {
let chroms = ["1", "2"];
Expand Down