/** ** Copyright (c) 2007-2009 Illumina, Inc. ** ** This software is covered by the "Illumina Genome Analyzer Software ** License Agreement" and the "Illumina Source Code License Agreement", ** and certain third party copyright/licenses, and any user of this ** source file is bound by the terms therein (see accompanying files ** Illumina_Genome_Analyzer_Software_License_Agreement.pdf and ** Illumina_Source_Code_License_Agreement.pdf and third party ** copyright/license notices). ** ** This file is part of the Consensus Assessment of Sequence And VAriation ** (CASAVA) software package. ** ** \file QvalWriter.hh ** ** \brief Writes Qval files and other associated files (filter, position). ** ** \author Roman Petrovski **/ #ifndef CASAVA_IO_QVAL_WRITER_HH #define CASAVA_IO_QVAL_WRITER_HH #include #include #include #include #include #include "common/Exceptions.hh" #include "common/FastIo.hh" namespace casava { namespace io { namespace fs = boost::filesystem; namespace cc = casava::common; /** ** \brief ofstream storing position values cluster by cluster in text form. **/ class QvalWriter { public: typedef std::vector Qvals; QvalWriter(const fs::path &filePath) : filePath_(filePath) , os_(casava::common::CompressionFactory::get("gzip")) , currentCluster_(0) { if (fs::exists(filePath_)) { BOOST_THROW_EXCEPTION(cc::IoException(EPERM, "File already exists: " + filePath_.string())); } os_.open(filePath_.string().c_str()); if (!os_) { BOOST_THROW_EXCEPTION(cc::IoException(errno, "Couldn't open qval file: " + filePath_.string())); } } ~QvalWriter(){ } void put(const Qvals &qvals){ putQvals(qvals); } void putQvals(const Qvals &qvals){ std::copy(qvals.begin(), qvals.end(), std::ostream_iterator(os_, "\n")); if (!os_) { BOOST_THROW_EXCEPTION(casava::common::IoException(errno, "Failed to write data into: " + filePath_.string())); } ++currentCluster_; } void close() { os_.close(); } private: const fs::path filePath_; cc::Ofstream os_; unsigned int currentCluster_; QvalWriter(); QvalWriter(const QvalWriter &); QvalWriter &operator=(const QvalWriter &); }; } // namespce io } // namespace casava #endif // CASAVA_IO_QVAL_WRITER_HH