12 #include <Evergreen/evergreen.hpp>
14 typedef unsigned long int uiint;
24 template <
typename Label>
34 std::map<int, double>
chgLLhoods = {{1, 0.7}, {2, 0.9}, {3, 0.7}, {4, 0.5}, {5, 0.5}};
41 return std::pow(2., log2(1. -
beta_) + summ * log2(1. -
alpha_));
49 evergreen::TableDependency<Label>
createProteinFactor(Label
id,
double prior,
int nrMissingPeps = 0);
70 evergreen::TableDependency<Label>
createSumFactor(
size_t nr_parents, Label nId);
72 evergreen::TableDependency<Label>
createChargeFactor(Label repId, Label chargeId,
int chg);
79 evergreen::PseudoAdditiveDependency<Label>
createBFPeptideProbabilisticAdderFactor(
const std::set<Label> & parentProteinIDs, Label nId,
const std::vector<evergreen::TableDependency <Label> > & deps);
96 const std::vector<std::vector<Label>> & parentsOfPeps,
97 const std::vector<double> & pepEvidences,
98 evergreen::InferenceGraphBuilder<Label> & igb);
108 template <
typename Label>
110 assert(0. <= alpha && alpha <= 1.);
111 assert(0. <= beta && beta <= 1.);
112 assert(0. <= gamma && gamma <= 1.);
115 assert(0. < pep_prior && pep_prior < 1.);
120 pepPrior_ = pep_prior;
123 template <
typename Label>
125 double prior = gamma_;
126 if (nrMissingPeps > 0)
128 double powFactor = std::pow(1.0 - alpha_, -nrMissingPeps);
129 prior = -prior/(prior * powFactor - prior - powFactor);
131 double table[] = {1.0 - prior, prior};
132 evergreen::LabeledPMF<Label> lpmf({
id}, evergreen::PMF({0L}, evergreen::Tensor<double>::from_array(table)));
133 return evergreen::TableDependency<Label>(lpmf,p_);
136 template <
typename Label>
138 if (nrMissingPeps > 0)
140 double powFactor = std::pow(1.0 - alpha_, -nrMissingPeps);
141 prior = -prior/(prior * powFactor - prior - powFactor);
143 double table[] = {1.0 - prior, prior};
144 evergreen::LabeledPMF<Label> lpmf({
id}, evergreen::PMF({0L}, evergreen::Tensor<double>::from_array(table)));
145 return evergreen::TableDependency<Label>(lpmf,p_);
148 template <
typename Label>
150 double table[] = {(1 - prob) * (1 - pepPrior_), prob * pepPrior_};
151 evergreen::LabeledPMF<Label> lpmf({
id}, evergreen::PMF({0L}, evergreen::Tensor<double>::from_array(table)));
152 return evergreen::TableDependency<Label>(lpmf,p_);
156 template <
typename Label>
158 evergreen::Tensor<double> table({
static_cast<unsigned long>(nrParents + 1) , 2});
159 for (
unsigned long i=0; i <= nrParents; ++i) {
160 double notConditional = notConditionalGivenSum(i);
161 unsigned long indexArr[2] = {i,0ul};
162 table[indexArr] = notConditional;
163 unsigned long indexArr2[2] = {i,1ul};
164 table[indexArr2] = 1.0 - notConditional;
167 evergreen::LabeledPMF<Label> lpmf({nId, pepId}, evergreen::PMF({0L,0L}, table));
169 return evergreen::TableDependency<Label>(lpmf,p_);
172 template <
typename Label>
174 evergreen::Tensor<double> table({
static_cast<unsigned long>(nrParents + 1) , 2});
175 unsigned long z[2]{0ul,0ul};
176 unsigned long z1[2]{0ul,1ul};
177 table[z] = 1. - beta_;
179 for (
unsigned long i=1; i <= nrParents; ++i) {
180 double notConditional = notConditionalGivenSum(i);
181 unsigned long indexArr[2] = {i,0ul};
182 table[indexArr] = notConditional / i;
183 unsigned long indexArr2[2] = {i,1ul};
184 table[indexArr2] = (1.0 - notConditional) / i;
187 evergreen::LabeledPMF<Label> lpmf({nId, pepId}, evergreen::PMF({0L,0L}, table));
189 return evergreen::TableDependency<Label>(lpmf,p_);
192 template <
typename Label>
194 evergreen::Tensor<double> table({nrParents+1});
195 for (
unsigned long i=0; i <= nrParents; ++i) {
196 table[i] = 1.0/(nrParents+1.);
199 evergreen::LabeledPMF<Label> lpmf({nId}, evergreen::PMF({0L}, table));
201 return evergreen::TableDependency<Label>(lpmf,p_);
204 template <
typename Label>
206 using arr =
unsigned long[2];
207 evergreen::Tensor<double> table({2,2});
208 table[arr{0,0}] = 0.999;
209 table[arr{0,1}] = 0.001;
210 table[arr{1,0}] = 0.1;
211 table[arr{1,1}] = 0.9;
213 evergreen::LabeledPMF<Label> lpmf({seqId,repId}, evergreen::PMF({0L,0L}, table));
215 return evergreen::TableDependency<Label>(lpmf,p_);
218 template <
typename Label>
220 double chgPrior = chgLLhoods[chg];
221 using arr =
unsigned long[2];
222 evergreen::Tensor<double> table({2,2});
223 table[arr{0,0}] = 0.999;
224 table[arr{0,1}] = 0.001;
225 table[arr{1,0}] = 0.1;
226 table[arr{1,1}] = chgPrior;
228 evergreen::LabeledPMF<Label> lpmf({repId,chgId}, evergreen::PMF({0L,0L}, table));
230 return evergreen::TableDependency<Label>(lpmf,p_);
233 template <
typename Label>
235 std::vector<std::vector<Label>> parents;
236 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const Label& l){return std::vector<Label>{l};});
237 return evergreen::AdditiveDependency<Label>(parents, {nId}, p_);
240 template <
typename Label>
242 std::vector<std::vector<Label>> parents;
243 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const Label& l){return std::vector<Label>{l};});
244 return evergreen::AdditiveDependency<Label>(parents, {nId}, p_);
247 template <
typename Label>
249 std::vector<std::vector<Label>> parents;
250 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const Label& l){return std::vector<Label>{l};});
251 return evergreen::PseudoAdditiveDependency<Label>(parents, {nId}, deps, p_);
256 template <
typename Label>
258 const std::vector<std::vector<Label>>& parentsOfPeps,
259 const std::vector<double>& pepEvidences,
260 evergreen::InferenceGraphBuilder<Label>& igb)
263 assert(parentsOfPeps.size() == pepEvidences.size());
264 for (
const std::vector<uiint>& parents : parentsOfPeps)
265 for (Label parent : parents)
266 assert(std::find(protIDs.begin(), protIDs.end(), parent) != protIDs.end());
268 for (
uiint pid : protIDs)
269 igb.insert_dependency(createProteinFactor(pid));
271 for (
uiint j = 0; j < parentsOfPeps.size(); j++)
273 igb.insert_dependency(createPeptideEvidenceFactor(j,pepEvidences[j]));
274 igb.insert_dependency(createSumEvidenceFactor(parentsOfPeps[j],j,j));
275 igb.insert_dependency(createPeptideProbabilisticAdderFactor(parentsOfPeps[j],j));
unsigned long int uiint
Definition: MessagePasserFactory.h:14
Definition: MessagePasserFactory.h:25
evergreen::TableDependency< Label > createProteinFactor(Label id, int nrMissingPeps=0)
Protein Factor initialized with model prior (missing peps are experimental)
Definition: MessagePasserFactory.h:124
double notConditionalGivenSum(unsigned long summ)
Definition: MessagePasserFactory.h:39
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:234
double alpha_
the model parameters
Definition: MessagePasserFactory.h:30
evergreen::TableDependency< Label > createSumEvidenceFactor(size_t nr_parents, Label id, Label pep_id)
Definition: MessagePasserFactory.h:157
MessagePasserFactory(double alpha, double beta, double gamma, double p, double pep_prior)
Constructor.
Definition: MessagePasserFactory.h:109
double beta_
Definition: MessagePasserFactory.h:30
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:257
evergreen::TableDependency< Label > createRegularizingSumEvidenceFactor(size_t nr_parents, Label id, Label pep_id)
Definition: MessagePasserFactory.h:173
evergreen::TableDependency< Label > createChargeFactor(Label repId, Label chargeId, int chg)
Definition: MessagePasserFactory.h:219
double gamma_
Definition: MessagePasserFactory.h:30
double pepPrior_
Definition: MessagePasserFactory.h:30
evergreen::TableDependency< Label > createReplicateFactor(Label seqId, Label repId)
Definition: MessagePasserFactory.h:205
evergreen::TableDependency< Label > createSumFactor(size_t nr_parents, Label nId)
Definition: MessagePasserFactory.h:193
evergreen::TableDependency< Label > createPeptideEvidenceFactor(Label id, double prob)
Definition: MessagePasserFactory.h:149
double p_
Definition: MessagePasserFactory.h:30
std::map< int, double > chgLLhoods
Definition: MessagePasserFactory.h:34
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:248
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19