Esempio n. 1
0
void
MSCalibrateForm::setContents( const adcontrols::MSCalibrateMethod& m )
{
    ui_locator accessor( ui );

    boost::get< QSpinBox *>( accessor( ePolynomialDegree ) )->setValue( m.polynomialDegree() );
    boost::get< QDoubleSpinBox *>( accessor( eMassTolerance ) )->setValue(m.massToleranceDa() );
    boost::get< QDoubleSpinBox *>( accessor( eMinimumRA ) )->setValue( m.minimumRAPercent() );
    boost::get< QDoubleSpinBox *>( accessor( eLowMass ) )->setValue( m.lowMass() );
    boost::get< QDoubleSpinBox *>( accessor( eHighMass ) )->setValue( m.highMass() );
}
Esempio n. 2
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;
}
Esempio n. 3
0
void
MSCalibrationForm::getCalibrateMethod( adcontrols::MSCalibrateMethod& method ) const
{
    QStandardItemModel& model = *pModel_;

    method.polynomialDegree( ui->spinPolynomials->value() );
    method.massToleranceDa( ui->spinMassTolerance->value() );
    method.minimumRAPercent( ui->spinMinimumRA->value() );
    method.lowMass( ui->spinLowMass->value() );
    method.highMass( ui->spinHighMass->value() );

    adcontrols::MSReferences references;
    
    int nRows = model.rowCount();

    for ( int row = 0; row < nRows; ++row ) {
        adcontrols::MSReference reference;

		reference.charge_count( model.index( row, c_charge ).data( Qt::EditRole ).toInt() );
		// parse formula that contains adduct or lose followed by '+' or '-' sign
        std::wstring text = model.index( row, c_formula ).data( Qt::EditRole ).toString().toStdWString();
        if ( ! parse_formula( text, reference ) )
            continue;
		reference.exact_mass( model.index( row, c_exact_mass ).data( Qt::EditRole ).toDouble() );
		reference.description( model.index( row, c_description ).data( Qt::EditRole ).toString().toStdWString().c_str() );

        QVariant enable  = model.index( row, c_enable ).data( Qt::EditRole );
        reference.enable( enable.toBool() );

        references << reference;
    }
    method.references( references );
}
Esempio n. 4
0
void
MSReferenceTable::getContents( adcontrols::MSCalibrateMethod& m )
{
    QStandardItemModel& model = *model_;    

    m.references().clear();

    int nRows = model.rowCount();
    for ( int row = 0; row < nRows; ++row ) {

        std::pair< std::wstring, std::wstring > adducts;
        std::wstring value = model.data( model.index( row, c_formula ), Qt::EditRole ).toString().toStdWString();
        std::wstring formula = adcontrols::ChemicalFormula::splitFormula( adducts, value, false );
        std::wstring adduct_string = adcontrols::ChemicalFormula::make_adduct_string( adducts );

        double exactMass = model.data( model.index( row, c_exact_mass ), Qt::EditRole ).toDouble();
        bool enable = model.data( model.index( row, c_enable ), Qt::CheckStateRole ).toBool();
        int charge = model.data( model.index( row, c_charge ) ).toInt();
        std::wstring description = model.data( model.index( row, c_description ) ).toString().toStdWString();

        m.references() << adcontrols::MSReference( formula.c_str(), true, adduct_string.c_str(), enable, exactMass, charge, description.c_str() );
    }    
}
Esempio n. 5
0
void
MSReferenceTable::setContents( const adcontrols::MSCalibrateMethod& m )
{
    QStandardItemModel& model = *model_;

    const adcontrols::MSReferences& references = m.references();
    int nRows = static_cast<int>( references.size() );
    if ( nRows < model.rowCount() )
        model.removeRows( 0, model.rowCount() ); // make sure all clear

    model.setRowCount( nRows + 1 ); // be sure last empty line
    int row = 0;
    for ( auto& ref: references )
        addReference( ref, row++ );

    resizeColumnsToContents();
    resizeRowsToContents();
}
Esempio n. 6
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;
}
Esempio n. 7
0
void
MSCalibrationForm::setCalibrateMethod( const adcontrols::MSCalibrateMethod& method )
{
    QStandardItemModel& model = *pModel_;

    ui->spinPolynomials->setValue( method.polynomialDegree() );
    ui->spinMassTolerance->setValue( method.massToleranceDa() );
    ui->spinMinimumRA->setValue( method.minimumRAPercent() );
    ui->spinLowMass->setValue( method.lowMass() );
    ui->spinHighMass->setValue( method.highMass() );

    const adcontrols::MSReferences& references = method.references();
    int nRows = static_cast<int>( references.size() );
    if ( nRows < model.rowCount() )
        model.removeRows( 0, model.rowCount() ); // make sure all clear

    model.setRowCount( nRows + 1 ); // be sure last empty line

    int row = 0;
    for ( auto& ref: references ) {
		std::wstring formula = ref.display_formula();
        
		model.setData( model.index( row, c_formula ),     qtwrapper::qstring::copy( formula ) );
		model.setData( model.index( row, c_exact_mass ),  ref.exact_mass() );
		model.setData( model.index( row, c_enable ),      ref.enable() );

        QStandardItem * chk = model.itemFromIndex( model.index( row, c_enable ) );
        if ( chk ) {
            chk->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
            chk->setEditable( true );
            model.setData( model.index( row, c_enable ),  ref.enable() ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole );
        }
		model.setData( model.index( row, c_description ), qtwrapper::qstring::copy( ref.description() ) );
		model.setData( model.index( row, c_charge ), ref.charge_count() );

        ++row;
    }
}