#ifndef SEQUENCEUTILS_HH_ #define SEQUENCEUTILS_HH_ /** * Project : CASAVA * Module : $RCSfile: SequenceUtils.hh,v $ * @author : Tony Cox * Copyright : Copyright (c) Illumina 2008, 2009. All rights reserved. * ** 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). * */ #include "common/Alignment.hh" #include "common/RelOrient.hh" #include #include #include #include using namespace casava::common; namespace casava { namespace common { /** * @class SequenceUtils * * @brief A Singleton class holding methods useful in operating on Sequence/Read * * $Header $ */ //TODO: Refactor with Pipeline code class SequenceUtils : private boost::noncopyable{ public: // compute the total read quality from its ASCII representation static int totalBaseQualityForRead(const char* readQuality) { int sum(0); const unsigned read_size(strlen(readQuality)); for (unsigned int i(0); i(qv)/10.))); } static double convertPhredToProbError(int qv) { return std::min(1.,std::pow(10.,(-static_cast(qv)/10.))); } static bool isValidQualString(const char* qual, const bool isQphred); static double getSemiAlignedReadMetric(const Alignment& alignment, const bool isQphred); static double getBreakPointHypothesisScore(const Alignment& alignment, const int breakPointPos, const bool isQphred, const bool enteringBreakPoint); static char comp(const char c) { switch (c) { case 'A': return 'T'; case 'C': return 'G'; case 'G': return 'C'; case 'T': return 'A'; case 'N': return 'N'; } comp_error(c); return 'X'; } // ~comp static void reverseComp(std::string& read) { const unsigned nr(read.size()); const unsigned nr2(nr/2); for (unsigned i(0); i<(nr2); ++i) { const char tmp(comp(read[i])); read[i] = comp(read[nr-(i+1)]); read[nr-(i+1)] = tmp; } if (nr%2==1) read[nr2] = comp(read[nr2]); } // ~reverseComp private: struct ReadScorer : private boost::noncopyable { /** Instance getter * */ static const ReadScorer& get(const bool isQphred) { static const ReadScorer rs_phred(true); static const ReadScorer rs_logodds(false); if(isQphred) { return rs_phred; } else { return rs_logodds; } } bool isValidQualString(const char* qual) const; double getSemiAlignedReadMetric( const Alignment& alignment ) const; double getAlignmentScoreAfterBreakPoint(const char* qualityString, const char* type) const; double getBreakPointHypothesisScore(const Alignment& alignment, const unsigned breakPointPos, const bool enteringBreakPoint) const; private: explicit ReadScorer(const bool isQphred); ~ReadScorer() {} double getAlignmentScore(const char* qualityString, const char* type) const; enum { MAX_Q64 = 128 }; const char _qmin; double _logpcorrectratio[MAX_Q64]; }; SequenceUtils() {} ~SequenceUtils() {} static void comp_error(const char c); }; } } // end namespace casava{ namespace { applications #endif /*SEQUENCEUTILS_HH_*/