From f3442bbba51d77c32edabc417f7fc0cf364dfcd2 Mon Sep 17 00:00:00 2001 From: Chris Norman Date: Mon, 14 Apr 2025 19:02:38 -0400 Subject: [PATCH 1/2] Restore ReferenceSequenceFileFactory method previously deleted. --- .../ReferenceSequenceFileFactory.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/htsjdk/samtools/reference/ReferenceSequenceFileFactory.java b/src/main/java/htsjdk/samtools/reference/ReferenceSequenceFileFactory.java index 63c16dee8c..e7d22ee5a1 100644 --- a/src/main/java/htsjdk/samtools/reference/ReferenceSequenceFileFactory.java +++ b/src/main/java/htsjdk/samtools/reference/ReferenceSequenceFileFactory.java @@ -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); + } + } + /** * 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 From e276fbdc319842dd381ebb88480d8faffeb730a7 Mon Sep 17 00:00:00 2001 From: Chris Norman Date: Tue, 22 Apr 2025 16:00:43 -0400 Subject: [PATCH 2/2] Remove redundant code. --- .../ReferenceSequenceFileFactory.java | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/main/java/htsjdk/samtools/reference/ReferenceSequenceFileFactory.java b/src/main/java/htsjdk/samtools/reference/ReferenceSequenceFileFactory.java index e7d22ee5a1..3247ad32c1 100644 --- a/src/main/java/htsjdk/samtools/reference/ReferenceSequenceFileFactory.java +++ b/src/main/java/htsjdk/samtools/reference/ReferenceSequenceFileFactory.java @@ -171,22 +171,8 @@ public static 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); } }