Beispiel #1
0
OpenSwath::SpectrumPtr OpenSwathDataAccessHelper::convertToSpectrumPtr(const OpenMS::MSSpectrum<> & spectrum)
{
    OpenSwath::BinaryDataArrayPtr intensity_array(new OpenSwath::BinaryDataArray);
    OpenSwath::BinaryDataArrayPtr mz_array(new OpenSwath::BinaryDataArray);
    for (MSSpectrum<>::const_iterator it = spectrum.begin(); it != spectrum.end(); it++)
    {
        mz_array->data.push_back(it->getMZ());
        intensity_array->data.push_back(it->getIntensity());
    }

    OpenSwath::SpectrumPtr sptr(new OpenSwath::Spectrum);
    sptr->setMZArray(mz_array);
    sptr->setIntensityArray(intensity_array);
    return sptr;
}
Beispiel #2
0
  OpenSwath::SpectrumPtr SpectrumAccessOpenMS::getSpectrumById(int id)
  {
    const MSSpectrumType& spectrum = (*ms_experiment_)[id];
    OpenSwath::BinaryDataArrayPtr intensity_array(new OpenSwath::BinaryDataArray);
    OpenSwath::BinaryDataArrayPtr mz_array(new OpenSwath::BinaryDataArray);
    for (MSSpectrumType::const_iterator it = spectrum.begin(); it != spectrum.end(); it++)
    {
      mz_array->data.push_back(it->getMZ());
      intensity_array->data.push_back(it->getIntensity());
    }

    OpenSwath::SpectrumPtr sptr(new OpenSwath::Spectrum);
    sptr->setMZArray(mz_array);
    sptr->setIntensityArray(intensity_array);
    return sptr;
  }
Beispiel #3
0
  OpenSwath::ChromatogramPtr SpectrumAccessOpenMS::getChromatogramById(int id)
  {
    const MSChromatogramType& chromatogram = ms_experiment_->getChromatograms()[id];
    OpenSwath::BinaryDataArrayPtr intensity_array(new OpenSwath::BinaryDataArray);
    OpenSwath::BinaryDataArrayPtr rt_array(new OpenSwath::BinaryDataArray);
    for (MSChromatogramType::const_iterator it = chromatogram.begin(); it != chromatogram.end(); it++)
    {
      rt_array->data.push_back(it->getRT());
      intensity_array->data.push_back(it->getIntensity());
    }

    // push back rt first, then intensity.
    // FEATURE (hroest) annotate which is which
    std::vector<OpenSwath::BinaryDataArrayPtr> binaryDataArrayPtrs;
    binaryDataArrayPtrs.push_back(rt_array);
    binaryDataArrayPtrs.push_back(intensity_array);

    OpenSwath::ChromatogramPtr cptr(new OpenSwath::Chromatogram);
    cptr->binaryDataArrayPtrs = binaryDataArrayPtrs;
    return cptr;
  }
  OpenSwath::SpectrumPtr SpectrumAccessOpenMSCached::getSpectrumById(int id) const
  {
    if (cache_.getSpectraIndex().empty())
    {
      // remove const from the cache since we need to recalculate the index
      // and re-read the data.
      (const_cast<CachedmzML*>(&cache_))->createMemdumpIndex(filename_cached_);
    }
    OpenSwath::BinaryDataArrayPtr mz_array(new OpenSwath::BinaryDataArray);
    OpenSwath::BinaryDataArrayPtr intensity_array(new OpenSwath::BinaryDataArray);
    int ms_level = -1;
    double rt = -1.0;
    // FEATURE check if we can keep the filestream open -> risky if someone else
    // accesses the file in the meantime
    std::ifstream ifs_((filename_cached_).c_str(), std::ios::binary);
    ifs_.seekg(cache_.getSpectraIndex()[id]);
    cache_.readSpectrumFast(mz_array, intensity_array, ifs_, ms_level, rt);

    OpenSwath::SpectrumPtr sptr(new OpenSwath::Spectrum);
    sptr->setMZArray(mz_array);
    sptr->setIntensityArray(intensity_array);
    return sptr;
  }
  OpenSwath::ChromatogramPtr SpectrumAccessOpenMSCached::getChromatogramById(int id) const
  {
    if (cache_.getChromatogramIndex().empty())
    {
      // remove const from the cache since we need to recalculate the index
      // and re-read the data.
      (const_cast<CachedmzML*>(&cache_))->createMemdumpIndex(filename_cached_);
    }
    OpenSwath::BinaryDataArrayPtr rt_array(new OpenSwath::BinaryDataArray);
    OpenSwath::BinaryDataArrayPtr intensity_array(new OpenSwath::BinaryDataArray);
    std::ifstream ifs_((filename_cached_).c_str(), std::ios::binary);
    ifs_.seekg(cache_.getChromatogramIndex()[id]);
    cache_.readChromatogramFast(rt_array, intensity_array, ifs_);

    // push back rt first, then intensity.
    // FEATURE (hroest) annotate which is which
    std::vector<OpenSwath::BinaryDataArrayPtr> binaryDataArrayPtrs;
    binaryDataArrayPtrs.push_back(rt_array);
    binaryDataArrayPtrs.push_back(intensity_array);

    OpenSwath::ChromatogramPtr cptr(new OpenSwath::Chromatogram);
    cptr->binaryDataArrayPtrs = binaryDataArrayPtrs;
    return cptr;
  }
Beispiel #6
0
  OpenMS::Interfaces::SpectrumPtr MzMLSpectrumDecoder::decodeBinaryData(std::vector<BinaryData>& data_)
  {
    Internal::MzMLHandlerHelper::decodeBase64Arrays(data_);
    OpenMS::Interfaces::SpectrumPtr sptr(new OpenMS::Interfaces::Spectrum);

    //look up the precision and the index of the intensity and m/z array
    bool x_precision_64 = true;
    bool int_precision_64 = true;
    SignedSize x_index = -1;
    SignedSize int_index = -1;
    Internal::MzMLHandlerHelper::computeDataProperties_(data_, x_precision_64, x_index, "m/z array");
    Internal::MzMLHandlerHelper::computeDataProperties_(data_, int_precision_64, int_index, "intensity array");

    //Abort if no m/z or intensity array is present
    if (int_index == -1 || x_index == -1)
    {
      // Warning ...
      return sptr;
    }

    // Error if intensity or m/z is encoded as int32|64 - they should be float32|64!
    if ((data_[x_index].ints_32.size() > 0) || (data_[x_index].ints_64.size() > 0))
    {
      //fatalError(LOAD, "Encoding m/z array as integer is not allowed!");
    }
    if ((data_[int_index].ints_32.size() > 0) || (data_[int_index].ints_64.size() > 0))
    {
      //fatalError(LOAD, "Encoding intensity array as integer is not allowed!");
    }

    // Warn if the decoded data has a different size than the defaultArrayLength
    Size mz_size = x_precision_64 ? data_[x_index].floats_64.size() : data_[x_index].floats_32.size();
    Size int_size = int_precision_64 ? data_[int_index].floats_64.size() : data_[int_index].floats_32.size();
    // Check if int-size and mz-size are equal
    if (mz_size != int_size)
    {
      std::cout << "Warning, intensity and m/z array length are unequal" << std::endl;
      return sptr;
    }
    Size default_array_length_ = mz_size;
    // maybe some checks here about internal consistency e.g. with defaultArrayLength ...

    //create meta data arrays and reserve enough space for the content
    if (data_.size() > 2)
    {
      // --> TODO the other arrays ... create and resize those ...
    }

    // Copy meta data from m/z and intensity binary
    // We don't have this as a separate location => store it in spectrum
    // --> maybe TODO

    OpenMS::Interfaces::BinaryDataArrayPtr intensity_array(new OpenMS::Interfaces::BinaryDataArray);
    OpenMS::Interfaces::BinaryDataArrayPtr x_array(new OpenMS::Interfaces::BinaryDataArray);
    for (Size n = 0; n < default_array_length_; n++)
    {
      DoubleReal xcoord = x_precision_64 ? data_[x_index].floats_64[n] : data_[x_index].floats_32[n];
      DoubleReal intensity = int_precision_64 ? data_[int_index].floats_64[n] : data_[int_index].floats_32[n];

      x_array->data.push_back(xcoord);
      intensity_array->data.push_back(intensity);

      // TODO the other arrays
    }
    sptr->setMZArray(x_array);
    sptr->setIntensityArray(intensity_array);
    return sptr;
  }