bpp-phyl  2.3.0
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 {
64 {
65 public:
68 
69 public:
81  const DRTreeLikelihood& drtl,
82  SubstitutionCount& substitutionCount,
83  bool verbose = true) throw (Exception)
84  {
85  std::vector<int> nodeIds;
86  return computeSubstitutionVectors(drtl, nodeIds, substitutionCount, verbose);
87  }
88 
103  const DRTreeLikelihood& drtl,
104  const std::vector<int>& nodeIds,
105  SubstitutionCount& substitutionCount,
106  bool verbose = true) throw (Exception);
107 
109  const DRTreeLikelihood& drtl,
110  const SubstitutionModelSet& modelSet,
111  const std::vector<int>& nodeIds,
112  SubstitutionCount& substitutionCount,
113  bool verbose = true) throw (Exception);
114 
136  const DRTreeLikelihood& drtl,
137  SubstitutionCount& substitutionCount,
138  bool verbose = true) throw (Exception);
139 
140 
160  const DRTreeLikelihood& drtl,
161  SubstitutionCount& substitutionCount,
162  bool verbose = true) throw (Exception);
163 
164 
181  const DRTreeLikelihood& drtl,
182  SubstitutionCount& substitutionCount,
183  bool verbose = true) throw (Exception);
184 
185 
194  const DRTreeLikelihood& drtl,
195  bool verbose = true) throw (Exception)
196  {
197  OneJumpSubstitutionCount ojsm(0);
198  return computeSubstitutionVectors(drtl, drtl.getTree().getNodesId(), ojsm, 0);
199  }
200 
201 
213  static void writeToStream(
214  const ProbabilisticSubstitutionMapping& substitutions,
215  const SiteContainer& sites,
216  size_t type,
217  std::ostream& out)
218  throw (IOException);
219 
220 
229  static void readFromStream(std::istream& in, ProbabilisticSubstitutionMapping& substitutions, size_t type)
230  throw (IOException);
231 
232 
240  static std::vector<double> computeTotalSubstitutionVectorForSitePerBranch(const SubstitutionMapping& smap, size_t siteIndex);
241 
249  static std::vector<double> computeTotalSubstitutionVectorForSitePerType(const SubstitutionMapping& smap, size_t siteIndex);
250 
262  static double computeNormForSite(const SubstitutionMapping& smap, size_t siteIndex);
263 
271  static std::vector<double> computeSumForBranch(const SubstitutionMapping& smap, size_t branchIndex);
272 
273 
281  static std::vector<double> computeSumForSite(const SubstitutionMapping& smap, size_t siteIndex);
282 
283 
296  static std::vector< std::vector<double> > getCountsPerBranch(
297  DRTreeLikelihood& drtl,
298  const std::vector<int>& ids,
299  SubstitutionModel* model,
300  const SubstitutionRegister& reg,
301  double threshold = -1,
302  bool verbose = true);
303 
304  static std::vector< std::vector<double> > getCountsPerBranch(
305  DRTreeLikelihood& drtl,
306  const std::vector<int>& ids,
307  const SubstitutionModelSet& modelSet,
308  const SubstitutionRegister& reg,
309  double threshold = -1,
310  bool verbose = true);
311 
312 
325  static std::vector< std::vector<double> > getNormalizationsPerBranch(
326  DRTreeLikelihood& drtl,
327  const std::vector<int>& ids,
328  const SubstitutionModel* nullModel,
329  const SubstitutionRegister& reg,
330  bool verbose = true);
331 
332 
345  static std::vector< std::vector<double> > getNormalizationsPerBranch(
346  DRTreeLikelihood& drtl,
347  const std::vector<int>& ids,
348  const SubstitutionModelSet* nullModelSet,
349  const SubstitutionRegister& reg,
350  bool verbose = true);
351 
352 
363  static std::vector< std::vector<double> > getNormalizedCountsPerBranch(
364  DRTreeLikelihood& drtl,
365  const std::vector<int>& ids,
366  SubstitutionModel* model,
367  SubstitutionModel* nullModel,
368  const SubstitutionRegister& reg,
369  bool verbose = true);
370 
381  static std::vector< std::vector<double> > getNormalizedCountsPerBranch(
382  DRTreeLikelihood& drtl,
383  const std::vector<int>& ids,
384  SubstitutionModelSet* modelSet,
385  SubstitutionModelSet* nullModelSet,
386  const SubstitutionRegister& reg,
387  bool verbose = true);
388 
406  static std::vector< std::vector<double> > getRelativeCountsPerBranch(
407  DRTreeLikelihood& drtl,
408  const std::vector<int>& ids,
409  SubstitutionModel* model,
410  const SubstitutionRegister& reg,
411  double threshold = -1);
412 
425  std::string& filename,
426  DRTreeLikelihood& drtl,
427  const std::vector<int>& ids,
428  SubstitutionModel* model,
429  const SubstitutionRegister& reg);
430 
443  std::string& filename,
444  DRTreeLikelihood& drtl,
445  const std::vector<int>& ids,
446  SubstitutionModel* model,
447  const SubstitutionRegister& reg);
448 
449 
461  const std::string& filenamePrefix,
462  DRTreeLikelihood& drtl,
463  const std::vector<int>& ids,
464  SubstitutionModel* model,
465  const SubstitutionRegister& reg);
466 };
467 } // end of namespace bpp.
468 
469 #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 std::vector< double > computeTotalSubstitutionVectorForSitePerType(const SubstitutionMapping &smap, size_t siteIndex)
Sum all type of substitutions for each type of a given position (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.
virtual std::vector< int > getNodesId() const =0
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 void outputTotalCountsPerTypePerSite(std::string &filename, DRTreeLikelihood &drtl, const std::vector< int > &ids, SubstitutionModel *model, const SubstitutionRegister &reg)
Output the sum over all branches of the counts per type per site, in a file.
static std::vector< double > computeTotalSubstitutionVectorForSitePerBranch(const SubstitutionMapping &smap, size_t siteIndex)
Sum all type of substitutions for each branch of a given position (specified by its index)...
static std::vector< std::vector< double > > getRelativeCountsPerBranch(DRTreeLikelihood &drtl, const std::vector< int > &ids, SubstitutionModel *model, const SubstitutionRegister &reg, 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...
virtual const Tree & getTree() const =0
Get the tree (topology and branch lengths).
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).
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 over all types of the counts per 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...