~ubuntu-branches/ubuntu/raring/libbpp-phyl/raring

« back to all changes in this revision

Viewing changes to test/test_nhx.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Dutheil
  • Date: 2011-06-09 11:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110609110000-yvx78svv6w7xxgph
Tags: upstream-2.0.2
Import upstream version 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// File: test_nhx.cpp
 
3
// Created by: Julien Dutheil
 
4
// Created on: Fri Dec 31 15:43 2010
 
5
//
 
6
 
 
7
/*
 
8
Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
 
9
 
 
10
This software is a computer program whose purpose is to provide classes
 
11
for numerical calculus. This file is part of the Bio++ project.
 
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
#include <Bpp/Phyl/TreeTemplate.h>
 
41
#include <Bpp/Phyl/TreeTemplateTools.h>
 
42
#include <Bpp/Phyl/Io/Nhx.h>
 
43
#include <string>
 
44
#include <vector>
 
45
#include <iostream>
 
46
 
 
47
using namespace bpp;
 
48
using namespace std;
 
49
 
 
50
int main() {
 
51
  //Get some leaf names:
 
52
  vector<string> leaves(5);
 
53
  for (size_t i = 0; i < leaves.size(); ++i)
 
54
    leaves[i] = "leaf" + TextTools::toString(i);
 
55
  
 
56
  //Generate a random tree, without branch lengths:
 
57
  TreeTemplate<Node>* tree = TreeTemplateTools::getRandomTree(leaves, true);
 
58
 
 
59
  //Now assign random properties:
 
60
  vector<Node*> nodes = tree->getNodes();
 
61
  for (size_t i = 0; i < nodes.size(); ++i) {
 
62
    nodes[i]->setDistanceToFather(RandomTools::giveRandomNumberBetweenZeroAndEntry(1.0));
 
63
    nodes[i]->setNodeProperty("GN", BppString("Gene" + TextTools::toString(i)));
 
64
    nodes[i]->setNodeProperty("AC", BppString("XXXXXX"));
 
65
    nodes[i]->setBranchProperty("B", Number<double>(floor(RandomTools::giveRandomNumberBetweenZeroAndEntry(100.) + 0.5)));
 
66
    nodes[i]->setBranchProperty("W", Number<int>(floor(RandomTools::giveRandomNumberBetweenZeroAndEntry(5.) + 0.5)));
 
67
  }
 
68
  
 
69
  //Convert tree to string and read it again:
 
70
  Nhx nhxParser(true);
 
71
  ofstream out("randomTree.nhx", ios::out);
 
72
  nhxParser.write(*tree, out);
 
73
  out.close();
 
74
  TreeTemplate<Node>* tree2 = nhxParser.read("randomTree.nhx");
 
75
  ofstream out2("randomTree2.nhx", ios::out);
 
76
  nhxParser.write(*tree2, out2);
 
77
  out2.close();
 
78
 
 
79
  delete tree;
 
80
  delete tree2;
 
81
  return 0;
 
82
}