Skip to content

Commit 6332941

Browse files
authored
Restore ReferenceSequenceFileFactory deleted in previous commit. (#1743)
* Restore ReferenceSequenceFileFactory method previously deleted.
1 parent 7034b33 commit 6332941

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

src/main/java/htsjdk/samtools/reference/ReferenceSequenceFileFactory.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,29 @@ public static ReferenceSequenceFile getReferenceSequenceFile(final Path path, fi
127127
return getReferenceSequenceFile(path, HtsPath::new, truncateNamesAtWhitespace, true);
128128
}
129129

130+
/**
131+
* Attempts to determine the type of the reference file and return an instance
132+
* of ReferenceSequenceFile that is appropriate to read it.
133+
*
134+
* @param path the reference sequence file path
135+
* @param truncateNamesAtWhitespace if true, only include the first word of the sequence name
136+
* @param preferIndexed if true attempt to return an indexed reader that supports non-linear traversal, else return the non-indexed reader
137+
*/
138+
public static ReferenceSequenceFile getReferenceSequenceFile(final Path path, final boolean truncateNamesAtWhitespace, final boolean preferIndexed) {
139+
// this should thrown an exception if the fasta file is not supported
140+
getFastaExtension(path);
141+
// Using faidx requires truncateNamesAtWhitespace
142+
if (truncateNamesAtWhitespace && preferIndexed && canCreateIndexedFastaReader(path)) {
143+
try {
144+
return IOUtil.isBlockCompressed(path, true) ? new BlockCompressedIndexedFastaSequenceFile(path) : new IndexedFastaSequenceFile(path);
145+
} catch (final IOException e) {
146+
throw new SAMException("Error opening FASTA: " + path, e);
147+
}
148+
} else {
149+
return new FastaSequenceFile(path, truncateNamesAtWhitespace);
150+
}
151+
}
152+
130153
/**
131154
* Attempts to determine the type of the reference file and return an instance
132155
* of ReferenceSequenceFile that is appropriate to read it. If the file represents
@@ -148,22 +171,8 @@ public static <T extends IOPath> ReferenceSequenceFile getReferenceSequenceFile(
148171
if (refIOPath.hasExtension(BundleJSON.BUNDLE_EXTENSION)) {
149172
final Bundle referenceBundle = BundleJSON.toBundle(IOUtils.getStringFromPath(refIOPath), ioPathConstructor);
150173
return getReferenceSequenceFileFromBundle(referenceBundle, truncateNamesAtWhitespace, preferIndexed);
151-
}
152-
else {
153-
// this should throw an exception if the fasta file is not supported
154-
getFastaExtension(path);
155-
// Using faidx requires truncateNamesAtWhitespace
156-
if (truncateNamesAtWhitespace && preferIndexed && canCreateIndexedFastaReader(path)) {
157-
try {
158-
return IOUtil.isBlockCompressed(path, true) ?
159-
new BlockCompressedIndexedFastaSequenceFile(path) :
160-
new IndexedFastaSequenceFile(path);
161-
} catch (final IOException e) {
162-
throw new SAMException("Error opening FASTA: " + path, e);
163-
}
164-
} else {
165-
return new FastaSequenceFile(path, truncateNamesAtWhitespace);
166-
}
174+
} else {
175+
return getReferenceSequenceFile(path, truncateNamesAtWhitespace, preferIndexed);
167176
}
168177
}
169178

0 commit comments

Comments
 (0)