use of net.sf.mzmine.datamodel.PeakInformation in project mzmine2 by mzmine.
the class PeakListOpenHandler_2_5 method endElement.
/**
* @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
* java.lang.String)
*/
@Override
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
if (canceled)
throw new SAXException("Parsing canceled");
// <NAME>
if (qName.equals(PeakListElementName_2_5.PEAKLIST_NAME.getElementName())) {
name = getTextOfElement();
logger.info("Loading feature list: " + name);
peakListName = name;
}
// <PEAKLIST_DATE>
if (qName.equals(PeakListElementName_2_5.PEAKLIST_DATE.getElementName())) {
dateCreated = getTextOfElement();
}
// <QUANTITY>
if (qName.equals(PeakListElementName_2_5.QUANTITY.getElementName())) {
String text = getTextOfElement();
totalRows = Integer.parseInt(text);
}
// <RAW_FILE>
if (qName.equals(PeakListElementName_2_5.RAWFILE.getElementName())) {
rawDataFileID = getTextOfElement();
RawDataFile dataFile = dataFilesIDMap.get(rawDataFileID);
if (dataFile == null) {
throw new SAXException("Cannot open feature list, because raw data file " + rawDataFileID + " is missing.");
}
currentPeakListDataFiles.add(dataFile);
}
// <SCAN_ID>
if (qName.equals(PeakListElementName_2_5.SCAN_ID.getElementName())) {
byte[] bytes = Base64.decodeToBytes(getTextOfElement());
// make a data input stream
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
scanNumbers = new int[numOfMZpeaks];
for (int i = 0; i < numOfMZpeaks; i++) {
try {
scanNumbers[i] = dataInputStream.readInt();
} catch (IOException ex) {
throw new SAXException(ex);
}
}
}
// <REPRESENTATIVE_SCAN>
if (qName.equals(PeakListElementName_2_5.REPRESENTATIVE_SCAN.getElementName())) {
representativeScan = Integer.valueOf(getTextOfElement());
}
// <FRAGMENT_SCAN>
if (qName.equals(PeakListElementName_2_5.FRAGMENT_SCAN.getElementName())) {
fragmentScan = Integer.valueOf(getTextOfElement());
}
// <All_MS2_FRAGMENT_SCANS>
if (qName.equals(PeakListElementName_2_5.ALL_MS2_FRAGMENT_SCANS.getElementName())) {
Integer fragmentNumber = Integer.valueOf(getTextOfElement());
currentAllMS2FragmentScans.add(fragmentNumber);
}
// <MASS>
if (qName.equals(PeakListElementName_2_5.MZ.getElementName())) {
byte[] bytes = Base64.decodeToBytes(getTextOfElement());
// make a data input stream
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
masses = new double[numOfMZpeaks];
for (int i = 0; i < numOfMZpeaks; i++) {
try {
masses[i] = dataInputStream.readFloat();
} catch (IOException ex) {
throw new SAXException(ex);
}
}
}
// <HEIGHT>
if (qName.equals(PeakListElementName_2_5.HEIGHT.getElementName())) {
byte[] bytes = Base64.decodeToBytes(getTextOfElement());
// make a data input stream
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
intensities = new double[numOfMZpeaks];
for (int i = 0; i < numOfMZpeaks; i++) {
try {
intensities[i] = dataInputStream.readFloat();
} catch (IOException ex) {
throw new SAXException(ex);
}
}
}
// <PEAK>
if (qName.equals(PeakListElementName_2_5.PEAK.getElementName())) {
DataPoint[] mzPeaks = new DataPoint[numOfMZpeaks];
Range<Double> peakRTRange = null, peakMZRange = null, peakIntensityRange = null;
RawDataFile dataFile = dataFilesIDMap.get(peakColumnID);
if (dataFile == null)
throw new SAXException("Error in project: data file " + peakColumnID + " not found");
for (int i = 0; i < numOfMZpeaks; i++) {
Scan sc = dataFile.getScan(scanNumbers[i]);
double retentionTime = sc.getRetentionTime();
double mz = masses[i];
double intensity = intensities[i];
if (peakIntensityRange == null) {
peakIntensityRange = Range.singleton(intensity);
} else {
peakIntensityRange = peakIntensityRange.span(Range.singleton(intensity));
}
if (intensity > 0) {
if (peakRTRange == null) {
peakRTRange = Range.singleton(retentionTime);
} else {
peakRTRange = peakRTRange.span(Range.singleton(retentionTime));
}
}
if (mz > 0.0) {
mzPeaks[i] = new SimpleDataPoint(mz, intensity);
if (peakMZRange == null)
peakMZRange = Range.singleton(mz);
else
peakMZRange = peakMZRange.span(Range.singleton(mz));
}
}
FeatureStatus status = FeatureStatus.valueOf(peakStatus);
// convert vector of allMS2FragmentScans to array
allMS2FragmentScanNumbers = new int[currentAllMS2FragmentScans.size()];
for (int i = 0; i < allMS2FragmentScanNumbers.length; i++) {
allMS2FragmentScanNumbers[i] = currentAllMS2FragmentScans.get(i);
}
// clear all MS2 fragment scan numbers list for next peak
currentAllMS2FragmentScans.clear();
SimpleFeature peak = new SimpleFeature(dataFile, mass, rt, height, area, scanNumbers, mzPeaks, status, representativeScan, fragmentScan, allMS2FragmentScanNumbers, peakRTRange, peakMZRange, peakIntensityRange);
peak.setCharge(currentPeakCharge);
if (currentIsotopes.size() > 0) {
SimpleIsotopePattern newPattern = new SimpleIsotopePattern(currentIsotopes.toArray(new DataPoint[0]), currentIsotopePatternStatus, currentIsotopePatternDescription);
peak.setIsotopePattern(newPattern);
currentIsotopes.clear();
}
peak.setParentChromatogramRowID(parentChromatogramRowID);
buildingRow.addPeak(dataFile, peak);
}
// <IDENTITY_PROPERTY>
if (qName.equals(PeakListElementName_2_5.IDPROPERTY.getElementName())) {
identityProperties.put(identityPropertyName, getTextOfElement());
}
// <INFO_PROPERTY>
if (qName.equals(PeakListElementName_2_5.INFO_PROPERTY.getElementName())) {
informationProperties.put(infoPropertyName, getTextOfElement());
}
// <PEAK_IDENTITY>
if (qName.equals(PeakListElementName_2_5.PEAK_IDENTITY.getElementName())) {
SimplePeakIdentity identity = new SimplePeakIdentity(identityProperties);
buildingRow.addPeakIdentity(identity, preferred);
}
if (qName.equals(PeakListElementName_2_5.PEAK_INFORMATION.getElementName())) {
PeakInformation information = new SimplePeakInformation(informationProperties);
buildingRow.setPeakInformation(information);
}
// <ROW>
if (qName.equals(PeakListElementName_2_5.ROW.getElementName())) {
buildingPeakList.addRow(buildingRow);
buildingRow = null;
parsedRows++;
}
// <ISOTOPE>
if (qName.equals(PeakListElementName_2_5.ISOTOPE.getElementName())) {
String text = getTextOfElement();
String[] items = text.split(":");
double mz = Double.valueOf(items[0]);
double intensity = Double.valueOf(items[1]);
DataPoint isotope = new SimpleDataPoint(mz, intensity);
currentIsotopes.add(isotope);
}
if (qName.equals(PeakListElementName_2_5.METHOD_NAME.getElementName())) {
String appliedMethod = getTextOfElement();
appliedMethods.add(appliedMethod);
}
if (qName.equals(PeakListElementName_2_5.METHOD_PARAMETERS.getElementName())) {
String appliedMethodParam = getTextOfElement();
appliedMethodParameters.add(appliedMethodParam);
}
}
Aggregations