コード例 #1
0
  @Override
  protected boolean isDataConsistent(ExperimentSummaryData summaryData) {
    if (!summaryData.getState().isPrecursorChargesLoaded())
      recordError("The experiment does not contain precursor charges");

    if (!summaryData.getState().isPrecursorMassesLoaded())
      recordError("The experiment does not contain precursor masses");

    if (summaryData.getProteinsPeptides().size() == 0)
      recordError("The experiment does not contain identifications data");

    return isValid();
  }
コード例 #2
0
  @Override
  protected void processData(ExperimentSummaryData summaryData) {
    List<Double> data = new ArrayList<Double>();

    for (ProteinPeptide pp : summaryData.getProteinsPeptides()) {
      SpectrumData sData;
      try {
        Comparable spectrumID = pp.getSpectrumID();
        sData = summaryData.getSpectrum(String.valueOf(spectrumID));
      } catch (ProteinPeptideException e) {
        // If there is not spectrumID, the precursor mass and charge could not be found
        continue;
      }

      double mz;
      int charge;
      try {
        mz = sData.getPrecursorMass();
        charge = (int) sData.getPrecursorCharge();
      } catch (Exception e) {
        System.err.println(e.getMessage());
        continue;
      }
      // the sum of the PTM masses is stored in the ProteinPeptide object, but for calling
      // the calculateDeltaMz method, we need a list of PTM (the Water loss mono mass value
      // will be added by the method)
      List<Double> ptmMasses = new ArrayList<Double>();
      ptmMasses.add(pp.getPtmMass());
      Double deltaMass =
          MoleculeUtilities.calculateDeltaMz(pp.getSequence(), mz, charge, ptmMasses);

      if (deltaMass != null) data.add(deltaMass);
    }

    if (data.size() == 0) {
      recordError("Peptide sequences could not be associated to a MS 1 precursor");
      return;
    }

    Map<Double, Integer> histogram = new HashMap<Double, Integer>();

    double min = Collections.min(data);
    double max = Collections.max(data);

    double binWidth = Math.abs((max - min) / (double) BINS);
    binWidth = binWidth < MIN_BIN_WIDTH ? MIN_BIN_WIDTH : binWidth;
    for (double value : data) {
      int bin = (int) Math.round(value / binWidth);
      double pos = bin * binWidth;
      if (histogram.keySet().contains(pos)) {
        histogram.put(pos, histogram.get(pos) + 1);
      } else {
        histogram.put(pos, 1);
      }
    }

    List<SeriesPair<Double, Double>> deltaMasses = new ArrayList<SeriesPair<Double, Double>>();

    if (histogram.keySet().size() == 1) {
      for (Double key : histogram.keySet()) {
        if (key > 0.0) { // To center the chart on 0
          deltaMasses.add(new SeriesPair<Double, Double>(-key - MIN_BIN_WIDTH, 0.0));
        }

        deltaMasses.add(new SeriesPair<Double, Double>(key - MIN_BIN_WIDTH, 0.0));
        deltaMasses.add(new SeriesPair<Double, Double>(key, 1.0));
        deltaMasses.add(new SeriesPair<Double, Double>(key + MIN_BIN_WIDTH, 0.0));

        if (key < 0.0) { // To center the chart on 0
          deltaMasses.add(new SeriesPair<Double, Double>(-key + MIN_BIN_WIDTH, 0.0));
        }
      }
    } else {
      int maxFreq = Collections.max(histogram.values());
      for (int pos = -BINS; pos < BINS; pos++) {
        double key = pos * binWidth;
        double value = histogram.containsKey(key) ? histogram.get(key) / (double) maxFreq : 0.0;
        deltaMasses.add(new SeriesPair<Double, Double>(key, value));
      }
    }

    DataSeries series = new DataSeries<Double, Double>(null, "deltaMasses", deltaMasses);
    intermediateData = new IntermediateData(series);
    try {
      intermediateData.setVariable("sequenceNumber", data.size());
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }