Skip to content
Open
Show file tree
Hide file tree
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 @@ -28,14 +28,11 @@
import htsjdk.samtools.SAMSequenceDictionary;
import htsjdk.samtools.seekablestream.ReadableSeekableStreamByteChannel;
import htsjdk.samtools.seekablestream.SeekableStream;
import htsjdk.samtools.util.BlockCompressedInputStream;
import htsjdk.samtools.util.IOUtil;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package htsjdk.samtools.reference;

import htsjdk.samtools.SAMException;
import htsjdk.samtools.util.BlockCompressedInputStream;
import htsjdk.samtools.util.GZIIndex;
import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMSequenceDictionary;
Expand All @@ -35,15 +34,11 @@
import htsjdk.samtools.util.FileExtensions;
import htsjdk.samtools.util.IOUtil;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
Expand Down Expand Up @@ -131,8 +126,18 @@ public static ReferenceSequenceFile getReferenceSequenceFile(final Path path, fi
* @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) {
// 2bit sequences
if (path.getFileName().toString().endsWith(FileExtensions.TWOBIT)) {
try {
return new TwoBitSequenceFile(path, truncateNamesAtWhitespace);
} catch (final IOException e) {
throw new SAMException("Error opening .2bit : " + path, e);
}
}

// this should thrown an exception if the fasta file is not supported
getFastaExtension(path);

// Using faidx requires truncateNamesAtWhitespace
if (truncateNamesAtWhitespace && preferIndexed && canCreateIndexedFastaReader(path)) {
try {
Expand All @@ -150,6 +155,7 @@ public static ReferenceSequenceFile getReferenceSequenceFile(final Path path, fi
*
* <p>For a FASTA file to be indexed, it requires to have:
* <ul>
* <li>A '.2bit' extension</li>
* <li>Associated .fai index ({@link FastaSequenceIndex}).</li>
* <li>Associated .gzi index if it is block-compressed ({@link GZIIndex}).</li>
* </ul>
Expand All @@ -160,9 +166,14 @@ public static ReferenceSequenceFile getReferenceSequenceFile(final Path path, fi
public static boolean canCreateIndexedFastaReader(final Path fastaFile) {
// this should thrown an exception if the fasta file is not supported
getFastaExtension(fastaFile);


if (!Files.exists(fastaFile)) return false;

// 2bit file
if (fastaFile.getFileName().toString().endsWith(FileExtensions.TWOBIT)) return true;

// both the FASTA file should exists and the .fai index should exist
if (Files.exists(fastaFile) && Files.exists(getFastaIndexFileName(fastaFile))) {
if (Files.exists(getFastaIndexFileName(fastaFile))) {
// open the file for checking for block-compressed input
try {
// if it is bgzip, it requires the .gzi index
Expand Down
Loading