1 /*  $Id: writedb_general.cpp 500404 2016-05-04 14:59:01Z camacho $
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:  Kevin Bealer
27  *
28  */
29 
30 /// @file writedb_general.cpp
31 /// Implementation for general purpose utilities for WriteDB.
32 #include <ncbi_pch.hpp>
33 #include <objtools/blast/seqdb_writer/writedb_general.hpp>
34 
35 BEGIN_NCBI_SCOPE
36 
37 /// Use standard C++ definitions.
38 USING_SCOPE(std);
39 
Sort()40 void CWriteDB_PackedSemiTree::Sort()
41 {
42     NON_CONST_ITERATE(TPackedMap, iter, m_Packed) {
43         iter->second->Sort();
44     }
45 }
46 
Clear()47 void CWriteDB_PackedSemiTree::Clear()
48 {
49     m_Buffer.Clear();
50     m_Size = 0;
51     TPackedMap empty;
52     m_Packed.swap(empty);
53 }
54 
55 /// Insert string data into the container.
Insert(const char * x,int L)56 void CWriteDB_PackedSemiTree::Insert(const char * x, int L)
57 {
58     if (L <= PREFIX) {
59         CArrayString<PREFIX> pre(x, L);
60         CRef<TPacked> & packed = m_Packed[pre];
61 
62         if (packed.Empty()) {
63             packed.Reset(new TPacked(m_Buffer));
64         }
65 
66         packed->Insert("", 0);
67     } else {
68         CArrayString<PREFIX> pre(x, PREFIX);
69         CRef<TPacked> & packed = m_Packed[pre];
70 
71         if (packed.Empty()) {
72             packed.Reset(new TPacked(m_Buffer));
73         }
74 
75         packed->Insert(x + PREFIX, L-PREFIX);
76     }
77     m_Size++;
78 }
79 
WriteDB_FindSequenceLength(bool protein,const string & seq)80 int WriteDB_FindSequenceLength(bool protein, const string & seq)
81 {
82     if (protein) {
83         return seq.size();
84     }
85 
86     int wholebytes = (int) seq.size() - 1;
87     return (wholebytes << 2) + (seq[wholebytes] & 0x3);
88 }
89 
90 END_NCBI_SCOPE
91 
92