NCBI C++ ToolKit
sequtil_shared.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef UTIL_SEQUTIL___SEQUTIL_SHARED__HPP
2 #define UTIL_SEQUTIL___SEQUTIL_SHARED__HPP
3 
4 /* $Id: sequtil_shared.hpp 70627 2016-01-08 13:02:41Z ivanov $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Mati Shomrat
30  *
31  * File Description:
32  * Shared utility functions for the various sequtil classes.
33  */
34 
35 #include <corelib/ncbistd.hpp>
36 
37 #include <util/sequtil/sequtil.hpp>
38 
39 
41 
42 
43 SIZE_TYPE convert_1_to_1(const char* src,
44  TSeqPos pos, TSeqPos length,
45  char* dst,
46  const Uint1* table);
47 
48 SIZE_TYPE convert_1_to_2(const char* src,
49  TSeqPos pos, TSeqPos length,
50  char* dst,
51  const Uint1* table);
52 
53 SIZE_TYPE convert_1_to_4(const char* src,
54  TSeqPos pos, TSeqPos length,
55  char* dst,
56  const Uint1* table);
57 
58 SIZE_TYPE copy_1_to_1_reverse(const char* src,
59  TSeqPos pos, TSeqPos length,
60  char* dst,
61  const Uint1* table);
62 
63 SIZE_TYPE revcmp(char* buf, TSeqPos pos, TSeqPos length, const Uint1* table);
64 
65 
66 size_t GetBasesPerByte(CSeqUtil::TCoding coding);
67 
69 
70 template <typename C>
71 bool OutOfRange(TSeqPos pos, const C& container, CSeqUtil::TCoding coding)
72 {
73  size_t bases_per_byte = GetBasesPerByte(coding);
74 
75  if ( (pos == kInvalidSeqPos) ||
76  (pos > (container.size() * bases_per_byte) - 1) ) {
77  return true;
78  }
79  return false;
80 }
81 
82 
83 template <typename C>
84 void ResizeDst(C& container, CSeqUtil::TCoding coding, TSeqPos length)
85 {
86  size_t new_size = GetBytesNeeded(coding, length);
87 
88  if ( container.size() < new_size ) {
89  container.resize(new_size);
90  }
91 }
92 
93 
94 template <typename C>
95 void AdjustLength(C& container, CSeqUtil::TCoding coding,
96  TSeqPos pos, TSeqPos& length)
97 {
98  size_t bases_per_byte = GetBasesPerByte(coding);
99 
100  if ( pos + length > container.size() * bases_per_byte ) {
101  length = (TSeqPos)(container.size() * bases_per_byte - pos);
102  }
103 }
104 
105 
107 
108 
109 #endif /* UTIL_SEQUTIL___SEQUTIL_SHARED__HPP */
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define C(s)
Definition: common.h:231
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:878
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
char * buf
bool OutOfRange(TSeqPos pos, const C &container, CSeqUtil::TCoding coding)
SIZE_TYPE convert_1_to_4(const char *src, TSeqPos pos, TSeqPos length, char *dst, const Uint1 *table)
SIZE_TYPE copy_1_to_1_reverse(const char *src, TSeqPos pos, TSeqPos length, char *dst, const Uint1 *table)
SIZE_TYPE convert_1_to_2(const char *src, TSeqPos pos, TSeqPos length, char *dst, const Uint1 *table)
size_t GetBasesPerByte(CSeqUtil::TCoding coding)
SIZE_TYPE GetBytesNeeded(CSeqUtil::TCoding coding, TSeqPos length)
SIZE_TYPE convert_1_to_1(const char *src, TSeqPos pos, TSeqPos length, char *dst, const Uint1 *table)
void ResizeDst(C &container, CSeqUtil::TCoding coding, TSeqPos length)
void AdjustLength(C &container, CSeqUtil::TCoding coding, TSeqPos pos, TSeqPos &length)
SIZE_TYPE revcmp(char *buf, TSeqPos pos, TSeqPos length, const Uint1 *table)
Modified on Sun May 05 05:18:17 2024 by modify_doxy.py rev. 669887