use of com.milaboratory.core.io.sequence.fasta.RandomAccessFastaIndex in project repseqio by repseqio.
the class AbstractRAFastaResolver method resolveReader.
public synchronized RandomAccessFastaReader<NucleotideSequence> resolveReader(SequenceAddress address) {
for (int retry = 0; retry < 2; ++retry) {
// Getting reader key
String readerKey = resolveReaderId(address);
// Checking if reader already opened
RandomAccessFastaReader<NucleotideSequence> reader = readers.get(readerKey);
Path file = null;
try {
// Getting fasta file path
// Download occur here
file = getFASTAFile(address);
// Creating or loading index
RandomAccessFastaIndex index = RandomAccessFastaIndex.index(file, true, getReporter());
// Caching reader
readers.put(readerKey, reader = new RandomAccessFastaReader<>(file, index, NucleotideSequence.ALPHABET));
return reader;
} catch (Exception e) {
// Something went wrong with file, removing for re-download.
log.warn("Error opening {}." + (deleteOnError ? " Removing." : ""), file, e);
// removing source file and index if exists
if (deleteOnError && file != null)
try {
Files.delete(file);
Path indexFile = file.resolveSibling(file.getFileName() + RandomAccessFastaIndex.INDEX_SUFFIX);
if (Files.exists(indexFile))
Files.delete(indexFile);
} catch (IOException e1) {
throw new RuntimeException(e1);
}
// Retry
}
}
throw new RuntimeException();
}
Aggregations