use of net.sf.mzmine.datamodel.impl.SimpleScan 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);
}
use of net.sf.mzmine.datamodel.impl.SimpleScan in project mzmine2 by mzmine.
the class AgilentCsvReadTask method run.
/**
* Reads the file.
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
Scanner scanner;
try {
scanner = new Scanner(this.file);
this.dataSource = this.getMetaData(scanner, "file name");
String[] range = this.getMetaData(scanner, "mass range").split(",");
newMZmineFile.setMZRange(1, Range.closed(Double.parseDouble(range[0]), Double.parseDouble(range[1])));
range = this.getMetaData(scanner, "time range").split(",");
newMZmineFile.setRTRange(1, Range.closed(Double.parseDouble(range[0]), Double.parseDouble(range[1])));
totalScans = Integer.parseInt(this.getMetaData(scanner, "number of spectra"));
// advance to the spectrum data...
while (!scanner.nextLine().trim().equals("[spectra]")) {
}
scanner.useDelimiter(",");
for (parsedScans = 0; parsedScans < totalScans; parsedScans++) {
if (isCanceled()) {
return;
}
// if the task is canceled.
double retentionTime = scanner.nextDouble();
// not sure about this value
int msLevel = scanner.nextInt();
scanner.next();
scanner.next();
int charge = (scanner.next().equals("+") ? 1 : -1);
scanner.next();
int spectrumSize = scanner.nextInt();
DataPoint[] dataPoints = new DataPoint[spectrumSize];
for (int j = 0; j < spectrumSize; j++) {
dataPoints[j] = new SimpleDataPoint(scanner.nextDouble(), scanner.nextDouble());
}
newMZmineFile.addScan(new SimpleScan(null, parsedScans + 1, msLevel, retentionTime, 0.0, charge, null, dataPoints, ScanUtils.detectSpectrumType(dataPoints), PolarityType.UNKNOWN, "", null));
scanner.nextLine();
}
finalRawDataFile = newMZmineFile.finishWriting();
project.addFile(finalRawDataFile);
} catch (Exception e) {
setErrorMessage(e.getMessage());
this.setStatus(TaskStatus.ERROR);
return;
}
this.setStatus(TaskStatus.FINISHED);
}
Aggregations