From e49d132e51c26f559bbdf1554b123375cc4e0c23 Mon Sep 17 00:00:00 2001 From: Mitchell Robert Vollger Date: Sun, 9 Jan 2022 16:32:29 -0800 Subject: [PATCH 1/4] Added code to ingnore commented lines in a bed file and added a simple test function --- src/io/bed.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/io/bed.rs b/src/io/bed.rs index 08182eb73..f79c2ca65 100644 --- a/src/io/bed.rs +++ b/src/io/bed.rs @@ -54,6 +54,7 @@ impl Reader { inner: csv::ReaderBuilder::new() .delimiter(b'\t') .has_headers(false) + .comment(Some(b'#')) .from_reader(reader), } } @@ -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"; @@ -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"]; From 3ee265e9f2e0dcb5c1e72f7fa0e068d254d5a745 Mon Sep 17 00:00:00 2001 From: Mitchell Robert Vollger Date: Tue, 11 Jan 2022 16:03:37 -0800 Subject: [PATCH 2/4] Updated change log for bed comment line fix. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7ca6bcea..895ce4e3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +# [0.38.1] - 2022-01-11 +- Fixed the bed reader to allow comment lines (@mrvollger). + # [0.35.0] - 2021-07-05 - Improved buffer control in Fasta and Fastq API (@natir). - Fixed an indexing bug in ArrayBackedIntervalTree (@wabain). From a0a0ce9e3d61bee5c34e76c230f36c7cad09afcc Mon Sep 17 00:00:00 2001 From: Mitchell Robert Vollger Date: Tue, 11 Jan 2022 16:06:14 -0800 Subject: [PATCH 3/4] Updated change log for bed comment line fix. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 895ce4e3f..60a283589 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -# [0.38.1] - 2022-01-11 +# [0.39.1] - 2022-01-11 - Fixed the bed reader to allow comment lines (@mrvollger). # [0.35.0] - 2021-07-05 From cb8312374a47815963fed846fc36e141a89f5dec Mon Sep 17 00:00:00 2001 From: Mitchell Robert Vollger Date: Tue, 11 Jan 2022 16:23:54 -0800 Subject: [PATCH 4/4] Update CHANGELOG.md Co-authored-by: Michael Hall --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60a283589..6d0d8cf98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -# [0.39.1] - 2022-01-11 +# [Unreleased](https://github.com/rust-bio/rust-bio/compare/v0.39.0...HEAD) - Fixed the bed reader to allow comment lines (@mrvollger). # [0.35.0] - 2021-07-05