protected static Path findFastaIndex(Path fastaFile) { Path indexFile = ReferenceSequenceFileFactory.getFastaIndexFileName(fastaFile); if (!Files.exists(indexFile)) return null; return indexFile; }
protected static Path findFastaIndex(Path fastaFile) { Path indexFile = ReferenceSequenceFileFactory.getFastaIndexFileName(fastaFile); if (!Files.exists(indexFile)) return null; return indexFile; }
protected static Path findRequiredFastaIndexFile(Path fastaFile) throws FileNotFoundException { Path ret = findFastaIndex(fastaFile); if (ret == null) throw new FileNotFoundException(ReferenceSequenceFileFactory.getFastaIndexFileName(fastaFile) + " not found."); return ret; }
protected static Path findRequiredFastaIndexFile(Path fastaFile) throws FileNotFoundException { Path ret = findFastaIndex(fastaFile); if (ret == null) throw new FileNotFoundException(ReferenceSequenceFileFactory.getFastaIndexFileName(fastaFile) + " not found."); return ret; }
/** * Checks if the provided FASTA file can be open as indexed. * * <p>For a FASTA file to be indexed, it requires to have: * <ul> * <li>Associated .fai index ({@link FastaSequenceIndex}).</li> * <li>Associated .gzi index if it is block-compressed ({@link GZIIndex}).</li> * </ul> * * @param fastaFile the reference sequence file path. * @return {@code true} if the file can be open as indexed; {@code false} otherwise. */ public static boolean canCreateIndexedFastaReader(final Path fastaFile) { // this should thrown an exception if the fasta file is not supported getFastaExtension(fastaFile); // both the FASTA file should exists and the .fai index should exist if (Files.exists(fastaFile) && Files.exists(getFastaIndexFileName(fastaFile))) { // open the file for checking for block-compressed input try { // if it is bgzip, it requires the .gzi index return !IOUtil.isBlockCompressed(fastaFile, true) || Files.exists(GZIIndex.resolveIndexNameForBgzipFile(fastaFile)); } catch (IOException e) { return false; } } return false; }
/** * Checks if the provided FASTA file can be open as indexed. * * <p>For a FASTA file to be indexed, it requires to have: * <ul> * <li>Associated .fai index ({@link FastaSequenceIndex}).</li> * <li>Associated .gzi index if it is block-compressed ({@link GZIIndex}).</li> * </ul> * * @param fastaFile the reference sequence file path. * @return {@code true} if the file can be open as indexed; {@code false} otherwise. */ public static boolean canCreateIndexedFastaReader(final Path fastaFile) { // this should thrown an exception if the fasta file is not supported getFastaExtension(fastaFile); // both the FASTA file should exists and the .fai index should exist if (Files.exists(fastaFile) && Files.exists(getFastaIndexFileName(fastaFile))) { // open the file for checking for block-compressed input try { // if it is bgzip, it requires the .gzi index return !IOUtil.isBlockCompressed(fastaFile, true) || Files.exists(GZIIndex.resolveIndexNameForBgzipFile(fastaFile)); } catch (IOException e) { return false; } } return false; }
/** * Creates a FASTA .fai index for the provided FASTA. * * @param fastaFile the file to build the index from. * @param overwrite if the .fai index already exists override it if {@code true}; otherwise, throws a {@link SAMException}. * * @throws SAMException if the fai file already exists or the file is malformed. * @throws IOException if an IO error occurs. */ public static void create(final Path fastaFile, final boolean overwrite) throws IOException { // get the index to write the file in final Path indexFile = ReferenceSequenceFileFactory.getFastaIndexFileName(fastaFile); if (!overwrite && Files.exists(indexFile)) { // throw an exception if the file already exists throw new SAMException("Index file " + indexFile + " already exists for " + fastaFile); } // build the index final FastaSequenceIndex index = buildFromFasta(fastaFile); index.write(indexFile); }
/** * Creates a FASTA .fai index for the provided FASTA. * * @param fastaFile the file to build the index from. * @param overwrite if the .fai index already exists override it if {@code true}; otherwise, throws a {@link SAMException}. * * @throws SAMException if the fai file already exists or the file is malformed. * @throws IOException if an IO error occurs. */ public static void create(final Path fastaFile, final boolean overwrite) throws IOException { // get the index to write the file in final Path indexFile = ReferenceSequenceFileFactory.getFastaIndexFileName(fastaFile); if (!overwrite && Files.exists(indexFile)) { // throw an exception if the file already exists throw new SAMException("Index file " + indexFile + " already exists for " + fastaFile); } // build the index final FastaSequenceIndex index = buildFromFasta(fastaFile); index.write(indexFile); }