1 /* $Id: seq_masker_uset_simple.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: Aleksandr Morgulis
27 *
28 * File Description:
29 * Implementation for CSeqMaskerUsetSimple class.
30 *
31 */
32
33 #include <ncbi_pch.hpp>
34
35 #include <sstream>
36 #include <algorithm>
37
38 #include "algo/winmask/seq_masker_uset_simple.hpp"
39 #include "algo/winmask/seq_masker_util.hpp"
40
41 BEGIN_NCBI_SCOPE
42
43 //------------------------------------------------------------------------------
GetErrCodeString() const44 const char * CSeqMaskerUsetSimple::Exception::GetErrCodeString() const
45 {
46 switch( GetErrCode() )
47 {
48 case eBadOrder: return "bad unit order";
49 case eSizeMismatch: return "size mismatch";
50 default: return CException::GetErrCodeString();
51 }
52 }
53
54 //------------------------------------------------------------------------------
add_info(Uint4 unit,Uint4 count)55 void CSeqMaskerUsetSimple::add_info( Uint4 unit, Uint4 count )
56 {
57 if( !units.empty() && unit <= units[units.size() - 1] )
58 {
59 ostringstream s;
60 s << "last unit: " << hex << units[units.size() - 1]
61 << " ; adding " << hex << unit;
62 NCBI_THROW( Exception, eBadOrder, s.str() );
63 }
64
65 units.push_back( unit );
66 counts.push_back( count );
67 }
68
69 //------------------------------------------------------------------------------
get_info(Uint4 unit) const70 Uint4 CSeqMaskerUsetSimple::get_info( Uint4 unit ) const
71 {
72 Uint4 runit = CSeqMaskerUtil::reverse_complement( unit, unit_size );
73
74 if( runit < unit )
75 unit = runit;
76
77 vector< Uint4 >::const_iterator res
78 = lower_bound( units.begin(), units.end(), unit );
79
80 if( res == units.end() || *res != unit )
81 return 0;
82 else return counts[res - units.begin()];
83 }
84
85 END_NCBI_SCOPE
86