use of uk.ac.ebi.jmzml.model.mzml.Spectrum in project mzmine2 by mzmine.
the class MzMLReadTask method run.
/**
* @see java.lang.Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Started parsing file " + file);
MzMLUnmarshaller unmarshaller = new MzMLUnmarshaller(file);
totalScans = unmarshaller.getObjectCountForXpath("/run/spectrumList/spectrum");
fillScanIdTable(unmarshaller.unmarshalCollectionFromXpath("/run/spectrumList/spectrum", Spectrum.class), totalScans);
MzMLObjectIterator<Spectrum> spectrumIterator = unmarshaller.unmarshalCollectionFromXpath("/run/spectrumList/spectrum", Spectrum.class);
try {
while (spectrumIterator.hasNext()) {
if (isCanceled())
return;
Spectrum spectrum = spectrumIterator.next();
// Ignore scans that are not MS, e.g. UV
if (!isMsSpectrum(spectrum)) {
parsedScans++;
continue;
}
String scanId = spectrum.getId();
Integer scanNumber = scanIdTable.get(scanId);
if (scanNumber == null)
throw new IllegalStateException("Cannot determine scan number: " + scanId);
// Extract scan data
int msLevel = extractMSLevel(spectrum);
double retentionTime = extractRetentionTime(spectrum);
PolarityType polarity = extractPolarity(spectrum);
int parentScan = extractParentScanNumber(spectrum);
double precursorMz = extractPrecursorMz(spectrum);
int precursorCharge = extractPrecursorCharge(spectrum);
String scanDefinition = extractScanDefinition(spectrum);
DataPoint[] dataPoints = extractDataPoints(spectrum);
// Auto-detect whether this scan is centroided
MassSpectrumType spectrumType = ScanUtils.detectSpectrumType(dataPoints);
SimpleScan scan = new SimpleScan(null, scanNumber, msLevel, retentionTime, precursorMz, precursorCharge, null, dataPoints, spectrumType, polarity, scanDefinition, null);
for (SimpleScan s : parentStack) {
if (s.getScanNumber() == parentScan) {
s.addFragmentScan(scanNumber);
}
}
/*
* Verify the size of parentStack. The actual size of the window to cover possible
* candidates is defined by limitSize.
*/
if (parentStack.size() > PARENT_STACK_SIZE) {
SimpleScan firstScan = parentStack.removeLast();
newMZmineFile.addScan(firstScan);
}
parentStack.addFirst(scan);
parsedScans++;
}
while (!parentStack.isEmpty()) {
SimpleScan scan = parentStack.removeLast();
newMZmineFile.addScan(scan);
}
finalRawDataFile = newMZmineFile.finishWriting();
project.addFile(finalRawDataFile);
} catch (Throwable e) {
e.printStackTrace();
setStatus(TaskStatus.ERROR);
setErrorMessage("Error parsing mzML: " + ExceptionUtils.exceptionToString(e));
e.printStackTrace();
return;
}
if (parsedScans == 0) {
setStatus(TaskStatus.ERROR);
setErrorMessage("No scans found");
return;
}
logger.info("Finished parsing " + file + ", parsed " + parsedScans + " scans");
setStatus(TaskStatus.FINISHED);
}
Aggregations