示例#1
0
bool
MappedSpectrum::transform( adcontrols::MassSpectrum& ms ) const
{
    auto& prop = ms.getMSProperty();

    int32_t nDelay = int32_t( ( delay_ / sampInterval_ ) + 0.5 );
    auto si = SamplingInfo( sampInterval_, delay_, nDelay, nSamples_, num_average_, 0 /* mode */ );
    si.fSampInterval( sampInterval_ );
    prop.setSamplingInfo( si );
    prop.setNumAverage( num_average_ );
    prop.setTrigNumber( trig_number_, trig_number_origin_ );
    prop.setTimeSinceEpoch( timeSinceEpoch_.second );

    ms.resize( data_.size() );
    ms.setCentroid( adcontrols::CentroidNative );
    //auto scanlaw = prop.scanLaw();
    
    for ( size_t idx = 0; idx < data_.size(); ++idx ) {
        double tof = this->time( idx );
        ms.setTime( idx, tof );
        //if ( scanlaw )
        //    ms.setMass( idx, ms.compute_mass( data_[ idx ].first ) ); 
        ms.setIntensity( idx, data_[ idx ].second );
    }
    return true;
}
示例#2
0
bool
DataprocHandler::doCentroid( adcontrols::MSPeakInfo& pkInfo
                             , adcontrols::MassSpectrum& res
                             , const adcontrols::MassSpectrum& profile
                             , const adcontrols::CentroidMethod& m )
{
    adcontrols::CentroidProcess peak_detector;
    bool result = false;
    
    res.clone( profile, false );

    if ( peak_detector( m, profile ) ) {
        result = peak_detector.getCentroidSpectrum( res );
        pkInfo = peak_detector.getPeakInfo();
    }

    if ( profile.numSegments() > 0 ) {
        for ( size_t fcn = 0; fcn < profile.numSegments(); ++fcn ) {
            adcontrols::MassSpectrum centroid;
            result |= peak_detector( profile.getSegment( fcn ) );
            pkInfo.addSegment( peak_detector.getPeakInfo() );
            peak_detector.getCentroidSpectrum( centroid );
            res.addSegment( centroid );
        }
    }
    return result;
}
示例#3
0
bool
QuanSampleProcessor::doCentroid( adcontrols::MSPeakInfo& pkInfo
                                 , adcontrols::MassSpectrum& res
                                 , const adcontrols::MassSpectrum& profile
                                 , const adcontrols::CentroidMethod& m )
{
    adcontrols::CentroidProcess peak_detector;
    bool result = false;
    
    res.clone( profile, false );
    
    if ( peak_detector( m, profile ) ) {
        result = peak_detector.getCentroidSpectrum( res );
        pkInfo = peak_detector.getPeakInfo();
    }
    
    if ( profile.numSegments() > 0 ) {
        for ( size_t fcn = 0; fcn < profile.numSegments(); ++fcn ) {
            auto centroid = std::make_shared< adcontrols::MassSpectrum >();
            result |= peak_detector( profile.getSegment( fcn ) );
            pkInfo.addSegment( peak_detector.getPeakInfo() );
            peak_detector.getCentroidSpectrum( *centroid );
            res << std::move( centroid ); 
        }
    }
    return result;
}
示例#4
0
bool
MSChromatogramExtractor::impl::doCentroid(adcontrols::MassSpectrum& centroid
                                          , const adcontrols::MassSpectrum& profile
                                          , const adcontrols::CentroidMethod& m )
{
    adcontrols::CentroidProcess peak_detector;
    bool result = false;
    
    centroid.clone( profile, false );
    
    if ( peak_detector( m, profile ) ) {
        result = peak_detector.getCentroidSpectrum( centroid );
        // pkInfo = peak_detector.getPeakInfo();
    }
    
    if ( profile.numSegments() > 0 ) {
        for ( size_t fcn = 0; fcn < profile.numSegments(); ++fcn ) {
            auto temp = std::make_shared< adcontrols::MassSpectrum >();
            result |= peak_detector( profile.getSegment( fcn ) );
            // pkInfo.addSegment( peak_detector.getPeakInfo() );
            peak_detector.getCentroidSpectrum( *temp );
            centroid <<  std::move( temp );
        }
    }
    return result;
}
示例#5
0
        void operator () ( const adcontrols::MassSpectrum& data
                           , adportable::counting::counting_result& result
                           , std::vector< double >& processed ) {

            assert ( method.algo_ == adcontrols::threshold_method::Differential );
            assert ( findPositive == ( method.slope == adcontrols::threshold_method::CrossUp ) );

            double level = method.threshold_level;

            adportable::counting::peak_finder< findPositive > finder;

            finder( data.getIntensityArray(), data.getIntensityArray() + data.size(), result.indices2(), level );
        }
示例#6
0
bool
TimeDigitalHistogram::translate( adcontrols::MassSpectrum& sp
                                 , const TimeDigitalHistogram& hgrm )
{
    sp.setCentroid( adcontrols::CentroidNative );

    using namespace adcontrols::metric;

    // ext_trig_delay should be managed before came here.  (ex. histogram::move())

    double ext_trig_delay = hgrm.this_protocol_.delay_pulses().at( adcontrols::TofProtocol::EXT_ADC_TRIG ).first;
    
    adcontrols::MSProperty prop;
    adcontrols::SamplingInfo info( hgrm.xIncrement()
                                   , hgrm.initialXOffset() + ext_trig_delay
                                   , int32_t( ( hgrm.initialXOffset() + ext_trig_delay ) / hgrm.xIncrement() )  // delay
                                   , uint32_t( hgrm.actualPoints() ) // this is for acq. time range calculation
                                   , uint32_t( hgrm.trigger_count() )
                                   , hgrm.this_protocol_.mode() /* mode */);
    
    prop.setAcceleratorVoltage( 0 ); // empty

    prop.setSamplingInfo( info );
        
    prop.setTimeSinceInjection( hgrm.initialXTimeSeconds() );
    prop.setTimeSinceEpoch( hgrm.timeSinceEpoch().first );
    prop.setNumAverage( uint32_t( hgrm.trigger_count() ) );
    prop.setTrigNumber( uint32_t( hgrm.serialnumber().first ) );

    prop.setDataInterpreterClsid( "adcontrols::TimeDigitalHistogram" );

    TimeDigitalHistogram::device_data data( hgrm.this_protocol_ );
    std::string ar;
    adportable::binary::serialize<>()( data, ar );
    prop.setDeviceData( ar.data(), ar.size() );
        
    sp.setMSProperty( prop );

    size_t size = hgrm.size();

    sp.resize( size );
    size_t idx = 0;
    for ( auto it = hgrm.begin(); it != hgrm.end(); ++it, ++idx ) {
        sp.setTime( idx, it->first );
        sp.setIntensity( idx, it->second );
    }
    
    return true;
}
示例#7
0
bool
rawdata::getSpectrum( int fcn, size_t pos, adcontrols::MassSpectrum& ms, uint32_t objid ) const
{
    auto it = std::find_if( conf_.begin(), conf_.end(), [=]( const adutils::AcquiredConf::data& c ){
            if ( objid == 0 )
                return c.trace_method == signalobserver::eTRACE_SPECTRA && c.trace_id == L"MS.PROFILE";
            else
                return c.objid == objid;
        });
    if ( it == conf_.end() )
        return false;

    adcontrols::translate_state state;
    uint64_t npos = npos0_ + pos;

    if ( fcn < 0 && fcnIdx_.size() > 1 ) {

        // find 'index' from <pos, fcn> array that indicates first 'pos' after protocol has been switched
        auto index = std::lower_bound( fcnIdx_.begin(), fcnIdx_.end(), npos
                                       , [] ( const std::pair< size_t, int >& a, size_t npos ) { return a.first < npos; } );
        if ( index == fcnIdx_.end() )
            return false;
        while ( index != fcnIdx_.begin() && index->first > npos )
            --index;
        int rep = int( npos - index->first );  // id within a replicates (rep'licates is the offset from (fcn=0,rep=0) spectrum)
        while ( index != fcnIdx_.begin() && index->second != 0 ) // find fcn=0
            --index;

        // read all protocols
        while ( ( state = fetchSpectrum( it->objid, it->dataInterpreterClsid, index->first + rep, ms, it->trace_id ) )
                == adcontrols::translate_indeterminate )
                if ( ++index == fcnIdx_.end() )  // move forward to next protocol (rep'licates is the offset for actual spectrum)
                    break;
    } else {

        state = fetchSpectrum( it->objid, it->dataInterpreterClsid, npos, ms, it->trace_id );

    }

    if ( ms.getMSProperty().dataInterpreterClsid() == 0 ) {
        // workaround for batchproc::import
        adcontrols::MSProperty prop = ms.getMSProperty();
        prop.setDataInterpreterClsid( adportable::utf::to_utf8( it->dataInterpreterClsid ).c_str() );
    }
    if ( fcn < 0 )
        return state == adcontrols::translate_complete;

    return state == adcontrols::translate_complete || state == adcontrols::translate_indeterminate;
}
示例#8
0
bool
DataprocHandler::doMSCalibration( adcontrols::MSCalibrateResult& res
                                  , adcontrols::MassSpectrum& centroid
                                  , const adcontrols::MSCalibrateMethod& m
                                  , const adcontrols::MSAssignedMasses& assigned )
{
    using adcontrols::MSProperty;

    const double tolerance = m.massToleranceDa();
    const double threshold = centroid.getMaxIntensity() * m.minimumRAPercent() / 100;
    res.tolerance( tolerance );  // set tolerance in result
    res.threshold( threshold );  // set threshold in result

    std::map< size_t, size_t > mode_map;
    for ( adcontrols::MSAssignedMasses::vector_type::const_iterator it = assigned.begin(); it != assigned.end(); ++it ) 
        mode_map[ it->mode() ]++;
    // std::map<size_t, size_t>::iterator itMax = std::max_element( mode_map.begin(), mode_map.end() );
    // int mode = static_cast<int>(itMax->first);

    mass_calibrator calibrator( assigned, centroid.getMSProperty() );
    adcontrols::MSCalibration calib;
    if ( ! calibrator.polfit( calib, m.polynomialDegree() + 1 ) )
        return false;

    res.references( m.references() );
    res.calibration( calib );
    centroid.setCalibration( calib, true ); // m/z assign based on manually determined peaks

    // continue auto-assign
    assign_masses assign( tolerance, threshold );
    adcontrols::MSAssignedMasses assignedMasses;
	adcontrols::segment_wrapper< adcontrols::MassSpectrum > segments( centroid );
	for ( size_t n = 0; n < segments.size(); ++n ) {
		assign( assignedMasses, segments[n], m.references(), 0, static_cast<int>(n) );
	}

    mass_calibrator calibrator2( assignedMasses, centroid.getMSProperty() );
    if ( calibrator2.polfit( calib, m.polynomialDegree() + 1 ) ) {
        for ( auto it: assignedMasses )
            it.mass( calibrator2.compute_mass( it.time(), it.mode(), calib ) );

        centroid.setCalibration( calib, true );
        res.calibration( calib );
        res.assignedMasses( assignedMasses );

        return true;
    }
    return false;
}
示例#9
0
bool
DataprocHandler::doMSCalibration( adcontrols::MSCalibrateResult& res
                                 , adcontrols::MassSpectrum& centroid
                                 , const adcontrols::MSCalibrateMethod& m )
{
    using adcontrols::MSProperty;

    res.calibration( centroid.calibration() );
    res.references( m.references() );
    double tolerance = m.massToleranceDa();
    double threshold = adcontrols::segments_helper::max_intensity( centroid ) * m.minimumRAPercent() / 100;
    res.tolerance( tolerance );
    res.threshold( threshold );

    assign_masses assigner( tolerance, threshold );

    adcontrols::MSAssignedMasses assignedMasses;
    
	adcontrols::segment_wrapper< adcontrols::MassSpectrum > segments( centroid );
    int n = 0;
	for ( auto seg: segments )
		assigner( assignedMasses, seg, res.references(), seg.mode(), n++ );

	res.assignedMasses( assignedMasses ); // set peak assign result

    // annotate each peak on spectrum
    doAnnotateAssignedPeaks( centroid, assignedMasses );

    mass_calibrator calibrator( assignedMasses, centroid.getMSProperty() );

    adcontrols::MSCalibration calib;
    if ( calibrator.polfit( calib, m.polynomialDegree() + 1 ) ) {
        for ( auto it: assignedMasses ) {
            double mass = calibrator.compute_mass( it.time(), it.mode(), calib );
            it.mass( mass );
        }
        res.calibration( calib );
        // res.assignedMasses( assignedMasses );
#if defined _DEBUG && 0
        calibresult_validation( res, centroid, threshold );
#endif
        return true;
    }
    return false;
}
示例#10
0
bool
TimeDigitalHistogram::translate( adcontrols::MassSpectrum& sp
                                 , const TimeDigitalHistogram& hgrm
                                 , mass_assignor_t mass_assignee )
{
    if ( translate( sp, hgrm ) ) {
        const adcontrols::MSProperty& prop = sp.getMSProperty();
        const auto& sinfo = prop.samplingInfo();
        
        double lMass = mass_assignee( sinfo.fSampDelay(), prop.mode() );
        double hMass = mass_assignee( sinfo.fSampDelay() + sinfo.fSampInterval() * sinfo.nSamples(), prop.mode() );
        
        sp.setAcquisitionMassRange( lMass, hMass );

        return sp.assign_masses( mass_assignee );
    }
    return false;
}
示例#11
0
//virtual
bool
datafile::getSpectrum( int /* fcn*/, size_t idx, adcontrols::MassSpectrum& ms, uint32_t /* objid */) const
{
    if ( unsigned( idx ) < spcfile_->number_of_subfiles() ) {

        const galactic::spchdr& hdr = *spcfile_->spchdr();
        const galactic::subhdr& sub = *spcfile_->subhdr( idx );

        std::pair< double, double > range = std::make_pair( hdr.ffirst(), hdr.flast() );
        const size_t npts = hdr.fnpts();
        ms.resize( npts );
        ms.setAcquisitionMassRange( range.first, range.second );
        
        for ( size_t i = 0; i < npts; ++i ) {
            ms.setMass( int(i), i * double(( range.second - range.first )) / ( npts - 1 ) + range.first );
            ms.setIntensity( int(i), sub[i] );
        }
        return true;
    }
	return false;
}
示例#12
0
static void
calibresult_validation( const adcontrols::MSCalibrateResult& res
                        , const adcontrols::MassSpectrum& centroid
                        , double threshold )
{
    const adcontrols::MSReferences& ref = res.references();
    const adcontrols::MSAssignedMasses& assigned = res.assignedMasses();
    
    std::ofstream of( "massassign.txt" );
    of << "#\tm/z(observed)\ttof(us)\tintensity\t\tformula,\tm/z(exact)\tm/z(calibrated)\terror(mDa)" << std::endl;
    
    adcontrols::MSReferences::vector_type::const_iterator refIt = ref.begin();
    for ( adcontrols::MSAssignedMasses::vector_type::const_iterator it = assigned.begin(); it != assigned.end(); ++it, ++refIt ) {
        const adcontrols::MSAssignedMass& a = *it;
        
        std::string formula = adportable::string::convert( a.formula() );
        of << std::setprecision(8)
           << std::setw(4) << a.idMassSpectrum() << "\t" // id
           << std::setw(15) << std::fixed << centroid.getMass( a.idMassSpectrum() ) << "\t"           // m/z(observed)
           << std::scientific << centroid.getTime( a.idMassSpectrum() ) << "\t"      // tof
           << std::fixed << std::setprecision( 0 ) << centroid.getIntensity( a.idMassSpectrum() ) << "\t" // intensity
           << formula << "\t"
           << std::setprecision(8) << std::fixed   << it->exactMass() << "\t"                             // mass(exact)
           << std::fixed   << a.mass() << "\t"                                    // m/z(calibrated)
           << std::setprecision(1) << ( a.mass() - it->exactMass() ) * 1000 << "\t"  // error(mDa)
           << ( it->enable() ? "used" : "not used" ) 
           << std::endl;
    }
    const std::vector<double>& coeffs = res.calibration().coeffs();
    
    of << "#--------------------------- Calibration coefficients: " << std::endl;
    for ( size_t i = 0; i < coeffs.size(); ++i )
        of << std::scientific << std::setprecision(14) << coeffs[i] << std::endl;
    
    of << "#--------------------------- centroid peak list (#,mass,intensity)--------------------------" << std::endl;
    
    adcontrols::MSReferences::vector_type::const_iterator it = res.references().begin();
    for ( size_t i = 0; i < centroid.size(); ++i ) {
        if ( centroid.getIntensity( i ) > threshold ) {
            
            double mq = adcontrols::MSCalibration::compute( res.calibration().coeffs(), centroid.getTime( i ) );
            double mass = mq * mq;
            
            double error = 0;
            if ( it != res.references().end() && std::abs( it->exactMass() - mass ) < 0.2 ) {
                error = ( it->exactMass() - mass ) * 1000; // mDa
                ++it;
            }
            of << i << "\t"
               << std::setprecision(8) << std::fixed << centroid.getMass( i ) << "\t"
               << std::setprecision(8) << mass << "\t"
                    << std::setprecision(1) << centroid.getIntensityArray()[i] << std::endl;
        }
    }
}
示例#13
0
//virtual
bool
datafile::getSpectrum( int /* fcn*/, size_t idx, adcontrols::MassSpectrum& ms, uint32_t /* objid */) const
{
    if ( lrpfile_ && unsigned( idx ) < lrpfile_->number_of_spectra() ) {

        if ( auto msdata = (*lrpfile_)[ idx ] ) {

            std::vector< double > time, intens;
            if ( lrpfile_->getMS( *msdata, time, intens ) ) {

                ms.resize( time.size() );
                ms.setMassArray( time.data() );
                ms.setIntensityArray( intens.data() );

                ms.setAcquisitionMassRange( time.front(), time.back() );

                return true;
            }
        }
    }
    return false;
}
示例#14
0
bool
MSChromatogramExtractor::impl::doMSLock( adcontrols::lockmass::mslock& mslock
                                       , const adcontrols::MassSpectrum& centroid
                                       , const adcontrols::MSLockMethod& m )
{
    // TODO: consider how to handle segmented spectrum -- current impl is always process first 
    adcontrols::MSFinder find( m.tolerance( m.toleranceMethod() ), m.algorithm(), m.toleranceMethod() );

    for ( auto& msref : msrefs_ ) {
        size_t idx = find( centroid, msref.second );
        if ( idx != adcontrols::MSFinder::npos ) 
            mslock << adcontrols::lockmass::reference( msref.first, msref.second, centroid.getMass( idx ), centroid.getTime( idx ) );
    }

    if ( mslock.fit() ) {
        // mslock( centroid, true );
        return true;
    }
    return false;
}
示例#15
0
bool
fsio::save_mscalibfile( adfs::filesystem& fs, const adcontrols::MassSpectrum& ms )
{
    return save( fs, ms, ms.dataClass(), L"/MSCalibration" );
}
示例#16
0
bool
QuanSampleProcessor::doMSLock( adcontrols::MSPeakInfo& pkInfo // will override
                               , adcontrols::MassSpectrum& centroid // will override
                               , const adcontrols::MSLockMethod& m
                               , const adcontrols::QuanCompounds& compounds )
{
    // find reference peak by mass window
    adcontrols::lockmass::mslock mslock;

    // TODO: consider how to handle segmented spectrum -- current impl is always process first 
    adcontrols::MSFinder find( m.tolerance( m.toleranceMethod() ), m.algorithm(), m.toleranceMethod() );

    for ( auto& compound : compounds ) {
        if ( compound.isLKMSRef() ) {
            double exactMass = cformula_->getMonoIsotopicMass( compound.formula() );
            size_t idx = find( centroid, exactMass );
            if ( idx != adcontrols::MSFinder::npos ) {
                // add found peaks into mslock
                mslock << adcontrols::lockmass::reference( compound.formula(), exactMass, centroid.getMass( idx ), centroid.getTime( idx ) );
            }
        }
    }

    if ( mslock.fit() ) {
        mslock( centroid, true );
        mslock( pkInfo, true );
        return true;
    }
    return false;
}
示例#17
0
void
MSPropertyForm::render( std::ostream& o, const adcontrols::MassSpectrum& ms )
{
    using adportable::utf;
    using namespace adcontrols::metric;

    static const char * const polarities [] = { "Indeterminant", "Positive", "Negative", "Mixed" };

    adcontrols::segment_wrapper< const adcontrols::MassSpectrum > segments( ms );

    std::vector< std::pair< std::string, std::string > > temp;
    temp.push_back( std::make_pair( "Spectrum", ( ms.isCentroid() ? "Centroid" : "Profile" ) ) );
    temp.push_back( std::make_pair( "Polarity", polarities[ ms.polarity() ] ) );

    o << "<hr>";
    o << "<table border=\"1\" cellpadding=\"1\">";
    o << "<caption>Descriptions</caption>";
    o << "<tr>";
    o << "<th>key</th>"
      << "<th>description</th>"
      << "</tr>";
    for ( auto it: temp ) {
        o << "<tr>"
          << "<td>" << it.first << "</td>"
          << "<td>" << it.second << "</td>"
          << "</tr>";
    }
    for ( size_t i = 0; i < ms.getDescriptions().size(); ++i ) {
        auto desc = ms.getDescriptions()[ i ];
        o << "<tr>"
          << "<td>" << utf::to_utf8( desc.key() ) << "</td>"
          << "<td>" << utf::to_utf8( desc.text() ) << "</td>"
          << "</tr>";
    }
    o << "</table>";

    std::pair< double, double > massrange = ms.getAcquisitionMassRange();
    o << "Acquisition mass range: " << boost::format( "%.3lf -- %.3lf" ) % massrange.first % massrange.second;

    o << "<table border=\"1\" cellpadding=\"4\">";
    o << "<caption>Acquisition and calibration parameter(s)</caption>";
    o << "<tr>";
    o << "<th>#seg</th>"
      << "<th>samp. interval(ps)</th>"
      << "<th>sampling start (&mu;s)</th>"
      << "<th>sampling end (&mu;s)</th>"
      << "<th>num. samples</th>"
      << "<th>num. average</th>"
      << "<th>mode</th>"
      << "<th>classid</th>"
      << "</tr>";
    int n = 0;
    for ( auto& m: segments ) {
        const adcontrols::MSCalibration& calib =  m.calibration();
        size_t nrowspan = calib.coeffs().empty() ? 1 : 2;
        const adcontrols::MSProperty& prop = m.getMSProperty();
        const adcontrols::MSProperty::SamplingInfo& info = prop.getSamplingInfo();
        double start_delay = scale_to<double, micro>( info.sampInterval * info.nSamplingDelay, pico );
        double time_end = scale_to<double, micro>( info.sampInterval * ( info.nSamplingDelay + info.nSamples ), pico );
        o << "<tr>"
          << boost::format( "<td rowspan=\"%1%\">" ) % nrowspan << n++ << "</td>"
          << "<td>" << info.sampInterval << "</td>"
          << "<td>" << boost::format( "%.4lf&mu;s" ) % start_delay << "</td>"
          << "<td>" << boost::format( "%.4lf&mu;s" ) % time_end << "</td>"
          << "<td>" << info.nSamples << "</td>"
          << "<td>" << info.nAverage << "</td>"
          << "<td>" << info.mode << "</td>"
		  << "<td>" << prop.dataInterpreterClsid() << "</td>"
          << "</tr>";

        if ( ! calib.coeffs().empty() ) {
            //-----------------------------
            o << "<tr>";
            o << "<td colspan=7><b>Calibration ID:</b><i>" << utf::to_utf8( calib.calibId() ) << "</i>"
              << "     " << calib.date();
            o << "<hr>";
            o << "&radic;<span style=\"text-decoration: overline\">&nbsp;<i>m/z</i></span> = "
              << boost::format( "%.14lf" ) % calib.coeffs()[0] << " + ";
            for ( size_t i = 1; i < calib.coeffs().size(); ++i )
                o << boost::format( "\t%.14lf &times; t<sup>%d</sup>" ) % calib.coeffs()[i] % i;

            if ( ! calib.t0_coeffs().empty() ) {
                o << "<br>"
                  << "T<sub>0</sub> = " << calib.t0_coeffs()[0];
                for ( size_t i = 1; i < calib.t0_coeffs().size(); ++i )
                    o << boost::format( "\t%.14lf &times; &radic;<span style=\"text-decoration: overline\">&nbsp;<i>m/z</i></span><sup>%d</sup>" )
                        % calib.coeffs()[i] % i;
                if ( calib.algorithm() == adcontrols::MSCalibration::MULTITURN_NORMALIZED )
                    o << "\t(MULTITURN_NORMAILZED algorithm)";
            }
            o << "</tr>";
            //-----------------------------            
		}
    }
    o << "</table>";
    o << "<hr>";

    try {
        // device (averager) dependent data (require data interpreter)
        std::vector < std::pair< std::string, std::string > > textv;
        auto& prop = ms.getMSProperty();
        const char * ipClsid = prop.dataInterpreterClsid();
        if ( ipClsid && (std::strlen( ipClsid )) > 0 ) {
            auto& interpreter = prop.spectrometer().getDataInterpreter();
            if ( interpreter.make_device_text( textv, ms.getMSProperty() ) ) {
                o << "<table border=\"1\" cellpadding=\"4\">";
                o << "<caption>Averager/digitizer dependent information</caption>";
                o << "<tr>";
                o << "<th>#seg</th>";
                std::for_each( textv.begin(), textv.end(), [&] ( const std::pair< std::string, std::string>& text ) { o << "<th>" << text.first << "</th>"; } );
                o << "</tr>";
                int seg = 0;
                for ( auto& m : segments ) {
                    if ( interpreter.make_device_text( textv, m.getMSProperty() ) ) {
                        o << "<tr>";
                        o << "<td>" << seg++ << "</td>";
                        std::for_each( textv.begin(), textv.end(), [&] ( const std::pair< std::string, std::string>& text ) { o << "<td>" << text.second << "</td>"; } );
                        o << "</tr>";
                    }
                }
                o << "</table>";
                o << "<hr>";
            }
        }
        else {
            o << "<hr>No dataInterpreterClsid specifid.</hr>";
            ADERROR() << "no dataInterpreterClisidSpecified.";
        }
    }
    catch ( boost::exception& ex ) {
        o << "<hr>data exception: " << boost::diagnostic_information( ex ) << "</hr>";
        ADERROR() << boost::diagnostic_information( ex );
    }
    catch ( ... ) {
        o << "<hr>data exception: " << boost::current_exception_diagnostic_information() << "</hr>";
        ADERROR() << boost::current_exception_diagnostic_information();
    }
}
示例#18
0
adcontrols::translate_state
DataInterpreter::translate_profile( adcontrols::MassSpectrum& ms
                                    , const char * data, size_t dsize
                                    , const char * meta, size_t msize
                                    , const adcontrols::MassSpectrometer& spectrometer
                                    , size_t idData ) const
{
	(void)idData;
    adportable::debug(__FILE__, __LINE__) << "translate_profile( dsize=" << dsize << ", msize=" << msize << ")";
    import_profile profile;
    import_continuum_massarray ma;
    
    const batchproc::MassSpectrometer* pSpectrometer = dynamic_cast< const batchproc::MassSpectrometer * >( &spectrometer );
    if ( pSpectrometer == 0 )
        return adcontrols::translate_error;

    if ( adportable::bzip2::is_a( data, dsize ) ) {

        std::string ar;
        adportable::bzip2::decompress( ar, data, dsize );
        adportable::debug(__FILE__, __LINE__) << "translate_profile deserialize import_profile w/ decompress";
        if ( ! adportable::serializer< import_profile >::deserialize( profile, ar.data(), ar.size() ) )
            return adcontrols::translate_error;

    } else {
        adportable::debug(__FILE__, __LINE__) << "translate_profile deserialize import_profile w/o decompress";
        if ( ! adportable::serializer< import_profile >::deserialize( profile, data, dsize ) ) 
            return adcontrols::translate_error;
    }

    if ( meta && msize ) {
        if ( adportable::bzip2::is_a( meta, msize ) ) {
            std::string ar;
            adportable::bzip2::decompress( ar, meta, msize );
            if ( ! adportable::serializer< import_continuum_massarray >::deserialize( ma, ar.data(), ar.size() ) )
                return adcontrols::translate_error;
        } else {
            if ( ! adportable::serializer< import_continuum_massarray >::deserialize( ma, meta, msize ) )
                return adcontrols::translate_error;
        }
    }

    adportable::debug(__FILE__, __LINE__) << "translate_profile checkpoint 3";
    const import_continuum_massarray& continuum_massarray = meta ? ma : pSpectrometer->continuum_massarray();
    
	ms.setMSProperty( profile.prop_ );
	ms.setPolarity( profile.polarity_ );
    ms.resize( profile.intensities_.size() );

    adportable::debug(__FILE__, __LINE__) << "translate_profile checkpoint 4";
    ms.setMassArray( continuum_massarray.masses_.data() );
    auto intens = profile.intensities_.data();
    for ( size_t i = 0; i < ms.size(); ++i )
        ms.setIntensity( i, *intens++ );

    adportable::debug(__FILE__, __LINE__) << "translate_profile checkpoint 5";
    ms.setAcquisitionMassRange( ms.getMass( 0 ), ms.getMass( ms.size() - 1 ) );

    adportable::debug(__FILE__, __LINE__) << "translate_profile checkpoint 6";

    return adcontrols::translate_complete;
}
示例#19
0
bool
fsio::load_mscalibfile( adfs::filesystem& fs, adcontrols::MassSpectrum& ms )
{
    return load( fs, ms, ms.dataClass(), L"/MSCalibration" );
}
示例#20
0
//virtual
bool
datafile::getSpectrum( int fcn, size_t pos, adcontrols::MassSpectrum& ms, uint32_t objId ) const
{
	(void)fcn;

	try {
		EDAL::IMSSpectrumCollectionPtr pSpectra = pAnalysis_->GetMSSpectrumCollection();
		EDAL::IMSSpectrumPtr pSpectrum = pSpectra->GetItem( long(pos) + 1 ); // 1-origin

		if ( pSpectrum->Polarity == EDAL::SpectrumPolarity::IonPolarity_Negative )
			ms.setPolarity( adcontrols::MS_POLARITY::PolarityNegative );
		else if ( pSpectrum->Polarity == EDAL::SpectrumPolarity::IonPolarity_Positive )
			ms.setPolarity( adcontrols::MS_POLARITY::PolarityPositive );
		else
			ms.setPolarity( adcontrols::MS_POLARITY::PolarityIndeterminate );

		adcontrols::MSProperty prop = ms.getMSProperty();
		prop.setTimeSinceInjection( static_cast< unsigned long >( pSpectrum->RetentionTime /* sec */ * 1.0e6 ) ); // usec
        ms.setMSProperty( prop ); // <- end of prop set

		_variant_t vMasses, vIntens;
        if ( objId <= 1 ) {
			pSpectrum->GetMassIntensityValues( EDAL::SpectrumType_Profile, &vMasses, &vIntens );
			ms.setCentroid( adcontrols::CentroidNone );  // profile
        } else { // objId should be 2
			pSpectrum->GetMassIntensityValues( EDAL::SpectrumType_Line, &vMasses, &vIntens );
			ms.setCentroid( adcontrols::CentroidNative );
		}

		SafeArray sa_masses( vMasses );
        ms.resize( sa_masses.size() );
        ms.setMassArray( reinterpret_cast< const double *>( sa_masses.p() ) );
    
		SafeArray sa_intensities( vIntens );
        ms.setIntensityArray( reinterpret_cast< const double *>( sa_intensities.p() ) );

        ms.setAcquisitionMassRange( ms.getMass( 0 ), ms.getMass( ms.size() - 1 ) );

		return true;
	} catch(_com_error& ex ) {
		ADERROR() << std::wstring( ex.ErrorMessage() );
		return false;
	}
	return false;
}
示例#21
0
adfs::file
QuanSampleProcessor::processIt( adcontrols::QuanSample& sample
                                , adcontrols::MassSpectrum& profile
                                , QuanDataWriter * writer
                                , bool bSerialize )
{
    if ( auto pCentroidMethod = procmethod_->find< adcontrols::CentroidMethod >() ) {

        adcontrols::MassSpectrum centroid;
        adcontrols::MSPeakInfo pkInfo;
        adcontrols::MassSpectrum filtered;

        bool result(false);

        if ( pCentroidMethod->noiseFilterMethod() == adcontrols::CentroidMethod::eDFTLowPassFilter ) {
            filtered.clone( profile, true );
            for ( auto& ms : adcontrols::segment_wrapper<>( filtered ) ) {
                adcontrols::waveform_filter::fft4c::lowpass_filter( ms, pCentroidMethod->cutoffFreqHz() );
                double base( 0 ), rms( 0 );
                const double * intens = ms.getIntensityArray();
                adportable::spectrum_processor::tic( uint32_t( ms.size() ), intens, base, rms );
                for ( size_t i = 0; i < ms.size(); ++i )
                    ms.setIntensity( i, intens[ i ] - base );
            }
            filtered.addDescription( adcontrols::description( L"process", dataproc::Constants::F_DFT_FILTERD ) );

            result = doCentroid( pkInfo, centroid, filtered, *pCentroidMethod );

        } else {
            result = doCentroid( pkInfo, centroid, profile, *pCentroidMethod );
        }

        if ( result ) {

            // doMSLock if required.
            if ( auto pCompounds = procmethod_->find< adcontrols::QuanCompounds >() ) {
                if ( auto lkMethod = procmethod_->find< adcontrols::MSLockMethod >() ) {
                    if ( lkMethod->enabled() )
                        doMSLock( pkInfo, centroid, *lkMethod, *pCompounds );
                }
            }
            
            // Look up compounds
            if ( auto pCompounds = procmethod_->find< adcontrols::QuanCompounds >() ) {
                if ( auto pTgtMethod = procmethod_->find< adcontrols::TargetingMethod >() ) {
                    doMSFind( pkInfo, centroid, sample, *pCompounds, *pTgtMethod );
                }
            }
            
            if ( bSerialize ) {
                adcontrols::MassSpectrum * pProfile = &profile;
                adcontrols::MassSpectrum * pFiltered = (filtered.size() > 0 ) ? &filtered : 0;
                adcontrols::MassSpectrum * pCentroid = &centroid;
                adcontrols::MSPeakInfo * pPkInfo = &pkInfo;
                if ( sample.channel() > 0 ) {
                    if ( auto p = profile.findProtocol( sample.channel() - 1 ) ) {
                        p->clearSegments();
                        pProfile = p;
                    }
                    if ( pFiltered ) {
                        if ( auto p = filtered.findProtocol( sample.channel() - 1 ) ) {
                            p->clearSegments();
                            pFiltered = p;

                        }
                    }
                    if ( auto p = centroid.findProtocol( sample.channel() - 1 ) ) {
                        p->clearSegments();
                        pCentroid = p;
                    }
                    if ( auto p = pkInfo.findProtocol( sample.channel() - 1 ) ) {
                        p->clearSegments();
                        pPkInfo = p;
                    }
                }

                std::lock_guard<std::mutex> lock( mutex_ );

                if ( adfs::file file = writer->write( *pProfile, sample.name() ) ) {

                    for ( auto& resp: sample.results() )
                        resp.dataGuid_ = file.name();
                    
                    if ( pFiltered )
                        writer->attach<adcontrols::MassSpectrum>( file, *pFiltered, dataproc::Constants::F_DFT_FILTERD );
                    
                    auto afile = writer->attach< adcontrols::MassSpectrum >( file, *pCentroid, dataproc::Constants::F_CENTROID_SPECTRUM );
                    
                    writer->attach< adcontrols::ProcessMethod >( afile, *procmethod_, L"ProcessMethod" );
                    writer->attach< adcontrols::MSPeakInfo >( file, *pPkInfo, dataproc::Constants::F_MSPEAK_INFO );
                    writer->attach< adcontrols::QuanSample >( file, sample, dataproc::Constants::F_QUANSAMPLE );
                    return file;
                }
            }
        }
    }
    return adfs::file();
}
示例#22
0
bool
waveform::fft::lowpass_filter( adcontrols::MassSpectrum& ms, double freq )
{
    if ( ms.isCentroid() )
        return false;

    size_t totalSize = ms.size();
	(void)totalSize;
	size_t N = 32;
    while ( N < ms.size() )
		N *= 2;
	const size_t NN = ms.size();
	double sampInterval = ms.getMSProperty().getSamplingInfo().fSampInterval(); // seconds
    if ( sampInterval == 0 )
        sampInterval = ( ms.getTime( ms.size() - 1 ) - ms.getTime( 0 ) ) / ms.size();
    const double T = N * sampInterval;  // time full scale in seconds.  Freq = n/T (Hz)
    // power spectrum has N/2 points and is n/T Hz horizontal axis  := data[N/2] = (N/2)/T Hz
    size_t cutoff = size_t( T * freq );

	adportable::array_wrapper<const double> pIntens( ms.getIntensityArray(), N );

	std::vector< std::complex<double> > spc( N );
	std::vector< std::complex<double> > fft( N );
	size_t n;
	for ( n = 0; n < N && n < NN; ++n )
		spc[ n ] = std::complex<double>( pIntens[ n ] );
	while ( n < N )
		spc[ n++ ] = pIntens[ NN - 1 ];

	adportable::fft::fourier_transform( fft, spc, false );
    // appodization
    for ( size_t i = cutoff; i < N - cutoff; ++i )
        fft[ i ] = 0;
    //adportable::fft::apodization( N/2 - N/16, N / 16, fft );
	adportable::fft::fourier_transform( spc, fft, true );

	std::vector<double> data( N );
	for ( size_t i = 0; i < NN; ++i )
		data[ i ] = spc[i].real();

	ms.setIntensityArray( &data[0] );

	return true;
}
示例#23
0
bool
assign_masses::operator()( adcontrols::MSAssignedMasses& assignedMasses
                           , const adcontrols::MassSpectrum& centroid
                           , const adcontrols::MSReferences& references
                           , int mode
                           , int fcn )
{
    using adportable::array_wrapper;
    using adcontrols::MSReferences;
    
    array_wrapper<const double> masses( centroid.getMassArray(), centroid.size() );
    array_wrapper<const double> intens( centroid.getIntensityArray(), centroid.size() );
    
    for ( MSReferences::vector_type::const_iterator it = references.begin(); it != references.end(); ++it ) {
        
        double exactMass = it->exact_mass();
        array_wrapper<const double>::const_iterator lBound = std::lower_bound( masses.begin(), masses.end(), exactMass - tolerance_ );
        array_wrapper<const double>::const_iterator uBound = std::lower_bound( masses.begin(), masses.end(), exactMass + tolerance_ );
        
        if ( lBound != masses.end() ) {
            
            size_t lIdx = std::distance( masses.begin(), lBound );
            size_t uIdx = std::distance( masses.begin(), uBound );
            
            // find closest
            size_t cIdx = lIdx;
            for ( size_t i = lIdx + 1; i < uIdx; ++i ) {
                double d0 = std::abs( masses[ cIdx ] - exactMass );
                double d1 = std::abs( masses[ i ] - exactMass );
                if ( d1 < d0 )
                    cIdx = i;
            }
            
            // find highest
            array_wrapper<const double>::const_iterator hIt = std::max_element( intens.begin() + lIdx, intens.begin() + uIdx );
            if ( *hIt < threshold_ )
                continue;
            
            size_t idx = std::distance( intens.begin(), hIt );

            adcontrols::MSAssignedMass assigned( uint32_t( std::distance( references.begin(), it ) )
				                                 , fcn
                                                 , uint32_t(idx)            // idMassSpectrum (index on centroid peak)
                                                 , it->display_formula()
                                                 , it->exact_mass()
                                                 , centroid.getTime( idx )
                                                 , masses[ idx ]
                                                 , it->enable()
                                                 , false          // flags
                                                 , mode );
            // duplicate assign check
            adcontrols::MSAssignedMasses::vector_type::iterator assignIt = 
                std::find_if( assignedMasses.begin(), assignedMasses.end(), [&]( const adcontrols::MSAssignedMass& a ){
                        return a.idPeak() == idx && a.idMassSpectrum() == unsigned(fcn);
                    });
            if ( assignIt != assignedMasses.end() ) {
                // already assined to another refernce
                if ( std::fabs( assignIt->exactMass() - assignIt->mass() ) > 
                     std::fabs( assigned.exactMass() - assigned.mass() ) ) {
                    *assignIt = assigned; // replace
                }
            } else 
                assignedMasses << assigned;
        }
    }
    return true;
    
}