MZXMLFile extends AbstractXMLBasedDataSource<MZXMLIndexElement, MZXMLIndex> { @Override public MZXMLIndex fetchIndex() throws FileParsingException { MZXMLIndex tmp = index; if (tmp == null) { synchronized (this) { tmp = getIndex(); if (tmp == null) { tmp = parseIndex(); index = tmp; } } } return tmp; } MZXMLFile(String path);  MZXMLFile(String path, boolean excludeEmptyScans); ObjectPool<XMLStreamReaderImpl> getReaderPool(); @Override MZXMLIndex getIndex(); @Override MZXMLIndex parseIndex(); @Override MZXMLIndex fetchIndex(); @Override LCMSRunInfo parseRunInfo(); @Override MZXMLMultiSpectraParser getSpectraParser(InputStream inputStream,
      LCMSDataSubset subset, ObjectPool<XMLStreamReaderImpl> readerPool, Integer numSpectra); @Override IndexBuilder<MZXMLIndexElement> getIndexBuilder(IndexBuilder.Info info);  }
@Test public void buildIndexTestLocation() throws Exception { String file = "DDA-1-scan-broken-index.mzXML"; int expectedCount = 1; long expectedOffset = 1426; int expectedLen = 11721; final Path path = ResourceUtils.getResource(this.getClass(), RESOURCE_LOCATION, file); if (!Files.exists(path)) { throw new IllegalStateException("Test file " + file + " was probably deleted."); } final MZXMLFile mzxml = new MZXMLFile(path.toString()); final MZXMLIndex index = mzxml.fetchIndex(); assertEquals("Wrong number of scans in the build index: " + file, expectedCount, index.size()); final MZXMLIndexElement elem = index.getMapByNum().firstEntry().getValue(); assertEquals("Wrong offset: " + file, expectedOffset, elem.getOffsetLength().offset); assertEquals("Wrong length: " + file, expectedLen, elem.getOffsetLength().length); }
@Test public void buildIndexTestCount() throws Exception { LinkedHashMap<String, Integer> file2scanCount = new LinkedHashMap<>(); file2scanCount.put("DDA-10-scans-no-index.mzXML", 10); for (Map.Entry<String, Integer> e : file2scanCount.entrySet()) { int expectedCount = e.getValue(); String file = e.getKey(); final Path path = ResourceUtils.getResource(this.getClass(), RESOURCE_LOCATION, file); if (!Files.exists(path)) { throw new IllegalStateException("Test file " + file + " was probably deleted."); } final MZXMLFile mzxml = new MZXMLFile(path.toString()); final MZXMLIndex index = mzxml.fetchIndex(); assertEquals("Wrong number of scans returned after building index: " + file, expectedCount, index.size()); } }
@Test public void parseWholeFile() throws Exception { for (Path p : paths) { System.out.printf("\n\nParsing whole file: %s\n", p.getFileName()); final MZXMLFile mzxml = new MZXMLFile(p.toString()); mzxml.setNumThreadsForParsing(null); mzxml.setTasksPerCpuPerBatch(1); mzxml.setParsingTimeout(30 * 1000); final MZXMLIndex index = mzxml.fetchIndex(); IScanCollection scans = new ScanCollectionDefault(true); scans.setDataSource(mzxml); scans.loadData(LCMSDataSubset.STRUCTURE_ONLY, StorageStrategy.STRONG); System.out.printf("\tFound/parsed %d spectra\n", scans.getMapNum2scan().size()); } }