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);
65 evergreen::TableDependency<Label>
createSumFactor(
size_t nrParents, Label nId);
67 evergreen::TableDependency<Label>
createChargeFactor(Label repId, Label chargeId,
int chg);
74 evergreen::PseudoAdditiveDependency<Label>
createBFPeptideProbabilisticAdderFactor(
const std::set<Label> & parentProteinIDs, Label nId,
const std::vector<evergreen::TableDependency <Label> > & deps);
91 const std::vector<std::vector<Label>> & parentsOfPeps,
92 const std::vector<double> & pepEvidences,
93 evergreen::InferenceGraphBuilder<Label> & igb);
103 template <
typename Label>
105 assert(0. <= alpha && alpha <= 1.);
106 assert(0. <= beta && beta <= 1.);
107 assert(0. <= gamma && gamma <= 1.);
110 assert(0. < pep_prior && pep_prior < 1.);
115 pepPrior_ = pep_prior;
118 template <
typename Label>
120 double prior = gamma_;
121 if (nrMissingPeps > 0)
123 double powFactor = std::pow(1.0 - alpha_, -nrMissingPeps);
124 prior = -prior/(prior * powFactor - prior - powFactor);
126 double table[] = {1.0 - prior, prior};
127 evergreen::LabeledPMF<Label> lpmf({
id}, evergreen::PMF({0L}, evergreen::Tensor<double>::from_array(table)));
128 return evergreen::TableDependency<Label>(lpmf,p_);
131 template <
typename Label>
133 if (nrMissingPeps > 0)
135 double powFactor = std::pow(1.0 - alpha_, -nrMissingPeps);
136 prior = -prior/(prior * powFactor - prior - powFactor);
138 double table[] = {1.0 - prior, prior};
139 evergreen::LabeledPMF<Label> lpmf({
id}, evergreen::PMF({0L}, evergreen::Tensor<double>::from_array(table)));
140 return evergreen::TableDependency<Label>(lpmf,p_);
143 template <
typename Label>
145 double table[] = {(1 - prob) * (1 - pepPrior_), prob * pepPrior_};
146 evergreen::LabeledPMF<Label> lpmf({
id}, evergreen::PMF({0L}, evergreen::Tensor<double>::from_array(table)));
147 return evergreen::TableDependency<Label>(lpmf,p_);
151 template <
typename Label>
153 evergreen::Tensor<double> table({
static_cast<unsigned long>(nrParents + 1) , 2});
154 for (
unsigned long i=0; i <= nrParents; ++i) {
155 double notConditional = notConditionalGivenSum(i);
156 unsigned long indexArr[2] = {i,0ul};
157 table[indexArr] = notConditional;
158 unsigned long indexArr2[2] = {i,1ul};
159 table[indexArr2] = 1.0 - notConditional;
162 evergreen::LabeledPMF<Label> lpmf({nId, pepId}, evergreen::PMF({0L,0L}, table));
164 return evergreen::TableDependency<Label>(lpmf,p_);
167 template <
typename Label>
169 evergreen::Tensor<double> table({
static_cast<unsigned long>(nrParents + 1) , 2});
170 unsigned long z[2]{0ul,0ul};
171 unsigned long z1[2]{0ul,1ul};
172 table[z] = 1. - beta_;
174 for (
unsigned long i=1; i <= nrParents; ++i) {
175 double notConditional = notConditionalGivenSum(i);
176 unsigned long indexArr[2] = {i,0ul};
177 table[indexArr] = notConditional / i;
178 unsigned long indexArr2[2] = {i,1ul};
179 table[indexArr2] = (1.0 - notConditional) / i;
182 evergreen::LabeledPMF<Label> lpmf({nId, pepId}, evergreen::PMF({0L,0L}, table));
184 return evergreen::TableDependency<Label>(lpmf,p_);
187 template <
typename Label>
189 evergreen::Tensor<double> table({nrParents+1});
190 for (
unsigned long i=0; i <= nrParents; ++i) {
191 table[i] = 1.0/(nrParents+1.);
194 evergreen::LabeledPMF<Label> lpmf({nId}, evergreen::PMF({0L}, table));
196 return evergreen::TableDependency<Label>(lpmf,p_);
199 template <
typename Label>
201 using arr =
unsigned long[2];
202 evergreen::Tensor<double> table({2,2});
203 table[arr{0,0}] = 0.999;
204 table[arr{0,1}] = 0.001;
205 table[arr{1,0}] = 0.1;
206 table[arr{1,1}] = 0.9;
208 evergreen::LabeledPMF<Label> lpmf({seqId,repId}, evergreen::PMF({0L,0L}, table));
210 return evergreen::TableDependency<Label>(lpmf,p_);
213 template <
typename Label>
215 double chgPrior = chgLLhoods[chg];
216 using arr =
unsigned long[2];
217 evergreen::Tensor<double> table({2,2});
218 table[arr{0,0}] = 0.999;
219 table[arr{0,1}] = 0.001;
220 table[arr{1,0}] = 0.1;
221 table[arr{1,1}] = chgPrior;
223 evergreen::LabeledPMF<Label> lpmf({repId,chgId}, evergreen::PMF({0L,0L}, table));
225 return evergreen::TableDependency<Label>(lpmf,p_);
228 template <
typename Label>
230 std::vector<std::vector<Label>> parents;
231 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const Label& l){return std::vector<Label>{l};});
232 return evergreen::AdditiveDependency<Label>(parents, {nId}, p_);
235 template <
typename Label>
237 std::vector<std::vector<Label>> parents;
238 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const Label& l){return std::vector<Label>{l};});
239 return evergreen::AdditiveDependency<Label>(parents, {nId}, p_);
242 template <
typename Label>
244 std::vector<std::vector<Label>> parents;
245 std::transform(parentProteinIDs.begin(), parentProteinIDs.end(), std::back_inserter(parents), [](
const Label& l){return std::vector<Label>{l};});
246 return evergreen::PseudoAdditiveDependency<Label>(parents, {nId}, deps, p_);
251 template <
typename Label>
253 const std::vector<std::vector<Label>>& parentsOfPeps,
254 const std::vector<double>& pepEvidences,
255 evergreen::InferenceGraphBuilder<Label>& igb)
258 assert(parentsOfPeps.size() == pepEvidences.size());
259 for (
const std::vector<uiint>& parents : parentsOfPeps)
260 for (Label parent : parents)
261 assert(std::find(protIDs.begin(), protIDs.end(), parent) != protIDs.end());
263 for (
uiint pid : protIDs)
264 igb.insert_dependency(createProteinFactor(pid));
266 for (
uiint j = 0; j < parentsOfPeps.size(); j++)
268 igb.insert_dependency(createPeptideEvidenceFactor(j,pepEvidences[j]));
269 igb.insert_dependency(createSumEvidenceFactor(parentsOfPeps[j],j,j));
270 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:119
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:229
double alpha_
the model parameters
Definition: MessagePasserFactory.h:30
MessagePasserFactory(double alpha, double beta, double gamma, double p, double pep_prior)
Constructor.
Definition: MessagePasserFactory.h:104
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:252
evergreen::TableDependency< Label > createChargeFactor(Label repId, Label chargeId, int chg)
Definition: MessagePasserFactory.h:214
double gamma_
Definition: MessagePasserFactory.h:30
double pepPrior_
Definition: MessagePasserFactory.h:30
evergreen::TableDependency< Label > createReplicateFactor(Label seqId, Label repId)
Definition: MessagePasserFactory.h:200
evergreen::TableDependency< Label > createSumFactor(size_t nrParents, Label nId)
Definition: MessagePasserFactory.h:188
evergreen::TableDependency< Label > createPeptideEvidenceFactor(Label id, double prob)
Definition: MessagePasserFactory.h:144
double p_
Definition: MessagePasserFactory.h:30
std::map< int, double > chgLLhoods
Definition: MessagePasserFactory.h:34
evergreen::TableDependency< Label > createRegularizingSumEvidenceFactor(size_t nrParents, Label nId, Label pepId)
Definition: MessagePasserFactory.h:168
evergreen::TableDependency< Label > createSumEvidenceFactor(size_t nrParents, Label nId, Label pepId)
Definition: MessagePasserFactory.h:152
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:243
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22