/** ** 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 Alignment.hh ** ** \brief Declaration of the alignment-related data types. ** ** \author Come Raczy **/ #ifndef CASAVA_COMMON_ALIGNMENT_HH #define CASAVA_COMMON_ALIGNMENT_HH #include "common/Sequence.hh" namespace casava { namespace common { /** ** \brief A match for a read on a reference sequence. **/ class Match { public: /// \brief NM is used on on both reads of a shadow pair typedef enum { None, Forward, Reverse, NM } Strand; /** ** \brief Constructor ** ** \param chromosome either the actual chromosome, a magic value (QC, NM, ** RM), an empty string or the number of matches (ee:ss:dd, with number ** of exact matches, single error and double errors) ** \param contig ** \param position ** \param strand ** \param isValid required to distinguish a valid partner match at ** position 0 from an invalid partner match **/ Match(const std::string &chromosome = "", const std::string &contig = "", long position = 0, Strand strand = None, bool isValid = false); Match(const Match &match); /// \b The actual content of the field (either chromosome or diagnostic) const std::string& getChromosome() const { return chromosome_; } const std::string& getContig() const { return contig_; } long getPosition() const { return position_; } Strand getStrand() const { return strand_; } /// \b The actual content of the field (either chromosome or diagnostic) void setChromosome(const std::string &chromosome) { chromosome_ = chromosome; } void setContig(const std::string &contig) { contig_ = contig; } void setPosition(const long position) { position_ = position; } void setStrand(const Strand strand) { strand_ = strand; } void setNoMatch() { chromosome_ = "NM"; } bool getValidity() const; Match &operator=(const Match &match); bool operator==(const Match &match) const; bool operator!=(const Match &match) const; private: // Match chromosome should be split into several columns to distinguish between // the name of the chromosome match and the reason why there is no match std::string chromosome_; // Match contig whene there is a match on a chromosome split into contigs std::string contig_; // Match position (absolute or relative) long position_; // Match strand Strand strand_; // Was there a match? If not, write position as '' not '0'. bool isValid_; // Code indicating reason for non-match (in place of chr). // The match descriptor is left out because of the way the export // file is currently designed // std::string descriptor_; friend std::ostream &operator<<(std::ostream &os, const Match &match); friend std::istream &operator>>(std::istream &is, Match &match); }; /** ** @brief Write an object of type Match. **/ std::ostream &operator<<(std::ostream &os, const Match &match); /** ** @brief Read an object of type Match. **/ std::istream &operator>>(std::istream &is, Match &match); /** ** \brief Definition of an alignment for GERALD ** ** Collects all the information needed fr the export files. **/ class Alignment: public Sequence { public: Alignment(const Sequence &sequence = Sequence(), const casava::common::Match &readMatch = casava::common::Match(), const std::string &matchDescriptor = "", int singleReadScore = 0, const casava::common::Match &partnerMatch = casava::common::Match(), int pairedReadScore = 0, bool isPaired = false); Alignment(const Alignment &alignment); Alignment &operator=(const Alignment &alignment); bool operator ==(const Alignment &alignment) const; bool operator !=(const Alignment &alignment) const; const Sequence &getSequence() const { return *static_cast (this); } const Match &getMatch() const { return readMatch_; } const std::string& getChromosome() const { return readMatch_.getChromosome(); } const std::string& getContig() const { return readMatch_.getContig(); } long getPosition() const { return readMatch_.getPosition(); } Match::Strand getStrand() const { return readMatch_.getStrand(); } const std::string &getMatchDescriptor() const { return matchDescriptor_; } int getSingleReadScore() const { return singleReadScore_; } const Match &getPartnerMatch() const { return partnerMatch_; } int getPairedReadScore() const { return pairedReadScore_; } void setSequence(const Sequence &sequence) { Sequence::operator=(sequence); } void setMatch(const Match &match) { readMatch_ = match; } void setMatchDescriptor(const std::string &descriptor) { matchDescriptor_ = descriptor; } void setSingleReadScore(int score) { singleReadScore_ = score; } void setPartnerMatch(const Match &match) { partnerMatch_ = match; isPaired_ = true; } void setPairedReadScore(int score) { pairedReadScore_ = score; isPaired_ = true; } void setIsPaired(bool isPaired) { isPaired_ = isPaired; } private: // Coordinates of the match if any Match readMatch_; // Match descriptor. Kept out of the Match because it does not exist for the partner std::string matchDescriptor_; // Single read alignment score int singleReadScore_; /** ** \brief Coordinates of the partner read. ** ** Defined only if it is a paired read. Chromosome (resp. contig) ** is set only for paired reads, when the partner read aligns to ** a different chromosome (resp. contig). **/ Match partnerMatch_; // Paired read alignment score int pairedReadScore_; bool isPaired_; friend std::ostream &operator<<(std::ostream &os, const Alignment &alignment); friend std::istream &operator>>(std::istream &is, Alignment &alignment); }; /** ** @brief Write a complete object of type Alignment, including the delimiter. **/ std::ostream &operator<<(std::ostream &os, const Alignment &alignment); /** ** @brief Read a complete object of type Alignment, including the delimiter. **/ std::istream &operator>>(std::istream &is, Alignment &alignment); /** ** @brief An input stream specialized for alignments. **/ typedef Reader AlignmentReader; /** ** @brief An output stream specialized for alignments. **/ typedef Writer AlignmentWriter; } // namespace common } // namespace casava #endif // #ifndef CASAVA_COMMON_ALIGNMENT_HH