/** * @param acc accession */ public SRAIndexedSequenceFile(SRAAccession acc) { this.acc = acc; if (!acc.isValid()) { throw new RuntimeException("Passed an invalid SRA accession into SRA reader: " + acc); } try { run = gov.nih.nlm.ncbi.ngs.NGS.openReadCollection(acc.toString()); sequenceDictionary = loadSequenceDictionary(); } catch (final ErrorMsg e) { throw new RuntimeException(e); } reset(); }
@BeforeGroups(groups = "sra") public final void checkIfCanResolve() { if (SRAAccession.checkIfInitialized() != null) { return; } canResolveNetworkAccession = SRAAccession.isValid(checkAccession); }
/** * Are the SRA native libraries loaded and initialized? Does the test accession have a valid name? */ @BeforeGroups(groups = {"sra"}) public final void checkIfCanResolve() { // Did SRA successfully load the native libraries and are fully initialized? if (!SRAAccession.isSupported()) { return; } // Is this is a valid SRA accession? canResolveNetworkAccession = SRAAccession.isValid(checkAccession); }
if (SRAAccession.isValid(fastaFile.getPath())) { return new SRAIndexedSequenceFile(new SRAAccession(fastaFile.getPath()));
@Test(dataProvider = "testReference") public void testReference(String acc, String refContig, int refStart, int refStop, String refBases) { final ReferenceSequenceFile refSeqFile = new SRAIndexedSequenceFile(new SRAAccession(acc)); final ReferenceSequence refSeq = refSeqFile.getSubsequenceAt(refContig, refStart, refStop); Assert.assertEquals(new String(refSeq.getBases()), refBases); }
/** * @return true if contained string is an SRA accession */ public boolean isValid() { return SRAAccession.isValid(acc); }
/** * @return true if SRA successfully loaded native libraries and fully initialized, * false otherwise * @deprecated use {@link #checkIfInitialized} instead */ @Deprecated public static boolean isSupported() { return checkIfInitialized() == null; }
private ReadCollection getReadCollection() { if (run != null) { return run; } log.debug("Recovering SRA read collection. Accession: " + accession); try { return run = NGS.openReadCollection(accession.toString()); } catch (ErrorMsg e) { throw new RuntimeException(e); } }
/** * Tries to initialize SRA. Initialization error is saved during first call, * all subsequent calls will return the same saved error or null. * * @return ExceptionInInitializerError if initialization failed, null if initialization was successful */ public static ExceptionInInitializerError checkIfInitialized() { final ExceptionInInitializerError ngsInitError; if (!initTried) { log.debug("Initializing SRA module"); ngsInitError = NGS.getInitializationError(); if (ngsInitError != null) { log.info("SRA initialization failed. Will not be able to read from SRA"); } else { NGS.setAppVersionString(getFullVersionString()); } initTried = true; } else { ngsInitError = NGS.getInitializationError(); } return ngsInitError; }
/** * Are the SRA native libraries loaded and initialized? * * @throws SkipException if the SRA native libraries are loaded and initialized */ @BeforeMethod public final void assertSRAIsSupported(){ if(!SRAAccession.isSupported()){ throw new SkipException("Skipping SRA Test because SRA native code is unavailable."); } }
public ReaderInitializer call() { try { if (threadAllocation.getNumIOThreads() > 0) blockInputStream = new BlockInputStream(dispatcher,readerID,false); SamReaderFactory factory = SamReaderFactory.makeDefault() .validationStringency(validationStringency) .setOption(SamReaderFactory.Option.EAGERLY_DECODE, false); if (SRAAccession.isValid(readerID.getSamFile().getPath())) { reader = factory.open(SamInputResource.of(new SRAAccession(readerID.getSamFile().getPath()))); } else { reader = factory.referenceSequence(referenceFile) .setOption(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, true) .open(readerID.getSamFile()); } } catch ( RuntimeIOException e ) { throw new UserException.CouldNotReadInputFile(readerID.getSamFile(), e); } catch ( SAMFormatException e ) { throw new UserException.MalformedBAM(readerID.getSamFile(), e.getMessage()); } // Picard is throwing a RuntimeException here when BAMs are malformed with bad headers (and so look like SAM files). // Let's keep this separate from the SAMFormatException (which ultimately derives from RuntimeException) case, // just in case we want to change this behavior later. catch ( RuntimeException e ) { throw new UserException.MalformedBAM(readerID.getSamFile(), e.getMessage()); } return this; } }
@Test(dataProvider = "testReferenceMt") public void testReferenceMt(String acc, List<TestReferenceMtData> parallelTests) throws Exception { final ReferenceSequenceFile refSeqFile = new SRAIndexedSequenceFile(new SRAAccession(acc)); final long timeout = 1000L * 5; // just in case final List<Thread> threads = new ArrayList<Thread>(parallelTests.size());
/** * @return true if contained string is an SRA accession */ public boolean isValid() { return SRAAccession.isValid(acc); }
/** * @return true if SRA successfully loaded native libraries and fully initialized, * false otherwise * @deprecated use {@link #checkIfInitialized} instead */ @Deprecated public static boolean isSupported() { return checkIfInitialized() == null; }
private ReadCollection getReadCollection() { if (run != null) { return run; } log.debug("Recovering SRA read collection. Accession: " + accession); try { return run = NGS.openReadCollection(accession.toString()); } catch (ErrorMsg e) { throw new RuntimeException(e); } }
/** * Tries to initialize SRA. Initialization error is saved during first call, * all subsequent calls will return the same saved error or null. * * @return ExceptionInInitializerError if initialization failed, null if initialization was successful */ public static ExceptionInInitializerError checkIfInitialized() { final ExceptionInInitializerError ngsInitError; if (!initTried) { log.debug("Initializing SRA module"); ngsInitError = NGS.getInitializationError(); if (ngsInitError != null) { log.info("SRA initialization failed. Will not be able to read from SRA"); } else { NGS.setAppVersionString(getFullVersionString()); } initTried = true; } else { ngsInitError = NGS.getInitializationError(); } return ngsInitError; }
if (!SRAAccession.isValid(readerID.getSamFile().getPath()) && !readerID.getSamFile().canRead() ) throw new UserException.CouldNotReadInputFile(readerID.getSamFile(),"file is not present or user does not have appropriate permissions. " + "Please check that the file is present and readable and try again."); ReferenceSequenceFile ref; if (SRAAccession.isValid(referenceFile.getPath())) { ref = new SRAIndexedSequenceFile(new SRAAccession(referenceFile.getPath())); } else { ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(referenceFile);
@Test(dataProvider = "testReferences") public void testReferences(String acc, int numberFirstReferenceFound, List<String> references, List<Integer> refLengths) { SamReader reader = SamReaderFactory.make().validationStringency(ValidationStringency.SILENT).open( SamInputResource.of(new SRAAccession(acc)) );
/** * @param acc accession */ public SRAIndexedSequenceFile(SRAAccession acc) { this.acc = acc; if (!acc.isValid()) { throw new RuntimeException("Passed an invalid SRA accession into SRA reader: " + acc); } try { run = gov.nih.nlm.ncbi.ngs.NGS.openReadCollection(acc.toString()); sequenceDictionary = loadSequenceDictionary(); } catch (final ErrorMsg e) { throw new RuntimeException(e); } reset(); }
/** Attempts to detect whether the file is an SRA accessioned file. If SRA support is not available, returns false. */ private boolean isSra(final File sourceFile) { try { // if SRA fails to initialize (the most common reason is a failure to find/load native libraries), // it will throw a subclass of java.lang.Error and here we only catch subclasses of java.lang.Exception // // Note: SRA initialization errors should not be ignored, but rather shown to user return SRAAccession.isValid(sourceFile.getPath()); } catch (final Exception e) { return false; } }