📄 aln_scoring.hpp
字号:
/* * =========================================================================== * PRODUCTION $Log: aln_scoring.hpp,v $ * PRODUCTION Revision 1000.2 2004/04/12 18:15:46 gouriano * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.6 * PRODUCTION * =========================================================================== */#ifndef GUI_WIDGETS_ALN_MULTIPLE___ALN_SCORING__HPP#define GUI_WIDGETS_ALN_MULTIPLE___ALN_SCORING__HPP/* $Id: aln_scoring.hpp,v 1000.2 2004/04/12 18:15:46 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Andrey Yazhuk * */#include <corelib/ncbistd.hpp>#include <corelib/ncbistl.hpp>#include <gui/opengl/glcolor.hpp>#include <gui/widgets/aln_multiple/attr_range_coll.hpp>#include <objtools/alnmgr/alnvec.hpp>BEGIN_NCBI_SCOPE/// IScoringMethod represents an abstract algorithm for calculating alignment/// scores and assigning colors.class IScoringMethod{public: typedef float TScore; typedef vector<TScore> TScoreVector; virtual ~IScoringMethod() {}; /// returns unique name of the method that can be used in UI to identify it virtual string GetName() = 0; /// calculates scores for a column virtual void CalculateScores(char cons, const string& column, TScore& col_score, TScoreVector& scores) = 0; /// returns a color corresponding to a given score value. It is recommended /// that this method be implemented using color table, on-the-fly creation /// of colors is expensive. virtual const CGlColor& GetColorForScore(TScore score) const = 0;};/// CSimpleScoringMethod - trivial implementation of IScoringMethod.////// Scores are calculated as frequences of symbols normalized to fit in range/// [0, 1]. CreateColorTable() must be called once before any GetColorForScore()/// cals.class CSimpleScoringMethod : public IScoringMethod{public: enum EOptions { //fAnchorAsConsensus = 0x01, fIgnoreEmptySpace = 0x02, fIgnoreGaps = 0x04 }; CSimpleScoringMethod(); virtual ~CSimpleScoringMethod(); void SetOptions(int options); // takes as argument combination of EOptions flags void CreateColorTable(int size); virtual string GetName(); virtual void CalculateScores(char cons, const string& column, TScore& col_score, TScoreVector& scores); virtual const CGlColor& GetColorForScore(TScore score) const;protected: int m_Options; /// combination of EOptions flags vector<CGlColor> m_vColors; vector<int> m_vCharCounts; /// histogramm of characters char m_Space; char m_Gap;};class CSNPScoringMethod : public CSimpleScoringMethod{public: virtual string GetName(); virtual void CalculateScores(char cons, const string& column, TScore& col_score, TScoreVector& scores);};/// CScoreCache class uses given scoring method to calculate scores for/// CAlnVec-type alignment. CScoreCache stores scores in compressed form/// as CAttrRangeCollection. To make fetching of sequence and calculation/// of scores more effective CScoreCache uses sequence buffer.class CScoreCache{public: typedef objects::CAlnVec::TNumrow TNumrow; typedef IScoringMethod::TScore TScore; typedef IScoringMethod::TScoreVector TScoreVector; typedef CAttrRangeCollection<TScore, TSeqPos> TScoreColl; CScoreCache(); /// Sets the number of score gradations. void SetGradNumber(int grad_n); void SetScoringMethod(IScoringMethod *method); IScoringMethod* GetScoringMethod(); const IScoringMethod* GetScoringMethod() const; void SetAlnVec(const objects::CAlnVec* aln_vec); void CalculateScores(); const TScoreColl& GetScores(TNumrow row) const; const CGlColor& GetColorForScore(TScore score) const; protected: // Sequence buffer routins. char x_BufferGetSeq(TSeqPos pos, TNumrow row) const; void x_BufferGetColumn(TSeqPos pos, string& column) const; void x_AllocBuffer(TSeqPos row_len); void x_FreeBuffer(); /// Fetches sequence from CAlnVec. void x_UpdateBuffer(TSeqPos start, TSeqPos stop); TSeqPos x_GetStart() const; TSeqPos x_GetStop() const; TSeqPos x_GetRowLength() const;protected: typedef vector<TScoreColl> TScoreCollVector; TScoreCollVector m_vScoreColls; /// score storage const objects::CAlnVec* m_pAlnVec; IScoringMethod* m_pMethod; int m_GradNumber; /// Sequence buffer data members. vector<string> m_vRows; TSeqPos m_BufferStart; /// Aln position corresponding to the first column of the buffer TSeqPos m_RowLength; /// buffer row length};inline const CGlColor& CScoreCache::GetColorForScore(TScore score) const{ return m_pMethod->GetColorForScore(score); }END_NCBI_SCOPE/* * =========================================================================== * $Log: aln_scoring.hpp,v $ * Revision 1000.2 2004/04/12 18:15:46 gouriano * PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.6 * * Revision 1.6 2004/04/02 16:37:39 yazhuk * Added to CSimpleScoringMethod options for ignoring empty space and gaps; * Added CSNPScoringMethod . * * Revision 1.5 2004/03/18 17:08:50 yazhuk * Added GetScoringMethod() * * Revision 1.4 2004/02/11 17:42:30 yazhuk * Added GetName() to IScoringMethod interface; added comments * * Revision 1.3 2003/11/06 20:01:09 dicuccio * Removed USING_SCOPE(objects) * * Revision 1.2 2003/10/29 23:25:33 yazhuk * Changed comments * * Revision 1.1 2003/10/10 19:03:53 yazhuk * Initial revision * * =========================================================================== */#endif // GUI_WIDGETS_ALN_MULTIPLE___ALN_SCORING__HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -