Skip to content

Commit

Permalink
Feat/improve calibration curve (#507)
Browse files Browse the repository at this point in the history
* Reversed points and slide

* Created CalibrationData class

* Added details about the calibration

* Added docking layout for Calibrator

* Enable implot zooming

* Using a Table for calibration parameters

* Fixed Reset Layout for Calibrators

* Handler outer points

* Implemented Zoom reset

* Added Margins and displayed points even if the curve is not found

* unit tests

* renamed Outer points to Outlier points

* Fixed SequenceSegmentHandler_test and SequenceSegmentProcessor_test compilation
  • Loading branch information
bertrandboudaud authored Jan 27, 2022
1 parent c82572b commit a06aef4
Show file tree
Hide file tree
Showing 12 changed files with 519 additions and 135 deletions.
10 changes: 4 additions & 6 deletions src/examples/source/SmartPeakGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ int main(int argc, char** argv)
if (ImGui::MenuItem("Reset Window Layout"))
{
split_window.reset_layout_ = true;
calibrators_line_plot_->reset_layout_ = true;
}
ImGui::EndMenu();
}
Expand Down Expand Up @@ -882,12 +883,9 @@ int main(int argc, char** argv)
// calibrators
if (calibrators_line_plot_->visible_)
{
exceeding_plot_points_ = !session_handler_.setCalibratorsScatterLinePlot(application_handler_.sequenceHandler_);
calibrators_line_plot_->setValues(&session_handler_.calibrators_conc_fit_data, &session_handler_.calibrators_feature_fit_data,
&session_handler_.calibrators_conc_raw_data, &session_handler_.calibrators_feature_raw_data, &session_handler_.calibrators_series_names,
session_handler_.calibrators_x_axis_title, session_handler_.calibrators_y_axis_title, session_handler_.calibrators_conc_min, session_handler_.calibrators_conc_max,
session_handler_.calibrators_feature_min, session_handler_.calibrators_feature_max,
"CalibratorsMainWindow");
SessionHandler::CalibrationData calibration_data;
exceeding_plot_points_ = !session_handler_.setCalibratorsScatterLinePlot(application_handler_.sequenceHandler_, calibration_data);
calibrators_line_plot_->setValues(calibration_data, "CalibratorsMainWindow");
}

// ======================================
Expand Down
13 changes: 12 additions & 1 deletion src/smartpeak/include/SmartPeak/core/SequenceSegmentHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,17 @@ namespace SmartPeak
const std::map<std::string, std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration>>&
getComponentsToConcentrations() const;

private:
void setOutlierComponentsToConcentrations(
const std::map<std::string, std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration>> components_to_concentrations
);

std::map<std::string, std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration>>&
getOutlierComponentsToConcentrations();

const std::map<std::string, std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration>>&
getOutlierComponentsToConcentrations() const;

private:
std::string sequence_segment_name_;
std::vector<size_t> sample_indices_; ///< The indices of each injection; this could be replaced with `std::shared_ptr<InjectionHandler>` to save the map lookup
std::vector<OpenMS::AbsoluteQuantitationStandards::runConcentration> standards_concentrations_;
Expand All @@ -126,5 +136,6 @@ namespace SmartPeak
std::shared_ptr<OpenMS::MRMFeatureQC> feature_rsd_estimations_ = nullptr; ///< Percent RSD estimations; shared between all raw data handlers in the sequence segment
std::shared_ptr<OpenMS::MRMFeatureQC> feature_background_estimations_ = nullptr; ///< Background interference estimations; shared between all raw data handlers in the sequence segment
std::map<std::string, std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration>> components_to_concentrations_;
std::map<std::string, std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration>> outlier_components_to_concentrations_;
};
}
30 changes: 22 additions & 8 deletions src/smartpeak/include/SmartPeak/core/SessionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,35 @@ namespace SmartPeak
*/
void getHeatMap(const SequenceHandler& sequence_handler, HeatMapData& result, const std::string& feature_name);

/*
@brief Calibration data structure, result of call to setCalibratorsScatterLinePlot
*/
struct CalibrationData
{
std::vector<std::vector<float>> conc_raw_data;
std::vector<std::vector<float>> feature_raw_data;
std::vector<std::vector<float>> outlier_conc_raw_data;
std::vector<std::vector<float>> outlier_feature_raw_data;
std::vector<std::vector<float>> conc_fit_data;
std::vector<std::vector<float>> feature_fit_data;
std::vector<std::string> series_names;
std::string x_axis_title;
std::string y_axis_title;
float conc_min;
float conc_max;
float feature_min;
float feature_max;
std::vector<OpenMS::AbsoluteQuantitationMethod> quant_methods;
};

/*
@brief Sets the data used for rendering the calibrators
@param[in] sequence_handler
@returns true if all points were added and false if points were omitted due to performance
*/
bool setCalibratorsScatterLinePlot(const SequenceHandler& sequence_handler);
bool setCalibratorsScatterLinePlot(const SequenceHandler& sequence_handler, CalibrationData& result);

Eigen::Tensor<std::string, 1> getInjectionExplorerHeader();
Eigen::Tensor<std::string, 2> getInjectionExplorerBody();
Expand Down Expand Up @@ -403,13 +424,6 @@ namespace SmartPeak
std::string feat_line_y_axis_title;
float feat_line_sample_min, feat_line_sample_max, feat_value_min, feat_value_max;
Eigen::Tensor<std::string, 1> feat_row_labels, feat_col_labels;
// data for the calibrators scatter/line plot
std::vector<std::vector<float>> calibrators_conc_raw_data, calibrators_feature_raw_data;
std::vector<std::vector<float>> calibrators_conc_fit_data, calibrators_feature_fit_data;
std::vector<std::string> calibrators_series_names;
std::string calibrators_x_axis_title;
std::string calibrators_y_axis_title;
float calibrators_conc_min , calibrators_conc_max, calibrators_feature_min, calibrators_feature_max;
private:
int feature_table_unique_samples_transitions_ = 0; // used to decide when to update the feature table data
int feature_matrix_unique_transitions_ = 0; // used to decide when to update the feature matrix data
Expand Down
20 changes: 20 additions & 0 deletions src/smartpeak/source/core/SequenceSegmentHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace SmartPeak
if (feature_rsd_estimations_ != nullptr) feature_rsd_estimations_ = std::make_shared<OpenMS::MRMFeatureQC>(OpenMS::MRMFeatureQC());
if (feature_background_estimations_ != nullptr) feature_background_estimations_ = std::make_shared<OpenMS::MRMFeatureQC>(OpenMS::MRMFeatureQC());
components_to_concentrations_.clear();
outlier_components_to_concentrations_.clear();
}

void SequenceSegmentHandler::setSequenceSegmentName(const std::string& sequence_segment_name)
Expand Down Expand Up @@ -343,4 +344,23 @@ namespace SmartPeak
{
return components_to_concentrations_;
}

void SequenceSegmentHandler::setOutlierComponentsToConcentrations(
const std::map<std::string, std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration>> components_to_concentrations
)
{
outlier_components_to_concentrations_ = components_to_concentrations;
}

std::map<std::string, std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration>>&
SequenceSegmentHandler::getOutlierComponentsToConcentrations()
{
return outlier_components_to_concentrations_;
}

const std::map<std::string, std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration>>&
SequenceSegmentHandler::getOutlierComponentsToConcentrations() const
{
return outlier_components_to_concentrations_;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace SmartPeak

absoluteQuantitation.setQuantMethods(sequenceSegmentHandler_IO.getQuantitationMethods());
std::map<std::string, std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration>> components_to_concentrations;
std::map<std::string, std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration>> outlier_components_to_concentrations;
for (const OpenMS::AbsoluteQuantitationMethod& row : sequenceSegmentHandler_IO.getQuantitationMethods()) {
// map standards to features
OpenMS::AbsoluteQuantitationStandards absoluteQuantitationStandards;
Expand All @@ -107,6 +108,9 @@ namespace SmartPeak
continue;
}

// Keep a copy to compute outer points
auto all_feature_concentrations = feature_concentrations_pruned;

try
{
absoluteQuantitation.optimizeSingleCalibrationCurve(
Expand All @@ -124,13 +128,36 @@ namespace SmartPeak
LOGW << "Warning: '" << row.getComponentName() << "' cannot be analysed.\n";
continue;
}
// find the optimal calibration curve for each component

// Compute outer points
std::vector<OpenMS::AbsoluteQuantitationStandards::featureConcentration> outlier_feature_concentrations;
for (const auto& feature : all_feature_concentrations)
{
bool found = false;
for (const auto& feature_pruned : feature_concentrations_pruned)
{
if ((feature.IS_feature == feature_pruned.IS_feature)
&& (std::abs(feature.actual_concentration - feature_pruned.actual_concentration) < 1e-9)
&& (std::abs(feature.IS_actual_concentration - feature_pruned.IS_actual_concentration) < 1e-9)
&& (std::abs(feature.dilution_factor - feature_pruned.dilution_factor) < 1e-9))
{
found = true;
break;
}
}
if (!found)
{
outlier_feature_concentrations.push_back(feature);
}
}
components_to_concentrations.erase(row.getComponentName());
components_to_concentrations.insert({row.getComponentName(), feature_concentrations_pruned});
components_to_concentrations.insert({row.getComponentName(), feature_concentrations_pruned });
outlier_components_to_concentrations.erase(row.getComponentName());
outlier_components_to_concentrations.insert({ row.getComponentName(), outlier_feature_concentrations });
}
// store results
sequenceSegmentHandler_IO.setComponentsToConcentrations(components_to_concentrations);
sequenceSegmentHandler_IO.setOutlierComponentsToConcentrations(outlier_components_to_concentrations);
sequenceSegmentHandler_IO.getQuantitationMethods() = absoluteQuantitation.getQuantMethods();
//sequenceSegmentHandler_IO.setQuantitationMethods(absoluteQuantitation.getQuantMethods());
LOGD << "END optimizeCalibrationCurves";
Expand Down
Loading

0 comments on commit a06aef4

Please sign in to comment.