Exemple #1
0
  /**
   * {@inheritDoc}
   *
   * <p>endElement()
   */
  @SuppressWarnings("null")
  public void endElement(String namespaceURI, String sName, String qName) throws SAXException {

    if (canceled) throw new SAXException("Parsing Cancelled");

    // <spectrumInstrument>
    if (qName.equalsIgnoreCase("spectrumInstrument")) {
      spectrumInstrumentFlag = false;
    }

    // <precursor>
    if (qName.equalsIgnoreCase("precursor")) {
      precursorFlag = false;
    }

    // <spectrum>
    if (qName.equalsIgnoreCase("spectrum")) {

      spectrumInstrumentFlag = false;

      // Auto-detect whether this scan is centroided
      MsSpectrumType spectrumType =
          SpectrumTypeDetectionAlgorithm.detectSpectrumType(mzBuffer, intensityBuffer, peaksCount);

      // Create a new scan
      MsFunction msFunction = MSDKObjectBuilder.getMsFunction(msLevel);

      MsScan newScan = MSDKObjectBuilder.getMsScan(dataStore, scanNumber, msFunction);

      newScan.setDataPoints(mzBuffer, intensityBuffer, peaksCount);
      newScan.setSpectrumType(spectrumType);
      newScan.setPolarity(polarity);

      if (retentionTime != null) {
        ChromatographyInfo chromInfo =
            MSDKObjectBuilder.getChromatographyInfo1D(SeparationType.UNKNOWN, retentionTime);
        newScan.setChromatographyInfo(chromInfo);
      }

      if (precursorMz != null) {
        IsolationInfo isolation =
            MSDKObjectBuilder.getIsolationInfo(
                Range.singleton(precursorMz), null, precursorMz, precursorCharge, null);
        newScan.getIsolations().add(isolation);
      }

      // Add the scan to the file
      newRawFile.addScan(newScan);
      parsedScans++;
    }

    // <mzArrayBinary>
    if (qName.equalsIgnoreCase("mzArrayBinary")) {

      mzArrayBinaryFlag = false;

      // Allocate space for the whole array
      if (mzBuffer.length < peaksCount) mzBuffer = new double[peaksCount * 2];

      byte[] peakBytes = Base64.decodeBase64(charBuffer.toString().getBytes());

      ByteBuffer currentMzBytes = ByteBuffer.wrap(peakBytes);

      if (endian.equals("big")) {
        currentMzBytes = currentMzBytes.order(ByteOrder.BIG_ENDIAN);
      } else {
        currentMzBytes = currentMzBytes.order(ByteOrder.LITTLE_ENDIAN);
      }

      for (int i = 0; i < peaksCount; i++) {
        if (precision == null || precision.equals("32"))
          mzBuffer[i] = (double) currentMzBytes.getFloat();
        else mzBuffer[i] = currentMzBytes.getDouble();
      }
    }

    // <intenArrayBinary>
    if (qName.equalsIgnoreCase("intenArrayBinary")) {

      intenArrayBinaryFlag = false;

      // Allocate space for the whole array
      if (intensityBuffer.length < peaksCount) intensityBuffer = new float[peaksCount * 2];

      byte[] peakBytes = Base64.decodeBase64(charBuffer.toString().getBytes());

      ByteBuffer currentIntensityBytes = ByteBuffer.wrap(peakBytes);

      if (endian.equals("big")) {
        currentIntensityBytes = currentIntensityBytes.order(ByteOrder.BIG_ENDIAN);
      } else {
        currentIntensityBytes = currentIntensityBytes.order(ByteOrder.LITTLE_ENDIAN);
      }

      for (int i = 0; i < peaksCount; i++) {
        if (precision == null || precision.equals("32"))
          intensityBuffer[i] = currentIntensityBytes.getFloat();
        else intensityBuffer[i] = (float) currentIntensityBytes.getDouble();
      }
    }
  }
  @Override
  public MsScan performFilter(MsScan scan) {

    if (!Avalues.containsKey(numOfDataPoints) || !Hvalues.containsKey(numOfDataPoints)) {
      return scan;
    }

    int[] aVals = Avalues.get(numOfDataPoints);
    int h = Hvalues.get(numOfDataPoints);

    int marginSize = (numOfDataPoints + 1) / 2 - 1;
    float sumOfInts;

    // Create data point list object and fill it with the scan data points
    MsSpectrumDataPointList dataPoints = MSDKObjectBuilder.getMsSpectrumDataPointList();
    scan.getDataPoints(dataPoints);
    float intensityValues[] = dataPoints.getIntensityBuffer();
    double mzValues[] = dataPoints.getMzBuffer();

    int newDataPointsLength = dataPoints.getSize() - (marginSize * 2);

    // only process MS level 1 scans
    if (scan.getMsFunction().getMsLevel() != 1) {
      return scan;
    }

    // only process scans with datapoints
    if (newDataPointsLength < 1) {
      return scan;
    }

    MsSpectrumDataPointList newDataPoints = MSDKObjectBuilder.getMsSpectrumDataPointList();

    for (int spectrumInd = marginSize;
        spectrumInd < (dataPoints.getSize() - marginSize);
        spectrumInd++) {

      // zero intensity data points must be left unchanged
      if (intensityValues[spectrumInd] == 0) {
        intensityValues[spectrumInd - marginSize] = intensityValues[spectrumInd];
        continue;
      }

      sumOfInts = aVals[0] * intensityValues[spectrumInd];

      for (int windowInd = 1; windowInd <= marginSize; windowInd++) {
        sumOfInts +=
            aVals[windowInd]
                * (intensityValues[spectrumInd + windowInd]
                    + intensityValues[spectrumInd - windowInd]);
      }

      sumOfInts = sumOfInts / h;

      if (sumOfInts < 0) {
        sumOfInts = 0;
      }
      newDataPoints.add(mzValues[spectrumInd], sumOfInts);
    }

    // Return a new scan with the new data points
    MsScan result = MSDKObjectBuilder.getMsScan(store, scan.getScanNumber(), scan.getMsFunction());
    result.setDataPoints(newDataPoints);
    result.setChromatographyInfo(scan.getChromatographyInfo());
    result.setRawDataFile(scan.getRawDataFile());

    return result;
  }