コード例 #1
0
PWIZ_API_DECL ChromatogramPtr ChromatogramList_ABI::chromatogram(size_t index, bool getBinaryData) const
{
    boost::call_once(indexInitialized_.flag, boost::bind(&ChromatogramList_ABI::createIndex, this));
    if (index>size_)
        throw runtime_error(("[ChromatogramList_ABI::chromatogram()] Bad index: " 
                            + lexical_cast<string>(index)).c_str());

    
    // allocate a new Chromatogram
    IndexEntry& ie = index_[index];
    ChromatogramPtr result = ChromatogramPtr(new Chromatogram);
    if (!result.get())
        throw std::runtime_error("[ChromatogramList_Thermo::chromatogram()] Allocation error.");

    result->index = index;
    result->id = ie.id;
    result->set(ie.chromatogramType);

    switch (ie.chromatogramType)
    {
        case MS_TIC_chromatogram:
        {
            map<double, double> fullFileTIC;

            int sampleCount = wifffile_->getSampleCount();
            for (int i=1; i <= sampleCount; ++i)
            {
                try
                {
                    int periodCount = wifffile_->getPeriodCount(i);
                    for (int ii=1; ii <= periodCount; ++ii)
                    {
                        //Console::WriteLine("Sample {0}, Period {1}", i, ii);

                        int experimentCount = wifffile_->getExperimentCount(i, ii);
                        for (int iii=1; iii <= experimentCount; ++iii)
                        {
                            ExperimentPtr msExperiment = (i == sample
                                ? experimentsMap_.find(pair<int, int>(ii, iii))->second
                                : wifffile_->getExperiment(i, ii, iii));

                            // add current experiment TIC to full file TIC
                            vector<double> times, intensities;
                            msExperiment->getTIC(times, intensities);
                            for (int iiii = 0, end = intensities.size(); iiii < end; ++iiii)
                                fullFileTIC[times[iiii]] += intensities[iiii];
                        }
                    }
                }
                catch (exception&)
                {
                    // TODO: log warning
                }
            }

            result->setTimeIntensityArrays(std::vector<double>(), std::vector<double>(), UO_minute, MS_number_of_detector_counts);

            if (getBinaryData)
            {
                BinaryDataArrayPtr timeArray = result->getTimeArray();
                BinaryDataArrayPtr intensityArray = result->getIntensityArray();

                timeArray->data.reserve(fullFileTIC.size());
                intensityArray->data.reserve(fullFileTIC.size());
                for (map<double, double>::iterator itr = fullFileTIC.begin();
                     itr != fullFileTIC.end();
                     ++itr)
                {
                    timeArray->data.push_back(itr->first);
                    intensityArray->data.push_back(itr->second);
                }
            }

            result->defaultArrayLength = fullFileTIC.size();
        }
        break;

        case MS_SRM_chromatogram:
        {
            ExperimentPtr experiment = ie.experiment;
            pwiz::vendor_api::ABI::Target target;
            experiment->getSRM(ie.transition, target);

            // TODO: move to global scan settings or leave out entirely?
            result->userParams.push_back(UserParam("MS_dwell_time", lexical_cast<string>(target.dwellTime /* milliseconds->seconds */ / 1000.0), "xs:float"));

            result->precursor.isolationWindow.set(MS_isolation_window_target_m_z, ie.q1, MS_m_z);
            //result->precursor.isolationWindow.set(MS_isolation_window_lower_offset, ie.q1, MS_m_z);
            //result->precursor.isolationWindow.set(MS_isolation_window_upper_offset, ie.q1, MS_m_z);
            result->precursor.activation.set(MS_CID);
            result->precursor.activation.set(MS_collision_energy, target.collisionEnergy, UO_electronvolt);
            result->precursor.activation.userParams.push_back(UserParam("MS_declustering_potential", lexical_cast<string>(target.declusteringPotential), "xs:float"));

            result->product.isolationWindow.set(MS_isolation_window_target_m_z, ie.q3, MS_m_z);
            //result->product.isolationWindow.set(MS_isolation_window_lower_offset, ie.q3, MS_m_z);
            //result->product.isolationWindow.set(MS_isolation_window_upper_offset, ie.q3, MS_m_z);

            result->setTimeIntensityArrays(std::vector<double>(), std::vector<double>(), UO_minute, MS_number_of_detector_counts);

            vector<double> times, intensities;
            experiment->getSIC(ie.transition, times, intensities);
            result->defaultArrayLength = times.size();

            if (getBinaryData)
            {
                BinaryDataArrayPtr timeArray = result->getTimeArray();
                BinaryDataArrayPtr intensityArray = result->getIntensityArray();
                std::swap(timeArray->data, times);
                std::swap(intensityArray->data, intensities);
            }
        }
        break;
    }

    return result;
}
コード例 #2
0
void test()
{
    {
    MSData tiny;
    examples::initializeTiny(tiny);

    MSDataFile::WriteConfig writeConfig;
    Serializer_mz5 serializer(writeConfig);

    IterationListenerRegistry ilr;
    serializer.write(testFilename, tiny, &ilr);

    MSData dummy;
    serializer.read(testFilename, dummy);

    // so we don't have any dangling references
    //dummy.instrumentPtrs.push_back(InstrumentPtr(new Instrument("LCQ_Deca")));
    dummy.dataProcessingPtrs.push_back(DataProcessingPtr(new DataProcessing(
            "pwiz_processing")));
    dummy.dataProcessingPtrs.push_back(DataProcessingPtr(new DataProcessing(
            "CompassXtract processing")));

    ChromatogramListPtr sl = dummy.run.chromatogramListPtr;

    // check easy functions

    unit_assert(sl.get());
    unit_assert(sl->size() == 2);
    unit_assert(sl->find("tic") == 0);
    unit_assert(sl->find("sic") == 1);

    // check tic

    ChromatogramPtr s = sl->chromatogram(0); // read without binary data
    unit_assert(s.get());
    unit_assert(s->id == "tic");
    unit_assert(s->binaryDataArrayPtrs.empty());

    unit_assert(sl->chromatogramIdentity(0).index == 0);
    unit_assert(sl->chromatogramIdentity(0).id == "tic");

    s = sl->chromatogram(0, true); // read with binary data

    vector < TimeIntensityPair > pairs;
    s->getTimeIntensityPairs(pairs);
    unit_assert(pairs.size() == 15);
    for (int i = 0; i < 15; i++)
        unit_assert(pairs[i].time == i && pairs[i].intensity == 15 - i);

    // check sic

    s = sl->chromatogram(1, true);
    unit_assert(s.get());
    unit_assert(s->id == "sic");

    unit_assert(sl->chromatogramIdentity(1).index == 1);
    unit_assert(sl->chromatogramIdentity(1).id == "sic");

    pairs.clear();
    s->getTimeIntensityPairs(pairs);
    unit_assert(pairs.size() == 10);
    for (int i = 0; i < 10; i++)
        unit_assert(pairs[i].time == i && pairs[i].intensity == (10 - i));

    }
    bfs::remove(testFilename);
}