示例#1
0
void initializeAnalyzers(MSDataAnalyzerContainer& analyzers,
                         const vector<string>& commands)
{
    shared_ptr<MSDataCache> cache(new MSDataCache);
    analyzers.push_back(cache);

    for (vector<string>::const_iterator it=commands.begin(); it!=commands.end(); ++it)
    {
        string name, args;
        istringstream iss(*it);
        iss >> name;
        getline(iss, args);

        if (supportedAnalyzer(name, analyzer_strings<MetadataReporter>::id()))
        {
            MSDataAnalyzerPtr anal(new MetadataReporter);
            analyzers.push_back(anal);
        }
        else if (supportedAnalyzer(name, analyzer_strings<RunSummary>::id()))
        {
            MSDataAnalyzerPtr anal(new RunSummary(*cache, args));
            analyzers.push_back(anal);
        }
        else if (supportedAnalyzer(name, analyzer_strings<SpectrumTable>::id()))
        {
            MSDataAnalyzerPtr anal(new SpectrumTable(*cache, args));
            analyzers.push_back(anal);
        }
        else if (supportedAnalyzer(name, analyzer_strings<SpectrumBinaryData>::id()))
        {
            MSDataAnalyzerPtr anal(new SpectrumBinaryData(*cache, args));
            analyzers.push_back(anal);
        }
        else if (supportedAnalyzer(name, analyzer_strings<RegionSlice>::id()))
        {
            MSDataAnalyzerPtr anal(new RegionSlice(*cache, args));
            analyzers.push_back(anal);
        }
        else if (supportedAnalyzer(name, analyzer_strings<RegionTIC>::id()))
        {
            MSDataAnalyzerPtr anal(new RegionTIC(*cache, args));
            analyzers.push_back(anal);
        }
        else if (supportedAnalyzer(name, analyzer_strings<RegionSIC>::id()))
        {
            MSDataAnalyzerPtr anal(new RegionSIC(*cache, args));
            analyzers.push_back(anal);
        }
        else if (supportedAnalyzer(name, analyzer_strings<Pseudo2DGel>::id()))
        {
            MSDataAnalyzerPtr anal(new Pseudo2DGel(*cache, args));
            analyzers.push_back(anal);
        }
        else
        {
            cerr << "Unknown analysis command \"" << name << "\".  Expected one of:" << supportedAnalyzers << "." << endl;
        }
    }
}
示例#2
0
void testUpdateRequest()
{
    if (os_) *os_ << "testUpdateRequest()\n";

    vector<MZIntensityPair> pairs(100);

    SpectrumListSimplePtr sl(new SpectrumListSimple);
    for (size_t i=0; i<10; i++)
    {
        SpectrumPtr spectrum(new Spectrum);
        spectrum->setMZIntensityPairs(pairs, MS_number_of_detector_counts);
        spectrum->index = i;
        spectrum->id = "scan=" + lexical_cast<string>(i);
        sl->spectra.push_back(spectrum);
    }

    MSData msd;
    msd.run.spectrumListPtr = sl;

    MSDataAnalyzerContainer analyzers;
    shared_ptr<MSDataCache> cache(new MSDataCache);
    analyzers.push_back(cache);
    analyzers.push_back(MSDataAnalyzerPtr(new EvenRequester));

    MSDataAnalyzerDriver driver(analyzers);
    driver.analyze(msd);

    for (size_t i=0, end=cache->size(); i<end; i++)
    {
        const SpectrumInfo& info = cache->at(i);
        if (os_) *os_ << info.index << " " << info.id << endl;

        // cache has only been updated with the spectra requested by EvenRequester

        unit_assert(i%2==0 && info.index==i && info.id=="scan="+lexical_cast<string>(i) ||
                    i%2==1 && info.index==(size_t)-1&& info.id.empty());
    }

    if (os_) *os_ << endl;
}
void testConfig(const RegionAnalyzer::Config& config)
{
    MSData msd;
    initialize(msd);

    shared_ptr<MSDataCache> cache(new MSDataCache);
    shared_ptr<RegionAnalyzer> regionAnalyzer(new RegionAnalyzer(config, *cache));

    MSDataAnalyzerContainer analyzers;
    analyzers.push_back(cache);
    analyzers.push_back(regionAnalyzer);

    MSDataAnalyzerDriver driver(analyzers);
    driver.analyze(msd);

    unit_assert(regionAnalyzer->spectrumStats().size() == 5);

    if (os_) *os_ << "sumIntensity (max) (peak):\n";

    vector<RegionAnalyzer::SpectrumStats>::const_iterator it = 
        regionAnalyzer->spectrumStats().begin();
    if (os_) *os_ << *it << endl;
    unit_assert(it->sumIntensity == 0);
    unit_assert_equal(it->max.mz, 0, epsilon_);
    unit_assert_equal(it->max.intensity, 0, epsilon_);
    unit_assert_equal(it->peak.mz, 0, epsilon_);
    unit_assert_equal(it->peak.intensity, 0, epsilon_);

    ++it;
    if (os_) *os_ << *it << endl;
    unit_assert(it->sumIntensity == 5);
    unit_assert_equal(it->max.mz, 3.1, epsilon_);
    unit_assert_equal(it->max.intensity, 2, epsilon_);
    unit_assert_equal(it->peak.mz, 3.1, epsilon_);
    unit_assert_equal(it->peak.intensity, 2, epsilon_);

    ++it;
    if (os_) *os_ << *it << endl;
    unit_assert(it->sumIntensity == 6); // with omitted sample intensity 4
    unit_assert_equal(it->max.mz, 1.9, epsilon_);
    unit_assert_equal(it->max.intensity, 3, epsilon_);
    unit_assert_equal(it->peak.mz, 2.9, epsilon_); // found the peak by interpolation
    unit_assert_equal(it->peak.intensity, 4, epsilon_);

    ++it;
    if (os_) *os_ << *it << endl;
    unit_assert(it->sumIntensity == 5);
    unit_assert_equal(it->max.mz, 3.1, epsilon_);
    unit_assert_equal(it->max.intensity, 2, epsilon_);
    unit_assert_equal(it->peak.mz, 3.1, epsilon_);
    unit_assert_equal(it->peak.intensity, 2, epsilon_);

    ++it;
    if (os_) *os_ << *it << endl;
    unit_assert(it->sumIntensity == 0);
    unit_assert_equal(it->max.mz, 0, epsilon_);
    unit_assert_equal(it->max.intensity, 0, epsilon_);
    unit_assert_equal(it->peak.mz, 0, epsilon_);
    unit_assert_equal(it->peak.intensity, 0, epsilon_);

    // Stats

    const RegionAnalyzer::Stats& stats = regionAnalyzer->stats();
    if (os_) *os_ << stats << endl; 
    unit_assert(stats.nonzeroCount == 3);
    unit_assert_equal(stats.sum_sumIntensity, 16, epsilon_);
    unit_assert_equal(stats.sum_peak_intensity, 8, epsilon_);
    unit_assert_equal(stats.mean_peak_mz, 3, epsilon_);
    unit_assert_equal(stats.variance_peak_mz, .01, epsilon_);
    unit_assert_equal(stats.sd_peak_mz, .1, epsilon_);
    unit_assert(stats.indexApex == 2);
}