38 #include <Evergreen/evergreen.hpp>
40 typedef unsigned long int uiint;
50 template <
typename Label>
60 std::map<int, double>
chgLLhoods = {{1, 0.7}, {2, 0.9}, {3, 0.7}, {4, 0.5}, {5, 0.5}};
67 return std::pow(2., log2(1. -
beta_) + summ * log2(1. -
alpha_));
75 evergreen::TableDependency<Label>
createProteinFactor(Label
id,
double prior,
int nrMissingPeps = 0);
91 evergreen::TableDependency<Label>
createSumFactor(
size_t nrParents, Label nId);
93 evergreen::TableDependency<Label>
createChargeFactor(Label repId, Label chargeId,
int chg);
100 evergreen::PseudoAdditiveDependency<Label>
createBFPeptideProbabilisticAdderFactor(
const std::set<Label> & parentProteinIDs, Label nId,
const std::vector<evergreen::TableDependency <Label> > & deps);
117 const std::vector<std::vector<Label>> & parentsOfPeps,
118 const std::vector<double> & pepEvidences,
119 evergreen::InferenceGraphBuilder<Label> & igb);
129 template <
typename Label>
131 assert(0. <= alpha && alpha <= 1.);
132 assert(0. <= beta && beta <= 1.);
133 assert(0. <= gamma && gamma <= 1.);
136 assert(0. < pep_prior && pep_prior < 1.);
141 pepPrior_ = pep_prior;
144 template <
typename Label>
146 double prior = gamma_;
147 if (nrMissingPeps > 0)
149 double powFactor = std::pow(1.0 - alpha_, -nrMissingPeps);
150 prior = -prior/(prior * powFactor - prior - powFactor);
152 double table[] = {1.0 - prior, prior};
153 evergreen::LabeledPMF<Label> lpmf({
id}, evergreen::PMF({0L}, evergreen::Tensor<double>::from_array(table)));
154 return evergreen::TableDependency<Label>(lpmf,p_);
157 template <
typename Label>
159 if (nrMissingPeps > 0)
161 double powFactor = std::pow(1.0 - alpha_, -nrMissingPeps);
162 prior = -prior/(prior * powFactor - prior - powFactor);
164 double table[] = {1.0 - prior, prior};
165 evergreen::LabeledPMF<Label> lpmf({
id}, evergreen::PMF({0L}, evergreen::Tensor<double>::from_array(table)));
166 return evergreen::TableDependency<Label>(lpmf,p_);
169 template <
typename Label>
171 double table[] = {(1 - prob) * (1 - pepPrior_), prob * pepPrior_};
172 evergreen::LabeledPMF<Label> lpmf({
id}, evergreen::PMF({0L}, evergreen::Tensor<double>::from_array(table)));
173 return evergreen::TableDependency<Label>(lpmf,p_);
177 template <
typename Label>
179 evergreen::Tensor<double> table({
static_cast<unsigned long>(nrParents + 1) , 2});
180 for (
unsigned long i=0; i <= nrParents; ++i) {
181 double notConditional = notConditionalGivenSum(i);
182 unsigned long indexArr[2] = {i,0ul};
183 table[indexArr] = notConditional;
184 unsigned long indexArr2[2] = {i,1ul};
185 table[indexArr2] = 1.0 - notConditional;
188 evergreen::LabeledPMF<Label> lpmf({nId, pepId}, evergreen::PMF({0L,0L}, table));
190 return evergreen::TableDependency<Label>(lpmf,p_);
193 template <
typename Label>
195 evergreen::Tensor<double> table({
static_cast<unsigned long>(nrParents + 1) , 2});
196 unsigned long z[2]{0ul,0ul};
197 unsigned long z1[2]{0ul,1ul};
198 table[z] = 1. - beta_;
200 for (
unsigned long i=1; i <= nrParents; ++i) {
201 double notConditional = notConditionalGivenSum(i);
202 unsigned long indexArr[2] = {i,0ul};
203 table[indexArr] = notConditional / i;
204 unsigned long indexArr2[2] = {i,1ul};
205 table[indexArr2] = (1.0 - notConditional) / i;
208 evergreen::LabeledPMF<Label> lpmf({nId, pepId}, evergreen::PMF({0L,0L}, table));
210 return evergreen::TableDependency<Label>(lpmf,p_);
213 template <
typename Label>
215 evergreen::Tensor<double> table({nrParents+1});
216 for (
unsigned long i=0; i <= nrParents; ++i) {
217 table[i] = 1.0/(nrParents+1.);
220 evergreen::LabeledPMF<Label> lpmf({nId}, evergreen::PMF({0L}, table));
222 return evergreen::TableDependency<Label>(lpmf,p_);
225 template <
typename Label>
227 using arr =
unsigned long[2];
228 evergreen::Tensor<double> table({2,2});
229 table[arr{0,0}] = 0.999;
230 table[arr{0,1}] = 0.001;
231 table[arr{1,0}] = 0.1;
232 table[arr{1,1}] = 0.9;
234 evergreen::LabeledPMF<Label> lpmf({seqId,repId}, evergreen::PMF({0L,0L}, table));
236 return evergreen::TableDependency<Label>(lpmf,p_);
239 template <
typename Label>
241 double chgPrior = chgLLhoods[chg];
242 using arr =
unsigned long[2];
243 evergreen::Tensor<double> table({2,2});
244 table[arr{0,0}] = 0.999;
245 table[arr{0,1}] = 0.001;
246 table[arr{1,0}] = 0.1;
247 table[arr{1,1}] = chgPrior;
249 evergreen::LabeledPMF<Label> lpmf({repId,chgId}, evergreen::PMF({0L,0L}, table));
251 return evergreen::TableDependency<Label>(lpmf,p_);
254 template <
typename Label>
256 std::vector<std::vector<Label>> parents;
257 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const Label& l){return std::vector<Label>{l};});
258 return evergreen::AdditiveDependency<Label>(parents, {nId}, p_);
261 template <
typename Label>
263 std::vector<std::vector<Label>> parents;
264 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const Label& l){return std::vector<Label>{l};});
265 return evergreen::AdditiveDependency<Label>(parents, {nId}, p_);
268 template <
typename Label>
270 std::vector<std::vector<Label>> parents;
271 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const Label& l){return std::vector<Label>{l};});
272 return evergreen::PseudoAdditiveDependency<Label>(parents, {nId}, deps, p_);
277 template <
typename Label>
279 const std::vector<std::vector<Label>>& parentsOfPeps,
280 const std::vector<double>& pepEvidences,
281 evergreen::InferenceGraphBuilder<Label>& igb)
284 assert(parentsOfPeps.size() == pepEvidences.size());
285 for (
const std::vector<uiint>& parents : parentsOfPeps)
286 for (Label parent : parents)
287 assert(
std::find(protIDs.begin(), protIDs.end(), parent) != protIDs.end());
289 for (
uiint pid : protIDs)
290 igb.insert_dependency(createProteinFactor(pid));
292 for (
uiint j = 0; j < parentsOfPeps.size(); j++)
294 igb.insert_dependency(createPeptideEvidenceFactor(j,pepEvidences[j]));
295 igb.insert_dependency(createSumEvidenceFactor(parentsOfPeps[j],j,j));
296 igb.insert_dependency(createPeptideProbabilisticAdderFactor(parentsOfPeps[j],j));
unsigned long int uiint
Definition: MessagePasserFactory.h:40
Definition: MessagePasserFactory.h:51
evergreen::TableDependency< Label > createProteinFactor(Label id, int nrMissingPeps=0)
Protein Factor initialized with model prior (missing peps are experimental)
Definition: MessagePasserFactory.h:145
double notConditionalGivenSum(unsigned long summ)
Definition: MessagePasserFactory.h:65
evergreen::AdditiveDependency< Label > createPeptideProbabilisticAdderFactor(const std::set< Label > &parentProteinIDs, Label nId)
To sum up distributions for the number of parent proteins of a peptide with convolution trees.
Definition: MessagePasserFactory.h:255
double alpha_
the model parameters
Definition: MessagePasserFactory.h:56
MessagePasserFactory(double alpha, double beta, double gamma, double p, double pep_prior)
Constructor.
Definition: MessagePasserFactory.h:130
double beta_
Definition: MessagePasserFactory.h:56
void fillVectorsOfMessagePassers(const std::vector< Label > &protIDs, const std::vector< std::vector< Label >> &parentsOfPeps, const std::vector< double > &pepEvidences, evergreen::InferenceGraphBuilder< Label > &igb)
Works on a vector of protein indices (potentially not consecutive)
Definition: MessagePasserFactory.h:278
evergreen::TableDependency< Label > createChargeFactor(Label repId, Label chargeId, int chg)
Definition: MessagePasserFactory.h:240
double gamma_
Definition: MessagePasserFactory.h:56
double pepPrior_
Definition: MessagePasserFactory.h:56
evergreen::TableDependency< Label > createReplicateFactor(Label seqId, Label repId)
Definition: MessagePasserFactory.h:226
evergreen::TableDependency< Label > createSumFactor(size_t nrParents, Label nId)
Definition: MessagePasserFactory.h:214
evergreen::TableDependency< Label > createPeptideEvidenceFactor(Label id, double prob)
Definition: MessagePasserFactory.h:170
double p_
Definition: MessagePasserFactory.h:56
std::map< int, double > chgLLhoods
Definition: MessagePasserFactory.h:60
evergreen::TableDependency< Label > createRegularizingSumEvidenceFactor(size_t nrParents, Label nId, Label pepId)
Definition: MessagePasserFactory.h:194
evergreen::TableDependency< Label > createSumEvidenceFactor(size_t nrParents, Label nId, Label pepId)
Definition: MessagePasserFactory.h:178
evergreen::PseudoAdditiveDependency< Label > createBFPeptideProbabilisticAdderFactor(const std::set< Label > &parentProteinIDs, Label nId, const std::vector< evergreen::TableDependency< Label > > &deps)
To sum up distributions for the number of parent proteins of a peptide brute-force.
Definition: MessagePasserFactory.h:269
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:886