NCBI C++ ToolKit
snp_bitfield_1_2.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: snp_bitfield_1_2.cpp 75466 2016-11-17 23:39:13Z rudnev $
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  * Authors: Melvin Quintos
27  *
28  * File Description:
29  * Provides implementation of CSnpBitfield_1_2 class. See snp_bitfield_1_2.hpp
30  * for class usage.
31  *
32  */
33 
34 #include <ncbi_pch.hpp>
35 
36 #include "snp_bitfield_1_2.hpp"
40 
41 #include <stdio.h>
42 
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 // Static globals, typedefs, etc
48 ///////////////////////////////////////////////////////////////////////////////
49 
50 //
51 // Create table lookups for the first 40 property fields
52 //
53 
54 // table lookup for the 40 property fields and their byte offset
55 static const int g_byteOffset[] = {
56  0,0,0,0,0,0,0,0, // F1 Link (first 8 properties) on byte 0
57  1,1, // F1 Link (9th and 10th properties) on byte 1
58  3,3,3, // F3 Map (next 3 properties) on byte 3
59  4,4,4,4, // F4 Freq (next 4 properties) on byte 4
60  5,5,5, // F5 GTY (next 3 properties) on byte 5
61  6,6,6,6,6,6, // F6 Hapmap (next 6 properties) on byte 6
62  7,7,7,7,7,7,7,7, // F7 Phenotype (next 8 properties) on byte 7
63  9,9,9,9,9,9 // F9 Quality (next 6 properties) on byte 9
64 };
65 
66 // table lookup for the 40 property fields and their bit offset in the byte
67 static const int g_bitOffset[] = {
76 };
77 
78 ///////////////////////////////////////////////////////////////////////////////
79 // Public Methods
80 ///////////////////////////////////////////////////////////////////////////////
82 {
83  if(feat.IsSetExt()) {
84  const CUser_object& user(feat.GetExt());
85  CConstRef<CUser_field> field(user.GetFieldRef("QualityCodes"));
86  if(field && field->CanGetData() && field->GetData().IsOs()) {
87  const vector<char>& data(field->GetData().GetOs());
88 
89  // check size, msut be exactly 10 bytes
90  // TODO: use NCBI assertions?
91  _ASSERT(data.size() == 10);
92 
93  std::vector<char>::const_iterator i_ci = data.begin();
94 
95  for(int i=0 ; i_ci != data.end(); ++i_ci, ++i) {
96  m_listBytes[i] = *i_ci;
97  }
98  }
99  }
100 }
101 
103 {
104  return 1;
105 }
106 
108 {
109  // located on 3rd byte
110  // Check higher order bits first
111  // Multiple bits may be set, but only the highest bit takes effect
112  if( (m_listBytes[2] & 0x80) != 0) return CSnpBitfield::eFrameshift;
113  else if ( (m_listBytes[2] & 0x40) != 0) return CSnpBitfield::eMissense;
114  else if ( (m_listBytes[2] & 0x20) != 0) return CSnpBitfield::eNonsense;
115  else if ( (m_listBytes[2] & 0x10) != 0) return CSnpBitfield::eSynonymous;
116  else if ( (m_listBytes[2] & 0x08) != 0) return CSnpBitfield::eUTR;
117  else if ( (m_listBytes[2] & 0x04) != 0) return CSnpBitfield::eAcceptor;
118  else if ( (m_listBytes[2] & 0x02) != 0) return CSnpBitfield::eDonor;
119  else if ( (m_listBytes[2] & 0x01) != 0) return CSnpBitfield::eIntron;
120  else return CSnpBitfield::eUnknownFxn;
121 }
122 
124 {
126  unsigned char byte;
127 
128  byte = m_listBytes[8];
129  if (byte <= CSnpBitfield::eMultiBase) // eMultiBase is last implemented variation
131  else
133 
134  return c;
135 }
136 
138 {
139  const int mask = 0x03;
140  return (m_listBytes[3] & mask);
141 }
142 
144 {
145  bool ret = false;
146 
147  // Return false if property queried is
148  // newer than last property implemented at 1.2 release
150  return false;
151 
152  int byteOffset = g_byteOffset[prop];
153  int bitMask = g_bitOffset[prop];
154 
155  ret = (m_listBytes[byteOffset] & bitMask) != 0;
156 
157  return ret;
158 }
159 
161 {
162  return (prop == GetFunctionClass());
163 }
164 
166 {
167  CSnpBitfield1_2 * obj = new CSnpBitfield1_2();
168 
169  memcpy(obj->m_listBytes, m_listBytes, sizeof(m_listBytes));
170  return obj;
171 }
172 
ncbi::TMaskedQueryRegions mask
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Implement SNP Bitfield format v1.2.
unsigned char m_listBytes[10]
virtual CSnpBitfield::EFunctionClass GetFunctionClass() const
virtual int GetWeight() const
virtual CSnpBitfield::EVariationClass GetVariationClass() const
virtual int GetVersion() const
virtual CSnpBitfield::IEncoding * Clone()
virtual bool IsTrue(CSnpBitfield::EProperty prop) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
bool IsSetExt(void) const
user defined structure extension Check if a value has been assigned to Ext data member.
Definition: Seq_feat_.hpp:1207
const TExt & GetExt(void) const
Get the Ext member data.
Definition: Seq_feat_.hpp:1219
int i
static void byte(MDB_val *v)
Definition: mdb_dump.c:81
static const int g_byteOffset[]
USING_SCOPE(objects)
static const int g_bitOffset[]
#define _ASSERT
Modified on Thu Feb 29 12:19:11 2024 by modify_doxy.py rev. 669887