bpp-phyl  2.2.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
SubstitutionMappingTools.h
Go to the documentation of this file.
1 //
2 // File: SubstitutionMappingTools.h
3 // Created by: Julien Dutheil
4 // Created on: Wed Apr 5 13:04 2006
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004, 2005, 2006)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
40 #ifndef _SUBSTITUTIONMAPPINGTOOLS_H_
41 #define _SUBSTITUTIONMAPPINGTOOLS_H_
42 
44 #include "SubstitutionCount.h"
46 #include "../Likelihood/DRTreeLikelihood.h"
47 
48 namespace bpp
49 {
63 {
64 public:
67 
68 public:
80  const DRTreeLikelihood& drtl,
81  SubstitutionCount& substitutionCount,
82  bool verbose = true) throw (Exception)
83  {
84  std::vector<int> nodeIds;
85  return computeSubstitutionVectors(drtl, nodeIds, substitutionCount, verbose);
86  }
87 
102  const DRTreeLikelihood& drtl,
103  const std::vector<int>& nodeIds,
104  SubstitutionCount& substitutionCount,
105  bool verbose = true) throw (Exception);
106 
108  const DRTreeLikelihood& drtl,
109  const SubstitutionModelSet& modelSet,
110  const std::vector<int>& nodeIds,
111  SubstitutionCount& substitutionCount,
112  bool verbose = true) throw (Exception);
113 
135  const DRTreeLikelihood& drtl,
136  SubstitutionCount& substitutionCount,
137  bool verbose = true) throw (Exception);
138 
139 
159  const DRTreeLikelihood& drtl,
160  SubstitutionCount& substitutionCount,
161  bool verbose = true) throw (Exception);
162 
163 
180  const DRTreeLikelihood& drtl,
181  SubstitutionCount& substitutionCount,
182  bool verbose = true) throw (Exception);
183 
184 
193  const DRTreeLikelihood& drtl,
194  bool verbose = true) throw (Exception)
195  {
196  OneJumpSubstitutionCount ojsm(0);
197  return computeSubstitutionVectors(drtl, drtl.getTree().getNodesId(), ojsm, 0);
198  }
199 
200 
212  static void writeToStream(
213  const ProbabilisticSubstitutionMapping& substitutions,
214  const SiteContainer& sites,
215  size_t type,
216  std::ostream& out)
217  throw (IOException);
218 
219 
228  static void readFromStream(std::istream& in, ProbabilisticSubstitutionMapping& substitutions, size_t type)
229  throw (IOException);
230 
231 
239  static std::vector<double> computeTotalSubstitutionVectorForSite(const SubstitutionMapping& smap, size_t siteIndex);
240 
241 
253  static double computeNormForSite(const SubstitutionMapping& smap, size_t siteIndex);
254 
255 
263  static std::vector<double> computeSumForBranch(const SubstitutionMapping& smap, size_t branchIndex);
264 
265 
273  static std::vector<double> computeSumForSite(const SubstitutionMapping& smap, size_t siteIndex);
274 
275 
288  static std::vector< std::vector<double> > getCountsPerBranch(
289  DRTreeLikelihood& drtl,
290  const std::vector<int>& ids,
291  SubstitutionModel* model,
292  const SubstitutionRegister& reg,
293  double threshold = -1,
294  bool verbose = true);
295 
296  static std::vector< std::vector<double> > getCountsPerBranch(
297  DRTreeLikelihood& drtl,
298  const std::vector<int>& ids,
299  const SubstitutionModelSet& modelSet,
300  const SubstitutionRegister& reg,
301  double threshold = -1,
302  bool verbose = true);
303 
304 
317  static std::vector< std::vector<double> > getNormalizationsPerBranch(
318  DRTreeLikelihood& drtl,
319  const std::vector<int>& ids,
320  const SubstitutionModel* nullModel,
321  const SubstitutionRegister& reg,
322  bool verbose = true);
323 
324 
337  static std::vector< std::vector<double> > getNormalizationsPerBranch(
338  DRTreeLikelihood& drtl,
339  const std::vector<int>& ids,
340  const SubstitutionModelSet* nullModelSet,
341  const SubstitutionRegister& reg,
342  bool verbose = true);
343 
344 
355  static std::vector< std::vector<double> > getNormalizedCountsPerBranch(
356  DRTreeLikelihood& drtl,
357  const std::vector<int>& ids,
358  SubstitutionModel* model,
359  SubstitutionModel* nullModel,
360  const SubstitutionRegister& reg,
361  bool verbose = true);
362 
373  static std::vector< std::vector<double> > getNormalizedCountsPerBranch(
374  DRTreeLikelihood& drtl,
375  const std::vector<int>& ids,
376  SubstitutionModelSet* modelSet,
377  SubstitutionModelSet* nullModelSet,
378  const SubstitutionRegister& reg,
379  bool verbose = true);
380 
396  static std::vector< std::vector<double> > getRelativeCountsPerBranch(
397  DRTreeLikelihood& drtl,
398  const std::vector<int>& ids,
399  SubstitutionModel* model,
400  const SubstitutionRegister& reg,
401  bool stationarity = true,
402  double threshold = -1);
403 
416  std::string& filename,
417  DRTreeLikelihood& drtl,
418  const std::vector<int>& ids,
419  SubstitutionModel* model,
420  const SubstitutionRegister& reg);
421 
422 
434  const std::string& filenamePrefix,
435  DRTreeLikelihood& drtl,
436  const std::vector<int>& ids,
437  SubstitutionModel* model,
438  const SubstitutionRegister& reg);
439 };
440 } // end of namespace bpp.
441 
442 #endif // _SUBSTITUTIONMAPPINGTOOLS_H_
static ProbabilisticSubstitutionMapping * computeSubstitutionVectorsNoAveraging(const DRTreeLikelihood &drtl, SubstitutionCount &substitutionCount, bool verbose=true)
Compute the substitutions vectors for a particular dataset using the double-recursive likelihood comp...
Substitution models manager for non-homogeneous / non-reversible models of evolution.
Interface for all substitution models.
static ProbabilisticSubstitutionMapping * computeOneJumpProbabilityVectors(const DRTreeLikelihood &drtl, bool verbose=true)
This method computes for each site and for each branch the probability that at least one jump occurre...
static std::vector< double > computeSumForBranch(const SubstitutionMapping &smap, size_t branchIndex)
Sum all substitutions for each type of a given branch (specified by its index).
static double computeNormForSite(const SubstitutionMapping &smap, size_t siteIndex)
Compute the norm of a substitution vector for a given position (specified by its index).
Data storage class for probabilistic substitution mappings.
General interface for storing mapping data.
The SubstitutionRegister interface.
static ProbabilisticSubstitutionMapping * computeSubstitutionVectorsMarginal(const DRTreeLikelihood &drtl, SubstitutionCount &substitutionCount, bool verbose=true)
Compute the substitutions vectors for a particular dataset using the double-recursive likelihood comp...
static std::vector< std::vector< double > > getRelativeCountsPerBranch(DRTreeLikelihood &drtl, const std::vector< int > &ids, SubstitutionModel *model, const SubstitutionRegister &reg, bool stationarity=true, double threshold=-1)
Returns the counts relative to the frequency of the states in case of non-stationarity.
static ProbabilisticSubstitutionMapping * computeSubstitutionVectorsNoAveragingMarginal(const DRTreeLikelihood &drtl, SubstitutionCount &substitutionCount, bool verbose=true)
Compute the substitutions vectors for a particular dataset using the double-recursive likelihood comp...
static void outputIndividualCountsPerBranchPerSite(const std::string &filenamePrefix, DRTreeLikelihood &drtl, const std::vector< int > &ids, SubstitutionModel *model, const SubstitutionRegister &reg)
Output individual counts par branch per site, in files.
Computes the probability that at least one jump occured on a branch, given the initial and final stat...
static std::vector< std::vector< double > > getNormalizedCountsPerBranch(DRTreeLikelihood &drtl, const std::vector< int > &ids, SubstitutionModel *model, SubstitutionModel *nullModel, const SubstitutionRegister &reg, bool verbose=true)
Returns the counts normalized by a null model.
The SubstitutionsCount interface.
static std::vector< double > computeSumForSite(const SubstitutionMapping &smap, size_t siteIndex)
Sum all substitutions for each type of a given site (specified by its index).
static std::vector< double > computeTotalSubstitutionVectorForSite(const SubstitutionMapping &smap, size_t siteIndex)
Sum all type of substitutions for each branch of a given position (specified by its index)...
Provide methods to compute substitution mappings.
static std::vector< std::vector< double > > getNormalizationsPerBranch(DRTreeLikelihood &drtl, const std::vector< int > &ids, const SubstitutionModel *nullModel, const SubstitutionRegister &reg, bool verbose=true)
Returns the normalization factors due to the null model on each branch, for each register.
Interface for double-recursive (DR) implementation of the likelihood computation. ...
static void readFromStream(std::istream &in, ProbabilisticSubstitutionMapping &substitutions, size_t type)
Read the substitutions vectors from a stream.
static std::vector< std::vector< double > > getCountsPerBranch(DRTreeLikelihood &drtl, const std::vector< int > &ids, SubstitutionModel *model, const SubstitutionRegister &reg, double threshold=-1, bool verbose=true)
Returns the counts on each branch.
static void outputTotalCountsPerBranchPerSite(std::string &filename, DRTreeLikelihood &drtl, const std::vector< int > &ids, SubstitutionModel *model, const SubstitutionRegister &reg)
Output the sum of the counts par branch per site, in a file.
static void writeToStream(const ProbabilisticSubstitutionMapping &substitutions, const SiteContainer &sites, size_t type, std::ostream &out)
Write the substitutions vectors to a stream.
static ProbabilisticSubstitutionMapping * computeSubstitutionVectors(const DRTreeLikelihood &drtl, SubstitutionCount &substitutionCount, bool verbose=true)
Compute the substitutions vectors for a particular dataset using the double-recursive likelihood comp...