@Override public boolean isIndexed() { return underlying.isIndexed(); } /**
/** * Checks if the set FASTA file is indexed * @return */ public Boolean hasIndex() { Boolean hasIndex = false; if (this.indexedFastaSequenceFile != null) { hasIndex = this.indexedFastaSequenceFile.isIndexed(); } return hasIndex; }
@Override public boolean isIndexed() { return underlying.isIndexed(); } /**
@Override public synchronized boolean isIndexed() { if (isClosed) throw new IllegalStateException("Underlying reference has closed"); return underlying.isIndexed(); }
public static void ensureIndexed(File fa) throws IOException { try (ReferenceSequenceFile reference = ReferenceSequenceFileFactory.getReferenceSequenceFile(fa)) { if (!reference.isIndexed()) { String msg = String.format("Unable to find index for %1$s. Please run 'samtools faidx %1$s' or picard tools BuildBamIndex to generate an index file.", fa); log.error(msg); throw new IOException(msg); } else { log.debug(fa, " is indexed."); } } } public void ensureDictionariesMatch() throws IOException {
@Override protected int doWork() { IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE); IOUtil.assertFileIsWritable(OUTPUT); final ReferenceSequenceFile refFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE, true); if (!refFile.isIndexed()) { throw new IllegalStateException("Reference file must be indexed, but no index file was found"); } if (refFile.getSequenceDictionary() == null) { throw new IllegalStateException("Reference file must include a dictionary, but no dictionary file was found"); } // get the intervals final IntervalList intervals = segregateReference(refFile, MAX_TO_MERGE); log.info(String.format("Found %d intervals in %d loci during %s seconds", intervalProgress.getCount(), locusProgress.getCount(), locusProgress.getElapsedSeconds())); /********************************** * Now output regions for calling * **********************************/ final IntervalList outputIntervals = new IntervalList(intervals.getHeader().clone()); log.info(String.format("Collecting requested type of intervals (%s)", OUTPUT_TYPE)); intervals.getIntervals().stream().filter(i -> OUTPUT_TYPE.accepts(i.getName())).forEach(outputIntervals::add); log.info("Writing Intervals."); outputIntervals.write(OUTPUT); log.info(String.format("Execution ending. Total time %d seconds", locusProgress.getElapsedSeconds())); return 0; }
@Override protected int doWork() { IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE); IOUtil.assertFileIsWritable(OUTPUT); final ReferenceSequenceFile refFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE, true); if (!refFile.isIndexed()) { throw new IllegalStateException("Reference file must be indexed, but no index file was found"); } if (refFile.getSequenceDictionary() == null) { throw new IllegalStateException("Reference file must include a dictionary, but no dictionary file was found"); } // get the intervals final IntervalList intervals = segregateReference(refFile, MAX_TO_MERGE); log.info(String.format("Found %d intervals in %d loci during %s seconds", intervalProgress.getCount(), locusProgress.getCount(), locusProgress.getElapsedSeconds())); /********************************** * Now output regions for calling * **********************************/ final IntervalList outputIntervals = new IntervalList(intervals.getHeader().clone()); log.info(String.format("Collecting requested type of intervals (%s)", OUTPUT_TYPE)); intervals.getIntervals().stream().filter(i -> OUTPUT_TYPE.accepts(i.getName())).forEach(outputIntervals::add); log.info("Writing Intervals."); outputIntervals.write(OUTPUT); log.info(String.format("Execution ending. Total time %d seconds", locusProgress.getElapsedSeconds())); return 0; }
byte[] findBasesByName(final String name, final boolean tryVariants) { if (rsFile == null || !rsFile.isIndexed()) return null; ReferenceSequence sequence = null; try { sequence = rsFile.getSequence(name); } catch (final SAMException e) { // the only way to test if rsFile contains the sequence is to try and catch exception. } if (sequence != null) return sequence.getBases(); if (tryVariants) { for (final String variant : getVariants(name)) { try { sequence = rsFile.getSequence(variant); } catch (final SAMException e) { log.warn("Sequence not found: " + variant); } if (sequence != null) return sequence.getBases(); } } return null; }
byte[] findBasesByName(final String name, final boolean tryVariants) { if (rsFile == null || !rsFile.isIndexed()) return null; ReferenceSequence sequence = null; try { sequence = rsFile.getSequence(name); } catch (final SAMException e) { // the only way to test if rsFile contains the sequence is to try and catch exception. } if (sequence != null) return sequence.getBases(); if (tryVariants) { for (final String variant : getVariants(name)) { try { sequence = rsFile.getSequence(variant); } catch (final SAMException e) { log.warn("Sequence not found: " + variant); } if (sequence != null) return sequence.getBases(); } } return null; }
protected byte[] findBasesByName(String name, boolean tryVariants) { if (rsFile == null || !rsFile.isIndexed()) return null; ReferenceSequence sequence = null; if (fastaSequenceIndex != null) if (fastaSequenceIndex.hasIndexEntry(name)) sequence = rsFile.getSequence(name); else sequence = null; if (sequence != null) return sequence.getBases(); if (tryVariants) { for (String variant : getVariants(name)) { try { sequence = rsFile.getSequence(variant); } catch (Exception e) { log.info("Sequence not found: " + variant); } if (sequence != null) { log.debug("Reference found in memory cache for name %s by variant %s", name, variant); return sequence.getBases(); } } } return null; }
/** * Get reference sequence without validating name or length. This is OK if the entire sequence * dictionary was validated before reading sequences. */ public ReferenceSequence get(final int sequenceIndex) { if (referenceSequence != null && referenceSequence.getContigIndex() == sequenceIndex) { return referenceSequence; } if (referenceSequence != null && referenceSequence.getContigIndex() > sequenceIndex) { throw new SAMException("Requesting earlier reference sequence: " + sequenceIndex + " < " + referenceSequence.getContigIndex()); } referenceSequence = null; if(referenceSequenceFile.isIndexed()) { final SAMSequenceRecord samSequenceRecord = referenceSequenceFile.getSequenceDictionary().getSequence(sequenceIndex); if(samSequenceRecord != null) { referenceSequence = referenceSequenceFile.getSequence(samSequenceRecord.getSequenceName()) ; } // else referenceSequence will remain null } else { do { referenceSequence = referenceSequenceFile.nextSequence(); } while (referenceSequence != null && referenceSequence.getContigIndex() < sequenceIndex); } if (referenceSequence == null || referenceSequence.getContigIndex() != sequenceIndex) { throw new SAMException("Reference sequence (" + sequenceIndex + ") not found in " + referenceSequenceFile.toString()); } return referenceSequence; }
/** * Get reference sequence without validating name or length. This is OK if the entire sequence * dictionary was validated before reading sequences. */ public ReferenceSequence get(final int sequenceIndex) { if (referenceSequence != null && referenceSequence.getContigIndex() == sequenceIndex) { return referenceSequence; } if (referenceSequence != null && referenceSequence.getContigIndex() > sequenceIndex) { throw new SAMException("Requesting earlier reference sequence: " + sequenceIndex + " < " + referenceSequence.getContigIndex()); } referenceSequence = null; if(referenceSequenceFile.isIndexed() && referenceSequenceFile.getSequenceDictionary() != null) { final SAMSequenceRecord samSequenceRecord = referenceSequenceFile.getSequenceDictionary().getSequence(sequenceIndex); if(samSequenceRecord != null) { referenceSequence = referenceSequenceFile.getSequence(samSequenceRecord.getSequenceName()) ; } // else referenceSequence will remain null } else { do { referenceSequence = referenceSequenceFile.nextSequence(); } while (referenceSequence != null && referenceSequence.getContigIndex() < sequenceIndex); } if (referenceSequence == null || referenceSequence.getContigIndex() != sequenceIndex) { throw new SAMException("Reference sequence (" + sequenceIndex + ") not found in " + referenceSequenceFile.toString()); } return referenceSequence; }
/** * Get reference sequence without validating name or length. This is OK if the entire sequence * dictionary was validated before reading sequences. */ public ReferenceSequence get(final int sequenceIndex) { if (referenceSequence != null && referenceSequence.getContigIndex() == sequenceIndex) { return referenceSequence; } if (referenceSequence != null && referenceSequence.getContigIndex() > sequenceIndex) { throw new SAMException("Requesting earlier reference sequence: " + sequenceIndex + " < " + referenceSequence.getContigIndex()); } referenceSequence = null; if(referenceSequenceFile.isIndexed() && referenceSequenceFile.getSequenceDictionary() != null) { final SAMSequenceRecord samSequenceRecord = referenceSequenceFile.getSequenceDictionary().getSequence(sequenceIndex); if(samSequenceRecord != null) { referenceSequence = referenceSequenceFile.getSequence(samSequenceRecord.getSequenceName()) ; } // else referenceSequence will remain null } else { do { referenceSequence = referenceSequenceFile.nextSequence(); } while (referenceSequence != null && referenceSequence.getContigIndex() < sequenceIndex); } if (referenceSequence == null || referenceSequence.getContigIndex() != sequenceIndex) { throw new SAMException("Reference sequence (" + sequenceIndex + ") not found in " + referenceSequenceFile.toString()); } return referenceSequence; }