1 /*  $Id: alnpos_ci.cpp 103491 2007-05-04 17:18:18Z kazimird $
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *               National Center for Biotechnology Information
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government have not placed any restriction on its use or reproduction.
13 *
14 *  Although all reasonable efforts have been taken to ensure the accuracy
15 *  and reliability of the software and data, the NLM and the U.S.
16 *  Government do not and cannot warrant the performance or results that
17 *  may be obtained by using this software or data. The NLM and the U.S.
18 *  Government disclaim all warranties, express or implied, including
19 *  warranties of performance, merchantability or fitness for any particular
20 *  purpose.
21 *
22 *  Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author:  Kamen Todorov, NCBI
27 *
28 * File Description:
29 *   Alignment position iterator. Uses CAlnMap.
30 *
31 * ===========================================================================
32 */
33 
34 
35 #include <ncbi_pch.hpp>
36 #include <objtools/alnmgr/alnpos_ci.hpp>
37 
38 BEGIN_NCBI_SCOPE
39 BEGIN_objects_SCOPE // namespace ncbi::objects::
40 
41 
CAlnPos_CI(const CAlnMap & alnmap,TSeqPos aln_pos)42 CAlnPos_CI::CAlnPos_CI(const CAlnMap& alnmap,
43                        TSeqPos aln_pos)
44     : m_AlnMap(alnmap),
45       m_AlnPos(aln_pos),
46       m_Valid(true),
47       m_Anchor(alnmap.GetAnchor())
48 {
49     // set iteration limits for the aln pos
50     m_AlnStart = m_AlnMap.GetAlnStart();
51     m_AlnStop  = m_AlnMap.GetAlnStop();
52     _ASSERT(m_AlnStart < m_AlnStop);
53 
54     // adjust m_AlnPos in case it is out of range
55     if (m_AlnPos < m_AlnStart) {
56         m_AlnPos = m_AlnStart;
57     } else if (m_AlnPos > m_AlnStop) {
58         m_AlnPos = m_AlnStop;
59     }
60 
61     // set m_AlnSeg, m_RDelta, m_LDelta
62     m_AlnSeg = m_AlnMap.GetSeg(m_AlnPos);
63     m_LDelta = aln_pos - m_AlnMap.GetAlnStart(m_AlnSeg);
64     m_RDelta = m_AlnMap.GetAlnStop(m_AlnSeg) - aln_pos;
65 
66     // resize & initialize cache
67     m_SeqStartsCache.resize(m_AlnMap.GetNumRows(), -2);
68 };
69 
70 
71 END_objects_SCOPE // namespace ncbi::objects::
72 END_NCBI_SCOPE
73