Output models in LaTex

From Bio++ Wiki
Jump to: navigation, search


Here is a small code to get the output of generators for LaTeX. For compilation, proceed:

g++ -lbpp-core -lbpp-seq -lbpp-phyl mod_latex.cpp -o mod_latex

and for usage:

mod_latex "alphabet=DNA" "model=GTR(a=3)"

<source lang="cpp">

// The SeqLib library:

  1. include <Bpp/Seq/Alphabet.all>
  2. include <Bpp/Seq/App/SequenceApplicationTools.h>

// The Phyllib library

  1. include <Bpp/App/BppApplication.h>
  2. include <Bpp/Phyl/App/PhylogeneticsApplicationTools.h>


// The STl library:

  1. include <cstdlib>
  2. include <iostream>

using namespace std;

using namespace bpp;

int main(int argc, char* argv[]) {

 VectorSiteContainer* sites=0;
 BppApplication bppml(argc, argv, "BppML");
 Alphabet* alphabet = SequenceApplicationTools::getAlphabet(bppml.getParams(), "", false, false);
 auto_ptr<GeneticCode> gCode;
 CodonAlphabet* codonAlphabet = dynamic_cast<CodonAlphabet*>(alphabet);
 if (codonAlphabet) {
   string codeDesc = ApplicationTools::getStringParameter("genetic_code", bppml.getParams(), "Standard", "", true, true);
   gCode.reset(SequenceApplicationTools::getGeneticCode(codonAlphabet->getNucleicAlphabet(), codeDesc));
 }
 
 SubstitutionModel* model=PhylogeneticsApplicationTools::getSubstitutionModel(alphabet,gCode.get(),sites,bppml.getParams(), "", true, true);
 unsigned int s=alphabet->getSize();
 
 cout << "\\begin{pmatrix}" << endl;
 for (unsigned int i=0;i<s;i++){
   for (unsigned int j=0;j<s-1;j++)
     cout << model->Qij(i,j) << " & ";
   cout << model->Qij(i,s-1) << " \\\\ " << endl;
 }
 
 cout << "\\end{pmatrix}" << endl;
 
 delete alphabet;
 delete model;

}


</source>