/** ** 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 SignalMeans.cpp ** ** \brief Implementation of the I/O API for signal means data type ( _all files). ** ** \author Mauricio Varea **/ #include #include #include #include "common/Exceptions.hh" #include "common/SignalMeans.hh" namespace casava { namespace common { SignalMeans::SignalMeans(const unsigned int lane, const unsigned int cycle) : lane_(lane) , cycle_(cycle) , intensities_(8) , baseCall_(5) { } SignalMeans::SignalMeans(const SignalMeans &ref) : lane_(ref.lane_) , cycle_(ref.cycle_) , intensities_(ref.intensities_) , baseCall_(ref.baseCall_) { } SignalMeans &SignalMeans::operator=(const SignalMeans &ref) { if (&ref != this) { lane_ = ref.lane_; cycle_ = ref.cycle_; intensities_ = ref.intensities_; baseCall_ = ref.baseCall_; } return *this; } bool SignalMeans::operator==(const SignalMeans &ref) const { return &ref == this || (lane_ == ref.lane_ && cycle_ == ref.cycle_ && intensities_ == ref.intensities_ && baseCall_ == ref.baseCall_); } bool SignalMeans::operator!=(const SignalMeans &ref) const { return !(ref == *this); } SignalMeans &SignalMeans::operator+=(const char &c) { switch(c) { case 'A': ++baseCall_[0]; break; case 'C': ++baseCall_[1]; break; case 'G': ++baseCall_[2]; break; case 'T': ++baseCall_[3]; break; case '.': ++baseCall_[4]; break; default: BOOST_THROW_EXCEPTION(CasavaException(EINVAL, (boost::format("Wrong format: '%c' is not a valid base") % c).str())); } return *this; } SignalMeans &SignalMeans::operator-=(const char &c) { switch(c) { case 'A': if (baseCall_[0]) --baseCall_[0]; break; case 'C': if (baseCall_[1]) --baseCall_[1]; break; case 'G': if (baseCall_[2]) --baseCall_[2]; break; case 'T': if (baseCall_[3]) --baseCall_[3]; break; case '.': if (baseCall_[4]) --baseCall_[4]; break; default: BOOST_THROW_EXCEPTION(CasavaException(EINVAL, (boost::format("Wrong format: '%c' is not a valid base") % c).str())); } return *this; } /*****************************************************************************/ std::ostream &operator<<(std::ostream &os, const SignalMeans &sm) { os.precision(1); os.setf(std::ios::fixed,std::ios::floatfield); putUnsignedInteger(os, sm.lane_); os.put('\t'); putUnsignedInteger(os, sm.cycle_); os.put('\t'); for (unsigned int i=0; i < 8; i++) { os << sm.intensities_[i]; os.put('\t'); } for (unsigned int j=0; j < 4; j++) { putUnsignedInteger(os, sm.baseCall_[j]); os.put('\t'); } putUnsignedInteger(os, sm.baseCall_[4]); os.put('\n'); // the delimiter for the end of a SignalMeans line return os; } std::istream &operator>>(std::istream &is, SignalMeans &sm) { getUnsignedInteger(is, sm.lane_, true); getUnsignedInteger(is, sm.cycle_, true); for (unsigned int i=0; i < 8; i++) { std::string sb; if (is >> sb) { sm.intensities_[i] = boost::lexical_cast(sb); } } is.ignore(); // this is a '\t' for (unsigned int j=0; j < 4; j++) { getUnsignedInteger(is, sm.baseCall_[j], true); } getUnsignedInteger(is, sm.baseCall_[4], false); is.ignore(); // this is a '\n' return is; } } // namespace common } // namespace casava