sequtil_shared.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:4k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: sequtil_shared.hpp,v $
  4.  * PRODUCTION Revision 1000.0  2003/10/29 16:03:02  gouriano
  5.  * PRODUCTION PRODUCTION: IMPORTED [ORIGINAL] Dev-tree R1.1
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. #ifndef UTIL_SEQUTIL___SEQUTIL_SHARED__HPP
  10. #define UTIL_SEQUTIL___SEQUTIL_SHARED__HPP
  11. /*  $Id: sequtil_shared.hpp,v 1000.0 2003/10/29 16:03:02 gouriano Exp $
  12.  * ===========================================================================
  13.  *
  14.  *                            PUBLIC DOMAIN NOTICE
  15.  *               National Center for Biotechnology Information
  16.  *
  17.  *  This software/database is a "United States Government Work" under the
  18.  *  terms of the United States Copyright Act.  It was written as part of
  19.  *  the author's official duties as a United States Government employee and
  20.  *  thus cannot be copyrighted.  This software/database is freely available
  21.  *  to the public for use. The National Library of Medicine and the U.S.
  22.  *  Government have not placed any restriction on its use or reproduction.
  23.  *
  24.  *  Although all reasonable efforts have been taken to ensure the accuracy
  25.  *  and reliability of the software and data, the NLM and the U.S.
  26.  *  Government do not and cannot warrant the performance or results that
  27.  *  may be obtained by using this software or data. The NLM and the U.S.
  28.  *  Government disclaim all warranties, express or implied, including
  29.  *  warranties of performance, merchantability or fitness for any particular
  30.  *  purpose.
  31.  *
  32.  *  Please cite the author in any work or product based on this material.
  33.  *
  34.  * ===========================================================================
  35.  *
  36.  * Author:  Mati Shomrat
  37.  *
  38.  * File Description:
  39.  *   Shared utility functions for the various sequtil classes.
  40.  */   
  41. #include <corelib/ncbistd.hpp>
  42. #include <util/sequtil/sequtil.hpp>
  43. BEGIN_NCBI_SCOPE
  44. SIZE_TYPE convert_1_to_1(const char* src, 
  45.                          TSeqPos pos, TSeqPos length,
  46.                          char* dst, 
  47.                          const Uint1* table);
  48. SIZE_TYPE convert_1_to_2(const char* src,
  49.                          TSeqPos pos, TSeqPos length,
  50.                          char* dst,
  51.                          const Uint1* table);
  52. SIZE_TYPE convert_1_to_4(const char* src, 
  53.                          TSeqPos pos, TSeqPos length,
  54.                          char* dst, 
  55.                          const Uint1* table);
  56. SIZE_TYPE copy_1_to_1_reverse(const char* src,
  57.                               TSeqPos pos, TSeqPos length,
  58.                               char* dst, 
  59.                               const Uint1* table);
  60. SIZE_TYPE revcmp(char* buf, TSeqPos pos, TSeqPos length, const Uint1* table);
  61. size_t GetBasesPerByte(CSeqUtil::TCoding coding);
  62. template <typename C>
  63. bool OutOfRange(TSeqPos pos, const C& container, CSeqUtil::TCoding coding)
  64. {
  65.     size_t bases_per_byte = GetBasesPerByte(coding);
  66.     
  67.     if ( (pos < 0)  ||  
  68.         (pos > (container.size() * bases_per_byte) - 1) ) {
  69.         return true;
  70.     }
  71.     return false;
  72. }
  73. template <typename C>
  74. void ResizeDst(C& container, CSeqUtil::TCoding coding, TSeqPos length)
  75. {
  76.     size_t bases_per_byte = GetBasesPerByte(coding);
  77.     
  78.     size_t new_size = length / bases_per_byte;
  79.     if ( (length %  bases_per_byte) != 0 ) {
  80.         ++new_size;
  81.     }
  82.     
  83.     if ( container.size() < new_size ) {
  84.         container.resize(new_size);
  85.     }
  86. }
  87. template <typename C>
  88. void AdjustLength(C& container, CSeqUtil::TCoding coding, 
  89.                   TSeqPos pos, TSeqPos& length)
  90. {
  91.     size_t bases_per_byte = GetBasesPerByte(coding);
  92.     
  93.     if ( pos + length > container.size() * bases_per_byte ) {
  94.         length = container.size() * bases_per_byte - pos;
  95.     }
  96. }
  97. END_NCBI_SCOPE
  98. #endif  /* UTIL_SEQUTIL___SEQUTIL_SHARED__HPP */
  99. /*
  100. * ===========================================================================
  101. *
  102. * $Log: sequtil_shared.hpp,v $
  103. * Revision 1000.0  2003/10/29 16:03:02  gouriano
  104. * PRODUCTION: IMPORTED [ORIGINAL] Dev-tree R1.1
  105. *
  106. * Revision 1.1  2003/10/08 13:36:07  shomrat
  107. * Initial version
  108. *
  109. *
  110. * ===========================================================================
  111. */