Skip to content

Commit ddf1689

Browse files
committed
fastq/record: Split name from definition on first separator
This previously searched for the separator from the end of the definition, which may contain part of the description if the separator appears multiple times. It now searches from the beginning of the definition.
1 parent 2687565 commit ddf1689

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
* Log messages are written to `stderr` rather than `stdout`.
88

9+
* fastq/record: Split name from definition on first separator.
10+
11+
This previously searched for the separator from the end of the definition,
12+
which may contain part of the description if the separator appears multiple
13+
times. It now searches from the beginning of the definition.
14+
915
### Removed
1016

1117
* Remove `--verbose` flag.

src/fastq/record.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,13 @@ impl Record {
7979
let definition = self.definition();
8080

8181
let pos = if let Some(c) = separator {
82-
definition.iter().rev().position(|&b| b == c)
82+
definition.iter().position(|&b| b == c)
8383
} else {
84-
definition
85-
.iter()
86-
.rev()
87-
.position(|&b| b == b'/' || b == b' ')
84+
definition.iter().position(|&b| b == b'/' || b == b' ')
8885
};
8986

9087
if let Some(i) = pos {
91-
self.name_end = definition.len() - i - 1;
88+
self.name_end = i;
9289
}
9390
}
9491
}
@@ -129,16 +126,15 @@ mod tests {
129126

130127
#[test]
131128
fn test_reset() {
132-
let mut record = Record::new("@fqlib/1", "", "", "");
133-
record.reset(None);
134-
assert_eq!(record.name(), b"@fqlib");
135-
136-
let mut record = Record::new("@fqlib 1", "", "", "");
137-
record.reset(None);
138-
assert_eq!(record.name(), b"@fqlib");
129+
fn t(definition: &str, separator: Option<u8>, expected: &[u8]) {
130+
let mut record = Record::new(definition, "", "", "");
131+
record.reset(separator);
132+
assert_eq!(record.name(), expected);
133+
}
139134

140-
let mut record = Record::new("@fqlib_1", "", "", "");
141-
record.reset(Some(b'_'));
142-
assert_eq!(record.name(), b"@fqlib");
135+
t("@fqlib/1", None, b"@fqlib");
136+
t("@fqlib 1", None, b"@fqlib");
137+
t("@fqlib/1 RG:rg0", None, b"@fqlib");
138+
t("@fqlib_1", Some(b'_'), b"@fqlib");
143139
}
144140
}

0 commit comments

Comments
 (0)