// -*- mode: c++; indent-tabs-mode: nil; -*- // // Copyright 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). // // /// \file #ifndef TAGALIGNER_H #define TAGALIGNER_H #include "variance/export.h" #include #include // Alignment type definitions typedef double ScoreType; typedef unsigned char NScoreType; typedef std::vector > DPMatrix; typedef std::vector > DPMatrixN; class TagAligner { public: TagAligner(const ScoreType mCost, const ScoreType mmCost, const ScoreType geCost, const ScoreType goCost, const char* const rSeq, const char* const tSeq, const char* const tqSeq) : refSeq(rSeq), tagSeq(tSeq), tagQualSeq(tqSeq), numMatches(-1), numMisMatches(-1), numInserts(-1), numDeletes(-1), numGaps(-1), matchDesc("-"), refAlnStart(-1), refAlnEnd(-1), tagAlnStart(-1), tagAlnEnd(-1), matchCost(mCost), misMatchCost(mmCost), gapExtendCost(geCost), gapOpenCost(goCost), xmax_(0), ymax_(0) {} TagAligner(const ScoreType mCost, const ScoreType mmCost, const ScoreType geCost, const ScoreType goCost ) : numMatches(-1), numMisMatches(-1), numInserts(-1), numDeletes(-1), numGaps(-1), matchDesc("-"), refAlnStart(-1), refAlnEnd(-1), tagAlnStart(-1), tagAlnEnd(-1), matchCost(mCost), misMatchCost(mmCost), gapExtendCost(geCost), gapOpenCost(goCost), xmax_(0), ymax_(0) {} // // Access function // // Alignment access const std::string& getMatchDesc() const { return(this->matchDesc); } ScoreType getAlnScore() const { return(this->alignmentScore); } ScoreType getReadAlnScore() const { return(this->readAlnScore); } ScoreType getReadNormAlnScore() const { return(this->readNormAlnScore); } // Ref access const std::string& getRefAlnSeq() const { return(this->refAlnSeq); } int getRefAlnStart() const { return(this->refAlnStart); } int getRefAlnEnd() const { return(this->refAlnEnd); } // Tag access const std::string& getTagAlnSeq() const { return(this->tagAlnSeq); } int getTagAlnStart() const { return(this->tagAlnStart); } int getTagAlnEnd() const { return(this->tagAlnEnd); } bool isInsideRef() const { return(this->insideRef); } int getNumMatches() const { return(this->numMatches); } int getNumMisMatches() const { return(this->numMisMatches); } int getNumInserts() const { return(this->numInserts); } int getNumDeletes() const { return(this->numDeletes); } int getNumGaps() const { return(this->numGaps); } bool isPerfectAlignment() const { return ((numMatches == static_cast(tagSeq.length())) and (numGaps == 0)); } void max3(ScoreType& max, NScoreType& which, const ScoreType v0, const ScoreType v1, const ScoreType v2 ) const { max=v0; which=0; if (v1>v0) { max=v1; which=1; } if (v2>max) { max=v2; which=2; } } // ~max3 // Manipulation Functions ScoreType align(); void setMatchDesc(); void setReadAlnScore(); void assignTag(const std::string& t) { this->tagSeq = t; } void assignRef(const std::string& r) { this->refSeq = r; } void setSequences( const char* const rSeq, const char* const tSeq, const char* const tqSeq, const char tStrand) { std::string tSeqSet; if (tStrand == 'R') { tSeqSet = Export::reverse(Export::complement(tSeq)); } else { tSeqSet = tSeq; } this->refSeq = rSeq; this->tagSeq = tSeqSet; this->tagQualSeq = tqSeq; this->strand = tStrand; } void allocateMatrices( unsigned int xs, unsigned int ys ); // Auxillary (Static) Functions static std::string getMatchDesc(const std::string& raSeq, const std::string& taSeq); static std::vector getAlignSeqs(const std::string& read, const std::string& desc); static void checkAlnDescFunc(const std::string& read, const std::string& desc, const std::string& raSeq, const std::string& taSeq); static ScoreType scoreAlignment(const std::string& raSeq, const std::string& taSeq, ScoreType m, ScoreType mm, ScoreType e, ScoreType o); std::string toString(); private: // Ref seq varaibales std::string refSeq; // Tag seq variables std::string tagSeq; std::string tagQualSeq; // Alignment result variables ScoreType alignmentScore; ScoreType readAlnScore; double readNormAlnScore; int numMatches; int numMisMatches; int numInserts; int numDeletes; int numGaps; bool insideRef; std::string matchDesc; std::string alnSeq; std::string refAlnSeq; int refAlnStart; int refAlnEnd; std::string tagAlnSeq; int tagAlnStart; int tagAlnEnd; char strand; // Alignment parameter variables const ScoreType matchCost; const ScoreType misMatchCost; const ScoreType gapExtendCost; const ScoreType gapOpenCost; std::vector > qualityVector; // Dynamic progamming structures temp strings std::string xt_; std::string yt_; std::string at_; // Dynamic programming matrices DPMatrix E_; DPMatrix F_; DPMatrix G_; DPMatrixN TE_; DPMatrixN TF_; DPMatrixN TG_; // Size of largest DP matrix seen so far unsigned int xmax_; unsigned int ymax_; }; // ~TagAligner() #endif // END OF FILE