Skip to content

Restore ReferenceSequenceFileFactory deleted in previous commit. #1743

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

Merged
merged 2 commits into from
Apr 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ public static ReferenceSequenceFile getReferenceSequenceFile(final Path path, fi
return getReferenceSequenceFile(path, HtsPath::new, truncateNamesAtWhitespace, true);
}

/**
* Attempts to determine the type of the reference file and return an instance
* of ReferenceSequenceFile that is appropriate to read it.
*
* @param path the reference sequence file path
* @param truncateNamesAtWhitespace if true, only include the first word of the sequence name
* @param preferIndexed if true attempt to return an indexed reader that supports non-linear traversal, else return the non-indexed reader
*/
public static ReferenceSequenceFile getReferenceSequenceFile(final Path path, final boolean truncateNamesAtWhitespace, final boolean preferIndexed) {
// this should thrown an exception if the fasta file is not supported
getFastaExtension(path);
// Using faidx requires truncateNamesAtWhitespace
if (truncateNamesAtWhitespace && preferIndexed && canCreateIndexedFastaReader(path)) {
try {
return IOUtil.isBlockCompressed(path, true) ? new BlockCompressedIndexedFastaSequenceFile(path) : new IndexedFastaSequenceFile(path);
} catch (final IOException e) {
throw new SAMException("Error opening FASTA: " + path, e);
}
} else {
return new FastaSequenceFile(path, truncateNamesAtWhitespace);
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe this can just delegate to the new method.

Copy link
Collaborator Author

@cmnbroad cmnbroad Apr 22, 2025

Choose a reason for hiding this comment

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

Fixed. Well, I restored the old method and changed the new one to delegate to the old one.

/**
* Attempts to determine the type of the reference file and return an instance
* of ReferenceSequenceFile that is appropriate to read it. If the file represents
Expand All @@ -148,22 +171,8 @@ public static <T extends IOPath> ReferenceSequenceFile getReferenceSequenceFile(
if (refIOPath.hasExtension(BundleJSON.BUNDLE_EXTENSION)) {
final Bundle referenceBundle = BundleJSON.toBundle(IOUtils.getStringFromPath(refIOPath), ioPathConstructor);
return getReferenceSequenceFileFromBundle(referenceBundle, truncateNamesAtWhitespace, preferIndexed);
}
else {
// this should throw an exception if the fasta file is not supported
getFastaExtension(path);
// Using faidx requires truncateNamesAtWhitespace
if (truncateNamesAtWhitespace && preferIndexed && canCreateIndexedFastaReader(path)) {
try {
return IOUtil.isBlockCompressed(path, true) ?
new BlockCompressedIndexedFastaSequenceFile(path) :
new IndexedFastaSequenceFile(path);
} catch (final IOException e) {
throw new SAMException("Error opening FASTA: " + path, e);
}
} else {
return new FastaSequenceFile(path, truncateNamesAtWhitespace);
}
} else {
return getReferenceSequenceFile(path, truncateNamesAtWhitespace, preferIndexed);
}
}

Expand Down
Loading