void writeToStream (const ValueUnion& data, OutputStream& output) const override { output.writeCompressedInt (1 + (int) data.binaryValue->getSize()); output.writeByte (varMarker_Binary); output << *data.binaryValue; }
void writeToStream (const ValueUnion& data, OutputStream& output) const override { output.writeCompressedInt (1); output.writeByte (data.boolValue ? (char) varMarker_BoolTrue : (char) varMarker_BoolFalse); }
void writeToStream (const ValueUnion&, OutputStream& output) const override { jassertfalse; // Can't write an object to a stream! output.writeCompressedInt (0); }
void writeToStream (const ValueUnion& data, OutputStream& output) const override { output.writeCompressedInt (9); output.writeByte (varMarker_Int64); output.writeInt64 (data.int64Value); }
void writeToStream (const ValueUnion& data, OutputStream& output) const override { output.writeCompressedInt (9); output.writeByte (varMarker_Double); output.writeDouble (data.doubleValue); }
void POVMS_Object::Write(OutputStream& stream, bool append, bool compress) { POVMSType encoding = kPOVMSRawStreamEncoding; POVMSStream headerstream[16]; POVMSStream *objectstream = NULL; POVMSStream *compressedstream = NULL; int maxheadersize = 0; int maxobjectsize = 0; int objectsize = 0; int datasize = 0; try { objectsize = POVMSStream_Size(&data); if(objectsize == 0) throw POV_EXCEPTION_CODE(pov_base::kNullPointerErr); if(append == false) { datasize = 0; maxheadersize = 12; // header datasize += POVMSStream_WriteString("POVRAYMS", headerstream + datasize, &maxheadersize); // header 8 byte datasize += POVMSStream_WriteInt(0x0370, headerstream + datasize, &maxheadersize); // version 4 byte if(!stream.write((void *)headerstream, datasize)) throw POV_EXCEPTION_CODE(pov_base::kFileDataErr); } objectstream = new POVMSStream[objectsize]; maxobjectsize = objectsize; (void)POVMSStream_Write(&data, objectstream, &maxobjectsize); #ifdef POVMS_COMPRESSION_ENABLED if(compress == true) { compressedstream = new POVMSStream[objectsize * 2]; // compress stream data uLongf destlen = (uLongf)(objectsize * 2); if(compress2((Bytef *)(compressedstream), &destlen, (Bytef *)(objectstream), (uLongf)(objectsize), Z_BEST_COMPRESSION) != Z_OK) throw POV_EXCEPTION_CODE(pov_base::kCannotHandleDataErr); datasize = 0; maxheadersize = 12; // header datasize += POVMSStream_WriteInt((POVMSInt)(destlen), headerstream + datasize, &maxheadersize); // data size 4 byte datasize += POVMSStream_WriteType(kPOVMSGZipStreamEncoding, headerstream + datasize, &maxheadersize); // encoding 4 byte datasize += POVMSStream_WriteInt(objectsize, headerstream + datasize, &maxheadersize); // object size 4 byte if(!stream.write((void *)headerstream, datasize)) throw POV_EXCEPTION_CODE(pov_base::kFileDataErr); if(!stream.write((void *)compressedstream, (int)(destlen))) // data x byte throw POV_EXCEPTION_CODE(pov_base::kFileDataErr); } else #endif { datasize = 0; maxheadersize = 8; // header datasize += POVMSStream_WriteInt(objectsize, headerstream + datasize, &maxheadersize); // object size 4 byte datasize += POVMSStream_WriteType(kPOVMSRawStreamEncoding, headerstream + datasize, &maxheadersize); // encoding 4 byte if(!stream.write((void *)headerstream, datasize)) throw POV_EXCEPTION_CODE(pov_base::kFileDataErr); if(!stream.write((void *)objectstream, objectsize)) // object x byte throw POV_EXCEPTION_CODE(pov_base::kFileDataErr); } if(objectstream != NULL) delete[] objectstream; objectstream = NULL; if(compressedstream != NULL) delete[] compressedstream; compressedstream = NULL; } catch(...) { if(objectstream != NULL) delete[] objectstream; if(compressedstream != NULL) delete[] compressedstream; throw; } }
StandardError::Redirection::Redirection ( OutputStream& output ) : myPredecessor(set(output.handle())) { }
void writeToStream (const ValueUnion&, OutputStream& output) const { output.writeCompressedInt (0); }
inline void write (OutputStream& output) { output.write (values, 2); }
void writeToStream (const ValueUnion& data, OutputStream& output) const { output.writeCompressedInt (5); output.writeByte (varMarker_Int); output.writeInt (data.intValue); }
void writeToStream (const ValueUnion&, OutputStream& output) const { jassertfalse; // Can't write a method to a stream! output.writeCompressedInt (0); }
void Definition::Dump(OutputStream& s, int level, bool fLast) { if(m_predefined) return; CStringW tabs(' ', level*4); CStringW str = tabs; if(m_predefined) str += '?'; if(m_priority == PLow) str += '*'; else if(m_priority == PHigh) str += '!'; if(!IsTypeUnknown() && !m_autotype) str += m_type; if(!IsNameUnknown()) str += '#' + m_name; str += ':'; s.PutString(L"%s", str); if(!m_nodes.IsEmpty()) { POSITION pos = m_nodes.GetHeadPosition(); while(pos) { Node* pNode = m_nodes.GetNext(pos); if(Reference* pRef = dynamic_cast<Reference*>(pNode)) { pRef->Dump(s, level, fLast); } else { ASSERT(!pNode->IsNameUnknown()); s.PutString(L" %s", pNode->m_name); } } s.PutString(L";\n"); if(!fLast && (!m_nodes.IsEmpty() || level == 0)) s.PutString(L"\n"); } else if(m_status == string) { CStringW str = m_value; str.Replace(L"\"", L"\\\""); s.PutString(L" \"%s\";\n", str); } else if(m_status == number) { CStringW str = m_value; if(!m_unit.IsEmpty()) str += m_unit; s.PutString(L" %s;\n", str); } else if(m_status == boolean) { s.PutString(L" %s;\n", m_value); } else if(m_status == block) { s.PutString(L" {%s};\n", m_value); } else { s.PutString(L" null;\n"); } }
void Palace::save(OutputStream& stream) const { StructureBase::save(stream); stream.writeSint32(specialWeaponTimer); }
void Path::writePathToStream (OutputStream& dest) const { dest.writeByte (useNonZeroWinding ? 'n' : 'z'); size_t i = 0; while (i < numElements) { const float type = data.elements [i++]; if (type == moveMarker) { dest.writeByte ('m'); dest.writeFloat (data.elements [i++]); dest.writeFloat (data.elements [i++]); } else if (type == lineMarker) { dest.writeByte ('l'); dest.writeFloat (data.elements [i++]); dest.writeFloat (data.elements [i++]); } else if (type == quadMarker) { dest.writeByte ('q'); dest.writeFloat (data.elements [i++]); dest.writeFloat (data.elements [i++]); dest.writeFloat (data.elements [i++]); dest.writeFloat (data.elements [i++]); } else if (type == cubicMarker) { dest.writeByte ('b'); dest.writeFloat (data.elements [i++]); dest.writeFloat (data.elements [i++]); dest.writeFloat (data.elements [i++]); dest.writeFloat (data.elements [i++]); dest.writeFloat (data.elements [i++]); dest.writeFloat (data.elements [i++]); } else if (type == closeSubPathMarker) { dest.writeByte ('c'); } } dest.writeByte ('e'); // marks the end-of-path }
int main(int args, char ** argv) { cout << "******************************************************************" << endl; cout << "* Bio++ Distance Methods, version 2.2.0 *" << endl; cout << "* Author: J. Dutheil Created 05/05/07 *" << endl; cout << "* Last Modif. 04/02/15 *" << endl; cout << "******************************************************************" << endl; cout << endl; if(args == 1) { help(); return 0; } try { BppApplication bppdist(args, argv, "BppDist"); bppdist.startTimer(); Alphabet* alphabet = SequenceApplicationTools::getAlphabet(bppdist.getParams(), "", false); auto_ptr<GeneticCode> gCode; CodonAlphabet* codonAlphabet = dynamic_cast<CodonAlphabet*>(alphabet); if (codonAlphabet) { string codeDesc = ApplicationTools::getStringParameter("genetic_code", bppdist.getParams(), "Standard", "", true, true); ApplicationTools::displayResult("Genetic Code", codeDesc); gCode.reset(SequenceApplicationTools::getGeneticCode(codonAlphabet->getNucleicAlphabet(), codeDesc)); } VectorSiteContainer* allSites = SequenceApplicationTools::getSiteContainer(alphabet, bppdist.getParams()); VectorSiteContainer* sites = SequenceApplicationTools::getSitesToAnalyse(* allSites, bppdist.getParams()); delete allSites; ApplicationTools::displayResult("Number of sequences", TextTools::toString(sites->getNumberOfSequences())); ApplicationTools::displayResult("Number of sites", TextTools::toString(sites->getNumberOfSites())); SubstitutionModel* model = PhylogeneticsApplicationTools::getSubstitutionModel(alphabet, gCode.get(), sites, bppdist.getParams()); DiscreteDistribution* rDist = 0; if (model->getNumberOfStates() > model->getAlphabet()->getSize()) { //Markov-modulated Markov model! rDist = new ConstantRateDistribution(); } else { rDist = PhylogeneticsApplicationTools::getRateDistribution(bppdist.getParams()); } DistanceEstimation distEstimation(model, rDist, sites, 1, false); string method = ApplicationTools::getStringParameter("method", bppdist.getParams(), "nj"); ApplicationTools::displayResult("Tree reconstruction method", method); TreeTemplate<Node>* tree; AgglomerativeDistanceMethod* distMethod = 0; if(method == "wpgma") { PGMA* wpgma = new PGMA(true); distMethod = wpgma; } else if(method == "upgma") { PGMA* upgma = new PGMA(false); distMethod = upgma; } else if(method == "nj") { NeighborJoining* nj = new NeighborJoining(); nj->outputPositiveLengths(true); distMethod = nj; } else if(method == "bionj") { BioNJ* bionj = new BioNJ(); bionj->outputPositiveLengths(true); distMethod = bionj; } else throw Exception("Unknown tree reconstruction method."); string type = ApplicationTools::getStringParameter("optimization.method", bppdist.getParams(), "init"); ApplicationTools::displayResult("Model parameters estimation method", type); if (type == "init") type = OptimizationTools::DISTANCEMETHOD_INIT; else if (type == "pairwise") type = OptimizationTools::DISTANCEMETHOD_PAIRWISE; else if (type == "iterations") type = OptimizationTools::DISTANCEMETHOD_ITERATIONS; else throw Exception("Unknown parameter estimation procedure '" + type + "'."); unsigned int optVerbose = ApplicationTools::getParameter<unsigned int>("optimization.verbose", bppdist.getParams(), 2); string mhPath = ApplicationTools::getAFilePath("optimization.message_handler", bppdist.getParams(), false, false); OutputStream* messenger = (mhPath == "none") ? 0 : (mhPath == "std") ? ApplicationTools::message : new StlOutputStream(new ofstream(mhPath.c_str(), ios::out)); ApplicationTools::displayResult("Message handler", mhPath); string prPath = ApplicationTools::getAFilePath("optimization.profiler", bppdist.getParams(), false, false); OutputStream* profiler = (prPath == "none") ? 0 : (prPath == "std") ? ApplicationTools::message : new StlOutputStream(new ofstream(prPath.c_str(), ios::out)); if(profiler) profiler->setPrecision(20); ApplicationTools::displayResult("Profiler", prPath); // Should I ignore some parameters? ParameterList allParameters = model->getParameters(); allParameters.addParameters(rDist->getParameters()); ParameterList parametersToIgnore; string paramListDesc = ApplicationTools::getStringParameter("optimization.ignore_parameter", bppdist.getParams(), "", "", true, false); bool ignoreBrLen = false; StringTokenizer st(paramListDesc, ","); while (st.hasMoreToken()) { try { string param = st.nextToken(); if (param == "BrLen") ignoreBrLen = true; else { if (allParameters.hasParameter(param)) { Parameter* p = &allParameters.getParameter(param); parametersToIgnore.addParameter(*p); } else ApplicationTools::displayWarning("Parameter '" + param + "' not found."); } } catch (ParameterNotFoundException& pnfe) { ApplicationTools::displayError("Parameter '" + pnfe.getParameter() + "' not found, and so can't be ignored!"); } } unsigned int nbEvalMax = ApplicationTools::getParameter<unsigned int>("optimization.max_number_f_eval", bppdist.getParams(), 1000000); ApplicationTools::displayResult("Max # ML evaluations", TextTools::toString(nbEvalMax)); double tolerance = ApplicationTools::getDoubleParameter("optimization.tolerance", bppdist.getParams(), .000001); ApplicationTools::displayResult("Tolerance", TextTools::toString(tolerance)); //Here it is: ofstream warn("warnings", ios::out); ApplicationTools::warning = new StlOutputStreamWrapper(&warn); tree = OptimizationTools::buildDistanceTree(distEstimation, *distMethod, parametersToIgnore, !ignoreBrLen, type, tolerance, nbEvalMax, profiler, messenger, optVerbose); warn.close(); delete ApplicationTools::warning; ApplicationTools::warning = ApplicationTools::message; string matrixPath = ApplicationTools::getAFilePath("output.matrix.file", bppdist.getParams(), false, false, "", false); if (matrixPath != "none") { ApplicationTools::displayResult("Output matrix file", matrixPath); string matrixFormat = ApplicationTools::getAFilePath("output.matrix.format", bppdist.getParams(), false, false, "", false); string format = ""; bool extended = false; std::map<std::string, std::string> unparsedArguments_; KeyvalTools::parseProcedure(matrixFormat, format, unparsedArguments_); if (unparsedArguments_.find("type") != unparsedArguments_.end()) { if (unparsedArguments_["type"] == "extended") { extended = true; } else if (unparsedArguments_["type"] == "classic") extended = false; else ApplicationTools::displayWarning("Argument '" + unparsedArguments_["type"] + "' for parameter 'Phylip#type' is unknown. " + "Default used instead: not extended."); } else ApplicationTools::displayWarning("Argument 'Phylip#type' not found. Default used instead: not extended."); ODistanceMatrix* odm = IODistanceMatrixFactory().createWriter(IODistanceMatrixFactory::PHYLIP_FORMAT, extended); odm->write(*distEstimation.getMatrix(), matrixPath, true); delete odm; } PhylogeneticsApplicationTools::writeTree(*tree, bppdist.getParams()); //Output some parameters: if (type == OptimizationTools::DISTANCEMETHOD_ITERATIONS) { // Write parameters to screen: ParameterList parameters = model->getParameters(); for (unsigned int i = 0; i < parameters.size(); i++) { ApplicationTools::displayResult(parameters[i].getName(), TextTools::toString(parameters[i].getValue())); } parameters = rDist->getParameters(); for (unsigned int i = 0; i < parameters.size(); i++) { ApplicationTools::displayResult(parameters[i].getName(), TextTools::toString(parameters[i].getValue())); } // Write parameters to file: string parametersFile = ApplicationTools::getAFilePath("output.estimates", bppdist.getParams(), false, false); if (parametersFile != "none") { ofstream out(parametersFile.c_str(), ios::out); parameters = model->getParameters(); for (unsigned int i = 0; i < parameters.size(); i++) { out << parameters[i].getName() << " = " << parameters[i].getValue() << endl; } parameters = rDist->getParameters(); for (unsigned int i = 0; i < parameters.size(); i++) { out << parameters[i].getName() << " = " << parameters[i].getValue() << endl; } out.close(); } } //Bootstrap: unsigned int nbBS = ApplicationTools::getParameter<unsigned int>("bootstrap.number", bppdist.getParams(), 0); if(nbBS > 0) { ApplicationTools::displayResult("Number of bootstrap samples", TextTools::toString(nbBS)); bool approx = ApplicationTools::getBooleanParameter("bootstrap.approximate", bppdist.getParams(), true); ApplicationTools::displayResult("Use approximate bootstrap", TextTools::toString(approx ? "yes" : "no")); if(approx) { type = OptimizationTools::DISTANCEMETHOD_INIT; parametersToIgnore = allParameters; ignoreBrLen = true; } bool bootstrapVerbose = ApplicationTools::getBooleanParameter("bootstrap.verbose", bppdist.getParams(), false, "", true, false); string bsTreesPath = ApplicationTools::getAFilePath("bootstrap.output.file", bppdist.getParams(), false, false); ofstream *out = NULL; if(bsTreesPath != "none") { ApplicationTools::displayResult("Bootstrap trees stored in file", bsTreesPath); out = new ofstream(bsTreesPath.c_str(), ios::out); } Newick newick; vector<Tree *> bsTrees(nbBS); ApplicationTools::displayTask("Bootstrapping", true); for(unsigned int i = 0; i < nbBS; i++) { ApplicationTools::displayGauge(i, nbBS-1, '='); VectorSiteContainer * sample = SiteContainerTools::bootstrapSites(*sites); if(approx) model->setFreqFromData(*sample); distEstimation.setData(sample); bsTrees[i] = OptimizationTools::buildDistanceTree( distEstimation, *distMethod, parametersToIgnore, ignoreBrLen, type, tolerance, nbEvalMax, NULL, NULL, (bootstrapVerbose ? 1 : 0) ); if(out && i == 0) newick.write(*bsTrees[i], bsTreesPath, true); if(out && i > 0) newick.write(*bsTrees[i], bsTreesPath, false); delete sample; } if(out) out->close(); if(out) delete out; ApplicationTools::displayTaskDone(); ApplicationTools::displayTask("Compute bootstrap values"); TreeTools::computeBootstrapValues(*tree, bsTrees); ApplicationTools::displayTaskDone(); for(unsigned int i = 0; i < nbBS; i++) delete bsTrees[i]; //Write resulting tree: PhylogeneticsApplicationTools::writeTree(*tree, bppdist.getParams()); } delete alphabet; delete sites; delete distMethod; delete tree; bppdist.done();} catch(exception & e) { cout << e.what() << endl; return 1; } return 0; }
inline void write (OutputStream& output) { output.writeByte (minValue); output.writeByte (maxValue); output.write ((void*)&colour, sizeof(Colour)); }