Exemple #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;
}
  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;
  }
  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;
  }