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

Go to the SVN repository for this file.

1 /* $Id: reader_snp.cpp 89919 2020-04-30 12:47:09Z grichenk $
2  * ===========================================================================
3  * PUBLIC DOMAIN NOTICE
4  * National Center for Biotechnology Information
5  *
6  * This software/database is a "United States Government Work" under the
7  * terms of the United States Copyright Act. It was written as part of
8  * the author's official duties as a United States Government employee and
9  * thus cannot be copyrighted. This software/database is freely available
10  * to the public for use. The National Library of Medicine and the U.S.
11  * Government have not placed any restriction on its use or reproduction.
12  *
13  * Although all reasonable efforts have been taken to ensure the accuracy
14  * and reliability of the software and data, the NLM and the U.S.
15  * Government do not and cannot warrant the performance or results that
16  * may be obtained by using this software or data. The NLM and the U.S.
17  * Government disclaim all warranties, express or implied, including
18  * warranties of performance, merchantability or fitness for any particular
19  * purpose.
20  *
21  * Please cite the author in any work or product based on this material.
22  *
23  * ===========================================================================
24  *
25  * Author: Anton Butanaev, Eugene Vasilchenko
26  *
27  * File Description: Data reader from ID1
28  *
29  */
30 
31 #include <ncbi_pch.hpp>
32 #include <corelib/ncbi_param.hpp>
35 
40 
44 
49 
53 
55 #include <objmgr/impl/tse_info.hpp>
56 
57 #include <serial/objectinfo.hpp>
58 #include <serial/objectiter.hpp>
59 #include <serial/objectio.hpp>
60 #include <serial/serial.hpp>
61 #include <serial/objistr.hpp>
62 #include <serial/objistrasnb.hpp>
63 #include <serial/objostrasnb.hpp>
64 #include <serial/iterator.hpp>
65 
67 
68 #include <algorithm>
69 #include <numeric>
70 
71 // for debugging
72 #include <serial/objostrasn.hpp>
73 
76 
77 
83 
84 
85 /////////////////////////////////////////////////////////////////////////////
86 // utility function
87 
88 NCBI_PARAM_DECL(bool, GENBANK, SNP_TABLE_STAT);
89 NCBI_PARAM_DEF_EX(bool, GENBANK, SNP_TABLE_STAT, false,
90  eParam_NoThread, GENBANK_SNP_TABLE_STAT);
91 
93 {
94  static CSafeStatic<NCBI_PARAM_TYPE(GENBANK, SNP_TABLE_STAT)> s_Value;
95  return s_Value->Get();
96 }
97 
98 
99 /////////////////////////////////////////////////////////////////////////////
100 // hook classes
101 
102 namespace {
103 
104 class CSeq_annot_hook : public CReadObjectHook
105 {
106 public:
108  const CObjectInfo& object)
109  {
110  m_Seq_annot = CType<CSeq_annot>::Get(object);
111  DefaultRead(in, object);
112  m_Seq_annot = null;
113  }
114 
115  CRef<CSeq_annot> m_Seq_annot;
116 };
117 
118 
119 class CSNP_Ftable_hook : public CReadChoiceVariantHook
120 {
121 public:
122  CSNP_Ftable_hook(CTSE_SetObjectInfo& set_info)
123  : m_SetObjectInfo(&set_info),
124  m_Seq_annot_hook(new CSeq_annot_hook)
125  {
126  }
127 
129  const CObjectInfoCV& variant);
130 
131  CRef<CTSE_SetObjectInfo> m_SetObjectInfo;
132  CRef<CSeq_annot_hook> m_Seq_annot_hook;
133 };
134 
135 
136 class CSNP_Seq_feat_hook : public CReadContainerElementHook
137 {
138 public:
139  CSNP_Seq_feat_hook(CSeq_annot_SNP_Info& annot_snp_info,
141  ~CSNP_Seq_feat_hook(void);
142 
143  void ReadContainerElement(CObjectIStream& in,
144  const CObjectInfo& ftable);
145 
146 private:
147  CSeq_annot_SNP_Info& m_Seq_annot_SNP_Info;
148  CSeq_annot::TData::TFtable& m_Ftable;
149  CRef<CSeq_feat> m_Feat;
150  size_t m_Count[SSNP_Info::eSNP_Type_last];
151 };
152 
153 
154 void CSNP_Ftable_hook::ReadChoiceVariant(CObjectIStream& in,
155  const CObjectInfoCV& variant)
156 {
157  _ASSERT(m_Seq_annot_hook->m_Seq_annot);
158  CObjectInfo data_info = variant.GetChoiceObject();
159  CObjectInfo ftable_info = *variant;
161 
163  (new CSeq_annot_SNP_Info(*m_Seq_annot_hook->m_Seq_annot));
164  {{
165  CSNP_Seq_feat_hook hook(*snp_info, data.SetFtable());
166  ftable_info.ReadContainer(in, hook);
167  }}
168  snp_info->x_FinishParsing();
169  if ( !snp_info->empty() ) {
170  m_SetObjectInfo->m_Seq_annot_InfoMap[m_Seq_annot_hook->m_Seq_annot].m_SNP_annot_Info = snp_info;
171  }
172 }
173 
174 
175 CSNP_Seq_feat_hook::CSNP_Seq_feat_hook(CSeq_annot_SNP_Info& annot_snp_info,
177  : m_Seq_annot_SNP_Info(annot_snp_info),
178  m_Ftable(ftable)
179 {
180  fill(m_Count, m_Count+SSNP_Info::eSNP_Type_last, 0);
181 }
182 
183 
184 static size_t s_TotalCount[SSNP_Info::eSNP_Type_last] = { 0 };
185 
186 
187 CSNP_Seq_feat_hook::~CSNP_Seq_feat_hook(void)
188 {
189  if ( CollectSNPStat() ) {
190  size_t total =
191  accumulate(m_Count, m_Count+SSNP_Info::eSNP_Type_last, size_t(0));
192  NcbiCout << "CSeq_annot_SNP_Info statistic (gi = " <<
193  m_Seq_annot_SNP_Info.GetSeq_id().AsFastaString() << "):\n";
194  for ( size_t i = 0; i < SSNP_Info::eSNP_Type_last; ++i ) {
195  if ( !m_Count[i] ) {
196  continue;
197  }
198  NcbiCout <<
199  setw(40) << SSNP_Info::s_SNP_Type_Label[i] << ": " <<
200  setw(6) << m_Count[i] << " " <<
201  setw(3) << int(m_Count[i]*100.0/total+.5) << "%\n";
202  s_TotalCount[i] += m_Count[i];
203  }
204  NcbiCout << NcbiEndl;
205 
206  total =
207  accumulate(s_TotalCount, s_TotalCount+SSNP_Info::eSNP_Type_last,size_t(0));
208  NcbiCout << "cumulative CSeq_annot_SNP_Info statistic:\n";
209  for ( size_t i = 0; i < SSNP_Info::eSNP_Type_last; ++i ) {
210  if ( !s_TotalCount[i] ) {
211  continue;
212  }
213  NcbiCout <<
214  setw(40) << SSNP_Info::s_SNP_Type_Label[i] << ": " <<
215  setw(6) << s_TotalCount[i] << " " <<
216  setw(3) << int(s_TotalCount[i]*100.0/total+.5) << "%\n";
217  }
218  NcbiCout << NcbiEndl;
219  }
220 }
221 
222 
223 #ifdef _DEBUG
224 NCBI_PARAM_DECL(bool, GENBANK, SNP_TABLE_DUMP);
225 NCBI_PARAM_DEF_EX(bool, GENBANK, SNP_TABLE_DUMP, false,
226  eParam_NoThread, GENBANK_SNP_TABLE_DUMP);
227 #endif
228 
229 void CSNP_Seq_feat_hook::ReadContainerElement(CObjectIStream& in,
230  const CObjectInfo& /*ftable*/)
231 {
232  if ( !m_Feat ) {
233  m_Feat.Reset(new CSeq_feat);
234  }
235  in.ReadObject(&*m_Feat, m_Feat->GetTypeInfo());
236  SSNP_Info snp_info;
237  SSNP_Info::ESNP_Type snp_type =
238  snp_info.ParseSeq_feat(*m_Feat, m_Seq_annot_SNP_Info);
239  ++m_Count[snp_type];
240  if ( snp_type == SSNP_Info::eSNP_Simple ) {
241  m_Seq_annot_SNP_Info.x_AddSNP(snp_info);
242  }
243  else {
244 #ifdef _DEBUG
245  static CSafeStatic<NCBI_PARAM_TYPE(GENBANK, SNP_TABLE_DUMP)> s_Value;
246  if ( s_Value->Get() ) {
247  NcbiCerr <<
248  "CSNP_Seq_feat_hook::ReadContainerElement: complex SNP: " <<
249  SSNP_Info::s_SNP_Type_Label[snp_type] << ":\n" <<
250  MSerial_AsnText << *m_Feat;
251  }
252 #endif
253  m_Ftable.push_back(m_Feat);
254  m_Feat.Reset();
255  }
256 }
257 
258 
259 } // anonymous namespace
260 
261 
263  const CObjectInfo& object,
264  CTSE_SetObjectInfo& set_info)
265 {
267 
268  if ( CProcessor::TrySNPTable() ) { // set SNP hook
269  CRef<CSNP_Ftable_hook> hook(new CSNP_Ftable_hook(set_info));
270  CObjectHookGuard<CSeq_annot> guard(*hook->m_Seq_annot_hook, &in);
271  CObjectHookGuard<CSeq_annot::TData> guard2("ftable", *hook, &in);
272  in.Read(object);
273  }
274  else {
275  in.Read(object);
276  }
277 }
278 
279 
282 {
284 
285  CRef<CSeq_annot> annot(new CSeq_annot);
286  CTSE_SetObjectInfo set_info;
287  Parse(in, Begin(*annot), set_info);
288  if ( !set_info.m_Seq_annot_InfoMap.empty() ) {
289  _ASSERT(set_info.m_Seq_annot_InfoMap.size() == 1);
290  _ASSERT(set_info.m_Seq_annot_InfoMap.begin()->first == annot);
291  ret = set_info.m_Seq_annot_InfoMap.begin()->second.m_SNP_annot_Info;
292  }
293  else {
294  ret = new CSeq_annot_SNP_Info(*annot);
295  }
296 
297  return ret;
298 }
299 
300 
302  CSeq_entry& tse,
303  CTSE_SetObjectInfo& set_info)
304 {
305  Parse(in, Begin(tse), set_info);
306 }
307 
308 
309 /////////////////////////////////////////////////////////////////////////////
310 // reading and storing in binary format
311 
312 static inline
313 void write_unsigned(CNcbiOstream& stream, size_t n, const char* name)
314 {
315  if ( sizeof(n) > 4 && Uint4(n) != n ) {
316  NCBI_THROW_FMT(CLoaderException, eLoaderFailed,
317  "write_unsigned overflow for "<<name<<": "<<n);
318  }
319  char c[4] = {
320  char(n >> 24),
321  char(n >> 16),
322  char(n >> 8),
323  char(n )
324  };
325  stream.write(c, sizeof(c));
326 }
327 
328 
329 static inline
330 unsigned read_unsigned(CNcbiIstream& stream, const char* name)
331 {
332  char c[4];
333  stream.read(c, sizeof(c));
334  if ( !stream ) {
335  NCBI_THROW(CLoaderException, eLoaderFailed,
336  string("Cannot read ")+name);
337  }
338  unsigned n =
339  (Uint1(c[0])<<24) |
340  (Uint1(c[1])<<16) |
341  (Uint1(c[2])<< 8) |
342  (Uint1(c[3]) );
343  return n;
344 }
345 
346 
347 static inline
348 void write_gi(CNcbiOstream& stream, TGi gi, const char* name)
349 {
350  TIntId n = GI_TO(TIntId, gi);
351  char c[8];
352  for ( int i = 7; i >= 0; --i ) {
353  c[i] = char(n);
354  n >>= 8;
355  }
356  stream.write(c, sizeof(c));
357 }
358 
359 
360 static inline
361 TGi read_gi(CNcbiIstream& stream, const char* name)
362 {
363  char c[8];
364  stream.read(c, sizeof(c));
365  if ( !stream ) {
366  NCBI_THROW(CLoaderException, eLoaderFailed,
367  string("Cannot read ")+name);
368  }
369  TIntId n =
370  (Uint1(c[4])<<24) |
371  (Uint1(c[5])<<16) |
372  (Uint1(c[6])<< 8) |
373  (Uint1(c[7]) );
374  TIntId n2 =
375  (Uint1(c[0])<<24) |
376  (Uint1(c[1])<<16) |
377  (Uint1(c[2])<< 8) |
378  (Uint1(c[3]) );
379 #ifdef NCBI_INT8_GI
380  n |= n2<<32;
381 #else
382  if ( n2 != (n>>31) ) { // high 32-bits must be the same as sign bit
383  NCBI_THROW(CLoaderException, eLoaderFailed,
384  string("GI overflow ")+name);
385  }
386 #endif
387  return GI_FROM(TIntId, n);
388 }
389 
390 
391 static inline
392 void write_size(CNcbiOstream& stream, size_t size)
393 {
394  // use ASN.1 binary like format
395  while ( size >= (1<<7) ) {
396  stream.put(char(size | (1<<7)));
397  size >>= 7;
398  }
399  stream.put(char(size));
400 }
401 
402 
403 static inline
404 size_t read_size(CNcbiIstream& stream, const char* name)
405 {
406  size_t size = 0;
407  static const int total_bits = sizeof(size)*8;
408  int shift = 0;
409  Uint1 c;
410  do {
411  c = stream.get();
412  if ( !stream ) {
413  NCBI_THROW(CLoaderException, eLoaderFailed,
414  string("Cannot read ")+name);
415  }
416  size_t bits = c & ((1<<7)-1);
417  if ( shift+7 > total_bits && (c>>(total_bits-shift)) != 0 ) {
418  NCBI_THROW(CLoaderException, eLoaderFailed,
419  string("read_size overflow for ")+name);
420  }
421  size |= bits << shift;
422  shift += 7;
423  } while ( c & (1<<7) );
424  return size;
425 }
426 
427 
428 static inline
429 void write_string(CNcbiOstream& stream, const string& str)
430 {
431  size_t size = str.size();
432  write_size(stream, size);
433  stream.write(str.data(), size);
434 }
435 
436 
437 static inline
438 void read_string(CNcbiIstream& stream, string& str, size_t max_length)
439 {
440  size_t size = read_size(stream, "SNP table string size");
441  if ( size > max_length ) {
442  NCBI_THROW(CLoaderException, eLoaderFailed,
443  "SNP table string is too long");
444  }
445  char buf[kMax_StringLength];
446  stream.read(buf, size);
447  if ( !stream ) {
448  NCBI_THROW(CLoaderException, eLoaderFailed,
449  "Cannot read SNP table string");
450  }
451  str.assign(buf, buf+size);
452 }
453 
454 
455 static inline
456 void write_seq_id(CNcbiOstream& stream, const CSeq_id& id)
457 {
458  write_string(stream, id.AsFastaString());
459 }
460 
461 
462 static inline
464 {
465  string str;
467  return Ref(new CSeq_id(str));
468 }
469 
470 
472  const CIndexedStrings& strings)
473 {
474  write_size(stream, strings.GetSize());
475  for (size_t idx = 0; idx < strings.GetSize(); ++idx) {
476  write_string(stream, strings.GetString(idx));
477  }
478 }
479 
480 
483  size_t max_index,
484  size_t max_length)
485 {
486  strings.Clear();
487  size_t count = read_size(stream, "SNP table strings count");
488  if ( count > unsigned(max_index+1) ) {
489  NCBI_THROW(CLoaderException, eLoaderFailed,
490  "SNP table string count is too big");
491  }
492  strings.Resize(count);
493  for (size_t idx = 0; idx < strings.GetSize(); ++idx) {
494  read_string(stream, strings.SetString(idx), max_length);
495  }
496 }
497 
498 
501 {
502  size_t element_size = strings.GetElementSize();
503  write_size(stream, element_size);
504  if ( element_size ) {
505  size_t total_size = strings.GetTotalSize();
506  write_size(stream, total_size);
507  stream.write(&strings.GetTotalString()[0], total_size);
508  }
509 }
510 
511 
514  size_t max_index,
515  size_t max_length)
516 {
517  strings.Clear();
518  size_t element_size =
519  read_size(stream, "SNP table OCTET STRING element size");
520  if ( element_size ) {
521  size_t total_size =
522  read_size(stream, "SNP table OCTET STRING total size");
523  if ( element_size == 0 || total_size%element_size != 0 ||
524  total_size > element_size*(max_index+1) ) {
525  NCBI_THROW(CLoaderException, eLoaderFailed,
526  "SNP table OCTET STRING count is too big");
527  }
529  s.resize(total_size);
530  stream.read(&s[0], total_size);
531  if ( !stream ) {
532  strings.Clear();
533  NCBI_THROW(CLoaderException, eLoaderFailed,
534  "Cannot read SNP table OCTET STRING");
535  }
536  strings.SetTotalString(element_size, s);
537  }
538 }
539 
540 
541 namespace {
542 
543 class CSeq_annot_WriteHook : public CWriteObjectHook
544 {
545 public:
547 
548  void WriteObject(CObjectOStream& stream,
549  const CConstObjectInfo& object)
550  {
551  const CSeq_annot* ptr = CType<CSeq_annot>::Get(object);
552  m_Index.insert(TIndex::value_type(ConstRef(ptr), CSeq_annot_SNP_Info_Reader::TAnnotIndex(m_Index.size())));
553  DefaultWrite(stream, object);
554  }
555 
556  TIndex m_Index;
557 };
558 
559 
560 class CSeq_annot_ReadHook : public CReadObjectHook
561 {
562 public:
564 
565  void ReadObject(CObjectIStream& stream,
566  const CObjectInfo& object)
567  {
568  CSeq_annot* ptr = CType<CSeq_annot>::Get(object);
569  m_Index.push_back(Ref(ptr));
570  DefaultRead(stream, object);
571  }
572 
573  TIndex m_Index;
574 };
575 
576 }
577 
578 
579 static const unsigned MAGIC = 0x12340008;
580 
582  const CConstObjectInfo& object,
583  const CTSE_SetObjectInfo& set_info)
584 {
585  write_unsigned(stream, MAGIC, "SNP table magic number");
586 
587  CRef<CSeq_annot_WriteHook> hook(new CSeq_annot_WriteHook);
588  {{
589  CObjectOStreamAsnBinary obj_stream(stream);
591  CObjectHookGuard<CSeq_annot> guard(*hook, &obj_stream);
592  obj_stream.Write(object);
593  }}
594 
595  write_unsigned(stream, set_info.m_Seq_annot_InfoMap.size(),
596  "number of SNP table annots");
598  set_info.m_Seq_annot_InfoMap ) {
599  TAnnotToIndex::const_iterator iter = hook->m_Index.find(it->first);
600  if ( iter == hook->m_Index.end() ) {
601  NCBI_THROW(CLoaderException, eLoaderFailed,
602  "Orphan CSeq_annot_SNP_Info");
603  }
604  write_unsigned(stream, iter->second, "SNP table annot index");
605  x_Write(stream, *it->second.m_SNP_annot_Info);
606  }
607  if ( !stream ) {
608  NCBI_THROW(CLoaderException, eLoaderFailed,
609  "SNP table store failed");
610  }
611 }
612 
613 
615  const CObjectInfo& object,
616  CTSE_SetObjectInfo& set_info)
617 {
618  unsigned magic = read_unsigned(stream, "SNP table magic number");
619  if ( magic != MAGIC ) {
620  NCBI_THROW(CLoaderException, eLoaderFailed,
621  "Incompatible version of SNP table");
622  }
623 
624  CRef<CSeq_annot_ReadHook> hook(new CSeq_annot_ReadHook);
625  {{
626  CObjectIStreamAsnBinary obj_stream(stream);
627  CObjectHookGuard<CSeq_annot> guard(*hook, &obj_stream);
628  obj_stream.Read(object);
629  }}
630 
631  unsigned count = read_unsigned(stream, "number of SNP table annots");
632  for ( unsigned i = 0; i < count; ++i ) {
633  unsigned index = read_unsigned(stream, "SNP table annot index");
634  if ( index >= hook->m_Index.size() ) {
635  NCBI_THROW(CLoaderException, eLoaderFailed,
636  "Orphan CSeq_annot_SNP_Info");
637  }
638  TAnnotRef annot = hook->m_Index[index];
639  _ASSERT(annot);
640  CRef<CSeq_annot_SNP_Info>& snp_info =
641  set_info.m_Seq_annot_InfoMap[annot].m_SNP_annot_Info;
642  if ( snp_info ) {
643  NCBI_THROW(CLoaderException, eLoaderFailed,
644  "Duplicate CSeq_annot_SNP_Info");
645  }
646  snp_info = new CSeq_annot_SNP_Info;
647  x_Read(stream, *snp_info);
648  snp_info->m_Seq_annot = annot;
649  }
650 }
651 
652 
654  const CSeq_annot_SNP_Info& snp_info)
655 {
656  x_Write(stream, snp_info);
657 
658  // complex Set_Info
659  CObjectOStreamAsnBinary obj_stream(stream);
660  obj_stream << *snp_info.m_Seq_annot;
661 }
662 
663 
665  CSeq_annot_SNP_Info& snp_info)
666 {
667  x_Read(stream, snp_info);
668 
669  // complex Set_Info
670  CRef<CSeq_annot> annot(new CSeq_annot);
671  {{
672  CObjectIStreamAsnBinary obj_stream(stream);
673  CProcessor::SetSNPReadHooks(obj_stream);
674  obj_stream >> *annot;
675  }}
676  if ( !stream ) {
677  NCBI_THROW(CLoaderException, eLoaderFailed,
678  "Bad format of SNP table");
679  }
680  snp_info.m_Seq_annot = annot;
681 }
682 
683 
685  const CSeq_annot_SNP_Info& snp_info)
686 {
687  // header
688  write_unsigned(stream, MAGIC, "SNP table magic number");
689  const CSeq_id& id = snp_info.GetSeq_id();
690  TGi gi = id.IsGi()? id.GetGi(): ZERO_GI;
691  write_gi(stream, gi, "SNP table GI");
692  if ( gi == ZERO_GI ) {
693  write_seq_id(stream, id);
694  }
695 
696  // strings
697  StoreIndexedStringsTo(stream, snp_info.m_Comments);
698  StoreIndexedStringsTo(stream, snp_info.m_Alleles);
699  StoreIndexedStringsTo(stream, snp_info.m_Extra);
700  StoreIndexedStringsTo(stream, snp_info.m_QualityCodesStr);
702 
703  // simple Set_Info
704  size_t count = snp_info.m_SNP_Set.size();
705  write_size(stream, count);
706  stream.write(reinterpret_cast<const char*>(&snp_info.m_SNP_Set[0]),
707  count*sizeof(SSNP_Info));
708 }
709 
710 
712  CSeq_annot_SNP_Info& snp_info)
713 {
714  snp_info.Reset();
715 
716  // header
717  unsigned magic = read_unsigned(stream, "SNP table magic number");
718  if ( magic != MAGIC ) {
719  NCBI_THROW(CLoaderException, eLoaderFailed,
720  "Incompatible version of SNP table");
721  }
722  TGi gi = read_gi(stream, "SNP table GI");
723  if ( gi == ZERO_GI ) {
724  snp_info.SetSeq_id(*read_seq_id(stream));
725  }
726  else {
727  CRef<CSeq_id> gi_id(new CSeq_id);
728  gi_id->SetGi(gi);
729  snp_info.SetSeq_id(*gi_id);
730  }
731 
732  // strings
733  LoadIndexedStringsFrom(stream,
734  snp_info.m_Comments,
737  LoadIndexedStringsFrom(stream,
738  snp_info.m_Alleles,
741  LoadIndexedStringsFrom(stream,
742  snp_info.m_Extra,
745  LoadIndexedStringsFrom(stream,
746  snp_info.m_QualityCodesStr,
750  snp_info.m_QualityCodesOs,
753 
754  // simple Set_Info
755  size_t count = read_size(stream, "SNP table simple SNP count");
756  if ( count ) {
757  snp_info.m_SNP_Set.resize(count);
758  stream.read(reinterpret_cast<char*>(&snp_info.m_SNP_Set[0]),
759  count*sizeof(SSNP_Info));
760  if ( !stream ) {
761  NCBI_THROW(CLoaderException, eLoaderFailed,
762  "Cannot read SNP table simple SNPs");
763  }
764  }
765  size_t comments_size = snp_info.m_Comments.GetSize();
766  size_t alleles_size = snp_info.m_Alleles.GetSize();
767  size_t extra_size = snp_info.m_Extra.GetSize();
768  size_t quality_str_size = snp_info.m_QualityCodesStr.GetSize();
769  size_t quality_os_size = snp_info.m_QualityCodesOs.GetSize();
771  size_t index = it->m_CommentIndex;
772  if ( index != SSNP_Info::kNo_CommentIndex &&
773  index >= comments_size ) {
774  snp_info.Reset();
775  NCBI_THROW(CLoaderException, eLoaderFailed,
776  "SNP table bad comment index");
777  }
778  index = it->m_ExtraIndex;
779  if ( index != SSNP_Info::kNo_ExtraIndex &&
780  index >= extra_size ) {
781  snp_info.Reset();
782  NCBI_THROW(CLoaderException, eLoaderFailed,
783  "SNP table bad extra index");
784  }
785  switch ( it->m_Flags & SSNP_Info::fQualityCodesMask ) {
786  case 0:
787  break;
789  index = it->m_QualityCodesIndex;
790  if ( index >= quality_str_size ) {
791  snp_info.Reset();
792  NCBI_THROW(CLoaderException, eLoaderFailed,
793  "SNP table bad quality code str index");
794  }
795  break;
797  index = it->m_QualityCodesIndex;
798  if ( index >= quality_os_size ) {
799  snp_info.Reset();
800  NCBI_THROW(CLoaderException, eLoaderFailed,
801  "SNP table bad quality code os index");
802  }
803  break;
804  default:
805  snp_info.Reset();
806  NCBI_THROW(CLoaderException, eLoaderFailed,
807  "SNP table bad quality code type");
808  }
809  for ( int i = SSNP_Info::kMax_AllelesCount-1; i >= 0; --i ) {
810  index = it->m_AllelesIndices[i];
811  if ( index != SSNP_Info::kNo_AlleleIndex &&
812  index >= alleles_size ) {
813  snp_info.Reset();
814  NCBI_THROW(CLoaderException, eLoaderFailed,
815  "SNP table bad allele index");
816  }
817  }
818  }
819 }
820 
821 
#define static
CConstObjectInfo –.
Definition: objectinfo.hpp:421
size_t GetSize(void) const
vector< char > TOctetString
size_t GetSize(void) const
Data loader exceptions, used by GenBank loader.
Helper class: installs hooks in constructor, and uninstalls in destructor.
Definition: objhook.hpp:397
CObjectIStreamAsnBinary –.
Definition: objistrasnb.hpp:59
CObjectIStream –.
Definition: objistr.hpp:93
CObjectInfoCV –.
Definition: objectiter.hpp:588
CObjectInfo –.
Definition: objectinfo.hpp:597
CObjectOStreamAsnBinary –.
Definition: objostrasnb.hpp:58
CObjectOStream –.
Definition: objostr.hpp:83
static bool TrySNPTable(void)
Definition: processors.cpp:335
static void SetSNPReadHooks(CObjectIStream &in)
Definition: processors.cpp:380
Read hook for a choice variant (CHOICE)
Definition: objhook.hpp:117
Read hook for a container element (SEQUENCE OF)
Definition: objhook.hpp:151
Read hook for a standalone object.
Definition: objhook.hpp:59
CSafeStatic<>::
vector< TAnnotRef > TIndexToAnnot
Definition: reader_snp.hpp:61
static void Write(CNcbiOstream &stream, const CSeq_annot_SNP_Info &snp_info)
Definition: reader_snp.cpp:653
static CRef< CSeq_annot_SNP_Info > ParseAnnot(CObjectIStream &in)
Definition: reader_snp.cpp:281
static void Read(CNcbiIstream &stream, CSeq_annot_SNP_Info &snp_info)
Definition: reader_snp.cpp:664
static void Parse(CObjectIStream &in, CSeq_entry &tse, CTSE_SetObjectInfo &set_info)
Definition: reader_snp.cpp:301
static void x_Read(CNcbiIstream &stream, CSeq_annot_SNP_Info &snp_info)
Definition: reader_snp.cpp:711
static void x_Write(CNcbiOstream &stream, const CSeq_annot_SNP_Info &snp_info)
Definition: reader_snp.cpp:684
const CSeq_id & GetSeq_id(void) const
CIndexedStrings m_Alleles
void SetSeq_id(const CSeq_id &id)
CIndexedStrings m_Comments
CRef< CSeq_annot > m_Seq_annot
CIndexedStrings m_Extra
CIndexedStrings m_QualityCodesStr
vector< SSNP_Info > TSNP_Set
CIndexedOctetStrings m_QualityCodesOs
Definition: Seq_entry.hpp:56
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
TSeq_annot_InfoMap m_Seq_annot_InfoMap
Definition: tse_info.hpp:163
Write hook for a standalone object.
Definition: objhook.hpp:161
size_type size() const
Definition: map.hpp:148
container_type::const_iterator const_iterator
Definition: map.hpp:53
const_iterator begin() const
Definition: map.hpp:151
bool empty() const
Definition: map.hpp:149
container_type::value_type value_type
Definition: map.hpp:52
Definition: map.hpp:338
Abstract reader-writer interface classes.
#define false
Definition: bool.h:36
static const char * str(char *buf, int n)
Definition: stats.c:84
static const char *const strings[]
Definition: utf8.c:21
char data[12]
Definition: iconv.c:80
#define GI_FROM(T, value)
Definition: ncbimisc.hpp:1086
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
Int8 TIntId
Definition: ncbimisc.hpp:999
#define ZERO_GI
Definition: ncbimisc.hpp:1088
#define GI_TO(T, gi)
Definition: ncbimisc.hpp:1085
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
Definition: ncbiexpt.hpp:719
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
static C * Get(const CTypesIterator &it)
Definition: objecttype.hpp:116
CBeginInfo Begin(C &obj)
Get starting point of object hierarchy.
Definition: iterator.hpp:1004
void DefaultWrite(CObjectOStream &out, const CConstObjectInfo &object)
Definition: objhook.cpp:212
void Read(const CObjectInfo &object)
Read object of know type.
Definition: objistr.cpp:952
TFlags SetFlags(TFlags flags)
const CObjectInfo & GetChoiceObject(void) const
Get containing choice.
void DefaultRead(CObjectIStream &in, const CObjectInfo &object)
Default read.
Definition: objhook.cpp:171
virtual void ReadObject(CObjectIStream &in, const CObjectInfo &object)=0
This method will be called at approriate time when the object of requested type is to be read.
virtual void WriteObject(CObjectOStream &out, const CConstObjectInfo &object)=0
This method will be called at approriate time when the object of requested type is to be written.
void Write(const CConstObjectInfo &object)
Definition: objostr.cpp:593
void ReadContainer(CObjectIStream &in, CReadContainerElementHook &hook)
Read element data from stream.
Definition: objectio.cpp:44
virtual void ReadChoiceVariant(CObjectIStream &in, const CObjectInfoCV &variant)=0
This method will be called at approriate time when the object of requested type is to be read.
CConstRef< C > ConstRef(const C *object)
Template function for conversion of const object pointer to CConstRef.
Definition: ncbiobj.hpp:2024
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
Definition: ncbiobj.hpp:2015
#define NCBI_PARAM_TYPE(section, name)
Generate typename for a parameter from its {section, name} attributes.
Definition: ncbi_param.hpp:149
@ eParam_NoThread
Do not use per-thread values.
Definition: ncbi_param.hpp:418
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NcbiEndl
Definition: ncbistre.hpp:548
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NcbiCout
Definition: ncbistre.hpp:543
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
#define NcbiCerr
Definition: ncbistre.hpp:544
TGi & SetGi(void)
Select the variant.
Definition: Seq_id_.hpp:896
list< CRef< CSeq_feat > > TFtable
Definition: Seq_annot_.hpp:193
CMapControl::TIndex TIndex
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
char * buf
int i
yy_size_t n
const struct ncbi::grid::netcache::search::fields::SIZE size
string s_Value(TValue value)
std::istream & in(std::istream &in_, double &x_)
#define count
static const size_t kMax_ExtraLength
Definition: reader_snp.cpp:79
void StoreIndexedOctetStringsTo(CNcbiOstream &stream, const CIndexedOctetStrings &strings)
Definition: reader_snp.cpp:499
static TGi read_gi(CNcbiIstream &stream, const char *name)
Definition: reader_snp.cpp:361
void LoadIndexedStringsFrom(CNcbiIstream &stream, CIndexedStrings &strings, size_t max_index, size_t max_length)
Definition: reader_snp.cpp:481
static void write_string(CNcbiOstream &stream, const string &str)
Definition: reader_snp.cpp:429
void StoreIndexedStringsTo(CNcbiOstream &stream, const CIndexedStrings &strings)
Definition: reader_snp.cpp:471
static const unsigned MAGIC
Definition: reader_snp.cpp:579
static void write_gi(CNcbiOstream &stream, TGi gi, const char *name)
Definition: reader_snp.cpp:348
static size_t read_size(CNcbiIstream &stream, const char *name)
Definition: reader_snp.cpp:404
static const size_t kMax_StringLength
Definition: reader_snp.cpp:82
static const size_t kMax_AlleleLength
Definition: reader_snp.cpp:80
static void write_unsigned(CNcbiOstream &stream, size_t n, const char *name)
Definition: reader_snp.cpp:313
static void write_size(CNcbiOstream &stream, size_t size)
Definition: reader_snp.cpp:392
static void write_seq_id(CNcbiOstream &stream, const CSeq_id &id)
Definition: reader_snp.cpp:456
static unsigned read_unsigned(CNcbiIstream &stream, const char *name)
Definition: reader_snp.cpp:330
static CRef< CSeq_id > read_seq_id(CNcbiIstream &stream)
Definition: reader_snp.cpp:463
NCBI_PARAM_DECL(bool, GENBANK, SNP_TABLE_STAT)
void LoadIndexedOctetStringsFrom(CNcbiIstream &stream, CIndexedOctetStrings &strings, size_t max_index, size_t max_length)
Definition: reader_snp.cpp:512
static const size_t kMax_QualityLength
Definition: reader_snp.cpp:81
NCBI_PARAM_DEF_EX(bool, GENBANK, SNP_TABLE_STAT, false, eParam_NoThread, GENBANK_SNP_TABLE_STAT)
static const size_t kMax_CommentLength
Definition: reader_snp.cpp:78
static void read_string(CNcbiIstream &stream, string &str, size_t max_length)
Definition: reader_snp.cpp:438
static bool CollectSNPStat(void)
Definition: reader_snp.cpp:92
static sljit_uw total_size
static const char *const s_SNP_Type_Label[eSNP_Type_last]
Definition: snp_info.hpp:95
ESNP_Type ParseSeq_feat(const CSeq_feat &feat, CSeq_annot_SNP_Info &annot_info)
@ kMax_AllelesCount
Definition: snp_info.hpp:150
@ kMax_AlleleIndex
Definition: snp_info.hpp:155
@ kNo_AlleleIndex
Definition: snp_info.hpp:154
@ kNo_ExtraIndex
Definition: snp_info.hpp:141
@ kMax_ExtraIndex
Definition: snp_info.hpp:142
@ kNo_CommentIndex
Definition: snp_info.hpp:129
@ kMax_CommentIndex
Definition: snp_info.hpp:130
@ eSNP_Type_last
Definition: snp_info.hpp:92
@ eSNP_Simple
Definition: snp_info.hpp:73
@ fQualityCodesStr
Definition: snp_info.hpp:165
@ fQualityCodesOs
Definition: snp_info.hpp:166
@ fQualityCodesMask
Definition: snp_info.hpp:167
@ kMax_QualityCodesIndex
Definition: snp_info.hpp:147
#define _ASSERT
#define ftable
Definition: utilfeat.h:37
#define const
Definition: zconf.h:232
Modified on Fri Sep 20 14:57:43 2024 by modify_doxy.py rev. 669887