本文整理汇总了Java中uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller类的典型用法代码示例。如果您正苦于以下问题:Java MzMLUnmarshaller类的具体用法?Java MzMLUnmarshaller怎么用?Java MzMLUnmarshaller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MzMLUnmarshaller类属于uk.ac.ebi.jmzml.xml.io包,在下文中一共展示了MzMLUnmarshaller类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSpectrum
import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller; //导入依赖的package包/类
private Spectrum getSpectrum(URL mzMLFileUrl, String id) {
assertNotNull(mzMLFileUrl);
// create the marshaller and check that the file is indexed
MzMLUnmarshaller um = new MzMLUnmarshaller(mzMLFileUrl);
assertTrue( um.isIndexedmzML() );
// the checksum is not correct, so we skip this test
// assertTrue(um.isOkFileChecksum());
MzML content = um.unmarshall();
assertNotNull(content);
// fine the spectrum with id "index=0"
List<Spectrum> spectrumList = content.getRun().getSpectrumList().getSpectrum();
Spectrum spectrum = null;
for (Spectrum sp : spectrumList) {
assertNotNull(sp);
if ( sp.getId() != null && sp.getId().equalsIgnoreCase(id) ) {
spectrum = sp;
}
}
assertNotNull(spectrum);
return spectrum;
}
示例2: testReadIndexedMzML
import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller; //导入依赖的package包/类
public void testReadIndexedMzML() throws MzMLUnmarshallerException {
assertTrue(isValidMzML(indexedmzMLFile));
MzMLUnmarshaller um = new MzMLUnmarshaller(indexedmzMLFile);
MzML mz = um.unmarshall();
assertNotNull(mz);
// same content checks as if it were a normal MzML
checkMzMLContent(mz);
// now check the index
IndexList idxl = um.getMzMLIndex();
assertNotNull(idxl);
// check that the index count is correct and as expected
assertEquals(idxl.getCount().intValue(), idxl.getIndex().size());
assertEquals(2, idxl.getIndex().size());
// and check some values
// note: there is a whole test class to check that the index is handled correctly
assertEquals("spectrum", idxl.getIndex().get(0).getName());
assertEquals("chromatogram", idxl.getIndex().get(1).getName());
}
示例3: testXMLIndex
import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller; //导入依赖的package包/类
public void testXMLIndex() throws Exception {
URL url = this.getClass().getClassLoader().getResource("tiny.pwiz.mzML");
assertNotNull(url);
MzMLUnmarshaller um = new MzMLUnmarshaller(url);
DataProcessing dh = um.unmarshalFromXpath("/dataProcessingList/dataProcessing", DataProcessing.class);
assertNotNull(dh);
MzML mz = um.unmarshall();
assertNotNull(mz);
FileDescription fd = um.unmarshalFromXpath("/fileDescription", FileDescription.class);
assertNotNull(fd);
MzMLMarshaller mm = new MzMLMarshaller();
String outFD = mm.marshall(fd);
assertNotNull(outFD);
String mzml = mm.marshall(mz);
assertNotNull(mzml);
int chromatogramCount = 0;
MzMLObjectIterator<Chromatogram> iter = um.unmarshalCollectionFromXpath("/run/chromatogramList/chromatogram", Chromatogram.class);
while (iter.hasNext()) {
iter.next();
chromatogramCount++;
}
Run run = um.unmarshalFromXpath("/run", Run.class);
ChromatogramList chl = run.getChromatogramList(); // can not unmarshal directly because not in xxindex inclusion list
assertEquals("Chromatogram count not equal!", chromatogramCount, chl.getCount().intValue());
assertEquals("Chromatogram count not equal!", chromatogramCount, um.getObjectCountForXpath("/run/chromatogramList/chromatogram"));
}
示例4: testComponents
import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller; //导入依赖的package包/类
/**
* Checking the instrument components, since they are special cases
* (the Class name does not reflect the XML element name).
*
* @throws MzMLUnmarshallerException in case of problems with the unmarshalling of XML elements.
*/
public void testComponents() throws MzMLUnmarshallerException {
assertTrue(isValidMzML(mzMLFile));
logger.info("mzML file is valid.");
MzMLUnmarshaller um = new MzMLUnmarshaller(mzMLFile);
assertNotNull(um);
SoftwareList softwareList = (SoftwareList) um.unmarshalFromXpath("/mzML/softwareList", SoftwareList.class);
assertEquals("software count 2", 3, softwareList.getCount().intValue());
int sourceCnt = um.getObjectCountForXpath("/mzML/instrumentConfigurationList/instrumentConfiguration/componentList/source");
assertEquals("Expected number of 'source' elements.", 1, sourceCnt);
MzMLObjectIterator<SourceComponent> sourceIter = um.unmarshalCollectionFromXpath("/mzML/instrumentConfigurationList/instrumentConfiguration/componentList/source", SourceComponent.class);
assertNotNull(sourceIter);
assertNotNull(sourceIter.next());
int analyzerCnt = um.getObjectCountForXpath("/mzML/instrumentConfigurationList/instrumentConfiguration/componentList/analyzer");
assertEquals("Expected number of 'analyzer' elements.", 1, analyzerCnt);
MzMLObjectIterator<AnalyzerComponent> analyzerIter = um.unmarshalCollectionFromXpath("/mzML/instrumentConfigurationList/instrumentConfiguration/componentList/analyzer", AnalyzerComponent.class);
assertNotNull(analyzerIter);
assertNotNull(analyzerIter.next());
int detectorCnt = um.getObjectCountForXpath("/mzML/instrumentConfigurationList/instrumentConfiguration/componentList/detector");
assertEquals("Expected number of 'detector' elements.", 1, detectorCnt);
MzMLObjectIterator<DetectorComponent> detectorIter = um.unmarshalCollectionFromXpath("/mzML/instrumentConfigurationList/instrumentConfiguration/componentList/detector", DetectorComponent.class);
assertNotNull(detectorIter);
assertNotNull(detectorIter.next());
}
示例5: testIndexedmzML
import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller; //导入依赖的package包/类
public void testIndexedmzML() throws MzMLUnmarshallerException {
URL url = this.getClass().getClassLoader().getResource("tiny.pwiz.err.idx.mzML");
assertNotNull(url);
MzMLUnmarshaller um = new MzMLUnmarshaller(url);
IndexList index = um.getMzMLIndex();
assertNotNull(index);
// check that we have as many index entries as we expect
// we expect 2 entries: 'chromatogram' and 'spectrum'
assertEquals(2, index.getCount().intValue());
assertEquals(index.getCount().intValue(), index.getIndex().size());
Spectrum spectrum = um.getSpectrumByRefId("scan=19");
assertNotNull(spectrum);
spectrum = um.getSpectrumByRefId("scan=21");
assertNotNull(spectrum);
spectrum = um.getSpectrumByRefId("scan=22");
assertNotNull(spectrum);
spectrum = um.getSpectrumBySpotId("A1,42x42,4242x4242");
assertNotNull(spectrum);
Chromatogram chr = um.getChromatogramByRefId("tic");
assertNotNull(chr);
chr = um.getChromatogramByRefId("sic");
assertNotNull(chr);
///// ///// ///// ///// ///// ///// ///// ///// ///// /////
// negative testing
// (tests that are not supposed to return useful results)
// here we check the bahaviour if we search for a id that is not in the index
spectrum = um.getSpectrumByRefId("nonexist");
assertNull(spectrum);
// here we try to retrieve a spectrum by scanTime, but no according entry exists in the index
spectrum = um.getSpectrumByScanTime(12345);
assertNull(spectrum);
// here we introduced a offset mismatch in the mzML index of the test file to
// test the behaviour of the unmarshaller in case of a index offset mismatch
Exception expected = null; // we expect an exception
try {
um.getSpectrumByRefId("scan=20");
} catch (MzMLUnmarshallerException mue) {
expected = mue;
}
assertNotNull(expected);
}
示例6: testReadWriteMzML
import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller; //导入依赖的package包/类
public void testReadWriteMzML() throws MzMLUnmarshallerException {
///// ///// ///// ///// FIRST READ ///// ///// ///// /////
// check if the instance file is valid
assertTrue(isValidMzML(mzMLFile));
logger.info("mzmML file is valid.");
MzMLUnmarshaller um_1 = new MzMLUnmarshaller(mzMLFile);
MzML mz_1 = um_1.unmarshall();
assertNotNull(mz_1);
assertNotNull(mz_1.getRun());
// check that there is no IndexList (since we only have a mzML and not an indexedmzML)
System.out.println("An ERROR could be logged here, which is perfectly fine.");
assertFalse(um_1.isIndexedmzML());
// now check if the content is as expected
checkMzMLContent(mz_1);
logger.info("Unmarshalling valid XML is OK.");
///// ///// ///// ///// WRITE BACK ///// ///// ///// /////
// now try to write it back to a temporary file
FileWriter fw;
File tmpFile;
try {
tmpFile = File.createTempFile("tmpMzML", ".xml");
tmpFile.deleteOnExit();
fw = new FileWriter(tmpFile);
} catch (IOException e) {
e.printStackTrace();
throw new IllegalStateException("Could not create or write to temporary file for marshalling.");
}
MzMLMarshaller mm = new MzMLMarshaller();
mm.marshall(mz_1, fw);
logger.info("Marshalled back to XML.");
// now check if the written mzML is valid
assertTrue(isValidMzML(tmpFile));
logger.info("Marshalling mzML is valid.");
///// ///// ///// ///// RE-READ WRITTEN mzML ///// ///// ///// /////
MzMLUnmarshaller um_2 = new MzMLUnmarshaller(tmpFile);
MzML mz_2 = um_2.unmarshall();
assertNotNull(mz_2);
// check that there is no IndexList (since we only have a mzML and not an indexedmzML)
System.out.println("An ERROR could be logged here, which is perfectly fine.");
assertFalse(um_2.isIndexedmzML());
// now check if the content is as expected
checkMzMLContent(mz_2);
// and compare the two versions (they have to have the same values!)
checkEqual(mz_1, mz_2);
logger.info("Re-unmarshalling mzML is OK.");
}
示例7: testReadWriteIndexedmzML
import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller; //导入依赖的package包/类
public void testReadWriteIndexedmzML() {
///// ///// ///// ///// FIRST READ ///// ///// ///// /////
// check if the instance file is valid
assertTrue(isValidMzML(indexedmzMLFile));
logger.info("zmML file is valid.");
MzMLUnmarshaller um_1 = new MzMLUnmarshaller(indexedmzMLFile);
MzMLObject mz_1 = um_1.unmarshall();
assertNotNull(mz_1);
// now check if the content is as expected
checkMzMLContent(mz_1);
logger.info("Unmarshalling valid XML is OK.");
///// ///// ///// ///// WRITE BACK ///// ///// ///// /////
// now try to write it back to a temporary file
FileWriter fw;
File tmpFile;
try {
// tmpFile = new File("tmpMzML.xml");
tmpFile = File.createTempFile("tmpMzML", "xml");
tmpFile.deleteOnExit();
fw = new FileWriter(tmpFile);
} catch (IOException e) {
e.printStackTrace();
throw new IllegalStateException("Could not create or write to temporary file for marshalling.");
}
MzMLMarshaller mm = new MzMLMarshaller();
mm.marshall(mz_1, fw);
logger.info("Marshalled back to XML.");
// now check if the written mzML is valid
assertTrue(isValidMzML(tmpFile));
logger.info("Marshalling mzML is valid.");
///// ///// ///// ///// RE-READ WRITTEN mzML ///// ///// ///// /////
MzMLUnmarshaller um_2 = new MzMLUnmarshaller(tmpFile);
MzML mz_2 = um_2.unmarshall();
assertNotNull(mz_2);
// now check if the content is as expected
checkMzMLContent(mz_2);
// and compare the two versions (they have to have the same values!)
checkEqual(mz_1, mz_2);
logger.info("Re-unmarshalling mzML is OK.");
}
示例8: testSpectrumIteration
import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller; //导入依赖的package包/类
public void testSpectrumIteration() {
assertTrue(isValidMzML(mzMLFile));
MzMLUnmarshaller um = new MzMLUnmarshaller(mzMLFile);
Iterator<Spectrum> iterator = um.unmarshalCollectionFromXpath(MzMLElement.Spectrum.getXpath(), Spectrum.class);
// count the number of spectra we are iterating over
logger.debug("Iterating over all spectra...");
int spectrumCnt = 0;
while (iterator.hasNext()) {
Spectrum spectrum = iterator.next();
if (logger.isDebugEnabled()) {
logger.debug("Spectrum: " + spectrum.getId());
}
spectrumCnt++;
}
// get the number of spectra entries in the index
int spectrumNo = um.getObjectCountForXpath(MzMLElement.Spectrum.getXpath());
// compare the two spectra counts
assertEquals(spectrumNo, spectrumCnt);
// additionally check one spectrum if we can detect binary arrays for m/z values and intensities
String spectrumId = null;
try {
spectrumId = um.getSpectrumIDs().iterator().next();
Spectrum testSpectrum = um.getSpectrumById(spectrumId);
boolean mzDataFound = false;
boolean intensityDataFound = false;
for (BinaryDataArray binaryDataArray : testSpectrum.getBinaryDataArrayList().getBinaryDataArray()) {
BinaryDataArray.DataType type = binaryDataArray.getDataType();
if (type.equals(BinaryDataArray.DataType.MZ_VALUES)) {
mzDataFound = true;
}
if (type.equals(BinaryDataArray.DataType.INTENSITY)) {
intensityDataFound = true;
}
}
assertTrue("m/z values not found!", mzDataFound);
assertTrue("intensity values not found!", intensityDataFound);
} catch (MzMLUnmarshallerException e) {
logger.error("Error reading binary data arrays for spectrum " + spectrumId, e);
}
}
示例9: addSpectra
import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller; //导入依赖的package包/类
/**
* Add spectra to the factory.
*
* @param spectrumFile the spectrum file, can be mgf or mzML
* @param waitingHandler the waiting handler
*
* @throws FileNotFoundException Exception thrown whenever the file was not
* found
* @throws IOException Exception thrown whenever an error occurred while
* reading the file
* @throws IllegalArgumentException Exception thrown if an unknown format
* was detected.
*/
public void addSpectra(File spectrumFile, WaitingHandler waitingHandler) throws FileNotFoundException, IOException, IllegalArgumentException {
String fileName = spectrumFile.getName();
filesMap.put(fileName, spectrumFile);
if (fileName.toLowerCase().endsWith(".mgf")|| fileName.toLowerCase().endsWith(".msp")) {
File indexFile = new File(spectrumFile.getParent(), getIndexName(fileName));
MgfIndex mgfIndex = null;
if (indexFile.exists()) {
try {
MgfIndex tempIndex = getIndex(indexFile);
Long indexLastModified = tempIndex.getLastModified();
if (indexLastModified != null) {
long fileLastModified = spectrumFile.lastModified();
if (indexLastModified == fileLastModified) {
mgfIndex = tempIndex;
} else {
System.err.println("Reindexing: " + fileName + ". (changes in the file detected)");
}
}
} catch (Exception e) {
System.err.println("Reindexing: " + fileName + ". (Reason: " + e.getLocalizedMessage() + ")");
}
}
if (mgfIndex == null) {
if(fileName.endsWith(".mgf")){
mgfIndex = MgfReader.getIndexMap(spectrumFile, waitingHandler);
}
else{
mgfIndex = MspReader.getIndexMap(spectrumFile, waitingHandler);
}
if (waitingHandler != null && waitingHandler.isRunCanceled()) {
return; // return without saving the partial index
}
writeIndex(mgfIndex, spectrumFile.getParentFile());
}
if (mgfIndex == null) {
throw new IllegalArgumentException("An error occurred while indexing " + spectrumFile.getAbsolutePath());
}
mgfRandomAccessFilesMap.put(fileName, new BufferedRandomAccessFile(spectrumFile, "r", 1024 * 100));
mgfIndexesMap.put(fileName, mgfIndex);
} else if (fileName.toLowerCase().endsWith(".mzml")) {
MzMLUnmarshaller mzMLUnmarshaller = new MzMLUnmarshaller(spectrumFile);
mzMLUnmarshallers.put(fileName, mzMLUnmarshaller);
} else {
throw new IllegalArgumentException("Spectrum file format not supported.");
}
}