1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
//
// File: bppTreeDraw.cpp
// Created by: Julien Dutheil
// Created on: Jul Tue 21 13:40 2009
//
/*
Copyright or © or Copr. Bio++ Development Team
This software is a computer program whose purpose is to draw phylogenies.
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
*/
// From the STL:
#include <iostream>
#include <iomanip>
using namespace std;
// From bpp-core:
#include <Bpp/Version.h>
#include <Bpp/App/BppApplication.h>
#include <Bpp/App/ApplicationTools.h>
#include <Bpp/Text/KeyvalTools.h>
#include <Bpp/Graphics/Svg/SvgGraphicDevice.h>
#include <Bpp/Graphics/Latex/PgfGraphicDevice.h>
#include <Bpp/Graphics/Fig/XFigGraphicDevice.h>
// From bpp-phyl:
#include <Bpp/Phyl/Tree.h>
#include <Bpp/Phyl/App/PhylogeneticsApplicationTools.h>
#include <Bpp/Phyl/Graphics/PhylogramPlot.h>
#include <Bpp/Phyl/Graphics/CladogramPlot.h>
#include <Bpp/Phyl/Graphics/TreeDrawingDisplayControler.h>
using namespace bpp;
/******************************************************************************/
void help()
{
(*ApplicationTools::message << "__________________________________________________________________________").endLine();
(*ApplicationTools::message << "bpptreedraw parameter1_name=parameter1_value parameter2_name=parameter2_value").endLine();
(*ApplicationTools::message << " ... param=option_file").endLine();
(*ApplicationTools::message).endLine();
(*ApplicationTools::message << " Refer to the Bio++ Program Suite Manual for a list of available options.").endLine();
(*ApplicationTools::message << "__________________________________________________________________________").endLine();
}
int main(int args, char ** argv)
{
cout << "******************************************************************" << endl;
cout << "* Bio++ Tree Drawing program, version " << BPP_VERSION << ". *" << endl;
cout << "* *" << endl;
cout << "* Authors: J. Dutheil Last Modif. " << BPP_REL_DATE << " *" << endl;
cout << "******************************************************************" << endl;
cout << endl;
if (args == 1)
{
help();
return 0;
}
try {
BppApplication bpptreedraw(args, argv, "BppTreeDraw");
bpptreedraw.startTimer();
// Get the tree to plot:
Tree* tree = PhylogeneticsApplicationTools::getTree(bpptreedraw.getParams());
ApplicationTools::displayResult("Number of leaves", TextTools::toString(tree->getNumberOfLeaves()));
// Get the graphic device:
GraphicDevice* gd = 0;
string outputPath = ApplicationTools::getAFilePath("output.drawing.file", bpptreedraw.getParams(), true, false, "", false);
ofstream file(outputPath.c_str(), ios::out);
string graphicTypeCmd = ApplicationTools::getStringParameter("output.drawing.format", bpptreedraw.getParams(), "Svg");
string graphicType;
map<string, string> graphicTypeArgs;
KeyvalTools::parseProcedure(graphicTypeCmd, graphicType, graphicTypeArgs);
if (graphicType == "Svg")
{
gd = new SvgGraphicDevice(file);
}
else if (graphicType == "Inkscape")
{
gd = new SvgGraphicDevice(file, true);
}
else if (graphicType == "Xfig")
{
gd = new XFigGraphicDevice(file);
dynamic_cast<XFigGraphicDevice *>(gd)->setFontFlag(XFigGraphicDevice::FONTFLAG_POSTSCRIPT);
}
else if (graphicType == "Pgf")
{
gd = new PgfGraphicDevice(file, 0.045);
}
else throw Exception("Unknown output format: " + graphicType);
// Get the tree plotter:
TreeDrawing* td = 0;
string plotTypeCmd = ApplicationTools::getStringParameter("output.drawing.plot", bpptreedraw.getParams(), "Cladogram");
string plotType;
map<string, string> plotTypeArgs;
KeyvalTools::parseProcedure(plotTypeCmd, plotType, plotTypeArgs);
if (plotType == "Cladogram")
{
td = new CladogramPlot();
}
else if (plotType == "Phylogram")
{
td = new PhylogramPlot();
}
else throw Exception("Unknown output format: " + plotType);
td->setTree(tree);
ApplicationTools::displayResult("Plot type", plotType);
double xunit = ApplicationTools::getDoubleParameter("xu", plotTypeArgs, 10);
double yunit = ApplicationTools::getDoubleParameter("yu", plotTypeArgs, 10);
td->setXUnit(xunit);
td->setYUnit(yunit);
string hOrientation = ApplicationTools::getStringParameter("direction.h", plotTypeArgs, "left2right");
if (hOrientation == "left2right")
{
dynamic_cast<AbstractDendrogramPlot*>(td)->setHorizontalOrientation(AbstractDendrogramPlot::ORIENTATION_LEFT_TO_RIGHT);
}
else if (hOrientation == "right2left")
{
dynamic_cast<AbstractDendrogramPlot*>(td)->setHorizontalOrientation(AbstractDendrogramPlot::ORIENTATION_RIGHT_TO_LEFT);
}
else throw Exception("Unknown orientation option: " + hOrientation);
string vOrientation = ApplicationTools::getStringParameter("direction.v", plotTypeArgs, "top2bottom");
if (vOrientation == "top2bottom")
{
dynamic_cast<AbstractDendrogramPlot*>(td)->setVerticalOrientation(AbstractDendrogramPlot::ORIENTATION_TOP_TO_BOTTOM);
}
else if (vOrientation == "bottom2top")
{
dynamic_cast<AbstractDendrogramPlot*>(td)->setVerticalOrientation(AbstractDendrogramPlot::ORIENTATION_BOTTOM_TO_TOP);
}
else throw Exception("Unknown orientation option: " + vOrientation);
//Plotting option:
TreeDrawingSettings tds;
BasicTreeDrawingDisplayControler* controler = new BasicTreeDrawingDisplayControler(&tds);
controler->registerTreeDrawing(td);
bool drawLeafNames = ApplicationTools::getBooleanParameter("draw.leaves", plotTypeArgs, true);
bool drawNodesId = ApplicationTools::getBooleanParameter("draw.ids" , plotTypeArgs, false);
bool drawBranchLengths = ApplicationTools::getBooleanParameter("draw.brlen" , plotTypeArgs, false);
bool drawBootstrapValues = ApplicationTools::getBooleanParameter("draw.bs" , plotTypeArgs, false);
controler->enableListener(controler->PROPERTY_LEAF_NAMES, drawLeafNames);
controler->enableListener(controler->PROPERTY_NODE_IDS, drawNodesId);
controler->enableListener(controler->PROPERTY_BRANCH_LENGTHS, drawBranchLengths);
controler->enableListener(controler->PROPERTY_BOOTSTRAP_VALUES, drawBootstrapValues);
ApplicationTools::displayBooleanResult("Draw leaf names" , drawLeafNames);
ApplicationTools::displayBooleanResult("Draw node ids" , drawNodesId);
ApplicationTools::displayBooleanResult("Draw branch lengths" , drawBranchLengths);
ApplicationTools::displayBooleanResult("Draw bootstrap values", drawBootstrapValues);
//Now draw the tree:
gd->begin();
td->plot(*gd);
gd->end();
//Finishing things:
file.close();
delete controler;
delete tree;
delete td;
delete gd;
bpptreedraw.done();
}
catch(exception & e)
{
cout << e.what() << endl;
return 1;
}
return 0;
}
|