DIAlign
CppInterface.hpp
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <fstream>
4 #include <sstream>
5 #include <stdio.h>
6 #include <vector>
7 #include <assert.h>
10 #include "alignment.h"
11 
12 #include "chromSimMatrix.h"
13 #include "alignment.h"
14 #include "gapPenalty.h"
15 #include "affinealignobj.h"
16 #include "affinealignment.h"
17 #include "constrainMat.h"
18 
21 // Why do we create a new namespace?
22 // Does it not conflict with the same namespace DIAlign we had in other files.
23 // Wait! Don't these namespace override each other? Can you just keep-on adding stuff in namespace?
24 // namespace is like a package, you add stuff inside it without breaking other parts.
25 
61 namespace DIAlign
62 {
63 
64 
94  const std::vector<std::vector<double> > & r1,
95  const std::vector<std::vector<double> > & r2,
96  std::string alignType,
97  const std::vector<double>& tA, const std::vector<double>& tB,
98  const std::string & normalization, const std::string& simType,
99  double B1p = 0.0, double B2p =0.0,
100  int noBeef = 0,
101  double goFactor = 0.125, double geFactor = 40,
102  double cosAngleThresh = 0.3, bool OverlapAlignment = true,
103  double dotProdThresh = 0.96, double gapQuantile = 0.5,
104  bool hardConstrain = false, double samples4gradient = 100.0)
105  {
106  SimMatrix s = SimilarityMatrix::getSimilarityMatrix(r1, r2, normalization, simType, cosAngleThresh, dotProdThresh);
107  obj.reset(s.n_row + 1, s.n_col + 1);
108 
109  double gapPenalty = getGapPenalty(s, gapQuantile, simType);
110  if (alignType == "hybrid")
111  {
112  SimMatrix MASK;
113  MASK.n_row = tA.size();
114  MASK.n_col = tB.size();
115  MASK.data.resize(MASK.n_row*MASK.n_col, 0.0);
116  double A1 = tA[0], A2 = tA[MASK.n_row-1];
117  double B1 = tB[0], B2 = tB[MASK.n_col-1];
118  ConstrainMatrix::calcNoBeefMask(MASK, A1, A2, B1, B2, B1p, B2p, noBeef, hardConstrain);
119  auto maxIt = max_element(std::begin(s.data), std::end(s.data));
120  double maxVal = *maxIt;
121  ConstrainMatrix::constrainSimilarity(s, MASK, -2.0*maxVal/samples4gradient);
122  }
123  AffineAlignment::doAffineAlignment(obj, s, gapPenalty*goFactor, gapPenalty*geFactor, OverlapAlignment); // Performs alignment on s matrix and returns AffineAlignObj struct
124  AffineAlignment::getAffineAlignedIndices(obj); // Performs traceback and fills aligned indices in AffineAlignObj struct
125  }
126 
140  SimMatrix getSimilarityMatrix(const std::vector<std::vector<double>>& d1,
141  const std::vector<std::vector<double>>& d2,
142  const std::string& Normalization,
143  const std::string& SimType,
144  double cosAngleThresh,
145  double dotProdThresh)
146  {
147  return SimilarityMatrix::getSimilarityMatrix(d1, d2, Normalization, SimType, cosAngleThresh, dotProdThresh);
148  }
149 
161  void doAffineAlignment(AffineAlignObj& obj, const SimMatrix& s, double goPenalty, double gePenalty, bool OverlapAlignment)
162  {
163  return AffineAlignment::doAffineAlignment(obj, s, goPenalty, gePenalty, OverlapAlignment);
164  }
165 
175  void getAffineAlignedIndices(AffineAlignObj &obj, int bandwidth = 0)
176  {
177  getAffineAlignedIndices(obj, bandwidth);
178  }
179 
180 }
181 
void getAffineAlignedIndices(AffineAlignObj &obj, int bandwidth=0)
Compute path using AffineAlignObj.
Definition: CppInterface.hpp:175
void alignChromatogramsCpp(AffineAlignObj &obj, const std::vector< std::vector< double > > &r1, const std::vector< std::vector< double > > &r2, std::string alignType, const std::vector< double > &tA, const std::vector< double > &tB, const std::string &normalization, const std::string &simType, double B1p=0.0, double B2p=0.0, int noBeef=0, double goFactor=0.125, double geFactor=40, double cosAngleThresh=0.3, bool OverlapAlignment=true, double dotProdThresh=0.96, double gapQuantile=0.5, bool hardConstrain=false, double samples4gradient=100.0)
Align two pairs of chromatograms derived from two LC-MS/MS experiments A and B.
Definition: CppInterface.hpp:93
void calcNoBeefMask(SimMatrix &MASK, double A1, double A2, double B1, double B2, double B1p, double B2p, int noBeef, bool hardConstrain)
Fill a diagonal strip with one through the matrix MASK.
Definition: constrainMat.cpp:13
An affine alignment object.
Definition: affinealignobj.h:44
void getAffineAlignedIndices(AffineAlignObj &affineAlignObj, int bandwidth)
Calculates aligned indices for source signal A and B, additionaly, builds an alignment path matrix wi...
Definition: affinealignment.cpp:193
void reset(int ROW_SIZE, int COL_SIZE)
Reset object to initial state (without allocating new memory)
Definition: affinealignobj.h:109
Generic namespace for all classes and functions of DIAlign.
Definition: affinealignment.cpp:29
void constrainSimilarity(SimMatrix &s, const SimMatrix &MASK, double constrainVal)
Applies the mask from calcNoBeefMask() on the similarity matrix.
Definition: constrainMat.cpp:71
std::vector< double > data
Similarity data.
Definition: similarityMatrix.h:16
Similarity matrix.
Definition: similarityMatrix.h:14
SimMatrix getSimilarityMatrix(const std::vector< std::vector< double >> &d1, const std::vector< std::vector< double >> &d2, const std::string Normalization, const std::string SimType, double cosAngleThresh, double dotProdThresh)
Returns a similarity matrix between d1 and d2 vector of vectors.
Definition: chromSimMatrix.cpp:324
void doAffineAlignment(AffineAlignObj &affineAlignObj, const SimMatrix &s, double go, double ge, bool OverlapAlignment)
Performs affine alignment on similarity-score matrix DIAlign::SimMatrix and fills M...
Definition: affinealignment.cpp:38
double getGapPenalty(const SimMatrix &s, double gapQuantile, std::string SimType)
returns a gap penalty from the distribution of similarity scores.
Definition: gapPenalty.cpp:5
SimMatrix getSimilarityMatrix(const std::vector< std::vector< double >> &d1, const std::vector< std::vector< double >> &d2, const std::string &Normalization, const std::string &SimType, double cosAngleThresh, double dotProdThresh)
Calculates similarity matrix of two fragment-ion chromatogram groups or extracted-ion chromatograms (...
Definition: CppInterface.hpp:140
void doAffineAlignment(AffineAlignObj &obj, const SimMatrix &s, double goPenalty, double gePenalty, bool OverlapAlignment)
Performs affine alignment on a given alignment object.
Definition: CppInterface.hpp:161