src/gui/widgets/hit_matrix/dense_hit.cpp

Go to the documentation of this file.
00001 /*  $Id: dense_hit.cpp 17179 2008-06-23 17:34:14Z yazhuk $
00002  * ===========================================================================
00003  *
00004  *                            PUBLIC DOMAIN NOTICE
00005  *               National Center for Biotechnology Information
00006  *
00007  *  This software/database is a "United States Government Work" under the
00008  *  terms of the United States Copyright Act.  It was written as part of
00009  *  the author's official duties as a United States Government employee and
00010  *  thus cannot be copyrighted.  This software/database is freely available
00011  *  to the public for use. The National Library of Medicine and the U.S.
00012  *  Government have not placed any restriction on its use or reproduction.
00013  *
00014  *  Although all reasonable efforts have been taken to ensure the accuracy
00015  *  and reliability of the software and data, the NLM and the U.S.
00016  *  Government do not and cannot warrant the performance or results that
00017  *  may be obtained by using this software or data. The NLM and the U.S.
00018  *  Government disclaim all warranties, express or implied, including
00019  *  warranties of performance, merchantability or fitness for any particular
00020  *  purpose.
00021  *
00022  *  Please cite the author in any work or product based on this material.
00023  *
00024  * ===========================================================================
00025  *
00026  * Authors:  Andrey Yazhuk
00027  *
00028  * File Description:
00029  *
00030  */
00031 
00032 #include <ncbi_pch.hpp>
00033 
00034 #include <gui/widgets/hit_matrix/dense_hit.hpp>
00035 
00036 #include <gui/widgets/data/sparse_functions.hpp>
00037 #include <objects/general/Object_id.hpp>
00038 
00039 BEGIN_NCBI_SCOPE
00040 USING_SCOPE(ncbi::objects);
00041 
00042 
00043 ///////////////////////////////////////////////////////////////////////////////
00044 /// CDenseSegHit
00045 
00046 bool CDenseSegHit::HasAlignment(const objects::CDense_seg& denseg,
00047                                 size_t q_index, size_t s_index,
00048                                 TDirection dir)
00049 {
00050     // check whether orientation of the specified rows matches "dir"
00051     bool reversed = false; // by default
00052     if(denseg.IsSetStrands())    {
00053         bool q_minus = denseg.GetSeqStrand(q_index) == eNa_strand_minus;
00054         bool s_minus = denseg.GetSeqStrand(s_index) == eNa_strand_minus;
00055         reversed = (q_minus != s_minus);
00056     }
00057 
00058     if((reversed  &&  dir == CAlnUserOptions::eDirect)  ||
00059        (! reversed  &&  dir == CAlnUserOptions::eReverse)) {
00060         return false; // this alignment does not qualify
00061     }
00062 
00063     // check whether do q_index and s_index define a pairwise alignment -
00064     // look for a column that has non-negative starts in both Q and S rows
00065     CDense_seg::TDim dim = denseg.GetDim();
00066     CDense_seg::TNumseg n_seg = denseg.GetNumseg();
00067     const CDense_seg::TStarts& starts = denseg.GetStarts();
00068 
00069     for( CDense_seg::TNumseg seg = 0;  seg < n_seg; seg++ )   {
00070         CDense_seg::TDim offset = seg * dim;
00071         TSignedSeqPos q_start = starts[q_index + offset];
00072         TSignedSeqPos s_start = starts[s_index + offset];
00073         if(q_start >= 0  && s_start >=0 )   {
00074             return true;
00075         }
00076     }
00077     return false;
00078 }
00079 
00080 
00081 CDenseSegHit::CDenseSegHit(const objects::CSeq_align& align, int q_index, int s_index)
00082 :   m_SeqAlign(&align),
00083     m_QueryIndex(q_index),
00084     m_SubjectIndex(s_index)
00085 {
00086     _ASSERT(align.GetSegs().IsDenseg());
00087     const CDense_seg& denseg = align.GetSegs().GetDenseg();
00088 
00089     /// using Alignment functions
00090     auto_ptr<SAlignedSeq> aln_seq;
00091     aln_seq.reset(CreateAlignRow(denseg, m_QueryIndex, m_SubjectIndex));
00092 
00093     _ASSERT(aln_seq.get());
00094     const SAlignedSeq::TAlignColl& coll = *aln_seq->m_AlignColl;
00095 
00096     ITERATE(SAlignedSeq::TAlignColl, it, coll)  {
00097         const SAlignedSeq::TAlignRange& range = *it;
00098 
00099         TRange q_r(range.GetFirstFrom(), range.GetFirstTo());
00100         TRange s_r(range.GetSecondFrom(), range.GetSecondTo());
00101         ENa_strand q_strand = eNa_strand_plus;
00102         ENa_strand s_strand = range.IsReversed() ? eNa_strand_minus : eNa_strand_plus;
00103         CDenseSegHitElement* elem = new CDenseSegHitElement(*this, q_r, s_r, q_strand, s_strand);
00104 
00105         m_Elements.push_back(elem);
00106     }
00107 }
00108 
00109 
00110 CDenseSegHit::~CDenseSegHit()
00111 {
00112     for(size_t i = 0; i < m_Elements.size(); i++)   {
00113         delete m_Elements[i];
00114     }
00115 }
00116 
00117 
00118 CDenseSegHit::TDim CDenseSegHit::GetElemsCount() const
00119 {
00120     return m_Elements.size();
00121 }
00122 
00123 
00124 const IHitElement& CDenseSegHit::GetElem(TDim elem_index) const
00125 {
00126     _ASSERT(size_t(elem_index) < m_Elements.size());
00127     return *m_Elements[elem_index];
00128 }
00129 
00130 
00131 double CDenseSegHit::GetScoreValue(const string& score_name) const
00132 {
00133     const objects::CSeq_align::TScore&   scores = m_SeqAlign->GetScore();
00134     ITERATE(objects::CSeq_align::TScore, itS, scores)   {
00135         const objects::CScore&   score = **itS;
00136         _ASSERT(score.CanGetId());
00137 
00138         if(score.GetId().GetStr() == score_name)  { // Match
00139             const objects::CScore::TValue& val = score.GetValue();
00140             switch(val.Which()) {
00141             case objects::CScore::TValue::e_Real: return val.GetReal(); break;
00142             case objects::CScore::TValue::e_Int: return val.GetInt(); break;
00143             default:    _ASSERT(false);
00144             }
00145         }
00146     }
00147     _ASSERT(false);
00148     return -1;
00149 }
00150 
00151 
00152 const objects::CSeq_align* CDenseSegHit::GetSeqAlign() const
00153 {
00154     return m_SeqAlign;
00155 }
00156 
00157 
00158 ///////////////////////////////////////////////////////////////////////////////
00159 ///
00160 CDenseSegHitElement::CDenseSegHitElement()
00161 :   m_Hit(NULL)
00162 {
00163 }
00164 
00165 CDenseSegHitElement::~CDenseSegHitElement()
00166 {
00167 }
00168 
00169 
00170 CDenseSegHitElement::CDenseSegHitElement(const CDenseSegHit& hit,
00171                                          const TRange& q_r, const TRange& s_r,
00172                                          ENa_strand q_strand,
00173                                          ENa_strand s_strand)
00174 :   m_Hit(&hit),
00175     m_QueryRange(q_r),
00176     m_SubjectRange(s_r),
00177     m_QueryStrand(q_strand),
00178     m_SubjectStrand(s_strand)
00179 {
00180 
00181 }
00182 
00183 
00184 const IHit& CDenseSegHitElement::GetHit() const
00185 {
00186     return *m_Hit;
00187 }
00188 
00189 
00190 TSignedSeqPos CDenseSegHitElement::GetQueryStart() const
00191 {
00192     return m_QueryRange.GetFrom();
00193 }
00194 
00195 
00196 TSignedSeqPos CDenseSegHitElement::GetSubjectStart() const
00197 {
00198     return m_SubjectRange.GetFrom();
00199 }
00200 
00201 
00202 TSeqPos CDenseSegHitElement::GetQueryLength() const
00203 {
00204     return m_QueryRange.GetLength();
00205 }
00206 
00207 
00208 TSeqPos CDenseSegHitElement::GetSubjectLength() const
00209 {
00210     return m_SubjectRange.GetLength();
00211 }
00212 
00213 
00214 objects::ENa_strand CDenseSegHitElement::GetQueryStrand() const
00215 {
00216     return m_QueryStrand;
00217 }
00218 
00219 
00220 objects::ENa_strand CDenseSegHitElement::GetSubjectStrand() const
00221 {
00222     return m_SubjectStrand;
00223 }
00224 
00225 
00226 
00227 END_NCBI_SCOPE
00228 
00229 

Generated on Wed Dec 9 04:37:43 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Wed Dec 09 08:18:04 2009 by modify_doxy.py rev. 173732