Skip to content

Fix lazy GenBank loading of multiple records - #1159

Merged
josemduarte merged 2 commits into
biojava:masterfrom
vera-rubin:fix/genbank-lazy-offsets
Nov 24, 2026
Merged

josemduarte merged 2 commits into
biojava:masterfrom
vera-rubin:fix/genbank-lazy-offsets

Conversation

@vera-rubin

Copy link
Copy Markdown
Contributor

With multiple records in a GenBank file, readGenbankDNASequence(file, true) returns the first record's DNA for later accessions. Two records containing AB123456 (AAAAAA) and AB123457 (CCCCCC) both return AAAAAA, even though the helper documents loading each sequence by accession.

GenbankReaderHelper.readGenbankDNASequence(file, true)
    .get("AB123457").getSequenceAsString()

We now pass each record's character offset to the sequence creator, preserving it across parser lookahead and line endings. We added a regression test for eager versus lazy loading and consecutive process(1) calls, and the reader and writer tests pass.

Reproduced on base commit 8f151db1d376ed0311979bd6bc2131f0eea11c1a.

— ChipLab

@josemduarte josemduarte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. This looks good in principle. Just curious. Have you measured any change of performance with this updated implementation?

PositionTrackingReader.readLine() read one character at a time through
BufferedReader.read(), which made eager GenBank reading slower. Keep a
private character buffer and scan whole lines instead, with the same
offset counting, mark/reset and CR, LF and CRLF handling.
@vera-rubin

Copy link
Copy Markdown
Contributor Author

Yes, I timed GenbankReaderHelper.readGenbankDNASequence at the base commit 8f151db and at this PR on JDK 17 (Temurin 17.0.21) on an Intel i9-13900 Linux server, with warm-up and 21 timed runs per case over 3 JVM launches. The first version made eager loading about 1.75x slower, for example from 246 ms to 429 ms for a generated 2000-record, 13 MB file, because the new readLine read one character at a time. I have pushed a revision that buffers that reader, and eager loading now measures at base speed (0.98x to 1.01x on all four test files) with the GenBank and FASTA reader and writer tests passing. Lazy loading now returns the right sequence for every record, where the old lazy path returned the first record's sequence for the later records in the multi-record files I measured, but it is slower than before on large files: from 86 ms to 198 ms at 500 records and from 382 ms to 2.0 s at 2000 records. That remaining cost is in SequenceFileProxyLoader, which skips from the start of the file to each record's offset and is outside the files this PR changes, and I can look at it in a follow-up if you want.

@josemduarte josemduarte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks

@josemduarte
josemduarte merged commit 8d67df6 into biojava:master Nov 24, 2026
josemduarte added a commit that referenced this pull request Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants