1 /* $Id: seq_masker_uset_array.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 CSeqMaskerUsetArray class.
30 *
31 */
32
33 #include <ncbi_pch.hpp>
34
35 #include <algorithm>
36
37 #include <algo/winmask/seq_masker_uset_array.hpp>
38 #include <algo/winmask/seq_masker_util.hpp>
39
40 BEGIN_NCBI_SCOPE
41
42 //------------------------------------------------------------------------------
GetErrCodeString() const43 const char * CSeqMaskerUsetArray::Exception::GetErrCodeString() const
44 {
45 switch( GetErrCode() )
46 {
47 case eSizeOdd: return "wrong array size";
48 default: return CException::GetErrCodeString();
49 }
50 }
51
52 //------------------------------------------------------------------------------
add_info(const Uint4 * arg_unit_data,Uint4 sz)53 void CSeqMaskerUsetArray::add_info( const Uint4 * arg_unit_data, Uint4 sz )
54 {
55 if( sz%2 != 0 )
56 NCBI_THROW( Exception, eSizeOdd,
57 "unit counts info must contain even number of words" );
58
59 unit_data = reinterpret_cast< const entry * >( arg_unit_data );
60 asize = sz/2;
61 }
62
63 //------------------------------------------------------------------------------
get_info(Uint4 unit) const64 Uint4 CSeqMaskerUsetArray::get_info( Uint4 unit ) const
65 {
66 const entry * ud = unit_data.get();
67
68 if( ud == 0 )
69 return 0;
70
71 Uint4 runit = CSeqMaskerUtil::reverse_complement( unit, unit_size );
72
73 if( runit < unit )
74 unit = runit;
75
76 entry target = { unit, 0 };
77 const entry * r = lower_bound( ud, ud + asize, target, less< entry >() );
78
79 if( r == ud + asize || r->u != unit )
80 return 0;
81 else return r->c;
82 }
83
84 END_NCBI_SCOPE
85