Skip to content

FastaSequenceIndexCreator cannot create an index for FASTA files with multiple empty lines at the end of the file #1748

@nvnieuwk

Description

@nvnieuwk

When trying to use this FASTA file (genome_no_index.fasta.txt, remove the .txt extension before use. github didn't allow me to upload it otherwise) in the following function:

FastaSequenceIndexCreator.create(Paths.get('<path-to-fasta>'), true);

I receive this error:

java.lang.StringIndexOutOfBoundsException: String index out of range: 0
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:1515)
	at htsjdk.samtools.reference.FastaSequenceIndexCreator.buildFromFasta(FastaSequenceIndexCreator.java:130)
	at htsjdk.samtools.reference.FastaSequenceIndexCreator.create(FastaSequenceIndexCreator.java:67)

After some debugging, I found that the issue is the two empty lines at the end of the file. It all works fine if I remove the second empty line, but it would be better if the function could work with these files instead of having to manually check every FASTA file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions