From 82d52a729d15588c7f75f2ae46b1d8e742461f2e Mon Sep 17 00:00:00 2001
From: Thomas Renne <thomas.renne@u-psud.fr>
Date: Thu, 19 Nov 2020 16:21:37 +0100
Subject: [PATCH] Add chargeDeconvolutionfilter test and correct the filter

---
 .../filters/filterchargedeconvolution.cpp     |  7 +-
 test/test_trace_filters.cpp                   | 66 +++++++++++++++++++
 2 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/src/pappsomspp/processing/filters/filterchargedeconvolution.cpp b/src/pappsomspp/processing/filters/filterchargedeconvolution.cpp
index cc5fa76b9..06029816c 100644
--- a/src/pappsomspp/processing/filters/filterchargedeconvolution.cpp
+++ b/src/pappsomspp/processing/filters/filterchargedeconvolution.cpp
@@ -277,16 +277,19 @@ pappso::FilterChargeDeconvolution::computeIsotopeDeconvolution(
 
           if(data_point_info->z_charge == 1)
             {
+
               for(DataPointInfoSp data : data_point_info->z1_vect)
                 {
-                  deconvoluted_point->data_point.y += data->data_point.y;
+                  deconvoluted_point->new_mono_charge_data_point.y +=
+                    data->data_point.y;
                 }
             }
           else if(data_point_info->z_charge == 2)
             {
               for(DataPointInfoSp data : data_point_info->z2_vect)
                 {
-                  deconvoluted_point->data_point.y += data->data_point.y;
+                  deconvoluted_point->new_mono_charge_data_point.y +=
+                    data->data_point.y;
                 }
             }
           else // if z.charge == 0
diff --git a/test/test_trace_filters.cpp b/test/test_trace_filters.cpp
index 6aaeaad96..b60537509 100644
--- a/test/test_trace_filters.cpp
+++ b/test/test_trace_filters.cpp
@@ -39,9 +39,11 @@
 #include <pappsomspp/processing/filters/filtercomplementionenhancer.h>
 #include <pappsomspp/psm/xtandem/xtandemhyperscore.h>
 #include <pappsomspp/processing/filters/filtersuitestring.h>
+#include <pappsomspp/processing/filters/filterchargedeconvolution.h>
 #include "common.h"
 #include "config.h"
 
+
 using namespace pappso;
 using namespace std;
 
@@ -421,5 +423,69 @@ main()
        << "filter_suite_str = "
        << filter_suite_str.get()->toString().toStdString() << endl;
 
+  cout << endl
+       << "..:: FilterChargeDeconvolution from FilterSuiteString ::.." << endl;
+
+  std::shared_ptr<pappso::FilterChargeDeconvolution>
+    filter_charge_deconvolution =
+      std::make_shared<pappso::FilterChargeDeconvolution>(
+        filter_suite_str.get()->toString());
+
+  Trace loaded_trace({// First peak z = 2
+                      DataPoint(10, 20),
+                      DataPoint(10.5, 18),
+                      DataPoint(11, 16),
+                      // Not a real peak
+                      DataPoint(15, 50),
+                      DataPoint(16, 51),
+                      // Second peak z = 1
+                      DataPoint(24, 200),
+                      DataPoint(25, 20),
+                      // Third peak z = 2
+                      DataPoint(31, 20),
+                      DataPoint(31.5, 15)});
+    Trace theorical_trace({// Not modified peaks
+                         DataPoint(15, 50),
+                         DataPoint(16, 51),
+                         // First peak merged
+                         DataPoint(20-MHPLUS, 54),
+                         // Second
+                         DataPoint(24, 220),
+                         // Third
+                         DataPoint(62-MHPLUS, 35)});
+  cout << "Transform Trace data" << endl;
+  filter_charge_deconvolution->filter(loaded_trace);
+  
+
+  if(loaded_trace != theorical_trace)
+    {
+      cerr << "transformed Trace are different from theorical trace :" << endl;
+
+      if(loaded_trace.xValues().size() == theorical_trace.xValues().size())
+        {
+          cerr << "transformed trace: \t";
+          for(std::size_t i = 0; i < loaded_trace.xValues().size(); i++)
+            {
+              cerr << "(" << loaded_trace.xValues()[i] << ", "
+                   << loaded_trace.yValues()[i] << ") ";
+            }
+          cerr << endl;
+          cerr << "theorical trace : \t";
+          for(std::size_t i = 0; i < theorical_trace.xValues().size(); i++)
+            {
+              cerr << "(" << theorical_trace.xValues()[i] << ", "
+                   << theorical_trace.yValues()[i] << ") ";
+            }
+          cerr << endl;
+        }
+      else
+        {
+          cerr << "Number of peaks is different : "
+               << loaded_trace.xValues().size() << " vs "
+               << theorical_trace.xValues().size();
+        }
+      return 1;
+    }
+
   return 0;
 }
-- 
GitLab