hit_data_adapter.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: hit_data_adapter.hpp,v $
- * PRODUCTION Revision 1000.1 2004/04/12 18:16:40 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- #ifndef GUI_WIDGETS_HIT_MATRIX___HIT_DATA_ADAPTER__HPP
- #define GUI_WIDGETS_HIT_MATRIX___HIT_DATA_ADAPTER__HPP
- /* $Id: hit_data_adapter.hpp,v 1000.1 2004/04/12 18:16:40 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
- *
- * File Description:
- *
- */
- #include <corelib/ncbistd.hpp>
- #include <objects/seq/Seq_annot.hpp>
- #include <objmgr/scope.hpp>
- #include <objects/seqloc/Seq_id.hpp>
- #include <objmgr/bioseq_handle.hpp>
- #include <objects/seqalign/Seq_align_set.hpp>
- #include <objects/seqalign/Seq_align.hpp>
- #include <objects/seqalign/Dense_seg.hpp>
- #include <objects/seqloc/Seq_id.hpp>
- #include <objects/seqalign/Score.hpp>
- #include <objects/general/Object_id.hpp>
- #include <serial/iterator.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- class CHitElemDataAdapter;
- /// Wraps a CSeq_align containing CDense_seg and provides a simple API for
- /// interpreting it as a pairwaise alignment of two sequences.
- ///
-
- class CHitDataAdapter
- {
- public:
- typedef CDense_seg::TDim TDim;
- typedef list< CRef< CScore > > TScore;
- CHitDataAdapter(const CSeq_align& align, const CDense_seg& denseg,
- int q_index, int s_index)
- : m_pSeqAlign(&align),
- m_pDenseSeg(&denseg),
- m_QueryIndex(q_index),
- m_SubjectIndex(s_index)
- {
- }
-
- CHitDataAdapter& operator=(const CHitDataAdapter& hit)
- {
- m_pSeqAlign = hit.m_pSeqAlign;
- m_pDenseSeg = hit.m_pDenseSeg;
- m_QueryIndex = hit.m_QueryIndex;
- m_SubjectIndex = hit.m_SubjectIndex;
- return *this;
- }
- inline TDim GetElemsCount() const
- {
- return m_pDenseSeg->GetNumseg();
- }
-
- inline CHitElemDataAdapter GetElem(TDim elem_index);
-
- inline const CHitElemDataAdapter GetElem(TDim elem_index) const;
-
- inline TSignedSeqPos GetQueryStart(TDim elem_index) const
- {
- TDim index = m_QueryIndex + elem_index * m_pDenseSeg->GetDim();
- return m_pDenseSeg->GetStarts()[index];
- }
- inline TSignedSeqPos GetSubjectStart(TDim elem_index) const
- {
- TDim index = m_SubjectIndex + elem_index * m_pDenseSeg->GetDim();
- return m_pDenseSeg->GetStarts()[index];
- }
- inline TSeqPos GetLength(TDim elem_index) const
- {
- return m_pDenseSeg->GetLens()[elem_index];
- }
- inline ENa_strand GetQueryStrand(TDim elem_index) const
- {
- TDim index = m_QueryIndex + elem_index * m_pDenseSeg->GetDim();
- return m_pDenseSeg->GetStrands()[index];
- }
- inline ENa_strand GetSubjectStrand(TDim elem_index) const
- {
- TDim index = m_SubjectIndex + elem_index * m_pDenseSeg->GetDim();
- return m_pDenseSeg->GetStrands()[index];
- }
- inline double GetScoreValue(const CObject_id& id) const
- {
- const CSeq_align::TScore& scores = m_pSeqAlign->GetScore();
- ITERATE(CSeq_align::TScore, itS, scores) {
- const CScore& score = **itS;
- _ASSERT(score.CanGetId());
- if(score.GetId().Compare(id) == 0) { // Match
- const CScore::C_Value& val = score.GetValue();
- switch(val.Which()) {
- case CScore::C_Value::e_Real: return val.GetReal();
- case CScore::C_Value::e_Int: return val.GetInt();
- default: _ASSERT(false);
- }
- }
- }
- _ASSERT(false);
- return -1;
- }
- protected:
- const CSeq_align* m_pSeqAlign;
- const CDense_seg* m_pDenseSeg;
- TDim m_QueryIndex;
- TDim m_SubjectIndex;
-
- };
- /// CHitElemDataAdapter represents a single element of a Hit.
- ///
- class CHitElemDataAdapter
- {
- public:
- typedef CDense_seg::TDim TDim;
- CHitElemDataAdapter()
- : m_pHit(NULL),
- m_ElemIndex(-1)
- {
- }
- CHitElemDataAdapter(const CHitDataAdapter& hit, TDim elem_index)
- : m_pHit(&hit),
- m_ElemIndex(elem_index)
- {
- }
- inline const CHitDataAdapter& GetHit() const
- {
- return *m_pHit;
- }
- inline TSignedSeqPos GetQueryStart() const
- {
- return m_pHit->GetQueryStart(m_ElemIndex);
- }
- inline TSignedSeqPos GetSubjectStart() const
- {
- return m_pHit->GetSubjectStart(m_ElemIndex);
- }
- inline TSeqPos GetLength() const
- {
- return m_pHit->GetLength(m_ElemIndex);
- }
- inline ENa_strand GetQueryStrand() const
- {
- return m_pHit->GetQueryStrand(m_ElemIndex);
- }
- inline ENa_strand GetSubjectStrand() const
- {
- return m_pHit->GetSubjectStrand(m_ElemIndex);
- }
- protected:
- const CHitDataAdapter* m_pHit; ///
- TDim m_ElemIndex; /// index of a segment in dense-seg
- };
- CHitElemDataAdapter CHitDataAdapter::GetElem(TDim elem_index)
- {
- return CHitElemDataAdapter(*this, elem_index);
- }
- const CHitElemDataAdapter CHitDataAdapter::GetElem(TDim elem_index) const
- {
- return CHitElemDataAdapter(*this, elem_index);
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: hit_data_adapter.hpp,v $
- * Revision 1000.1 2004/04/12 18:16:40 gouriano
- * PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.3
- *
- * Revision 1.3 2004/02/04 20:04:45 yazhuk
- * Clean-up
- *
- * Revision 1.2 2003/12/05 17:52:56 yazhuk
- * Added functions for retrieving strand information
- *
- * Revision 1.1 2003/12/01 17:01:13 yazhuk
- * Initial revision
- *
- * ===========================================================================
- */
- #endif // GUI_WIDGETS_HIT_MATRIX___HIT_DATA_ADAPTER__HPP