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

Go to the SVN repository for this file.

1 /* $Id: pubseq_gateway_convert_utils.cpp 101697 2024-01-26 18:43:53Z satskyse $
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: Sergey Satskiy
27  *
28  * File Description:
29  *
30  */
31 #include <ncbi_pch.hpp>
32 
33 #include <corelib/ncbistr.hpp>
35 
37 #include "pubseq_gateway_utils.hpp"
38 
40 
41 static const string kAccessionItem = "\"accession\": ";
42 static const string kVersionItem = "\"version\": ";
43 static const string kSeqIdTypeItem = "\"seq_id_type\": ";
44 static const string kNameItem = "\"name\": ";
45 static const string kGiItem = "\"gi\": ";
46 static const string kDateChangedItem = "\"date_changed\": ";
47 static const string kHashItem = "\"hash\": ";
48 static const string kLengthItem = "\"length\": ";
49 static const string kMolItem = "\"mol\": ";
50 static const string kSatItem = "\"sat\": ";
51 static const string kSatKeyItem = "\"sat_key\": ";
52 static const string kBlobIdItem = "\"blob_id\": ";
53 static const string kSeqIdsItem = "\"seq_ids\": ";
54 static const string kSeqStateItem = "\"seq_state\": ";
55 static const string kStateItem = "\"state\": ";
56 static const string kTaxIdItem = "\"tax_id\": ";
57 static const string kSep = ", ";
58 static const string kDictValueSep = ": ";
59 static const string kKeyItem = "\"key\": ";
60 static const string kLastModifiedItem = "\"last_modified\": ";
61 static const string kFlagsItem = "\"flags\": ";
62 static const string kSizeItem = "\"size\": ";
63 static const string kSizeUnpackedItem = "\"size_unpacked\": ";
64 static const string kClassItem = "\"class\": ";
65 static const string kDateAsn1Item = "\"date_asn1\": ";
66 static const string kHupDateItem = "\"hup_date\": ";
67 static const string kDivItem = "\"div\": ";
68 static const string kId2InfoItem = "\"id2_info\": ";
69 static const string kOwnerItem = "\"owner\": ";
70 static const string kUserNameItem = "\"username\": ";
71 static const string kNChunksItem = "\"n_chunks\": ";
72 static const string kStartItem = "\"start\": ";
73 static const string kStopItem = "\"stop\": ";
74 static const string kAnnotInfoItem = "\"annot_info\": ";
75 static const string kSeqAnnotInfoItem = "\"seq_annot_info\": ";
76 static const string kRequestItem = "\"request\": ";
77 static const string kSecSeqIdItem = "\"sec_seq_id\": ";
78 static const string kSecSeqIdTypeItem = "\"sec_seq_id_type\": ";
79 static const string kSecSeqStateItem = "\"sec_seq_state\": ";
80 static const string kSatNameItem = "\"sat_name\": ";
81 static const string kChunksRequestedItem = "\"chunk_requested\": ";
82 static const string kBlopPropProvidedItem = "\"blob_prop_provided\": ";
83 static const string kSplitVersionItem = "\"split_version\": ";
84 static const string kAnnotNamesItem = "\"annotation_names\": ";
85 static const string kDateItem = "\"date\": ";
86 static const string kChainItem = "\"chain\": ";
87 static const string kIPGItem = "\"ipg\": ";
88 static const string kProteinItem = "\"protein\": ";
89 static const string kNucleotideItem = "\"nucleotide\": ";
90 static const string kProductNameItem = "\"product_name\": ";
91 static const string kDivisionItem = "\"division\": ";
92 static const string kAssemblyItem = "\"assembly\": ";
93 static const string kStrainItem = "\"strain\": ";
94 static const string kBioProjectItem = "\"bio_project\": ";
95 static const string kGBStateItem = "\"gb_state\": ";
96 
97 
98 
99 string ToBioseqProtobuf(const CBioseqInfoRecord & bioseq_info)
100 {
101  // Used to prepare a binary content out of the structured data
102  // BioseqInfoReply needs to be sent back
103  psg::retrieval::BioseqInfoReply protobuf_bioseq_info_reply;
104 
105  // Reply status
106  psg::retrieval::ReplyStatus * protobuf_bioseq_info_reply_status =
107  protobuf_bioseq_info_reply.mutable_status();
108  protobuf_bioseq_info_reply_status->set_status_code(psg::retrieval::STATUS_SUCCESS);
109 
110  // Reply key
111  psg::retrieval::BioseqInfoKey * protobuf_bioseq_info_reply_key =
112  protobuf_bioseq_info_reply.mutable_key();
113  protobuf_bioseq_info_reply_key->set_accession(bioseq_info.GetAccession());
114  protobuf_bioseq_info_reply_key->set_version(bioseq_info.GetVersion());
115  protobuf_bioseq_info_reply_key->set_seq_id_type(
116  static_cast<psg::retrieval::EnumSeqIdType>(bioseq_info.GetSeqIdType()));
117  protobuf_bioseq_info_reply_key->set_gi(bioseq_info.GetGI());
118 
119  // Reply value
120  psg::retrieval::BioseqInfoValue * protobuf_bioseq_info_value =
121  protobuf_bioseq_info_reply.mutable_value();
122 
123  psg::retrieval::BlobPropKey * protobuf_blob_prop_key =
124  protobuf_bioseq_info_value->mutable_blob_key();
125  protobuf_blob_prop_key->set_sat(bioseq_info.GetSat());
126  protobuf_blob_prop_key->set_sat_key(bioseq_info.GetSatKey());
127 
128  protobuf_bioseq_info_value->set_seq_state(
129  static_cast<psg::retrieval::EnumSeqState>(bioseq_info.GetSeqState()));
130  protobuf_bioseq_info_value->set_state(
131  static_cast<psg::retrieval::EnumSeqState>(bioseq_info.GetState()));
132  protobuf_bioseq_info_value->set_mol(
133  static_cast<psg::retrieval::EnumSeqMolType>(bioseq_info.GetMol()));
134  protobuf_bioseq_info_value->set_hash(bioseq_info.GetHash());
135  protobuf_bioseq_info_value->set_length(bioseq_info.GetLength());
136  protobuf_bioseq_info_value->set_date_changed(bioseq_info.GetDateChanged());
137  protobuf_bioseq_info_value->set_tax_id(bioseq_info.GetTaxId());
138 
139  for (const auto & item : bioseq_info.GetSeqIds()) {
140  psg::retrieval::BioseqInfoValue_SecondaryId * protobuf_secondary_id =
141  protobuf_bioseq_info_value->add_seq_ids();
142  protobuf_secondary_id->set_sec_seq_id_type(
143  static_cast<psg::retrieval::EnumSeqIdType>(get<0>(item)));
144  protobuf_secondary_id->set_sec_seq_id(get<1>(item));
145  }
146 
147  protobuf_bioseq_info_value->set_name(bioseq_info.GetName());
148 
149  // Convert to binary
150  string bioseq_protobuf;
151  protobuf_bioseq_info_reply.SerializeToString(&bioseq_protobuf);
152  return bioseq_protobuf;
153 }
154 
155 
156 string ToJsonString(const CBioseqInfoRecord & bioseq_info,
158  const string & custom_blob_id)
159 {
160  string json;
161  bool some = false;
162 
163  char buf[64];
164  long len;
165 
166  json.append(1, '{');
167  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_CanonicalId) {
168  len = PSGToString(bioseq_info.GetVersion(), buf);
169  json.append(kAccessionItem)
170  .append(1, '"')
171  .append(NStr::JsonEncode(bioseq_info.GetAccession()))
172  .append(1, '"')
173  .append(kSep)
174  .append(kVersionItem)
175  .append(buf, len)
176  .append(kSep)
177  .append(kSeqIdTypeItem);
178 
179  len = PSGToString(bioseq_info.GetSeqIdType(), buf);
180  json.append(buf, len);
181  some = true;
182  }
183  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_Name) {
184  if (some) json.append(kSep);
185  else some = true;
186 
187  json.append(kNameItem)
188  .append(1, '"')
189  .append(NStr::JsonEncode(bioseq_info.GetName()))
190  .append(1, '"');
191  }
192  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_Gi) {
193  if (some) json.append(kSep);
194  else some = true;
195 
196  len = PSGToString(bioseq_info.GetGI(), buf);
197  json.append(kGiItem)
198  .append(buf, len);
199  }
200  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_DateChanged) {
201  if (some) json.append(kSep);
202  else some = true;
203 
204  len = PSGToString(bioseq_info.GetDateChanged(), buf);
205  json.append(kDateChangedItem)
206  .append(buf, len);
207  }
208  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_Hash) {
209  if (some) json.append(kSep);
210  else some = true;
211 
212  len = PSGToString(bioseq_info.GetHash(), buf);
213  json.append(kHashItem)
214  .append(buf, len);
215  }
216  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_Length) {
217  if (some) json.append(kSep);
218  else some = true;
219 
220  len = PSGToString(bioseq_info.GetLength(), buf);
221  json.append(kLengthItem)
222  .append(buf, len);
223  }
224  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_MoleculeType) {
225  if (some) json.append(kSep);
226  else some = true;
227 
228  len = PSGToString(bioseq_info.GetMol(), buf);
229  json.append(kMolItem)
230  .append(buf, len);
231  }
232  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_BlobId) {
233  if (some) json.append(kSep);
234  else some = true;
235 
236  if (custom_blob_id.empty()) {
237  len = PSGToString(bioseq_info.GetSat(), buf);
238  json.append(kSatItem)
239  .append(buf, len)
240  .append(kSep)
241  .append(kSatKeyItem);
242 
243  len = PSGToString(bioseq_info.GetSatKey(), buf);
244  json.append(buf, len)
245  .append(kSep);
246 
247  // Adding blob_id as a string for future replacement of the separate
248  // sat and sat_key
249  json.append(kBlobIdItem)
250  .append(1, '"');
251 
252  len = PSGToString(bioseq_info.GetSat(), buf);
253  json.append(buf, len)
254  .append(1, '.');
255 
256  len = PSGToString(bioseq_info.GetSatKey(), buf);
257  json.append(buf, len)
258  .append(1, '"');
259  } else {
260  // If a custom blob_id is provided then there is no need to send
261  // the one from bioseq info
262  json.append(kBlobIdItem)
263  .append(1, '"')
264  .append(custom_blob_id)
265  .append(1, '"');
266  }
267  }
268  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_SeqIds) {
269  if (some) json.append(kSep);
270  else some = true;
271 
272  json.append(kSeqIdsItem)
273  .append(1, '[');
274 
275  bool not_first = false;
276  for (const auto & item : bioseq_info.GetSeqIds()) {
277  if (not_first)
278  json.append(kSep);
279  else
280  not_first = true;
281 
282  len = PSGToString(get<0>(item), buf);
283  json.append(1, '[')
284  .append(buf, len)
285  .append(kSep)
286  .append(1, '"')
287  .append(NStr::JsonEncode(get<1>(item)))
288  .append(1, '"')
289  .append(1, ']');
290  }
291  json.append(1, ']');
292  }
293 
294  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_SeqState) {
295  if (some) json.append(kSep);
296  else some = true;
297 
298  len = PSGToString(bioseq_info.GetSeqState(), buf);
299  json.append(kSeqStateItem)
300  .append(buf, len);
301  }
302  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_State) {
303  if (some) json.append(kSep);
304  else some = true;
305 
306  len = PSGToString(bioseq_info.GetState(), buf);
307  json.append(kStateItem)
308  .append(buf, len);
309  }
310  if (include_data_flags & SPSGS_ResolveRequest::fPSGS_TaxId) {
311  if (some) json.append(kSep);
312  // else some = true; // suppress dead assignment warning
313 
314  len = PSGToString(bioseq_info.GetTaxId(), buf);
315  json.append(kTaxIdItem)
316  .append(buf, len);
317  }
318 
319  json.append(1, '}');
320  return json;
321 }
322 
323 
324 string ToJsonString(const CBlobRecord & blob_prop)
325 {
326  string json;
327  char buf[64];
328  long len;
329 
330  json.append(1, '{');
331  len = PSGToString(blob_prop.GetKey(), buf);
332  json.append(kKeyItem)
333  .append(buf, len);
334  len = PSGToString(blob_prop.GetModified(), buf);
335  json.append(kSep)
336  .append(kLastModifiedItem)
337  .append(buf, len);
338  len = PSGToString(blob_prop.GetFlags(), buf);
339  json.append(kSep)
340  .append(kFlagsItem)
341  .append(buf, len);
342  len = PSGToString(blob_prop.GetSize(), buf);
343  json.append(kSep)
344  .append(kSizeItem)
345  .append(buf, len);
346  len = PSGToString(blob_prop.GetSizeUnpacked(), buf);
347  json.append(kSep)
348  .append(kSizeUnpackedItem)
349  .append(buf, len);
350  len = PSGToString(blob_prop.GetClass(), buf);
351  json.append(kSep)
352  .append(kClassItem)
353  .append(buf, len);
354  len = PSGToString(blob_prop.GetDateAsn1(), buf);
355  json.append(kSep)
356  .append(kDateAsn1Item)
357  .append(buf, len);
358  len = PSGToString(blob_prop.GetHupDate(), buf);
359  json.append(kSep)
360  .append(kHupDateItem)
361  .append(buf, len)
362 
363  .append(kSep)
364  .append(kDivItem)
365  .append(1, '"')
366  .append(NStr::JsonEncode(blob_prop.GetDiv()))
367  .append(1, '"')
368 
369  .append(kSep)
370  .append(kId2InfoItem)
371  .append(1, '"')
372  .append(blob_prop.GetId2Info()) // Cannot have chars need to escape
373  .append(1, '"');
374 
375  len = PSGToString(blob_prop.GetOwner(), buf);
376  json.append(kSep)
377  .append(kOwnerItem)
378  .append(buf, len)
379 
380  .append(kSep)
381  .append(kUserNameItem)
382  .append(1, '"')
383  .append(NStr::JsonEncode(blob_prop.GetUserName()))
384  .append(1, '"');
385 
386  len = PSGToString(blob_prop.GetNChunks(), buf);
387  json.append(kSep)
388  .append(kNChunksItem)
389  .append(buf, len)
390  .append(1, '}');
391 
392  return json;
393 }
394 
395 
396 string ToJsonString(const CNAnnotRecord & annot_record,
397  int32_t sat,
398  const string & custom_blob_id)
399 {
400  string json;
401  char buf[64];
402  long len;
403 
404  json.append(1, '{');
405 
406  len = PSGToString(annot_record.GetModified(), buf);
407  json.append(kLastModifiedItem)
408  .append(buf, len);
409 
410  if (custom_blob_id.empty()) {
411  len = PSGToString(sat, buf);
412  json.append(kSep)
413  .append(kSatItem)
414  .append(buf, len);
415 
416  len = PSGToString(annot_record.GetSatKey(), buf);
417  json.append(kSep)
418  .append(kSatKeyItem)
419  .append(buf, len);
420 
421  // Adding blob_id as a string for future replacement of the separate
422  // sat and sat_key
423  len = PSGToString(sat, buf);
424  json.append(kSep)
425  .append(kBlobIdItem)
426  .append(1, '"')
427  .append(buf, len)
428  .append(1, '.');
429  len = PSGToString(annot_record.GetSatKey(), buf);
430  json.append(buf, len)
431  .append(1, '"');
432  } else {
433  // If a custom blob_id is provided then there is no need to send
434  // the one from bioseq info
435  json.append(kSep)
436  .append(kBlobIdItem)
437  .append(1, '"')
438  .append(custom_blob_id)
439  .append(1, '"');
440  }
441 
442  json.append(kSep)
443  .append(kAccessionItem)
444  .append(1, '"')
445  .append(NStr::JsonEncode(annot_record.GetAccession()))
446  .append(1, '"');
447 
448  len = PSGToString(annot_record.GetVersion(), buf);
449  json.append(kSep)
450  .append(kVersionItem)
451  .append(buf, len);
452 
453  len = PSGToString(annot_record.GetSeqIdType(), buf);
454  json.append(kSep)
455  .append(kSeqIdTypeItem)
456  .append(buf, len);
457 
458  len = PSGToString(annot_record.GetStart(), buf);
459  json.append(kSep)
460  .append(kStartItem)
461  .append(buf, len);
462 
463  len = PSGToString(annot_record.GetStop(), buf);
464  json.append(kSep)
465  .append(kStopItem)
466  .append(buf, len)
467 
468  .append(kSep)
469  .append(kAnnotInfoItem)
470  .append("\"{}\"")
471 
472  .append(kSep)
473  .append(kSeqAnnotInfoItem)
474  .append(1, '"')
475  .append(NStr::Base64Encode(annot_record.GetSeqAnnotInfo(), 0))
476  .append(1, '"')
477 
478  .append(1, '}');
479  return json;
480 }
481 
482 
483 string ToJsonString(const map<string, int> & per_na_results)
484 {
485  string json;
486  char buf[64];
487  long len;
488 
489  json.append(1, '{');
490 
491  bool need_sep = false;
492  for (const auto & item : per_na_results) {
493  if (need_sep)
494  json.append(kSep);
495  need_sep = true;
496 
497  len = PSGToString(item.second, buf);
498  json.append(1, '"')
499  .append(NStr::JsonEncode(item.first))
500  .append(1, '"')
501  .append(kDictValueSep)
502  .append(buf, len);
503  }
504 
505  json.append(1, '}');
506  return json;
507 }
508 
509 
510 string ToJsonString(const CBioseqInfoFetchRequest & request)
511 {
512  string json;
513  char buf[64];
514  long len;
515 
516  json.append(1, '{')
517  .append(kRequestItem)
518  .append("\"BioseqInfo request\"");
519 
521  json.append(kSep)
522  .append(kAccessionItem)
523  .append(1, '"')
524  .append(NStr::JsonEncode(request.GetAccession()))
525  .append(1, '"');
526  else
527  json.append(kSep)
528  .append(kAccessionItem)
529  .append("null");
530 
532  len = PSGToString(request.GetVersion(), buf);
533  json.append(kSep)
534  .append(kVersionItem)
535  .append(buf, len);
536  } else {
537  json.append(kSep)
538  .append(kVersionItem)
539  .append("null");
540  }
541 
543  len = PSGToString(request.GetSeqIdType(), buf);
544  json.append(kSep)
545  .append(kSeqIdTypeItem)
546  .append(buf, len);
547  } else {
548  json.append(kSep)
549  .append(kSeqIdTypeItem)
550  .append("null");
551  }
552 
554  len = PSGToString(request.GetGI(), buf);
555  json.append(kSep)
556  .append(kGiItem)
557  .append(buf, len);
558  } else {
559  json.append(kSep)
560  .append(kGiItem)
561  .append("null");
562  }
563 
564  json.append(1, '}');
565  return json;
566 }
567 
568 
569 string ToJsonString(const CSi2CsiFetchRequest & request)
570 {
571  string json;
572  char buf[64];
573  long len;
574 
575  json.append(1, '{')
576  .append(kRequestItem)
577  .append("\"Si2Csi request\"");
578 
580  json.append(kSep)
581  .append(kSecSeqIdItem)
582  .append(1, '"')
583  .append(NStr::JsonEncode(request.GetSecSeqId()))
584  .append(1, '"');
585  else
586  json.append(kSep)
587  .append(kSecSeqIdItem)
588  .append("null");
589 
591  len = PSGToString(request.GetSecSeqIdType(), buf);
592  json.append(kSep)
593  .append(kSecSeqIdTypeItem)
594  .append(buf, len);
595  } else {
596  json.append(kSep)
597  .append(kSecSeqIdTypeItem)
598  .append("null");
599  }
600  json.append(1, '}');
601  return json;
602 }
603 
604 string ToJsonString(const CBlobFetchRequest & request)
605 {
606  string json;
607  char buf[64];
608  long len;
609 
610  json.append(1, '{')
611  .append(kRequestItem)
612  .append("\"Blob prop request\"");
613 
615  len = PSGToString(request.GetSat(), buf);
616  json.append(kSep)
617  .append(kSatItem)
618  .append(buf, len);
619  } else {
620  json.append(kSep)
621  .append(kSatItem)
622  .append("null");
623  }
624 
626  len = PSGToString(request.GetSatKey(), buf);
627  json.append(kSep)
628  .append(kSatKeyItem)
629  .append(buf, len);
630  } else {
631  json.append(kSep)
632  .append(kSatKeyItem)
633  .append("null");
634  }
635 
637  len = PSGToString(request.GetLastModified(), buf);
638  json.append(kSep)
639  .append(kLastModifiedItem)
640  .append(buf, len);
641  } else {
642  json.append(kSep)
643  .append(kLastModifiedItem)
644  .append("null");
645  }
646 
647  json.append(1, '}');
648  return json;
649 }
650 
651 
652 string ToJsonString(const CSI2CSIRecord & record)
653 {
654  string json;
655  char buf[64];
656  long len;
657 
658  json.append(1, '{')
659  .append(kSecSeqIdItem)
660  .append(1, '"')
661  .append(NStr::JsonEncode(record.GetSecSeqId()))
662  .append(1, '"');
663 
664  len = PSGToString(record.GetSecSeqIdType(), buf);
665  json.append(kSep)
666  .append(kSecSeqIdTypeItem)
667  .append(buf, len)
668 
669  .append(kSep)
670  .append(kAccessionItem)
671  .append(1, '"')
672  .append(NStr::JsonEncode(record.GetAccession()))
673  .append(1, '"');
674 
675  len = PSGToString(record.GetGI(), buf);
676  json.append(kSep)
677  .append(kGiItem)
678  .append(buf, len);
679 
680  len = PSGToString(record.GetSecSeqState(), buf);
681  json.append(kSep)
682  .append(kSecSeqStateItem)
683  .append(buf, len);
684 
685  len = PSGToString(record.GetSeqIdType(), buf);
686  json.append(kSep)
687  .append(kSeqIdTypeItem)
688  .append(buf, len);
689 
690  len = PSGToString(record.GetVersion(), buf);
691  json.append(kSep)
692  .append(kVersionItem)
693  .append(buf, len);
694 
695  json.append(1, '}');
696  return json;
697 }
698 
699 
700 string ToJsonString(const CCassBlobTaskLoadBlob & request)
701 {
702  string json;
703  char buf[64];
704  long len;
705 
706  json.append(1, '{')
707  .append(kRequestItem)
708  .append("\"Blob request\"")
709 
710  .append(kSep)
711  .append(kSatNameItem)
712  .append(1, '"')
713  .append(request.GetKeySpace())
714  .append(1, '"');
715 
716  len = PSGToString(request.GetSatKey(), buf);
717  json.append(kSep)
718  .append(kSatKeyItem)
719  .append(buf, len);
720 
721  auto last_modified = request.GetModified();
722  if (last_modified == CCassBlobTaskLoadBlob::kAnyModified) {
723  json.append(kSep)
724  .append(kLastModifiedItem)
725  .append("null");
726  } else {
727  len = PSGToString(last_modified, buf);
728  json.append(kSep)
729  .append(kLastModifiedItem)
730  .append(buf, len);
731  }
732 
733  json.append(kSep)
734  .append(kBlopPropProvidedItem);
735  if (request.BlobPropsProvided())
736  json.append("true");
737  else
738  json.append("false");
739 
740  json.append(kSep)
741  .append(kChunksRequestedItem);
742  if (request.LoadChunks())
743  json.append("true");
744  else
745  json.append("false");
746 
747  json.append(1, '}');
748  return json;
749 }
750 
751 
753 {
754  string json;
755  char buf[64];
756  long len;
757 
758  json.append(1, '{')
759  .append(kRequestItem)
760  .append("\"Split history request\"")
761 
762  .append(kSep)
763  .append(kSatNameItem)
764  .append(1, '"')
765  .append(request.GetKeySpace())
766  .append(1, '"');
767 
768  len = PSGToString(request.GetKey(), buf);
769  json.append(kSep)
770  .append(kSatKeyItem)
771  .append(buf, len);
772 
773  auto split_version = request.GetSplitVersion();
774  if (split_version == CCassBlobTaskFetchSplitHistory::kAllVersions) {
775  json.append(kSep)
776  .append(kSplitVersionItem)
777  .append("null");
778  } else {
779  len = PSGToString(split_version, buf);
780  json.append(kSep)
781  .append(kSplitVersionItem)
782  .append(buf, len);
783  }
784 
785  json.append(1, '}');
786  return json;
787 }
788 
789 
790 string ToJsonString(const CCassNAnnotTaskFetch & request)
791 {
792  string json;
793  char buf[64];
794  long len;
795 
796  json.append(1, '{')
797  .append(kRequestItem)
798  .append("\"Named annotation request\"")
799 
800  .append(kSep)
801  .append(kSatNameItem)
802  .append(1, '"')
803  .append(request.GetKeySpace())
804  .append(1, '"')
805 
806  .append(kSep)
807  .append(kAccessionItem)
808  .append(1, '"')
809  .append(NStr::JsonEncode(request.GetAccession()))
810  .append(1, '"');
811 
812  len = PSGToString(request.GetVersion(), buf);
813  json.append(kSep)
814  .append(kVersionItem)
815  .append(buf, len);
816 
817  len = PSGToString(request.GetSeqIdType(), buf);
818  json.append(kSep)
819  .append(kSeqIdTypeItem)
820  .append(buf, len);
821 
822  json.append(kSep)
823  .append(kAnnotNamesItem)
824  .append(1, '[');
825 
826  bool is_empty_list = true;
827  for (const auto & item : request.GetAnnotNames()) {
828  if (is_empty_list) is_empty_list = false;
829  else json.append(kSep);
830 
831  json.append(1, '"')
832  .append(NStr::JsonEncode(item))
833  .append(1, '"');
834  }
835 
836  json.append(1, ']');
837  json.append(1, '}');
838  return json;
839 }
840 
841 
843 {
844  string json;
845  char buf[64];
846  long len;
847 
848  json.append(1, '{')
849  .append(kRequestItem)
850  .append("\"Public comment request\"")
851 
852  .append(kSep)
853  .append(kSatNameItem)
854  .append(1, '"')
855  .append(request.GetKeySpace())
856  .append(1, '"');
857 
858  len = PSGToString(request.GetKey(), buf);
859  json.append(kSep)
860  .append(kSatKeyItem)
861  .append(buf, len);
862 
863  json.append(1, '}');
864  return json;
865 }
866 
867 
869 {
870  string json;
871  char buf[64];
872  long len;
873 
874  json.append(1, '{')
875  .append(kRequestItem)
876  .append("\"Accession version history request\"")
877 
878  .append(kSep)
879  .append(kSatNameItem)
880  .append(1, '"')
881  .append(request.GetKeySpace())
882  .append(1, '"')
883 
884  .append(kSep)
885  .append(kAccessionItem)
886  .append(1, '"')
887  .append(NStr::JsonEncode(request.GetAccession()))
888  .append(1, '"');
889 
890  len = PSGToString(request.GetVersion(), buf);
891  json.append(kSep)
892  .append(kVersionItem)
893  .append(buf, len);
894 
895  len = PSGToString(request.GetSeqIdType(), buf);
896  json.append(kSep)
897  .append(kSeqIdTypeItem)
898  .append(buf, len)
899 
900  .append(1, '}');
901  return json;
902 }
903 
904 
906 {
907  string json;
908  char buf[64];
909  long len;
910 
911  json.append(1, '{')
912  .append(kRequestItem)
913  .append("\"IPG resolve request\"")
914  .append(kSep)
915  .append(kProteinItem)
916  .append(1, '"');
917 
918  if (request.HasProtein())
919  json.append(SanitizeInputValue(NStr::JsonEncode(request.GetProtein())));
920  else
921  json.append("<null>");
922 
923  json.append(1, '"')
924  .append(kSep)
925  .append(kNucleotideItem)
926  .append(1, '"');
927 
928  if (request.HasNucleotide())
929  json.append(SanitizeInputValue(NStr::JsonEncode(request.GetNucleotide())));
930  else
931  json.append("<null>");
932 
933  json.append(1, '"')
934  .append(kSep)
935  .append(kIPGItem);
936 
937  if (request.HasIpg()) {
938  len = PSGToString(request.GetIpg(), buf);
939  json.append(buf, len);
940  } else {
941  json.append("<null>");
942  }
943  json.append(1, '}');
944 
945  return json;
946 }
947 
948 
949 string ToJsonString(const SAccVerHistRec & history_record)
950 {
951  string json;
952  char buf[64];
953  long len;
954 
955  json.append(1, '{');
956 
957  len = PSGToString(history_record.gi, buf);
958  json.append(kGiItem)
959  .append(buf, len)
960 
961  .append(kSep)
962  .append(kAccessionItem)
963  .append(1, '"')
964  .append(NStr::JsonEncode(history_record.accession))
965  .append(1, '"');
966 
967  len = PSGToString(history_record.version, buf);
968  json.append(kSep)
969  .append(kVersionItem)
970  .append(buf, len);
971 
972  len = PSGToString(history_record.seq_id_type, buf);
973  json.append(kSep)
974  .append(kSeqIdTypeItem)
975  .append(buf, len);
976 
977  len = PSGToString(history_record.date, buf);
978  json.append(kSep)
979  .append(kDateItem)
980  .append(buf, len);
981 
982  len = PSGToString(history_record.sat_key, buf);
983  json.append(kSep)
984  .append(kSatKeyItem)
985  .append(buf, len);
986 
987  len = PSGToString(history_record.sat, buf);
988  json.append(kSep)
989  .append(kSatItem)
990  .append(buf, len);
991 
992  len = PSGToString(history_record.chain, buf);
993  json.append(kSep)
994  .append(kChainItem)
995  .append(buf, len)
996 
997  .append(1, '}');
998  return json;
999 }
1000 
1001 
1002 string ToJsonString(const CIpgStorageReportEntry & ipg_entry)
1003 {
1004  string json;
1005  char buf[64];
1006  long len;
1007 
1008  // The incoming parameter is 'protein' so it is returned accordingly
1009  json.append(1, '{')
1010  .append(kProteinItem)
1011  .append(1, '"')
1012  .append(NStr::JsonEncode(ipg_entry.GetAccession()))
1013  .append(1, '"');
1014 
1015  len = PSGToString(ipg_entry.GetIpg(), buf);
1016  json.append(kSep)
1017  .append(kIPGItem)
1018  .append(buf, len)
1019 
1020  // The incoming parameter is 'nucleotide' so it is returned accordingly
1021  .append(kSep)
1022  .append(kNucleotideItem)
1023  .append(1, '"')
1024  .append(NStr::JsonEncode(ipg_entry.GetNucAccession()))
1025  .append(1, '"')
1026 
1027  .append(kSep)
1028  .append(kProductNameItem)
1029  .append(1, '"')
1030  .append(NStr::JsonEncode(ipg_entry.GetProductName()))
1031  .append(1, '"')
1032 
1033  .append(kSep)
1034  .append(kDivisionItem)
1035  .append(1, '"')
1036  .append(NStr::JsonEncode(ipg_entry.GetDiv()))
1037  .append(1, '"')
1038 
1039  .append(kSep)
1040  .append(kAssemblyItem)
1041  .append(1, '"')
1042  .append(NStr::JsonEncode(ipg_entry.GetAssembly()))
1043  .append(1, '"');
1044 
1045  len = PSGToString(ipg_entry.GetTaxid(), buf);
1046  json.append(kSep)
1047  .append(kTaxIdItem)
1048  .append(buf, len)
1049 
1050  .append(kSep)
1051  .append(kStrainItem)
1052  .append(1, '"')
1053  .append(NStr::JsonEncode(ipg_entry.GetStrain()))
1054  .append(1, '"')
1055 
1056  .append(kSep)
1057  .append(kBioProjectItem)
1058  .append(1, '"')
1059  .append(NStr::JsonEncode(ipg_entry.GetBioProject()))
1060  .append(1, '"');
1061 
1062  len = PSGToString(ipg_entry.GetLength(), buf);
1063  json.append(kSep)
1064  .append(kLengthItem)
1065  .append(buf, len);
1066 
1067  len = PSGToString(ipg_entry.GetGbState(), buf);
1068  json.append(kSep)
1069  .append(kGBStateItem)
1070  .append(buf, len)
1071 
1072  .append(1, '}');
1073  return json;
1074 }
1075 
CBioseqInfoRecord::TSeqIdType GetSeqIdType() const
Definition: request.hpp:118
CBioseqInfoRecord::TAccession GetAccession() const
Definition: request.hpp:94
CBioseqInfoRecord::TVersion GetVersion() const
Definition: request.hpp:110
CBioseqInfoRecord::TGI GetGI() const
Definition: request.hpp:102
bool HasField(EFields field) const
Definition: request.hpp:126
TSeqIdType GetSeqIdType() const
Definition: record.hpp:208
TVersion GetVersion() const
Definition: record.hpp:203
TSatKey GetSatKey() const
Definition: record.hpp:243
TTaxId GetTaxId() const
Definition: record.hpp:268
TMol GetMol() const
Definition: record.hpp:233
TSeqState GetSeqState() const
Definition: record.hpp:258
TDateChanged GetDateChanged() const
Definition: record.hpp:213
TSeqIds & GetSeqIds()
Definition: record.hpp:248
TSat GetSat() const
Definition: record.hpp:238
TGI GetGI() const
Definition: record.hpp:223
TState GetState() const
Definition: record.hpp:263
TLength GetLength() const
Definition: record.hpp:228
TAccession const & GetAccession() const
Definition: record.hpp:198
TName GetName() const
Definition: record.hpp:273
THash GetHash() const
Definition: record.hpp:218
CBlobRecord::TSatKey GetSatKey() const
Definition: request.hpp:229
int32_t GetSat() const
Definition: request.hpp:221
CBlobRecord::TTimestamp GetLastModified() const
Definition: request.hpp:237
bool HasField(EFields field) const
Definition: request.hpp:245
int32_t GetNChunks() const
int16_t GetClass() const
TSize GetSizeUnpacked() const
string GetDiv() const
TTimestamp GetDateAsn1() const
string GetUserName() const
TBlobFlagBase GetFlags() const
int32_t GetOwner() const
TTimestamp GetModified() const
TTimestamp GetHupDate() const
TSize GetSize() const
TSatKey GetKey() const
string GetId2Info() const
int16_t GetVersion() const
Definition: tasks.hpp:79
int16_t GetSeqIdType() const
Definition: tasks.hpp:84
string GetAccession() const
Definition: tasks.hpp:74
SSplitHistoryRecord::TSplitVersion GetSplitVersion() const
static const SSplitHistoryRecord::TSplitVersion kAllVersions
static const CBlobRecord::TTimestamp kAnyModified
Definition: load_blob.hpp:91
bool BlobPropsProvided() const
Definition: load_blob.hpp:161
CBlobRecord::TSatKey GetSatKey() const
Definition: load_blob.hpp:146
CBlobRecord::TTimestamp GetModified() const
Definition: load_blob.hpp:151
bool LoadChunks() const
Definition: load_blob.hpp:156
string GetKeySpace() const
int32_t GetKey() const
int16_t GetSeqIdType() const
Definition: fetch.hpp:107
vector< string > GetAnnotNames() const
Definition: fetch.hpp:112
int16_t GetVersion() const
Definition: fetch.hpp:102
string GetAccession() const
Definition: fetch.hpp:97
TAnnotInfo const & GetSeqAnnotInfo() const
Definition: record.hpp:199
int16_t GetSeqIdType() const
Definition: record.hpp:164
TSatKey GetSatKey() const
Definition: record.hpp:169
TCoord GetStop() const
Definition: record.hpp:179
string const & GetAccession() const
Definition: record.hpp:154
TCoord GetStart() const
Definition: record.hpp:174
int16_t GetVersion() const
Definition: record.hpp:159
TTimestamp GetModified() const
Definition: record.hpp:184
TSecSeqId const & GetSecSeqId() const
Definition: record.hpp:126
TAccession const & GetAccession() const
Definition: record.hpp:136
TVersion GetVersion() const
Definition: record.hpp:156
TSeqIdType GetSeqIdType() const
Definition: record.hpp:151
TGI GetGI() const
Definition: record.hpp:141
TSecSeqIdType GetSecSeqIdType() const
Definition: record.hpp:131
TSecSeqState GetSecSeqState() const
Definition: record.hpp:146
CSI2CSIRecord::TSecSeqIdType GetSecSeqIdType() const
Definition: request.hpp:335
CSI2CSIRecord::TSecSeqId GetSecSeqId() const
Definition: request.hpp:327
bool HasField(EFields field) const
Definition: request.hpp:343
The NCBI C++ standard methods for dealing with std::string.
static string Base64Encode(const CTempString str, size_t line_len=0)
Base64-encode string.
Definition: ncbistr.cpp:6266
static string JsonEncode(const CTempString str, EJsonEncode encoding=eJsonEnc_UTF8)
Encode a string for JSON.
Definition: ncbistr.cpp:4630
char * buf
int len
static const string kDateItem
static const string kDateAsn1Item
static const string kBioProjectItem
static const string kNameItem
static const string kSecSeqIdTypeItem
static const string kSeqAnnotInfoItem
static const string kKeyItem
static const string kFlagsItem
static const string kAnnotNamesItem
static const string kNChunksItem
static const string kSecSeqStateItem
static const string kHashItem
static const string kIPGItem
static const string kHupDateItem
static const string kChunksRequestedItem
static const string kProteinItem
static const string kLastModifiedItem
static const string kChainItem
static const string kStopItem
static const string kSatNameItem
static const string kLengthItem
static const string kVersionItem
static const string kDictValueSep
static const string kProductNameItem
static const string kSecSeqIdItem
static const string kStrainItem
string ToJsonString(const CBioseqInfoRecord &bioseq_info, SPSGS_ResolveRequest::TPSGS_BioseqIncludeData include_data_flags, const string &custom_blob_id)
static const string kSplitVersionItem
static const string kUserNameItem
static const string kStartItem
static const string kNucleotideItem
static const string kDivisionItem
string ToBioseqProtobuf(const CBioseqInfoRecord &bioseq_info)
static const string kSeqIdTypeItem
static const string kId2InfoItem
static const string kStateItem
static const string kGBStateItem
static const string kBlobIdItem
static const string kSeqStateItem
static const string kSeqIdsItem
static const string kDivItem
static const string kAssemblyItem
static const string kSatKeyItem
static const string kSizeUnpackedItem
static const string kDateChangedItem
static const string kSep
static const string kAnnotInfoItem
static const string kMolItem
static const string kBlopPropProvidedItem
static const string kClassItem
static const string kRequestItem
static const string kSizeItem
static const string kOwnerItem
static const string kGiItem
static const string kTaxIdItem
static const string kSatItem
static const string kAccessionItem
string SanitizeInputValue(const string &input_val)
long PSGToString(long signed_value, char *buf)
signed int int32_t
Definition: stdint.h:123
string const & GetAssembly() const
string const & GetProductName() const
string const & GetAccession() const
TGbState GetGbState() const
string const & GetBioProject() const
string const & GetDiv() const
string const & GetStrain() const
string const & GetNucAccession() const
int64_t date
Definition: record.hpp:56
int16_t sat
Definition: record.hpp:58
int16_t version
Definition: record.hpp:53
int64_t gi
Definition: record.hpp:51
int32_t sat_key
Definition: record.hpp:57
string accession
Definition: record.hpp:52
int64_t chain
Definition: record.hpp:59
int16_t seq_id_type
Definition: record.hpp:54
Modified on Mon Mar 04 05:11:32 2024 by modify_doxy.py rev. 669887