/** ** Copyright (c) 2010 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 RelOrient.cpp ** ** \brief Encapsulation of the concept of a read pair relative orientation. ** ** Encapsulation of the concept of a read pair relative orientation. ** ** \author Richard Shaw **/ /*****************************************************************************/ #include "common/Exceptions.hh" #include "common/RelOrient.hh" /*****************************************************************************/ namespace casava { namespace common { /*****************************************************************************/ using casava::common::CasavaException; /*****************************************************************************/ RelOrient::RelOrient() : myVal(Rp) { ; } /*****************************************************************************/ RelOrient::RelOrient(const std::string& relOrientStr) { if (relOrientStr == "Fm") { myVal = Fm; } else if (relOrientStr == "Fp") { myVal = Fp; } else if (relOrientStr == "Rm") { myVal = Rm; } else if (relOrientStr == "Rp") { myVal = Rp; } else { BOOST_THROW_EXCEPTION(CasavaException(EINVAL, "Unrecognised relative " "orientation " + relOrientStr)); } } /*****************************************************************************/ RelOrient::RelOrient(const long read1Pos, const Match::Strand& read1Strand, const long read2Pos, const Match::Strand& read2Strand) { const bool read1IsToLeft(read1Pos < read2Pos); if (read2Strand != read1Strand) { const Match::Strand leftStrand(read1IsToLeft ? read1Strand : read2Strand); myVal = ((leftStrand == Match::Forward) ? Rp : Rm); } else { myVal = ((read1IsToLeft == (read1Strand == Match::Forward)) ? Fp : Fm); } } /*****************************************************************************/ void RelOrient::operator=(const RelOrient& relOrient) { myVal = relOrient.myVal; } /*****************************************************************************/ bool RelOrient::operator==(const RelOrient& relOrient) const { return (relOrient.myVal == myVal); } const std::string RelOrient::string() const { switch (myVal) { case RelOrient::Fm: return "Fm"; case RelOrient::Fp: return "Fp"; case RelOrient::Rm: return "Rm"; case RelOrient::Rp: return "Rp"; default: BOOST_ASSERT(false && "Invalid RelOrient enum value"); } } /*****************************************************************************/ std::ostream& operator<<(std::ostream& ostrm, const RelOrient& relOrient) { switch (relOrient.myVal) { case RelOrient::Fm: ostrm << "Fm"; break; case RelOrient::Fp: ostrm << "Fp"; break; case RelOrient::Rm: ostrm << "Rm"; break; case RelOrient::Rp: ostrm << "Rp"; break; default: ostrm << "N/A"; } return ostrm; } /*****************************************************************************/ } // namespace common } // namespace casava /*****************************************************************************/