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

Go to the SVN repository for this file.

1 /* $Id: remote_blast.cpp 102905 2024-08-05 14:31:10Z merezhuk $
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 * Author: Kevin Bealer
27 *
28 * ===========================================================================
29 */
30 
31 /// @file remote_blast.cpp
32 /// Queueing and Polling code for Remote Blast API.
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbi_system.hpp>
36 #include <corelib/ncbitime.hpp>
37 #include <corelib/stream_utils.hpp>
38 #include <serial/iterator.hpp>
42 
45 #include <objects/blast/names.hpp>
46 #include <objects/seq/Seq_data.hpp>
47 #include <objects/seq/Bioseq.hpp>
53 #include "psiblast_aux_priv.hpp" // For CPsiBlastValidate::Pssm()
54 #include <util/format_guess.hpp> // for CFormatGuess
55 #include <serial/objistrxml.hpp> // for CObjectIStreamXml
56 #include <serial/objistrasnb.hpp> // for CObjectIStreamAsnBinary
57 #include <serial/objistrasn.hpp> // for CObjectIStreamAsn
59 
60 #if defined(NCBI_OS_UNIX)
61 #include <unistd.h>
62 #endif
63 
64 /** @addtogroup AlgoBlast
65  *
66  * @{
67  */
68 
71 BEGIN_SCOPE(blast)
72 
73 
74 // Static functions
75 
76 
77 /// Error value type used by Blast4 ASN.1 objects.
79 
80 
81 /// Determine whether the search is still running.
82 /// @param reply Reply from get-search-results request.
83 /// @return True if search needs more time, false if done or failed.
84 static bool
86 {
87  const list< CRef<objects::CBlast4_error> > & errors = reply->GetErrors();
88 
89  TErrorList::const_iterator i;
90 
91  for(i = errors.begin(); i != errors.end(); i++) {
92  if ((*i)->GetCode() == eBlast4_error_code_search_pending) {
93  return true;
94  }
95  }
96  return false;
97 }
98 
99 
101 {
102  const list< CRef<CBlast4_error> > & errors = reply->GetErrors();
103 
104  TErrorList::const_iterator i;
105 
106  for(i = errors.begin(); i != errors.end(); i++) {
107  string msg;
108 
109  if ((*i)->CanGetMessage() && (! (*i)->GetMessage().empty())) {
110  msg = ": ";
111  msg += (*i)->GetMessage();
112  }
113 
114  switch((*i)->GetCode()) {
116  // if message contains core_nt skip adding conversion_warning WB-6333
117  if( NStr::MatchesMask(msg,"*core_nt*",NStr::eNocase) == TRUE ) {
118  m_Warn.push_back(msg.substr (2)); // skip previously added ': '
119  }
120  else {
121  m_Warn.push_back(string("conversion_warning") + msg);
122  }
123  break;
124 
126  m_Errs.push_back(string("internal_error") + msg);
127  break;
128 
130  m_Errs.push_back(string("not_implemented") + msg);
131  break;
132 
134  m_Errs.push_back(string("not_allowed") + msg);
135  break;
136 
138  m_Errs.push_back(string("bad_request") + msg);
139  break;
140 
142  m_Errs.push_back(string("Invalid/unknown RID (bad_request_id)") +
143  msg);
144  break;
145  }
146  }
147 }
148 
149 
150 
151 // CBlast4Option methods
152 
154 {
155  // If not configured, throw an exception - the associated string
156  // will contain a list of the missing pieces.
157 
158  if (0 != m_NeedConfig) {
159  string cfg("Configuration required:");
160 
161  if (eProgram & m_NeedConfig) {
162  cfg += " <program>";
163  }
164 
165  if (eService & m_NeedConfig) {
166  cfg += " <service>";
167  }
168 
169  if (eQueries & m_NeedConfig) {
170  cfg += " <queries>";
171  }
172 
173  if (eSubject & m_NeedConfig) {
174  cfg += " <subject>";
175  }
176 
177  NCBI_THROW(CRemoteBlastException, eIncompleteConfig, cfg);
178  }
179 }
180 
183 {
185  x_CheckConfig();
186  string errors(GetErrors());
187  if ( !errors.empty() ) {
188  NCBI_THROW(CRemoteBlastException, eIncompleteConfig, errors);
189  }
191  if ( !m_ClientId.empty() ) {
192  retval->SetIdent(m_ClientId);
193  }
194  retval->SetBody(*body);
195  return retval;
196 }
197 
200 {
201  // If not configured, throw.
202  x_CheckConfig();
203 
204  // Create the request; optionally echo it
205 
207  if ( !m_ClientId.empty() ) {
208  request->SetIdent(m_ClientId);
209  }
210  request->SetBody(*body);
211 
212  if (eDebug == m_Verbose) {
213  NcbiCout << MSerial_AsnText << *request << endl;
214  }
215 
216  // submit to server, get reply; optionally echo it
217 
219 
220  try {
222 
223  if (eDebug == m_Verbose) {
224  NcbiCout << "Starting network transaction (" << sw.Elapsed() << ")" << endl;
225  }
226 
227  CBlast4Client().Ask(*request, *reply);
228 
229  if (eDebug == m_Verbose) {
230  NcbiCout << "Done network transaction (" << sw.Elapsed() << ")" << endl;
231  }
232  }
233  catch(const CEofException&) {
234  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
235  "No response from server, cannot complete request.");
236  }
237 
238  if (eDebug == m_Verbose) {
239  NcbiCout << MSerial_AsnText << *reply << endl;
240  }
241 
242  return reply;
243 }
244 
247 {
250 
251  gsrr->SetRequest_id(m_RID);
252 
254  body->SetGet_search_results(*gsrr);
255 
256  return x_SendRequest(body);
257 }
258 
259 // Pre: start, wait, or done
260 // Post: failed or done
261 
262 // Returns: true if done
263 
264 bool CRemoteBlast::SubmitSync(int seconds)
265 {
266  // eFailed: no work to do, already an error.
267  // eDone: already done, just return.
268 
269  EImmediacy immed = ePollAsync;
270 
271  switch(x_GetState()) {
272  case eStart:
273  x_SubmitSearch();
274  if (! m_Errs.empty()) {
275  break;
276  }
277  immed = ePollImmed;
278  // fall through
279 
280  case eWait:
281  x_PollUntilDone(immed, seconds);
282  break;
283  default:
284  break;
285  }
286 
287  return (x_GetState() == eDone);
288 }
289 
290 
291 
292 // Pre: start
293 // Post: failed, wait or done
294 
295 // Returns: true if no error so far
296 
298 {
299  switch(x_GetState()) {
300  case eStart:
301  x_SubmitSearch();
302  default: break;
303  }
304 
305  return m_Errs.empty();
306 }
307 
308 //
309 // The following table summarizes how to determine the status of a given
310 // RID/search submission:
311 //
312 // | CheckDone() | CheckDone()
313 // | returns true | returns false
314 // ------------------------------------------------------------
315 // GetErrors() == kEmptyStr | DONE | PENDING
316 // ------------------------------------------------------------
317 // GetErrors() != kEmptyStr | FAILED | UNKNOWN RID
318 // ------------------------------------------------------------
319 //
322 {
324 
325  bool done = CheckDone();
326  string errors = GetErrors();
327 
328  if (done && errors == kEmptyStr) {
329  retval = eStatus_Done;
330  } else if (!done && errors == kEmptyStr) {
331  retval = eStatus_Pending;
332  } else if (!done && errors.find("bad_request_id") != NPOS) {
333  retval = eStatus_Unknown;
334  } else if (done && errors != kEmptyStr) {
335  retval = eStatus_Failed;
336  }
337  return retval;
338 }
339 
341 {
342  bool retval = false;
343  if (NStr::Find(GetErrors(), "bad_request_id") != NPOS) {
344  retval = true;
345  }
346  return retval;
347 }
348 
349 // Pre: start, wait or done
350 // Post: wait, done, or failed
351 
352 // Returns: true if done
353 
355 {
356  switch(x_GetState()) {
357  case eFailed:
358  case eDone:
359  break;
360 
361  case eStart:
362  Submit();
363  break;
364 
365  case eWait:
367  }
368 
369  int state = x_GetState();
370  return (state == eDone || (state == eFailed && !x_IsUnknownRID()));
371 }
372 
374 {
375  TGSRR* rv = NULL;
376 
377  if (m_ReadFile)
378  {
379  rv = &(m_Archive->SetResults());
380  }
381  else if (SubmitSync() &&
382  m_Reply.NotEmpty() &&
383  m_Reply->CanGetBody() &&
384  m_Reply->GetBody().IsGet_search_results()) {
385 
386  rv = & (m_Reply->SetBody().SetGet_search_results());
387  }
388 
389  return rv;
390 }
391 
393 {
395 
396  TGSRR * gsrr = x_GetGSRR();
397 
398  if (gsrr && gsrr->CanGetAlignments()) {
399  rv = & (gsrr->SetAlignments());
400  }
401 
402  return rv;
403 }
404 
406 {
408 
409  TSeqAlignVector rv;
410 
411  CRef<CSeq_align_set> cur_set;
412  CConstRef<CSeq_id> current_id;
413 
414  // this loop groups all matches to one target sequences in one vector element.
415  TSeqAlignVector temp;
416 
417  if (al.NotEmpty())
418  {
419  ITERATE(CSeq_align_set::Tdata, it, al->Get()) {
420  // index 0 = query, index 1 = subject
421  const int query_index = 0;
422  CConstRef<CSeq_id> this_id( & (*it)->GetSeq_id(query_index) );
423 
424  if (current_id.Empty() || (CSeq_id::e_YES != this_id->Compare(*current_id))) {
425  if (cur_set.NotEmpty()) {
426  temp.push_back(cur_set);
427  }
428  cur_set.Reset(new CSeq_align_set);
429  current_id = this_id;
430  }
431  cur_set->Set().push_back(*it);
432  }
433  }
434 
435  if (cur_set.NotEmpty()) {
436  temp.push_back(cur_set);
437  }
438 
440  x_ExtractQueryIds(query_ids);
441 
442  // Fill out the return value, with empty Seq-align-set if not match for a query.
443  TSeqAlignVector::size_type sap_index = 0;
444  ITERATE(CSearchResultSet::TQueryIdVector, it, query_ids) {
445  const int query_index = 0;
446  if (sap_index < temp.size())
447  {
448  list< CRef< CSeq_align > > sal = temp[sap_index]->Get();
449  CConstRef<CSeq_id> this_id( & (sal.front()->GetSeq_id(query_index) ));
450  if (CSeq_id::e_YES == (*it)->Compare(sal.front()->GetSeq_id(query_index) ))
451  {
452  rv.push_back(temp[sap_index]);
453  sap_index++;
454  }
455  else
456  {
457  cur_set.Reset(new CSeq_align_set);
458  rv.push_back(cur_set);
459  }
460  }
461  else
462  {
463  cur_set.Reset(new CSeq_align_set);
464  rv.push_back(cur_set);
465  }
466  }
467 
468  return rv;
469 }
470 
472 {
474 
475  TGSRR * gsrr = x_GetGSRR();
476 
477  if (gsrr && gsrr->CanGetPhi_alignments()) {
478  rv = & (gsrr->SetPhi_alignments());
479  }
480 
481  return rv;
482 }
483 
484 // N.B.: this function assumes that the BLAST 4 server sends the query masked
485 // locations for each query adjacent to one another in the list of masks (i.e.:
486 // masks-for-query1-frameA, masks-for-query1-frameB, ...,
487 // masks-for-query2-frameA, masks-for-query2-frameB, ... etc).
490 {
491  TSeqLocInfoVector retval;
492  retval.resize(GetQueries()->GetNumQueries());
493 
494  TGSRR::TMasks network_masks = x_GetMasks();
495  if (network_masks.empty()) {
496  return retval;
497  }
498 
500  m_Service);
501  CConstRef<CSeq_id> previous_seqid;
502  size_t query_index = 0;
503 
504  ITERATE(TGSRR::TMasks, masks_for_frame, network_masks) {
505 
506  _ASSERT(masks_for_frame->NotEmpty());
507 
508  CConstRef<CSeq_id> current_seqid
509  ((*masks_for_frame)->GetLocations().front()->GetId());
510  if (previous_seqid.Empty()) {
511  previous_seqid = current_seqid;
512  }
513 
514  // determine which query are we setting the masks for...
515  TMaskedQueryRegions* mqr = NULL;
516  if (CSeq_id::e_YES == current_seqid->Compare(*previous_seqid)) {
517  mqr = &retval[query_index];
518  } else {
519  mqr = &retval[++query_index];
520  previous_seqid = current_seqid;
521  }
522 
523  // all the masks for a given query and frame are in a single
524  // Packed-seqint
525  _ASSERT((*masks_for_frame)->GetLocations().size() == (size_t) 1);
526  _ASSERT((*masks_for_frame)->GetLocations().front().NotEmpty());
527  CRef<CSeq_loc> masks =
528  (*masks_for_frame)->GetLocations().front();
529  _ASSERT(masks->IsPacked_int());
530 
531  const CPacked_seqint& packed_int = masks->GetPacked_int();
532  const EBlast4_frame_type frame = (*masks_for_frame)->GetFrame();
533  ITERATE(CPacked_seqint::Tdata, mask, packed_int.Get()) {
535  (new CSeq_interval(const_cast<CSeq_id&>((*mask)->GetId()),
536  (*mask)->GetFrom(), (*mask)->GetTo()));
538  (new CSeqLocInfo(si, NetworkFrame2FrameNumber(frame, program)));
539  mqr->push_back(sli);
540  }
541  }
542 
543  // _ASSERT(query_index == GetQueries()->GetNumQueries() - 1);
544 
545  return retval;
546 }
547 
548 CRemoteBlast::TGSRR::TMasks CRemoteBlast::x_GetMasks(void)
549 {
550  TGSRR::TMasks rv;
551 
552  TGSRR * gsrr = x_GetGSRR();
553 
554  if (gsrr && gsrr->CanGetMasks()) {
555  rv = gsrr->SetMasks();
556  }
557 
558  return rv;
559 }
560 
561 list< CRef<objects::CBlast4_ka_block > > CRemoteBlast::GetKABlocks(void)
562 {
563  list< CRef<CBlast4_ka_block > > rv;
564 
565  TGSRR * gsrr = x_GetGSRR();
566 
567  if (gsrr && gsrr->CanGetKa_blocks()) {
568  rv = (gsrr->SetKa_blocks());
569  }
570 
571  return rv;
572 }
573 
574 list< string > CRemoteBlast::GetSearchStats(void)
575 {
576  list< string > rv;
577 
578  TGSRR * gsrr = x_GetGSRR();
579 
580  if (gsrr && gsrr->CanGetSearch_stats()) {
581  rv = (gsrr->SetSearch_stats());
582  }
583 
584  return rv;
585 }
586 
588 {
590 
591  TGSRR * gsrr = x_GetGSRR();
592 
593  if (gsrr && gsrr->CanGetPssm()) {
594  rv = & (gsrr->SetPssm());
595  }
596 
597  return rv;
598 }
599 
600 
601 // Internal CRemoteBlast methods
602 
604 {
605  // CBlast4Option states:
606 
607  // 0. start (no rid, no errors)
608  // 1. failed (errors)
609  // 2. wait (has rid, no errors, still pending)
610  // 3. done (has rid, no errors, not pending)
611 
612  EState rv = eDone;
613 
614  if (! m_Errs.empty()) {
615  rv = eFailed;
616  } else if (m_RID.empty()) {
617  rv = eStart;
618  } else if (m_Pending) {
619  rv = eWait;
620  }
621 
622  return rv;
623 }
624 
627 {
629 
630  if (m_QSR.Empty()) {
631  m_Errs.push_back("No request exists and no RID was specified.");
632  return retval;
633  }
634 
635  x_SetAlgoOpts();
637 
638  retval.Reset(new CBlast4_request_body);
639  retval->SetQueue_search(*m_QSR);
640  return retval;
641 }
642 
644 {
646  CRef<CBlast4_reply> reply;
647 
648  try {
649  reply = x_SendRequest(body);
650  }
651  catch(const CEofException&) {
652  m_Errs.push_back("No response from server, cannot complete request.");
653  return;
654  }
655 
656  if (reply->CanGetBody() &&
657  reply->GetBody().GetQueue_search().CanGetRequest_id()) {
658 
659  m_RID = reply->GetBody().GetQueue_search().GetRequest_id();
660  }
661 
662  x_SearchErrors(reply);
663 
664  if (m_Errs.empty()) {
665  m_Pending = true;
666  }
667 }
668 
670 {
671  if (! m_Errs.empty()) {
672  m_Pending = false;
673  }
674 
675  if (! m_Pending) {
676  return;
677  }
678 
680 
681  bool try_again = true;
682 
683  while(try_again) {
684  try {
685  r = x_GetSearchResults();
687  try_again = false;
688  }
689  catch(const CEofException&) {
690  --m_ErrIgn;
691 
692  if (m_ErrIgn == 0) {
693  m_Errs.push_back("No response from server, "
694  "cannot complete request.");
695  return;
696  }
697 
698  SleepSec(10);
699  }
700  }
701 
702  if (! m_Pending) {
703  x_SearchErrors(r);
704 
705  if (! m_Errs.empty()) {
706  return;
707  } else if (r->CanGetBody() && r->GetBody().IsGet_search_results()) {
708  m_Reply = r;
709  } else {
710  m_Errs.push_back("Results were not a get-search-results reply");
711  }
712  }
713 }
714 
715 // The input here is a hint as to whether the request might be ready.
716 // If the flag is true, then we are polling immediately after
717 // submission. In this case, the results will not be ready, and so we
718 // skip the first results check to reduce net traffic. If the flag is
719 // false, then the user is using the asynchronous interface, and we do
720 // not know how long it has been since the request was submitted. In
721 // this case, we check the results before sleeping.
722 //
723 // If this was always set to 'true' then async mode would -always-
724 // sleep. This is undesireable in the case where (for example) 100
725 // requests are batched together - the mandatory sleeps would add to a
726 // total of 1000 seconds, more than a quarter hour.
727 //
728 // If it were always specified as 'false', then synchronous mode would
729 // shoot off an immediate 'check results' as soon as the "submit"
730 // returned, which creates unnecessary traffic.
731 //
732 // Futher optimizations are no doubt possible.
733 
735 {
736  if (eDebug == m_Verbose)
737  cout << "polling " << 0 << endl;
738 
739  // Configuration - internal for now
740 
741  double start_sec = 10.0;
742  double increment = 1.30;
743  double max_sleep = 300.0;
744  double max_time = timeout;
745 
746  if (eDebug == m_Verbose)
747  cout << "polling " << start_sec << "/" << increment << "/" << max_sleep << "/" << max_time << "/" << endl;
748 
749  // End config
750 
751  double sleep_next = start_sec;
752  double sleep_totl = 0.0;
753 
754  if (eDebug == m_Verbose)
755  cout << "line " << __LINE__ << " sleep next " << sleep_next << " sleep totl " << sleep_totl << endl;
756 
757  if (ePollAsync == immed) {
759  }
760 
761  while (m_Pending && (sleep_totl < max_time)) {
762  if (eDebug == m_Verbose)
763  cout << " about to sleep " << sleep_next << endl;
764 
765  double max_left = max_time - sleep_totl;
766 
767  // Don't oversleep
768  if (sleep_next > max_left) {
769  sleep_next = max_left;
770 
771  // But never sleep less than 2
772  if (sleep_next < 2.0)
773  sleep_next = 2.0;
774  }
775 
776  SleepSec(int(sleep_next));
777  sleep_totl += sleep_next;
778 
779  if (eDebug == m_Verbose)
780  cout << " done, total = " << sleep_totl << endl;
781 
782  if (sleep_next < max_sleep) {
783  sleep_next *= increment;
784  if (sleep_next > max_sleep) {
785  sleep_next = max_sleep;
786  }
787  }
788 
789  if (eDebug == m_Verbose)
790  cout << " next sleep time = " << sleep_next << endl;
791 
793  }
794 }
795 
797 {
798 
799  // m_Archive.Reset(new CBlast4_archive);
800  CFormatGuess::EFormat fmt_type = ncbi::CFormatGuess().Format(f);
801  switch (fmt_type) {
804  break;
805 
807  m_ObjectStream.reset(new CObjectIStreamAsn(f));
808  break;
809 
810  case CFormatGuess::eXml:
812  break;
813 
814  default:
815  NCBI_THROW(CBlastException, eInvalidArgument,
816  "BLAST archive must be one of text ASN.1, binary ASN.1 or XML.");
817  }
818  m_ReadFile = true;
819  m_ObjectType = fmt_type;
820  m_ErrIgn = 5;
821  m_Verbose = eSilent;
824 }
825 
827 {
828  string p;
829  string s;
831 
832  x_Init(opts, p, s);
833 }
834 
836  const string & program,
837  const string & service)
838 {
839  if ((! opts_handle) || program.empty() || service.empty()) {
840  if (! opts_handle) {
841  NCBI_THROW(CBlastException, eInvalidArgument,
842  "NULL argument specified: options handle");
843  }
844  if (program.empty()) {
845  NCBI_THROW(CBlastException, eInvalidArgument,
846  "NULL argument specified: program");
847  }
848  NCBI_THROW(CBlastException, eInvalidArgument,
849  "NULL argument specified: service");
850  }
851 
852  m_CBOH.Reset( opts_handle );
853  m_ErrIgn = 5;
854  m_Pending = false;
855  m_Verbose = eSilent;
857  m_QueryMaskingLocations.clear();
858  m_ReadFile = false;
861 
863 
864  m_QSR->SetProgram(m_Program = program);
865  m_QSR->SetService(m_Service = service);
866 
868 
869  if (! (opts_handle && opts_handle->SetOptions().GetBlast4AlgoOpts())) {
870  // This happens if you do not specify eRemote for the
871  // CBlastOptions subclass constructor.
872 
873  NCBI_THROW(CBlastException, eInvalidArgument,
874  "CRemoteBlast: No remote API options.");
875  }
877 }
878 
879 void CRemoteBlast::x_Init(const string & RID)
880 {
881  if (RID.empty()) {
882  NCBI_THROW(CBlastException, eInvalidArgument,
883  "Empty RID string specified");
884  }
885 
886  m_RID = RID;
887  m_ErrIgn = 5;
888  m_Pending = true;
889  m_Verbose = eSilent;
891  m_QueryMaskingLocations.clear();
892  m_ReadFile = false;
895 }
896 
898 {
899  CBlast4_parameters * algo_opts =
900  m_CBOH->SetOptions().GetBlast4AlgoOpts();
901 
902  string user_ipv6_address;
904  if( env.Get("HTTP_X_FORWARDED_FOR_IPV6") != kEmptyStr )
905  user_ipv6_address = env.Get("HTTP_X_FORWARDED_FOR_IPV6");
906  if( !user_ipv6_address.empty() ){
907  algo_opts->Add( string("HTTP_X_FORWARDED_FOR_IPV6"), user_ipv6_address );
908  }
909 
910  m_QSR->SetAlgorithm_options().Set() = *algo_opts;
911 }
912 
913 // the "int" version is not actually used (no program options need it.)
914 void CRemoteBlast::x_SetOneParam(objects::CBlast4Field & field,
915  const int * x)
916 {
918  v->SetInteger(*x);
919 
921  p->SetName(field.GetName());
922  p->SetValue(*v);
923  _ASSERT(field.Match(*p));
924 
925  m_QSR->SetProgram_options().Set().push_back(p);
926 }
927 
928 void CRemoteBlast::x_SetOneParam(objects::CBlast4Field & field,
930 {
932  v->SetQuery_mask(*mask);
933 
935  // as dictated by internal/blast/interfaces/blast4/params.hpp
936  p->SetName(field.GetName());
937  p->SetValue(*v);
938  _ASSERT(field.Match(*p));
939 
940  m_QSR->SetProgram_options().Set().push_back(p);
941 }
942 
943 void CRemoteBlast::x_SetOneParam(objects::CBlast4Field & field,
944  const list<int> * x)
945 {
947  v->SetInteger_list() = *x;
948 
950  p->SetName(field.GetName());
951  p->SetValue(*v);
952  _ASSERT(field.Match(*p));
953 
954  m_QSR->SetProgram_options().Set().push_back(p);
955 }
956 
957 void CRemoteBlast::x_SetOneParam(objects::CBlast4Field & field,
958  const list<Int8> * x)
959 {
961  v->SetBig_integer_list() = *x;
962 
964  p->SetName(field.GetName());
965  p->SetValue(*v);
966  _ASSERT(field.Match(*p));
967 
968  m_QSR->SetProgram_options().Set().push_back(p);
969 }
970 
971 
972 void CRemoteBlast::x_SetOneParam(objects::CBlast4Field & field,
973  const char ** x)
974 {
976  v->SetString().assign((x && (*x)) ? (*x) : "");
977 
979  p->SetName(field.GetName());
980  p->SetValue(*v);
981  _ASSERT(field.Match(*p));
982 
983  m_QSR->SetProgram_options().Set().push_back(p);
984 }
985 
987 {
988  if (bioseqs.Empty()) {
989  NCBI_THROW(CBlastException, eInvalidArgument,
990  "Empty reference for query.");
991  }
992 
994  m_Queries->SetBioseq_set(*bioseqs);
995 
996  m_QSR->SetQueries(*m_Queries);
998 }
999 
1001  const TSeqLocInfoVector& masking_locations)
1002 {
1003  SetQueries(bioseqs);
1004  x_SetMaskingLocationsForQueries(masking_locations);
1005 }
1006 
1007 void CRemoteBlast::SetQueryMasks(const TSeqLocInfoVector& masking_locations)
1008 {
1009  if (!m_QSR->IsSetQueries())
1010  {
1011  NCBI_THROW(CBlastException, eInvalidArgument,
1012  "Queries must be set before setting the masks.");
1013  }
1014  x_SetMaskingLocationsForQueries(masking_locations);
1015 }
1016 
1018 {
1019  if (seqlocs.empty()) {
1020  NCBI_THROW(CBlastException, eInvalidArgument,
1021  "Empty list for query.");
1022  }
1023 
1025  m_Queries->SetSeq_loc_list() = seqlocs;
1026 
1027  m_QSR->SetQueries(*m_Queries);
1029 }
1030 
1032  const TSeqLocInfoVector& masking_locations)
1033 {
1034  SetQueries(seqlocs);
1035  x_SetMaskingLocationsForQueries(masking_locations);
1036 }
1037 
1038 void
1040  masking_locations)
1041 {
1042  _ASSERT(m_QSR->CanGetQueries());
1043  if (masking_locations.empty()) {
1044  return;
1045  }
1046 
1047  if (m_QSR->GetQueries().GetNumQueries() != masking_locations.size()) {
1048  CNcbiOstrstream oss;
1049  oss << "Mismatched number of queries ("
1050  << m_QSR->GetQueries().GetNumQueries()
1051  << ") and masking locations (" << masking_locations.size() << ")";
1052  NCBI_THROW(CBlastException, eInvalidArgument,
1054  }
1055 
1056  m_QueryMaskingLocations = const_cast<TSeqLocInfoVector&>(masking_locations);
1057 }
1058 
1059 /** Creates a Blast4-mask which is supposed to contain all masked locations for
1060  * a given query sequence and frame, all of which are in the packed_int
1061  * argument.
1062  */
1063 static CRef<CBlast4_mask>
1065 {
1066  CRef<CBlast4_mask> retval(new CBlast4_mask);
1067 
1068  CRef<CSeq_loc> seqloc(new CSeq_loc);
1069  ITERATE(CPacked_seqint::Tdata, masked_region, packed_int.Get()) {
1070  CRef<CSeq_interval> seqint
1071  (new CSeq_interval(const_cast<CSeq_id&>((*masked_region)->GetId()),
1072  (*masked_region)->GetFrom(),
1073  (*masked_region)->GetTo()));
1074  if ((*masked_region)->CanGetStrand() &&
1075  (*masked_region)->GetStrand() == eNa_strand_minus) {
1076  // skip this as locations on the negative strand are not
1077  // represented in the remote masking locations
1078  continue;
1079  }
1080  seqloc->SetPacked_int().Set().push_back(seqint);
1081  }
1082  retval->SetLocations().push_back(seqloc);
1083 
1084  /// The frame can only be notset for protein queries or plus1 for
1085  /// nucleotide queries
1086  EBlast4_frame_type frame =
1087  (Blast_QueryIsNucleotide(program) || Blast_QueryIsTranslated(program))
1090  retval->SetFrame(frame);
1091 
1092  return retval;
1093 }
1094 
1097  EBlastProgramType program,
1098  vector<string>* warnings /* = NULL */)
1099 {
1101 
1102  ITERATE(TSeqLocInfoVector, query_masks, masking_locations) {
1103  CRef<CPacked_seqint> packed_seqint(new CPacked_seqint);
1104 
1105  if (query_masks->empty()) {
1106  continue;
1107  }
1108 
1109  int current_frame = query_masks->front()->GetFrame();
1110  ITERATE(TMaskedQueryRegions, mask_locs, *query_masks) {
1111  if (Blast_QueryIsTranslated(program) && current_frame != (*mask_locs)->GetFrame())
1112  {
1113  if (!packed_seqint.Empty())
1114  {
1115  CRef<CBlast4_mask> network_mask = s_CreateBlastMask(*packed_seqint, program);
1116  network_mask->SetFrame(FrameNumber2NetworkFrame(current_frame, program));
1117  retval.push_back(network_mask);
1118  }
1119  current_frame = (*mask_locs)->GetFrame();
1120  packed_seqint.Reset(new CPacked_seqint);
1121  }
1122 
1123  packed_seqint->AddInterval((*mask_locs)->GetSeqId(),
1124  (*mask_locs)->GetInterval().GetFrom(),
1125  (*mask_locs)->GetInterval().GetTo());
1126  }
1127 
1128  if (!packed_seqint.Empty())
1129  {
1130  CRef<CBlast4_mask> network_mask = s_CreateBlastMask(*packed_seqint, program);
1131  if (Blast_QueryIsTranslated(program))
1132  network_mask->SetFrame(FrameNumber2NetworkFrame(current_frame, program));
1133  retval.push_back(network_mask);
1134  }
1135  packed_seqint.Reset();
1136  }
1137  return retval;
1138 }
1139 // Puts in each Blast4-mask all the masks that correspond to the same query
1140 // and the same frame.
1141 void
1143 {
1144  if (m_QueryMaskingLocations.empty()) {
1145  return;
1146  }
1147 
1148  m_CBOH->GetOptions().GetRemoteProgramAndService_Blast3(m_Program,
1149  m_Service);
1151  m_Service);
1152 
1153  const CBlast4_get_search_results_reply::TMasks& network_masks =
1155  program, &m_Warn);
1156  ITERATE(CBlast4_get_search_results_reply::TMasks, itr, network_masks) {
1158  }
1159 
1160 }
1161 
1163 {
1164  if (pssm.Empty()) {
1165  NCBI_THROW(CBlastException, eInvalidArgument,
1166  "Empty reference for query pssm.");
1167  }
1168 
1169  CPsiBlastValidate::Pssm(*pssm);
1170 
1171  string psi_program("blastp");
1172  string old_service("plain");
1173  string new_service("psi");
1174  string delta_service("delta_blast");
1175 
1176  if (m_QSR->GetProgram() != psi_program) {
1177  NCBI_THROW(CBlastException, eNotSupported,
1178  "PSI-Blast is only supported for blastp.");
1179  }
1180 
1181  if (m_QSR->GetService().empty()) {
1182  NCBI_THROW(CBlastException, eInvalidArgument,
1183  "Internal error: service is not set.");
1184  }
1185 
1186  if ((m_QSR->GetService() != old_service) &&
1187  (m_QSR->GetService() != new_service) &&
1188  (m_QSR->GetService() != delta_service)) {
1189 
1190  // Allowing "psi" allows the matrix to be set, then replaced.
1191 
1192  NCBI_THROW(CBlastException, eInvalidArgument,
1193  string("PSI-Blast cannot also be ") +
1194  m_QSR->GetService() + ".");
1195  }
1196 
1197  CRef<CBlast4_queries> queries_p(new CBlast4_queries);
1198  queries_p->SetPssm(*pssm);
1199 
1200  m_QSR->SetQueries(*queries_p);
1202 
1203  if(m_QSR->GetService() != delta_service) {
1204  m_QSR->SetService(new_service);
1205  }
1206 }
1207 
1209 {
1210  if (m_Errs.empty()) {
1211  return string();
1212  }
1213 
1214  string rvalue = m_Errs[0];
1215 
1216  for(unsigned i = 1; i<m_Errs.size(); i++) {
1217  rvalue += "\n";
1218  rvalue += m_Errs[i];
1219  }
1220 
1221  return rvalue;
1222 }
1223 
1225 {
1226  if (m_Warn.empty()) {
1227  return string();
1228  }
1229 
1230  string rvalue = m_Warn[0];
1231 
1232  for(unsigned i = 1; i<m_Warn.size(); i++) {
1233  rvalue += "\n";
1234  rvalue += m_Warn[i];
1235  }
1236 
1237  return rvalue;
1238 }
1239 
1240 const vector<string> & CRemoteBlast::GetWarningVector()
1241 {
1242  return m_Warn;
1243 }
1244 
1245 const vector<string> & CRemoteBlast::GetErrorVector()
1246 {
1247  return m_Errs;
1248 }
1249 
1251 {
1252  x_Init(f);
1253  x_InitDiskCache();
1254 }
1255 
1256 CRemoteBlast::CRemoteBlast(const string & RID)
1257 {
1258  x_Init(RID);
1259  x_InitDiskCache();
1260 }
1261 
1263 {
1264  x_Init(algo_opts);
1265  x_InitDiskCache();
1266 }
1267 
1269  CRef<CBlastOptionsHandle> opts_handle,
1270  const CSearchDatabase & db)
1271 {
1272  x_Init(opts_handle, db);
1273  x_InitQueries(queries);
1274  x_InitDiskCache();
1275 }
1276 
1277 void
1278 FlattenBioseqSet(const CBioseq_set & bss, list< CRef<CBioseq> > & seqs)
1279 {
1280  if (bss.CanGetSeq_set()) {
1281  ITERATE(CBioseq_set::TSeq_set, iter, bss.GetSeq_set()) {
1282  if (iter->NotEmpty()) {
1283  const CSeq_entry & entry = **iter;
1284 
1285  if (entry.IsSeq()) {
1286  CBioseq & bs = const_cast<CBioseq &>(entry.GetSeq());
1287  seqs.push_back(CRef<CBioseq>(& bs));
1288  } else {
1289  _ASSERT(entry.IsSet());
1290  FlattenBioseqSet(entry.GetSet(), seqs);
1291  }
1292  }
1293  }
1294  }
1295 }
1296 
1298  CRef<CBlastOptionsHandle> opts_handle,
1299  CRef<IQueryFactory> subjects)
1300 {
1301  x_Init(&* opts_handle);
1302  x_InitQueries(queries);
1303  SetSubjectSequences(subjects);
1304  x_InitDiskCache();
1305 }
1306 
1308 {
1309  if (queries.Empty()) {
1311  eInvalidArgument,
1312  "Error: No queries specified");
1313  }
1314 
1316  CRef<CBioseq_set> bss = Q->GetBioseqSet();
1318 
1319  if (bss.Empty() && sll.empty()) {
1321  eInvalidArgument,
1322  "Error: No query data.");
1323  }
1324 
1325  // Check if there are any range restrictions applied and if local IDs are
1326  // being used to determine how to specify the query sequence(s)
1327 
1328  bool has_local_ids = false;
1329 
1330  if ( !sll.empty() ) {
1331  // Only one range restriction can be sent in this protocol
1332  if (sll.front()->IsInt()) {
1333  const int kStart((int)sll.front()->GetStart(eExtreme_Positional));
1334  const int kStop((int)sll.front()->GetStop(eExtreme_Positional));
1335  const int kRangeLength = kStop - kStart + 1;
1336 
1337  _ASSERT(bss->CanGetSeq_set());
1338  _ASSERT( !bss->GetSeq_set().empty() );
1339  _ASSERT(bss->GetSeq_set().front()->IsSeq());
1340  _ASSERT(bss->GetSeq_set().front()->GetSeq().CanGetInst());
1341  const int kFullLength =
1342  bss->GetSeq_set().front()->GetSeq().GetInst().GetLength();
1343 
1344  if (kFullLength != kRangeLength) {
1347  }
1348  }
1349 
1350  ITERATE(IRemoteQueryData::TSeqLocs, itr, sll) {
1351  if (IsLocalId((*itr)->GetId())) {
1352  has_local_ids = true;
1353  break;
1354  }
1355  }
1356  }
1357 
1358  TSeqLocInfoVector user_specified_masks;
1359  x_ExtractUserSpecifiedMasks(queries, user_specified_masks);
1360 
1361  if (has_local_ids) {
1362  SetQueries(bss, user_specified_masks);
1363  } else {
1364  SetQueries(sll, user_specified_masks);
1365  }
1366 }
1367 
1368 void
1370  TSeqLocInfoVector& masks)
1371 {
1372  masks.clear();
1373  CObjMgr_QueryFactory* objmgrqf = NULL;
1374  if ( (objmgrqf = dynamic_cast<CObjMgr_QueryFactory*>(&*query_factory))) {
1375  masks = objmgrqf->ExtractUserSpecifiedMasks();
1376  }
1377 }
1378 
1380  CRef<CBlastOptionsHandle> opts_handle,
1381  const CSearchDatabase & db)
1382 {
1383  if (pssm.Empty()) {
1385  eInvalidArgument,
1386  "Error: No PSSM specified");
1387  }
1388 
1389  x_Init(opts_handle, db);
1390 
1391  SetQueries(pssm);
1392 }
1393 
1395  const CSearchDatabase & db)
1396 {
1397  if (opts_handle.Empty()) {
1399  eInvalidArgument,
1400  "Error: No options specified");
1401  }
1402 
1403  if (db.GetDatabaseName().empty()) {
1405  eInvalidArgument,
1406  "Error: No database specified");
1407  }
1408 
1409  x_Init(&* opts_handle);
1410 
1413  // Set the GI list restriction
1414  {{
1415  const CSearchDatabase::TGiList& tmplist = db.GetGiListLimitation();
1416  if ( !tmplist.empty() ) {
1417  list<TGi> gilist;
1418  copy(tmplist.begin(), tmplist.end(), back_inserter(gilist));
1419  SetGIList(gilist);
1420  }
1421  }}
1422 
1423  // Set the negative GI list
1424  {{
1425  const CSearchDatabase::TGiList& tmplist =
1427  if ( !tmplist.empty() ) {
1428  list<TGi> gilist;
1429  copy(tmplist.begin(), tmplist.end(), back_inserter(gilist));
1430  SetNegativeGIList(gilist);
1431  }
1432  }}
1433 
1434  // Set the filtering algorithms
1437 }
1438 // initialize disk cache support variables
1440 {
1441  m_use_disk_cache = false;
1442  m_disk_cache_error_flag = false;
1443  m_disk_cache_error_msg.clear();
1445  if( env.Get("BLAST4_DISK_CACHE") != kEmptyStr )
1446  {
1447  string l_disk_cache_flag = env.Get("BLAST4_DISK_CACHE");
1448  if( !NStr::CompareNocase(l_disk_cache_flag,"ON") )
1449  {
1450  m_use_disk_cache = true;
1451  LOG_POST(Info << "CRemoteBlast: DISK CACHE IS ON" );
1452  }
1453  }
1454 }
1455 
1457 {
1458 }
1459 
1460 void CRemoteBlast::SetGIList(const list<TGi> & gi_list)
1461 {
1462  if (gi_list.empty()) {
1463  return;
1464  } else {
1465  NCBI_THROW(CBlastException, eNotSupported,
1466  "Submitting gi lists remotely is currently not supported");
1467  }
1468 
1469  #ifdef NCBI_STRICT_GI
1470  list<int> int_gi_list;
1471  ITERATE ( list<TGi>, it, gi_list ) {
1472  int_gi_list.push_back(GI_TO( int, *it));
1473  }
1475  #else
1477  #endif
1478  m_GiList.clear();
1479  copy(gi_list.begin(), gi_list.end(), back_inserter(m_GiList));
1480 }
1481 
1483 {
1484  if (algo_id == -1)
1485  return;
1486 
1488  m_DbFilteringAlgorithmId = algo_id;
1489  int mask = (int) mask_type;
1491  m_SubjectMaskingType = mask_type;
1492 }
1493 
1495 {
1496  if (algo_key == kEmptyStr)
1497  return;
1498 
1499  const char * key = algo_key.c_str();
1501  m_DbFilteringAlgorithmKey = algo_key;
1502  int mask = (int) mask_type;
1504  m_SubjectMaskingType = mask_type;
1505 }
1506 
1509 {
1510  return m_SubjectMaskingType;
1511 }
1512 
1513 void CRemoteBlast::SetNegativeGIList(const list<TGi> & gi_list)
1514 {
1515  if (gi_list.empty()) {
1516  return;
1517  } else {
1518  NCBI_THROW(CBlastException, eNotSupported,
1519  "Submitting negative gi lists remotely is currently not supported");
1520  }
1521  #ifdef NCBI_STRICT_GI
1522  list<int> int_gi_list;
1523  ITERATE ( list<TGi>, it, gi_list ) {
1524  int_gi_list.push_back(GI_TO( int, *it));
1525  }
1527  #else
1529  #endif
1530 
1531  m_NegativeGiList.clear();
1532  copy(gi_list.begin(), gi_list.end(), back_inserter(m_NegativeGiList));
1533 }
1534 
1535 void CRemoteBlast::x_SetDatabase(const string & x)
1536 {
1538 
1539  if (m_Program == "blastp" ||
1540  m_Program == "blastx" ||
1541  (m_Program == "tblastn" && m_Service == "rpsblast")) {
1542 
1544  } else {
1546  }
1547 
1549  m_Dbs->SetName(x);
1550  m_Dbs->SetType(rtype);
1551 
1552  m_SubjectSequences.clear();
1553 }
1554 
1555 void CRemoteBlast::SetDatabase(const string & x)
1556 {
1557  if (x.empty()) {
1558  NCBI_THROW(CBlastException, eInvalidArgument,
1559  "NULL specified for database.");
1560  }
1561 
1562  CRef<CBlast4_subject> subject_p(new CBlast4_subject);
1563  subject_p->SetDatabase(x);
1564  m_QSR->SetSubject(*subject_p);
1566 
1567  x_SetDatabase(x);
1568 }
1569 
1571 {
1573  CRef<CBioseq_set> bss = Q->GetBioseqSet();
1574 
1575  if (bss.Empty()) {
1577  eInvalidArgument,
1578  "Error: No query data.");
1579  }
1580 
1581  list< CRef<CBioseq> > seqs;
1582  FlattenBioseqSet(*bss, seqs);
1583 
1584  SetSubjectSequences(seqs);
1585 }
1586 
1587 void
1589 {
1590  CRef<CBlast4_subject> subject_p(new CBlast4_subject);
1591  subject_p->SetSequences() = subj;
1592 
1593  m_QSR->SetSubject(*subject_p);
1595 
1596  x_SetSubjectSequences(subj);
1597 }
1598 
1599 void
1601 {
1602  m_SubjectSequences = subj;
1603  m_Dbs.Reset();
1604 }
1605 
1606 void CRemoteBlast::SetEntrezQuery(const char * x)
1607 {
1608  if (!x) {
1609  NCBI_THROW(CBlastException, eInvalidArgument,
1610  "NULL specified for entrez query.");
1611  }
1612 
1613  if (*x) { // Ignore empty strings.
1615  m_EntrezQuery.assign(x);
1616  }
1617 }
1618 
1620 {
1621  return SubmitSync( x_DefaultTimeout() );
1622 }
1623 
1624 const string & CRemoteBlast::GetRID(void)
1625 {
1626  return m_RID;
1627 }
1628 
1630 {
1631  m_Verbose = verb;
1632 }
1633 
1634 /// The default timeout is 3.5 hours.
1636 {
1637  return int(3600*3.5);
1638 }
1639 
1640 static const string
1641  kNoRIDSpecified("Cannot fetch query info: No RID was specified.");
1642 
1643 static const string
1644  kNoArchiveFile("Cannot fetch query info: No archive file.");
1645 
1646 void
1648 {
1649  if(m_ReadFile == true){
1651  }
1652  else{
1654  }
1655 }
1656 
1657 bool
1659 {
1660  if (m_ObjectStream->EndOfData())
1661  return false;
1662 
1665 
1666  m_Errs.empty();
1667  if(m_Archive->IsSetMessages()) {
1668  const list< CRef< CBlast4_error > > & msgs = m_Archive->GetMessages();
1669  ITERATE(list< CRef< CBlast4_error > >, itr, msgs) {
1670  if((*itr)->IsSetMessage()) {
1671  string msg = (*itr)->GetMessage();
1672  if((*itr)->IsSetCode()) {
1673  switch ((*itr)->GetCode()) {
1674  case EDiagSev::eDiag_Info :
1675  LOG_POST(Info << msg);
1676  break;
1678  LOG_POST(Warning << msg);
1679  break;
1680  case EDiagSev::eDiag_Error :
1681  LOG_POST(Error << msg);
1682  break;
1684  LOG_POST(Critical << msg);
1685  break;
1686  case EDiagSev::eDiag_Fatal :
1687  LOG_POST(Fatal << msg);
1688  break;
1689  case EDiagSev::eDiag_Trace :
1690  LOG_POST(Trace << msg);
1691  break;
1692  default :
1693  LOG_POST(Error <<"Unknown Error Code: " << msg);
1694  break;
1695  }
1696  }
1697  }
1698  }
1699  }
1700 
1701  if (!IsErrMsgArchive()) {
1702  x_GetRequestInfoFromFile(); // update info.
1703  }
1704  return true;
1705 }
1706 
1707 
1708 void
1710 {
1711  // Archive file must be present to fetch.
1712  if (!m_Archive || m_Archive.Empty()) {
1713  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1714  kNoArchiveFile);
1715  }
1716 
1717  if (m_Archive->CanGetRequest())
1718  {
1719  CRef<objects::CBlast4_request> request(&m_Archive->SetRequest());
1720  CImportStrategy strategy(request);
1721  m_Program = strategy.GetProgram();
1722  m_Service = strategy.GetService();
1723  m_CreatedBy = strategy.GetCreatedBy();
1724  m_Queries = strategy.GetQueries();
1725  m_AlgoOpts.Reset( strategy.GetAlgoOptions() );
1726  m_ProgramOpts.Reset( strategy.GetProgramOptions() );
1727 
1728  if (strategy.GetSubject()->IsDatabase())
1729  x_SetDatabase(strategy.GetSubject()->GetDatabase());
1730  else
1731  m_SubjectSequences = strategy.GetSubject()->SetSequences();
1732 
1733  if(m_Service == "psi")
1734  {
1735  // Would have errored out in CImportStrategy if we can't get queue search
1736  m_FormatOpts.Reset( strategy.GetWebFormatOptions());
1737  }
1738  // Ignore return value, want side effect of setting fields.
1739  GetSearchOptions();
1740  return;
1741  }
1742 
1743  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1744  "Could not get information from archive file.");
1745 }
1746 
1747 void
1749 {
1750  // Must have an RID to do this.
1751 
1752  if (m_RID.empty()) {
1753  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1754  kNoRIDSpecified);
1755  }
1756 
1757  // First... poll until done.
1758 
1760 
1761  if (x_GetState() != eDone) {
1762  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1763  "Polling terminated, but search is in incomplete state.");
1764  }
1765 
1766  // Build the request
1767 
1770  if ( !m_ClientId.empty() ) {
1771  request->SetIdent(m_ClientId);
1772  }
1773 
1775  request->SetBody(*body);
1776 
1778 
1779  if (eDebug == m_Verbose) {
1780  NcbiCout << MSerial_AsnText << *request << endl;
1781  }
1782 
1783  try {
1785 
1786  if (eDebug == m_Verbose) {
1787  NcbiCout << "Starting network transaction (" << sw.Elapsed() << ")" << endl;
1788  }
1789 
1790  // Send request.
1791  CBlast4Client().Ask(*request, *reply);
1792 
1793  if (eDebug == m_Verbose) {
1794  NcbiCout << "Done network transaction (" << sw.Elapsed() << ")" << endl;
1795  }
1796  }
1797  catch(const CEofException&) {
1798  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1799  "No response from server, cannot complete request.");
1800  }
1801 
1802  if (eDebug == m_Verbose) {
1803  NcbiCout << MSerial_AsnText << *reply << endl;
1804  }
1805 
1806  if (reply->CanGetBody()) {
1807  if (reply->GetBody().IsGet_request_info()) {
1809  (& reply->SetBody().SetGet_request_info());
1810 
1811  if (grir->GetDatabase().GetName() != "n/a") {
1812  m_Dbs.Reset( & grir->SetDatabase() );
1813  } else {
1814  x_GetSubjects();
1815  }
1816 
1817  m_Program = grir->GetProgram();
1818  m_Service = grir->GetService();
1819  m_CreatedBy = grir->GetCreated_by();
1820 
1821  m_Queries .Reset( & grir->SetQueries() );
1822  m_AlgoOpts .Reset( & grir->SetAlgorithm_options() );
1823  m_ProgramOpts.Reset( & grir->SetProgram_options() );
1824  if( grir->IsSetFormat_options() )
1825  m_FormatOpts.Reset( & grir->SetFormat_options() );
1826 
1827  return;
1828  }
1829  }
1830 
1831  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1832  "Could not get information from search.");
1833 }
1834 
1835 
1838 {
1839  if (! m_Dbs.Empty()) {
1840  return m_Dbs;
1841  }
1842 
1843  x_GetRequestInfo();
1844 
1845  return m_Dbs;
1846 }
1847 
1848 bool
1850 {
1851  if (m_Dbs.Empty() && m_SubjectSequences.empty() && m_SubjectSeqLocs.empty())
1852  x_GetRequestInfo();
1853 
1854  if (! m_Dbs.Empty()) {
1855  return true;
1856  }
1857  return false;
1858 }
1859 
1860 list< CRef<objects::CBioseq> >
1862 {
1863  if (x_HasRetrievedSubjects()) {
1864  return m_SubjectSequences;
1865  }
1866 
1867  x_GetRequestInfo();
1868 
1869  return m_SubjectSequences;
1870 }
1871 
1874 {
1875  if (x_HasRetrievedSubjects()) {
1876  return m_SubjectSeqLocs;
1877  }
1878 
1879  x_GetRequestInfo();
1880 
1881  return m_SubjectSeqLocs;
1882 }
1883 
1884 string
1886 {
1887  if (! m_Program.empty()) {
1888  return m_Program;
1889  }
1890 
1891  x_GetRequestInfo();
1892 
1893  return m_Program;
1894 }
1895 
1896 string
1898 {
1899  if (! m_Service.empty()) {
1900  return m_Service;
1901  }
1902 
1903  x_GetRequestInfo();
1904 
1905  return m_Service;
1906 }
1907 
1908 string
1910 {
1911  if (! m_CreatedBy.empty()) {
1912  return m_CreatedBy;
1913  }
1914 
1915  x_GetRequestInfo();
1916 
1917  return m_CreatedBy;
1918 }
1919 
1922 {
1923  if (! m_Queries.Empty()) {
1924  return m_Queries;
1925  }
1926 
1927  x_GetRequestInfo();
1928 
1929  return m_Queries;
1930 }
1931 
1933 NetworkProgram2BlastProgramType(const string& program, const string& service)
1934 {
1935  _ASSERT(!program.empty());
1936  _ASSERT(!service.empty());
1937 
1939  Int2 rv = BlastProgram2Number(program.c_str(), &retval);
1940  _ASSERT(rv == 0);
1941  rv += 0; // to eliminate compiler warning
1942  _ASSERT(retval != eBlastTypeUndefined);
1943 
1944  if (service == "rpsblast") {
1945 
1946  if (program == "blastp") {
1947  retval = eBlastTypeRpsBlast;
1948  } else if (program == "tblastn" || program == "blastx") {
1949  retval = eBlastTypeRpsTblastn;
1950  } else {
1951  abort();
1952  }
1953 
1954  }
1955 
1956  if (service == "psi") {
1957  _ASSERT(program == "blastp");
1958  retval = eBlastTypePsiBlast;
1959  }
1960 
1961  return retval;
1962 }
1963 
1964 
1967 {
1968  if (Blast_QueryIsTranslated(program)) {
1969  switch (frame) {
1970  case 1: return eBlast4_frame_type_plus1;
1971  case 2: return eBlast4_frame_type_plus2;
1972  case 3: return eBlast4_frame_type_plus3;
1973  case -1: return eBlast4_frame_type_minus1;
1974  case -2: return eBlast4_frame_type_minus2;
1975  case -3: return eBlast4_frame_type_minus3;
1976  default: abort();
1977  }
1978  _TROUBLE;
1979  }
1980 
1981  if (Blast_QueryIsNucleotide(program)) {
1982  _ASSERT(frame == -1 || frame == 1);
1983  // For some reason, the return value here is not set...
1985  }
1986 
1988 }
1989 
1992  EBlastProgramType program)
1993 {
1994  if (Blast_QueryIsTranslated(program)) {
1995  switch (frame) {
2002  default: abort();
2003  }
2004  _TROUBLE;
2005  }
2006 
2007  // The BLAST formatter expects nucleotide masks to have a 'not-set' strand,
2008  // which implies that they're on the plus strand. If they're set to
2009  // anything else, it won't display them.
2010  //if (Blast_QueryIsNucleotide(program)) {
2011  // _ASSERT(frame == eBlast4_frame_type_plus1);
2012  // return CSeqLocInfo::eFramePlus1;
2013  //}
2014 
2016 }
2017 
2019 {
2020  if (m_CBOH.Empty()) {
2021  string program_s = GetProgram();
2022  string service_s = GetService();
2023 
2024  CBlastOptionsBuilder bob(program_s, service_s, CBlastOptions::eRemote );
2025 
2027  &m_Task);
2028 
2029  if (bob.HaveEntrezQuery()) {
2030  m_EntrezQuery = bob.GetEntrezQuery();
2031  }
2032 
2033  if (bob.HaveFirstDbSeq()) {
2034  m_FirstDbSeq = bob.GetFirstDbSeq();
2035  }
2036 
2037  if (bob.HaveFinalDbSeq()) {
2038  m_FinalDbSeq = bob.GetFinalDbSeq();
2039  }
2040 
2041  if (bob.HaveGiList()) {
2042  m_GiList = bob.GetGiList();
2043  }
2044 
2045  if(bob.HaveTaxidList()){
2046  list<TTaxId> list = bob.GetTaxidList();
2047  m_TaxidList.clear();
2048  m_TaxidList.insert(list.begin(), list.end());
2049  }
2050 
2051  if(bob.HaveNegativeTaxidList()){
2052  list<TTaxId> list = bob.GetNegativeTaxidList();
2054  m_NegativeTaxidList.insert(list.begin(), list.end());
2055  }
2056 
2057  if (bob.HasDbFilteringAlgorithmId() &&
2058  bob.GetDbFilteringAlgorithmId() != -1) {
2060  }
2061 
2062  if (bob.HasDbFilteringAlgorithmKey() &&
2065  }
2066 
2067  if (bob.HaveNegativeGiList()) {
2069  }
2070  }
2071 
2072  return m_CBOH;
2073 }
2074 
2075 /// Extract the query IDs from a CBioseq_set
2076 /// @param bss CBioseq_set object used as source [in]
2077 /// @param query_ids where the query_ids will be added [in|out]
2080  query_ids)
2081 {
2082  // sacrifice speed for protection against infinite loops
2084  for (; itr; ++itr) {
2085  query_ids.push_back(FindBestChoice(itr->GetId(), CSeq_id::BestRank));
2086  }
2087 }
2088 
2089 void
2091 {
2092  query_ids.clear();
2093  CRef<CBlast4_queries> queries = GetQueries();
2094  query_ids.reserve(queries->GetNumQueries());
2095  _ASSERT(queries);
2096 
2097  if (queries->IsPssm()) {
2098  const CSeq_entry& seq_entry = queries->GetPssm().GetQuery();
2099  if (seq_entry.IsSeq()) {
2100  query_ids.push_back(FindBestChoice(seq_entry.GetSeq().GetId(),
2102  } else {
2103  _ASSERT(seq_entry.IsSet());
2104  s_ExtractQueryIdsFromBioseqSet(seq_entry.GetSet(), query_ids);
2105  }
2106  } else if (queries->IsSeq_loc_list()) {
2107  query_ids.reserve(queries->GetSeq_loc_list().size());
2109  CConstRef<CSeq_id> id((*i)->GetId());
2110  query_ids.push_back(id);
2111  }
2112  } else {
2113  _ASSERT(queries->IsBioseq_set());
2114  s_ExtractQueryIdsFromBioseqSet(queries->GetBioseq_set(), query_ids);
2115  }
2116 }
2117 
2118 /// Submit the search and return the results.
2119 /// @return Search results.
2121 {
2122  CRef<CSearchResultSet> retval;
2123  if (m_ReadFile == false)
2124  SubmitSync();
2125 
2126  TSeqAlignVector alignments = GetSeqAlignSets();
2127 
2128  /* Process errors and warnings */
2129  TSearchMessages search_messages;
2130  {
2131  const vector<string> & W = GetWarningVector();
2132  const vector<string> & E = GetErrorVector();
2133 
2134  TQueryMessages query_messages;
2135 
2136  // Represents the context of the error, not the error id.
2137  int err = kBlastMessageNoContext;
2138 
2139  ITERATE(vector<string>, itw, W) {
2141  sm(new CSearchMessage(eBlastSevWarning, err, *itw));
2142 
2143  query_messages.push_back(sm);
2144  }
2145 
2146  ITERATE(vector<string>, ite, E) {
2147  err = kBlastMessageNoContext;
2148 
2150  sm(new CSearchMessage(eBlastSevError, err, *ite));
2151 
2152  query_messages.push_back(sm);
2153  }
2154 
2155  // Since there is no way to report per-query messages, all
2156  // warnings and errors are applied to all queries.
2157  search_messages.insert(search_messages.end(),
2158  alignments.empty() ? 1 : alignments.size(),
2159  query_messages);
2160 
2161  if (eDebug == m_Verbose) {
2162  NcbiCout << "Error/Warning messages: '"
2163  << search_messages.ToString() << "'" << endl;
2164  }
2165  }
2166 
2168  x_ExtractQueryIds(query_ids);
2169 
2170  if (alignments.empty()) {
2171  // this is required by the CSearchResultSet ctor
2172  alignments.resize(1);
2173  try { x_ExtractQueryIds(query_ids); }
2174  catch (const CRemoteBlastException& e) {
2175  if (e.GetMsg() == kNoRIDSpecified) {
2176  retval.Reset(new CSearchResultSet(alignments, search_messages));
2177  return retval;
2178  }
2179  throw;
2180  }
2181  }
2182 
2183  /* Build the ancillary data structure */
2184  CSearchResultSet::TAncillaryVector ancill_vector;
2185  {
2186  /* Get the effective search space */
2187  const string kTarget("Effective search space used: ");
2188  const string kLength_Adj("Length adjustment: ");
2189  list<string> search_stats = GetSearchStats();
2190  Int8 effective_search_space = 0;
2191  Int8 length_adjustment = 0;
2192  NON_CONST_ITERATE(list<string>, itr, search_stats) {
2193  if (NStr::Find(*itr, kTarget) != NPOS) {
2194  NStr::ReplaceInPlace(*itr, kTarget, kEmptyStr);
2195  effective_search_space =
2197  }
2198  if (NStr::Find(*itr, kLength_Adj) != NPOS) {
2199  NStr::ReplaceInPlace(*itr, kLength_Adj, kEmptyStr);
2200  length_adjustment =
2202  }
2203  }
2204 
2205  if((m_Service == "rpsblast") || (m_Service == "rpstblastn") )
2206  {
2207  const string kTmp("Matrix: ");
2208  NON_CONST_ITERATE(list<string>, itr, search_stats) {
2209  if (NStr::Find(*itr, kTmp) != NPOS) {
2210  NStr::ReplaceInPlace(*itr, kTmp, kEmptyStr);
2211  m_CBOH->SetOptions().SetMatrixName((*itr).c_str());
2212  break;
2213  }
2214  }
2215  }
2216 
2217  /* Get the Karlin-Altschul parameters */
2218  bool found_gapped = false, found_ungapped = false;
2219  pair<double, double> lambdas, Ks, Hs;
2220  TKarlinAltschulBlocks ka_blocks = GetKABlocks();
2221 
2222  ITERATE(TKarlinAltschulBlocks, itr, ka_blocks) {
2223  if ((*itr)->GetGapped()) {
2224  lambdas.second = (*itr)->GetLambda();
2225  Ks.second = (*itr)->GetK();
2226  Hs.second = (*itr)->GetH();
2227  found_gapped = true;
2228  } else {
2229  lambdas.first = (*itr)->GetLambda();
2230  Ks.first = (*itr)->GetK();
2231  Hs.first = (*itr)->GetH();
2232  found_ungapped = true;
2233  }
2234 
2235  if (found_gapped && found_ungapped) {
2236  break;
2237  }
2238  }
2239 
2240  // N.B.: apparently the BLAST3 protocol doesn't send PSI-BLAST Karlin &
2241  // Altschul parameters, so we don't set the is_psiblast
2242  // CBlastAncillaryData constructor argument
2243  CRef<CBlastAncillaryData> ancillary_data
2244  (new CBlastAncillaryData(lambdas, Ks, Hs, effective_search_space, m_Task == "psiblast"));
2245  ancillary_data->SetLengthAdjustment(length_adjustment);
2246  ancill_vector.insert(ancill_vector.end(), alignments.size(),
2247  ancillary_data);
2248  }
2249 
2250  TSeqLocInfoVector masks = GetMasks();
2251  retval.Reset(new CSearchResultSet(query_ids, alignments, search_messages,
2252  ancill_vector, &masks));
2253  retval->SetRID(GetRID());
2254  return retval;
2255 }
2256 
2259 {
2260  // First try to read a Blast4-get-search-strategy-reply...
2262  bool succeeded = false;
2263  try {
2264  switch (CFormatGuess().Format(in)) {
2266  b4_ss_reply.Reset(new CBlast4_get_search_strategy_reply);
2267  in >> MSerial_AsnBinary >> *b4_ss_reply;
2268  succeeded = true;
2269  break;
2270 
2272  b4_ss_reply.Reset(new CBlast4_get_search_strategy_reply);
2273  in >> MSerial_AsnText >> *b4_ss_reply;
2274  succeeded = true;
2275  break;
2276 
2277  case CFormatGuess::eXml:
2278  {
2279  unique_ptr<CObjectIStream> is(
2281  dynamic_cast<CObjectIStreamXml*>
2282  (is.get())->SetEnforcedStdXml(true);
2283  b4_ss_reply.Reset(new CBlast4_get_search_strategy_reply);
2284  *is >> *b4_ss_reply;
2285  succeeded = true;
2286  }
2287  break;
2288 
2289  default:
2290  _ASSERT(b4_ss_reply.Empty());
2291  }
2292  } catch (const CException&) {
2293  succeeded = false;
2294  }
2295 
2296  CRef<CBlast4_request> retval;
2297  if (succeeded) {
2298  retval.Reset(&b4_ss_reply->Set());
2299  return retval;
2300  }
2301  b4_ss_reply.Reset();
2302  in.seekg(0);
2303 
2304  // Go for broke and try the Blast4-request...
2305  retval.Reset(new CBlast4_request);
2306  switch (CFormatGuess().Format(in)) {
2308  in >> MSerial_AsnBinary >> *retval;
2309  break;
2310 
2312  in >> MSerial_AsnText >> *retval;
2313  break;
2314 
2315  case CFormatGuess::eXml:
2316  {
2317  unique_ptr<CObjectIStream> is(
2319  dynamic_cast<CObjectIStreamXml*>
2320  (is.get())->SetEnforcedStdXml(true);
2321  *is >> *retval;
2322  }
2323  break;
2324 
2325  default:
2326  NCBI_THROW(CSerialException, eInvalidData,
2327  "Unrecognized input format ");
2328  }
2329 
2330  return retval;
2331 }
2332 
2334 s_BuildSearchInfoRequest(const string& rid,
2335  const string& name,
2336  const string& value)
2337 {
2339  info_request->SetRequest_id(rid);
2340  info_request->SetInfo().Add(name, value);
2342  retval->SetGet_search_info(*info_request);
2343  return retval;
2344 }
2345 
2346 string
2348  const string& name,
2349  const string& value)
2350 {
2351  string retval;
2352  if (reply.Empty() || !reply->CanGetBody()) {
2353  return retval;
2354  }
2355  if (reply->GetBody().IsGet_search_info()) {
2356  const CBlast4_get_search_info_reply &info_reply = reply->GetBody().GetGet_search_info();
2357  if (info_reply.CanGetRequest_id() && (info_reply.GetRequest_id() == m_RID)) {
2358  if( info_reply.CanGetInfo() ){
2359  const CBlast4_parameters &params = info_reply.GetInfo();
2360  const string reply_name =
2362  CRef< CBlast4_parameter > search_param =
2363  params.GetParamByName(reply_name);
2364  if( search_param.NotEmpty() && search_param->GetValue().IsString()) {
2365  retval = search_param->GetValue().GetString();
2366  }
2367  } // get info
2368  } // request id == m_RID
2369  } // search info reply
2370  return retval;
2371 }
2372 
2373 
2374 //
2375 // based on a new request
2376 //
2378 {
2379  // Build the request
2380  CRef<CBlast4_request_body> request_body =
2384  CRef<CBlast4_reply> reply = x_SendRequest(request_body);
2385  return x_GetStringFromSearchInfoReply(reply,
2388 
2389 }
2390 // Disk Cache version: x_CheckResults
2391 // only difference is that if search finished,
2392 // different approach to call and get results will be orchestrated
2393 // to fist get data from services as-is an deserialize them
2394 // later. This steps will minimize time OM is working.
2395 //
2397 {
2398  LOG_POST(Info << "CRemoteBlast::x_CheckResultsDC");
2399  if (! m_Errs.empty()) {
2400  m_Pending = false;
2401  }
2402 
2403  if (! m_Pending) {
2404  return;
2405  }
2406 
2408 
2409  bool try_again = true;
2410 
2411  while(try_again) {
2412  try {
2413  // asking for search statistics
2414  r = x_GetSearchStatsOnly();
2416  try_again = false;
2417  }
2418  catch(const CEofException&) {
2419  --m_ErrIgn;
2420 
2421  if (m_ErrIgn == 0) {
2422  m_Errs.push_back("No response from server, "
2423  "cannot complete request.");
2424  return;
2425  }
2426 
2427  SleepSec(10);
2428  }
2429  }
2430 
2431  if (! m_Pending) {
2432  // search finishedi check for errors
2433  x_SearchErrors(r);
2434 
2435  if (! m_Errs.empty()) {
2436  return;
2437  }
2438 
2439  if( !r->CanGetBody() ) {
2440  m_Errs.push_back("Results were not a get-search-results reply 2");
2441  return;
2442  }
2443  if( r->CanGetBody() && !r->GetBody().IsGet_search_results()) {
2444  m_Errs.push_back("Results were not a get-search-results reply");
2445  return;
2446  }
2447  //ATTENTION: fullscale get results call
2448  // search finished, retriev results
2450  if( r.Empty() ){
2451  m_Errs.push_back("Results were not a get-search-results reply 3");
2452  return;
2453  }
2454  if( r->CanGetBody() && !r->GetBody().IsGet_search_results()) {
2455  m_Errs.push_back("Results were not a get-search-results reply 4");
2456  return;
2457  }
2459  m_Reply = r;
2460  }
2461 
2462 }
2463 // disk cache support.
2464 // ask for search statistics to check status w/o polling results.
2467 {
2470 
2471  gsrr->SetRequest_id(m_RID);
2472  // result-types
2473  gsrr->ResetResult_types();
2474  gsrr->SetResult_types( 16) ;
2475 
2477  body->SetGet_search_results(*gsrr);
2478 
2479  return x_SendRequest(body);
2480 }
2481 //
2482 // get search results caching first on a file system.
2483 // TODO: check for errors and disable disk caching
2486 {
2488  CStopWatch swatch;
2490  string BLAST4_CONN_SERVICE_NAME = "blast4";
2491  if( env.Get("BLAST4_CONN_SERVICE_NAME") != kEmptyStr )
2492  BLAST4_CONN_SERVICE_NAME = env.Get("BLAST4_CONN_SERVICE_NAME");
2493 
2494  // construct request
2496  gsrr->SetRequest_id( m_RID);
2497 
2499  body->SetGet_search_results(*gsrr);
2500 
2501  CRef<CBlast4_request> request( new CBlast4_request );
2502  request->SetBody(*body );
2503  // call service
2504  swatch.Start();
2505  CConn_ServiceStream ios( BLAST4_CONN_SERVICE_NAME , fSERV_HttpPost, 0);
2506  ios << MSerial_AsnBinary << *request;
2507  ios.flush();
2508  // cache answer to the file
2509  char incoming_buffer[8192];
2510  int read_max = 8192;
2511  int l_total_bytes=0, n_read;
2512  bool l_cached_ok = true;
2513 
2514  unique_ptr<fstream> tmp_stream( CDirEntry::CreateTmpFile() );
2515  do{
2516  n_read = static_cast<int>( CStreamUtils::Readsome(ios,incoming_buffer, read_max) );
2517  if( n_read > 0 ){
2518  l_total_bytes += n_read;
2519  try{
2520  tmp_stream->write(incoming_buffer,n_read);
2521  if( tmp_stream->bad() || tmp_stream->fail() )
2522  {
2523  l_cached_ok = false;
2524  LOG_POST(Error << "CRemoteBlast::x_GetSearchResultsHTTP CAN'T WRITE CACHED DATA: BAD/FAIL STATE" );
2525  m_disk_cache_error_msg = "bad/fail fstream state on write";
2526  break;
2527  }
2528  }
2529  catch ( ios_base::failure &err){
2530  LOG_POST(Error << "CRemoteBlast::x_GetSearchResultsHTTP CAN'T WRITE CACHED DATA: "<<err.what() );
2531  l_cached_ok = false;
2532  m_disk_cache_error_msg = err.what();
2533  break;
2534  }
2535  }
2536  }
2537  while( ios );
2538  swatch.Stop();
2539 
2540  if(!l_cached_ok ){
2541  // Attention: in case of caching error, disable it and re-read w/o caching
2542  LOG_POST(Info << "CRemoteBlast::x_GetSearchResultsHTTP: DISABLE CACHE, RE-READ");
2543  m_use_disk_cache = false;
2544  m_disk_cache_error_flag = true;
2545  return x_GetSearchResults();
2546  }
2547 
2548  tmp_stream->seekg(0);
2549  // read cached answer
2550  swatch.Restart();
2551  try {
2552  unique_ptr<CObjectIStream>
2553  in_stream( CObjectIStream::Open(eSerial_AsnBinary, *tmp_stream) );
2554  in_stream->Read(ObjectInfo(*one_reply), CObjectIStream::eNoFileHeader);
2555 
2556  }
2557  catch(...){
2558  LOG_POST(Info << "CRemoteBlast::x_GetSearchResultsHTTP: DISABLE CACHE, CAN'T READ CACHED FILE, RE-READ");
2559  m_use_disk_cache = false;
2560  m_disk_cache_error_flag = true;
2561  return x_GetSearchResults();
2562  }
2563  swatch.Stop();
2564 
2565  return one_reply ;
2566 }
2567 //
2568 // Get search subject and set
2569 // m_SubjectSeqLocs or m_SubjectSequences
2570 //
2572 {
2573  if( !m_SubjectSequences.empty() && !m_SubjectSeqLocs.empty() )
2574  return; // already got data
2575 
2576  // Build the request
2579  request->SetBody(*body);
2580 
2582 
2583  if (eDebug == m_Verbose) {
2584  NcbiCout << MSerial_AsnText << *request << endl;
2585  }
2586 
2587  try {
2589 
2590  if (eDebug == m_Verbose) {
2591  NcbiCout << "Starting network transaction (" << sw.Elapsed() << ")" << endl;
2592  }
2593 
2594  // Send request.
2595  CBlast4Client().Ask(*request, *reply);
2596 
2597  if (eDebug == m_Verbose) {
2598  NcbiCout << "Done network transaction (" << sw.Elapsed() << ")" << endl;
2599  }
2600  }
2601  catch(const CEofException&) {
2602  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
2603  "No response from server, cannot complete request.");
2604  }
2605 
2606  if (eDebug == m_Verbose) {
2607  NcbiCout << MSerial_AsnText << *reply << endl;
2608  }
2609 
2610  // get reply. it will be status and subjects
2611  if (reply->CanGetBody()) {
2612  if (reply->GetBody().IsGet_search_info()) {
2613  const CBlast4_get_search_info_reply &info_reply = reply->GetBody().GetGet_search_info();
2614  if( info_reply.CanGetRequest_id() && ( info_reply.GetRequest_id() == m_RID ) ){
2615  if( info_reply.CanGetInfo() ){
2616  const CBlast4_parameters &params = info_reply.GetInfo();
2617  string reply_name =
2620  CRef< CBlast4_parameter > search_param = params.GetParamByName (reply_name);
2621  // reply could have string, seq-loc-list or
2622  // bioseq-list, but we don't care about string result for bl2seq
2623  if( search_param.NotEmpty() && search_param->GetValue().IsSeq_loc_list())
2624  {
2625  m_SubjectSeqLocs = search_param->GetValue().GetSeq_loc_list();
2626  }
2627  // bioseq-list // SEQUENCE OF Bioseq
2628  else if( search_param.NotEmpty() && search_param->GetValue().IsBioseq_list())
2629  {
2630  x_SetSubjectSequences( search_param->GetValue().GetBioseq_list() );
2631 
2632  }
2633  else
2634  {
2635  NCBI_THROW(CRemoteBlastException, eIncompleteConfig,
2636  "Obtained database name for remote bl2seq search");
2637  }
2638 
2639  } // get info
2640  } // request id == m_RID
2641  } // search info reply
2642  } // get body
2643 }
2644 
2646 {
2647  unsigned int iter_num = 0;
2648  if(!m_FormatOpts.Empty())
2649  {
2651  if( param.NotEmpty())
2652  {
2653  iter_num = param->GetValue().GetInteger();
2654  }
2655  }
2656  else if(!m_RID.empty())
2657  {
2658  iter_num = x_GetPsiIterationsFromServer();
2659  }
2660 
2661  return iter_num;
2662 }
2663 
2665 {
2666  unsigned int retval=0;
2667 
2668  CRef<CBlast4_request_body> request_body =
2672  CRef<CBlast4_reply> reply = x_SendRequest(request_body);
2673  string num = x_GetStringFromSearchInfoReply(reply,
2676  if ( !num.empty() ) {
2677  try { retval = NStr::StringToUInt(num); }
2678  catch (...) {} // ignore errors and leave as unset
2679  }
2680  return retval;
2681 }
2682 
2684 {
2685  if((m_Archive) != NULL && m_Archive->IsSetRequest() && m_Archive->GetRequest().CanGetBody() &&
2686  m_Archive->GetRequest().GetBody().IsGet_request_info() &&
2687  m_Archive->GetRequest().GetBody().GetGet_request_info().IsSetRequest_id() &&
2688  (m_Archive->GetRequest().GetBody().GetGet_request_info().GetRequest_id() == "Error")) {
2689  return true;
2690  }
2691  return false;
2692 }
2693 
2694 
2695 END_SCOPE(blast)
2697 
2698 /* @} */
#define static
@ eExtreme_Positional
numerical value
Definition: Na_strand.hpp:63
User-defined methods of the data storage class.
User-defined methods of the data storage class.
ESubjectMaskingType
Define the possible subject masking types.
Definition: blast_def.h:235
@ eBlastSevError
Definition: blast_message.h:58
@ eBlastSevWarning
Definition: blast_message.h:57
const int kBlastMessageNoContext
Declared in blast_message.h as extern const.
Definition: blast_message.c:36
Declares the CBlastOptionsBuilder class.
Boolean Blast_QueryIsTranslated(EBlastProgramType p)
Returns true if the query is translated.
Definition: blast_program.c:60
Boolean Blast_QueryIsNucleotide(EBlastProgramType p)
Returns true if the query is nucleotide.
Definition: blast_program.c:43
EBlastProgramType
Defines the engine's notion of the different applications of the BLAST algorithm.
Definition: blast_program.h:72
@ eBlastTypeRpsTblastn
Definition: blast_program.h:85
@ eBlastTypePsiBlast
Definition: blast_program.h:82
@ eBlastTypeRpsBlast
Definition: blast_program.h:84
@ eBlastTypeUndefined
Definition: blast_program.h:89
vector< CRef< objects::CSeq_align_set > > TSeqAlignVector
Vector of Seq-align-sets.
Int2 BlastProgram2Number(const char *program, EBlastProgramType *number)
Set number for a given program type.
Definition: blast_util.c:278
User-defined methods of the data storage class.
ncbi::TMaskedQueryRegions mask
CBlast4Client –.
Definition: blastclient.hpp:66
const string & GetName() const
Get field name (key).
Definition: names.cpp:357
static CBlast4Field & Get(EBlastOptIdx opt)
Definition: names.cpp:45
CBlast4_archive –.
CBlast4_error –.
CBlast4_get_search_info_reply –.
CBlast4_get_search_info_request –.
CBlast4_get_search_results_request –.
CBlast4_get_search_strategy_reply –.
CBlast4_mask –.
Definition: Blast4_mask.hpp:66
CBlast4_parameter –.
CRef< CBlast4_parameter > GetParamByName(const string name) const
Returns Blast4_parameter with specified name.
CRef< CBlast4_parameter > Add(const string name, const int &value)
Append Blast4_parameter.
size_t GetNumQueries() const
Retrieve the number of queries in this object.
CBlast4_queue_search_request –.
CBlast4_reply –.
CBlast4_request_body –.
CBlast4_request –.
CBlast4_subject –.
CBlast4_value –.
Class used to return ancillary data from a blast search, i.e.
Defines BLAST error codes (user errors included)
Class to build CBlastOptionsHandle from blast4 ASN objects.
Handle to the options to the BLAST algorithm.
@ eRemote
To be used when running BLAST remotely.
virtual void GetRemoteProgramAndService_Blast3(string &p, string &s) const
Get the program and service name for remote blast.
This stream exchanges data with a named service, in a constraint that the service is implemented as o...
Class implements different ad-hoc unreliable file format identifications.
EFormat
The formats are checked in the same order as declared here.
@ eBinaryASN
Binary ASN.1.
@ eTextASN
Text ASN.1.
Class to return parts of the CBlast4_request, or data associated with a CBlast4_request,...
CNcbiEnvironment –.
Definition: ncbienv.hpp:110
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
NCBI C++ Object Manager dependant implementation of IQueryFactory.
CObjectIStreamAsnBinary –.
Definition: objistrasnb.hpp:59
CObjectIStreamAsn –.
Definition: objistrasn.hpp:54
CObjectIStreamXml –.
Definition: objistrxml.hpp:56
const CSeq_entry & GetQuery() const
Retrieve the query sequence.
CRef –.
Definition: ncbiobj.hpp:618
Exception class for the CRemoteBlast class.
Blast Search Subject.
Error or Warning Message from search.
Search Results for All Queries.
structure for seqloc info
Definition: seqlocinfo.hpp:48
Definition: Seq_entry.hpp:56
Root class for all serialization exceptions.
Definition: exception.hpp:50
CStopWatch –.
Definition: ncbitime.hpp:1937
Template class for iteration on objects of class C (non-medifiable version)
Definition: iterator.hpp:767
Collection of masked regions for a single query sequence.
Definition: seqlocinfo.hpp:113
Class for the messages for an individual query sequence.
typedef for the messages for an entire BLAST search, which could be comprised of multiple query seque...
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
void clear()
Definition: set.hpp:153
static const char si[8][64]
Definition: des.c:146
static int failure
Definition: t0019.c:11
static HENV env
Definition: transaction2.c:38
static FILE * f
Definition: readconf.c:23
bool LoadFromArchive()
Loads next chunk of archive from file.
CRef< CBlastOptionsHandle > GetSearchOptions()
Get the search options used for this search.
string GetTitle(void)
Get the title assigned for this search.
void x_SearchErrors(CRef< objects::CBlast4_reply > reply)
Iterate over error list, splitting into errors and warnings.
string GetDatabaseName() const
Accessor for the database name.
void x_CheckResultsDC(void)
Try to get and process results using disk cache.
int GetFirstDbSeq()
Get the OID range start point.
CRef< objects::CPssmWithParameters > GetPSSM(void)
Get the PSSM produced by the search.
objects::CBlast4_get_search_results_reply TGSRR
An alias for the most commonly used part of the Blast4 search results.
ENeedConfig m_NeedConfig
Bitfield to track whether all necessary configuration is done.
static CRef< CBlast4_mask > s_CreateBlastMask(const CPacked_seqint &packed_int, EBlastProgramType program)
Creates a Blast4-mask which is supposed to contain all masked locations for a given query sequence an...
string x_GetStringFromSearchInfoReply(CRef< CBlast4_reply > reply, const string &name, const string &value)
CRef< objects::CBlast4_reply > x_GetSearchResults(void)
Try to get the search results.
list< CRef< objects::CBioseq > > m_SubjectSequences
Subject Sequences.
CRef< objects::CBlast4_queries > m_Queries
Queries associated with this search.
objects::EBlast4_frame_type FrameNumber2NetworkFrame(int frame, EBlastProgramType program)
Converts the return value of CSeqLocInfo::GetFrame into the Blast4-frame-type field.
list< CRef< objects::CBlast4_ka_block > > TKarlinAltschulBlocks
Convenience typedef for a list of CRef<CBlast4_ka_block>
CRef< objects::CBlast4_reply > x_GetSearchResultsHTTP(void)
list< TGi > m_GiList
GI list.
bool HaveFirstDbSeq()
Check whether an OID range start point is specified.
string m_RID
Request ID of submitted or pre-existing search.
int GetDbFilteringAlgorithmId()
Get the database filtering algorithm ID.
string GetErrors(void)
This returns a string containing any errors that were produced by the search.
void SetDbFilteringAlgorithmKey(string algo_key, ESubjectMaskingType mask_type=eSoftSubjMasking)
Sets the filtering algorithm key to be applied to the BLAST database (not supported by server yet)
void x_CheckResults(void)
Try to get and process results.
void x_GetSubjects(void)
TSeqLocInfoVector m_QueryMaskingLocations
Masking locations for queries.
TSeqAlignVector GetSeqAlignSets()
Get the seqalign vector from the results.
list< TGi > m_NegativeGiList
Negative GI list.
CFormatGuess::EFormat m_ObjectType
Type of object CBlast4_archive as determined by CFormatGuess.
bool x_IsUnknownRID(void)
Determine if this is an unknown RID.
bool HaveNegativeTaxidList()
Check whether a negative tax id list is specified.
int GetFilteringAlgorithm() const
Accessor for the filtering algorithm ID.
const TGiList GetNegativeGiListLimitation() const
bool m_use_disk_cache
Use disk cache for retrieving results default: false.
ENeedConfig
This class attempts to verify whether all necessary configuration is complete before attempting to su...
CRef< objects::CBlast4_archive > m_Archive
Archive of BLAST search and results.
void x_InitQueries(CRef< IQueryFactory > queries)
Initialize queries based on a query factory.
static CRef< CBlast4_request_body > s_BuildSearchInfoRequest(const string &rid, const string &name, const string &value)
ESearchStatus CheckStatus()
Returns the status of a previously submitted search/RID.
void SetVerbose(EDebugMode verb=eDebug)
Adjust the debugging level.
void x_GetRequestInfoFromRID()
Fetch the requested info from splitd.
list< TGi > GetNegativeGiList()
Get the negative GI list.
string GetFilteringAlgorithmKey() const
Accessor for the filtering algorithm key.
CRef< objects::CBlast4_reply > x_GetSearchStatsOnly(void)
const string & GetRID(void)
Gets the request id (RID) associated with the search.
CRef< blast::CBlastOptionsHandle > m_CBOH
Options for new search.
void SetRID(const string &rid)
Sets the RID for these results.
ESearchStatus
Represents the status of previously submitted search/RID.
vector< CConstRef< objects::CSeq_id > > TQueryIdVector
List of query ids.
void SetDatabase(const string &x)
Set the name of the database to search against.
CRef< objects::CBlast4_parameters > m_FormatOpts
Options relevant to the format application.
void x_ExtractQueryIds(CSearchResultSet::TQueryIdVector &query_ids)
Extract the query IDs from the CBlast4_queries for a given search.
static objects::CBlast4_get_search_results_reply::TMasks ConvertToRemoteMasks(const TSeqLocInfoVector &masking_locations, EBlastProgramType program, vector< string > *warnings=NULL)
Convert a TSeqLocInfoVector to a list< CRef<CBlast4_mask> > objects.
TGSRR::TMasks x_GetMasks(void)
Get the query masks from the results.
vector< string > m_Warn
List of warnings encountered.
bool HaveGiList()
Check whether a GI list is specified.
CBlastOptions & SetOptions()
Returns a reference to the internal options class which this object is a handle for.
EDebugMode
Debugging support can be turned on with eDebug or off with eSilent.
void SetSubjectSequences(CRef< IQueryFactory > subj)
Set a list of subject sequences to search against.
list< CRef< objects::CSeq_loc > > TSeqLocs
Type definition for CSeq_loc set used as queries in the BLAST remote search class.
Definition: query_data.hpp:123
CRef< objects::CBlast4_request_body > x_GetBlast4SearchRequestBody()
Retrieve the request body for a search submission.
static const string kNoRIDSpecified("Cannot fetch query info: No RID was specified.")
void SetGIList(const list< TGi > &gi_list)
This restricts the subject database to this list of GIs (this is not supported yet on the server end)...
CRef< objects::CBlast4_queries > GetQueries()
Get the queries used for this search.
list< TTaxId > GetTaxidList()
Get the Tax list.
void SetQueryMasks(const TSeqLocInfoVector &masking_locations)
Set the masking locations for queries.
int m_DbFilteringAlgorithmId
filtering algorithm to use in the database
EDebugMode m_Verbose
Verbosity mode: whether to produce debugging info on stdout.
EImmediacy
Indicates whether to use async mode.
ESubjectMaskingType GetSubjectMaskingType() const
set< TTaxId > m_NegativeTaxidList
vector< string > m_Errs
List of errors encountered.
void x_SetSubjectSequences(const list< CRef< objects::CBioseq > > &subj)
Set a list of subject sequences to search against (only m_SubjectSequences)
bool HaveEntrezQuery()
Check whether an Entrez query is specified.
list< TTaxId > GetNegativeTaxidList()
Get the negative tax id list.
void x_PollUntilDone(EImmediacy poll_immed, int seconds)
Poll until results are found, error occurs, or timeout expires.
~CRemoteBlast()
Destruct the search object.
void x_Init(CNcbiIstream &f)
Uses the file to populate results.
void x_ExtractUserSpecifiedMasks(CRef< IQueryFactory > query_factory, TSeqLocInfoVector &masks)
Extract the user specified masking locations from the query factory.
vector< TGi > TGiList
Define a list of gis.
void FlattenBioseqSet(const CBioseq_set &bss, list< CRef< CBioseq > > &seqs)
void SetQueries(CRef< objects::CBioseq_set > bioseqs)
Set the query as a Bioseq_set.
void SetNegativeGIList(const list< TGi > &gi_list)
This excludes the provided GIs from the subject database (this is not supported yet on the server end...
unique_ptr< CObjectIStream > m_ObjectStream
Use to ready CBlast4_archive.
CRef< objects::CBlast4_request > ExtractBlast4Request(CNcbiIstream &in)
Extract a Blast4-request (a.k.a.
list< CRef< objects::CBlast4_error > > TErrorList
Error value type used by Blast4 ASN.1 objects.
void x_SetMaskingLocationsForQueries(const TSeqLocInfoVector &masking_locations)
Set the masking locations AFTER the queries have been set in the m_QSR field.
string m_Service
Service value used when submitting this search.
bool HasDbFilteringAlgorithmKey()
Check whether a database filtering algorithm key is specified.
static void s_ExtractQueryIdsFromBioseqSet(const CBioseq_set &bss, CSearchResultSet::TQueryIdVector &query_ids)
Extract the query IDs from a CBioseq_set.
CRef< objects::CSeq_align_set > GetAlignments(void)
Get the seqalign set from the results.
bool IsLocalId(const objects::CSeq_id *seqid)
Returns true if the CSeq_id is a local id.
Definition: blast_aux.cpp:1094
void SetDbFilteringAlgorithmId(int algo_id, ESubjectMaskingType mask_type=eSoftSubjMasking)
Sets the filtering algorithm ID to be applied to the BLAST database (not supported by server yet)
string ToString() const
Converts messages to a string, which is returned.
Definition: blast_aux.cpp:1013
const CBlastOptions & GetOptions() const
Return the object which this object is a handle for.
virtual CRef< objects::CBioseq_set > GetBioseqSet()=0
Accessor for the CBioseq_set.
void x_InitDiskCache(void)
Initialize disk caching.
bool Submit(void)
This submits the search (if necessary) and returns immediately.
bool m_ReadFile
true if a CBlast4_archive should be read in.
int GetFinalDbSeq()
Get the OID range end point.
CBlast4_subject::TSeq_loc_list m_SubjectSeqLocs
This field is populated when dealing with a remote bl2seq search (e.g.
TSeqLocInfoVector GetMasks(void)
Get the queries' masked locations.
string m_FinalDbSeq
Final database sequence.
CRef< objects::CBlast4_database > GetDatabases()
Get the database used by the search.
list< TGi > GetGiList()
Get the GI list.
CRef< objects::CBlast4_parameters > m_AlgoOpts
Options relevant to the search algorithm.
const vector< string > & GetErrorVector()
This returns any errors encountered as a vector of strings.
string m_FirstDbSeq
First database sequence.
EState
Various states the search can be in.
void x_SubmitSearch(void)
Submit the search and process results (of submit action).
CRef< objects::CBlast4_database > m_Dbs
Databases.
CRef< objects::CBlast4_request > GetSearchStrategy()
Fetch the search strategy for this object without submitting the search.
CRef< IRemoteQueryData > MakeRemoteQueryData()
Creates and caches an IRemoteQueryData.
Definition: query_data.cpp:61
EBlastProgramType NetworkProgram2BlastProgramType(const string &program, const string &service)
Function to convert from program and service name into the CORE BLAST program type This is based on t...
string m_ClientId
Client ID submitting requests throw this interface.
TSeqLocInfoVector ExtractUserSpecifiedMasks()
Retrieve any user specified masking locations.
CRef< objects::CBlast4_parameters > m_ProgramOpts
Options relevant to the search application.
CRef< objects::CBlast4_reply > x_SendRequest(CRef< objects::CBlast4_request_body > body)
Send a Blast4 request and get a reply.
static void Pssm(const objects::CPssmWithParameters &pssm, bool require_scores=false)
Perform validation on the PSSM.
list< string > GetSearchStats(void)
Get the search statistics block as a list of strings.
const TGiList GetGiListLimitation() const
void x_GetRequestInfo()
Fetch the request info (wait for completion if necessary).
CRef< CSearchResultSet > GetResultSet()
Submit the search (if necessary) and return the results.
CRef< CBlastOptionsHandle > GetSearchOptions(const objects::CBlast4_parameters *aopts, const objects::CBlast4_parameters *popts, const objects::CBlast4_parameters *fopts, string *task_name=NULL)
Build and return options as a CBlastOptionsHandle.
void SetLengthAdjustment(int len_adj)
Set the length adjustment for boundary conditions.
CRef< objects::CBlast4_queue_search_request > m_QSR
Request object for new search.
set< TTaxId > m_TaxidList
int x_DefaultTimeout(void)
The default timeout is 3.5 hours.
void x_QueryMaskingLocationsToNetwork()
Converts the provided query masking locations (if any) to the network representation following the BL...
string GetService()
Get the service used for this search.
bool CheckDone(void)
Check whether the search has completed.
TKarlinAltschulBlocks GetKABlocks(void)
Get the Karlin/Altschul parameter blocks produced by the search.
string m_DbFilteringAlgorithmKey
filtering algorithm key to use in the database
CRef< objects::CBlast4_reply > m_Reply
Results of BLAST search.
CBlast4_subject::TSeq_loc_list GetSubjectSeqLocs()
list< CRef< objects::CSeq_loc > > TSeqLocList
Typedef for a list of Seq-locs.
string GetCreatedBy()
Get the created-by string associated with this search.
const vector< string > & GetWarningVector()
This returns any warnings encountered as a vector of strings.
string GetWarnings(void)
This returns any warnings encountered.
bool HaveNegativeGiList()
Check whether a negative GI list is specified.
string m_disk_cache_error_msg
disk cache error message
static const string kNoArchiveFile("Cannot fetch query info: No archive file.")
bool IsErrMsgArchive(void)
bool m_Pending
Pending state: indicates that search still needs to be queued.
string m_Task
Task used when the search was submitted (recovered via CBlastOptionsBuilder)
virtual TSeqLocs GetSeqLocs()=0
Accessor for the TSeqLocs.
bool m_disk_cache_error_flag
disk cache error flag
string GetEntrezQuery()
Get the Entrez query.
void x_SetAlgoOpts(void)
Configure new search from options handle passed to constructor.
ESubjectMaskingType m_SubjectMaskingType
string m_Program
Program value used when submitting this search.
void x_CheckConfig(void)
Verify that search object contains mandatory fields.
vector< CRef< CBlastAncillaryData > > TAncillaryVector
typedef for a vector of CRef<CBlastAncillaryData>
list< CRef< objects::CBioseq > > GetSubjectSequences()
Returns subject sequences if "bl2seq" mode used.
void x_GetRequestInfoFromFile()
Fetch the requested info from an archive file.
TGSRR * x_GetGSRR(void)
Poll until done, return the CBlast4_get_search_results_reply.
string m_EntrezQuery
Entrez Query, if any.
bool x_HasRetrievedSubjects() const
string GetDbFilteringAlgorithmKey()
Get the database filtering algorithm key.
TBlast4Opts * GetBlast4AlgoOpts()
CRemoteBlast(const string &RID)
Use the specified RID to get results for an existing search.
string m_CreatedBy
Created-by attribution for this search.
bool HasDbFilteringAlgorithmId()
Check whether a database filtering algorithm ID is specified.
void x_SetDatabase(const string &x)
Sets a subset (only m_Dbs) of what the public SetDatabase sets.
int m_ErrIgn
Count of server glitches (communication errors) to ignore.
bool IsDbSearch()
Return values states whether GetDatabases or GetSubjectSequences call should be used.
string GetEntrezQueryLimitation() const
Accessor for the entrez query.
string GetProgram()
Get the program used for this search.
bool HaveFinalDbSeq()
Check whether an OID range end point is specified.
void x_SetOneParam(objects::CBlast4Field &field, const int *value)
Set an integer parameter (not used yet).
CRef< objects::CBlast4_phi_alignments > GetPhiAlignments(void)
Get the results of a PHI-Align request, if PHI pattern was set.
void SetEntrezQuery(const char *x)
Restrict search to sequences matching this Entrez query.
EState x_GetState(void)
Determine what state the search is in.
unsigned int x_GetPsiIterationsFromServer(void)
unsigned int GetPsiNumberOfIterations(void)
static bool s_SearchPending(CRef< objects::CBlast4_reply > reply)
Determine whether the search is still running.
CSeqLocInfo::ETranslationFrame NetworkFrame2FrameNumber(objects::EBlast4_frame_type frame, EBlastProgramType program)
Converts Blast4-frame-type into CSeqLocInfo::ETranslationFrame.
bool SubmitSync(void)
This submits the search (if necessary) and polls for results.
@ eStatus_Failed
Completed but failed, call GetErrors/GetErrorVector()
@ eStatus_Pending
Not completed yet.
@ eStatus_Unknown
Never submitted or purged from the system.
@ eStatus_Done
Completed successfully.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define GI_TO(T, gi)
Definition: ncbimisc.hpp:1085
string
Definition: cgiapp.hpp:690
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
@ eDiag_Trace
Trace message.
Definition: ncbidiag.hpp:657
@ eDiag_Info
Informational message.
Definition: ncbidiag.hpp:651
@ eDiag_Error
Error message.
Definition: ncbidiag.hpp:653
@ eDiag_Warning
Warning message.
Definition: ncbidiag.hpp:652
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
Definition: ncbidiag.hpp:655
@ eDiag_Critical
Critical error message.
Definition: ncbidiag.hpp:654
void Critical(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1203
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
#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
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
void Trace(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1179
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
void Fatal(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1209
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
static fstream * CreateTmpFile(const string &filename=kEmptyStr, ETextBinary text_binary=eBinary, EAllowRead allow_read=eAllowRead)
Create temporary file and return pointer to corresponding stream.
Definition: ncbifile.cpp:2985
#define MSerial_AsnBinary
Definition: serialbase.hpp:697
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
@ eSerial_Xml
XML.
Definition: serialdef.hpp:75
@ eSerial_AsnBinary
ASN.1 binary.
Definition: serialdef.hpp:74
static int BestRank(const CRef< CSeq_id > &id)
Definition: Seq_id.hpp:774
E_SIC Compare(const CSeq_id &sid2) const
Compare() - more general.
Definition: Seq_id.cpp:411
@ e_YES
SeqIds compared, but are different.
Definition: Seq_id.hpp:583
void SetPacked_int(TPacked_int &v)
Definition: Seq_loc.hpp:984
CConstBeginInfo ConstBegin(const C &obj)
Get starting point of non-modifiable object hierarchy.
Definition: iterator.hpp:1012
@ eDetectLoops
Definition: iterator.hpp:998
pair< TObjectPtr, TTypeInfo > ObjectInfo(C &obj)
Definition: objectinfo.hpp:762
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
bool Empty(void) const THROWS_NONE
Check if CConstRef is empty – not pointing to any object which means having a null value.
Definition: ncbiobj.hpp:1385
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool NotEmpty(void) const THROWS_NONE
Check if CRef is not empty – pointing to an object and has a non-null value.
Definition: ncbiobj.hpp:726
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
Definition: ncbiobj.hpp:719
int16_t Int2
2-byte (16-bit) signed integer
Definition: ncbitype.h:100
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define USING_SCOPE(ns)
Use the specified namespace.
Definition: ncbistl.hpp:78
#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
@ fSERV_HttpPost
#define NcbiCout
Definition: ncbistre.hpp:543
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
static streamsize Readsome(CNcbiIstream &is, CT_CHAR_TYPE *buf, streamsize buf_size)
#define kEmptyStr
Definition: ncbistr.hpp:123
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
static Int8 StringToInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Int8.
Definition: ncbistr.cpp:793
static bool MatchesMask(CTempString str, CTempString mask, ECase use_case=eCase)
Match "str" against the "mask".
Definition: ncbistr.cpp:389
#define NPOS
Definition: ncbistr.hpp:133
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
Definition: ncbistr.cpp:2882
static unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned int.
Definition: ncbistr.cpp:642
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3396
@ fConvErr_NoThrow
Do not throw an exception on error.
Definition: ncbistr.hpp:285
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
double Restart(void)
Return time elapsed since first Start() or last Restart() call (in seconds).
Definition: ncbitime.hpp:2816
double Elapsed(void) const
Return time elapsed since first Start() or last Restart() call (in seconds).
Definition: ncbitime.hpp:2775
void Stop(void)
Suspend the timer.
Definition: ncbitime.hpp:2792
void Start(void)
Start the timer.
Definition: ncbitime.hpp:2764
@ eStart
Start timer immediately after creating.
Definition: ncbitime.hpp:1941
C::value_type FindBestChoice(const C &container, F score_func)
Find the best choice (lowest score) for values in a container.
Definition: ncbiutil.hpp:250
strategy
Block allocation strategies.
Definition: bmconst.h:146
void SetIdent(const TIdent &value)
Assign a value to Ident data member.
bool IsSeq_loc_list(void) const
Check if variant Seq_loc_list is selected.
const TInfo & GetInfo(void) const
Get the Info member data.
bool CanGetRequest_id(void) const
Check if it is safe to call GetRequest_id method.
TQuery_mask & SetQuery_mask(void)
Select the variant.
bool CanGetInfo(void) const
Check if it is safe to call GetInfo method.
TGet_search_results & SetGet_search_results(void)
Select the variant.
TInteger_list & SetInteger_list(void)
Select the variant.
bool IsPssm(void) const
Check if variant Pssm is selected.
void SetBody(TBody &value)
Assign a value to Body data member.
TSequences & SetSequences(void)
Select the variant.
list< CRef< CSeq_loc > > TSeq_loc_list
TGet_request_info & SetGet_request_info(void)
Select the variant.
const TBioseq_set & GetBioseq_set(void) const
Get the variant data.
bool IsBioseq_set(void) const
Check if variant Bioseq_set is selected.
const TSeq_loc_list & GetSeq_loc_list(void) const
Get the variant data.
TGet_search_info & SetGet_search_info(void)
Select the variant.
EBlast4_frame_type
Access to EBlast4_frame_type's attributes (values, names) as defined in spec.
const TRequest_id & GetRequest_id(void) const
Get the Request_id member data.
const TPssm & GetPssm(void) const
Get the variant data.
TQueue_search & SetQueue_search(void)
Select the variant.
TString & SetString(void)
Select the variant.
EBlast4_residue_type
Access to EBlast4_residue_type's attributes (values, names) as defined in spec.
TBig_integer_list & SetBig_integer_list(void)
Select the variant.
void SetRequest_id(const TRequest_id &value)
Assign a value to Request_id data member.
TInteger & SetInteger(void)
Select the variant.
TPssm & SetPssm(void)
Select the variant.
list< CRef< CSeq_loc > > TSeq_loc_list
virtual void Ask(const TRequest &request, TReply &reply)
TDatabase & SetDatabase(void)
Select the variant.
@ eBlast4_error_code_bad_request_id
The RID requested is unknown or it has expired.
@ eBlast4_error_code_not_implemented
Request type is not implemented in the blast4 server.
@ eBlast4_error_code_search_pending
The search is pending.
@ eBlast4_error_code_conversion_warning
A conversion issue was found when converting to/from blast3 from/to blast4 protocol in the blast4 ser...
@ eBlast4_error_code_not_allowed
Request type is not allowed in the blast4 server.
@ eBlast4_error_code_bad_request
Malformed/invalid requests (e.g.: parsing errors or invalid data in request)
@ eBlast4_error_code_internal_error
Indicates internal errors in the blast4 server.
@ eBlast4_frame_type_minus2
@ eBlast4_frame_type_plus2
@ eBlast4_frame_type_plus3
@ eBlast4_frame_type_plus1
@ eBlast4_frame_type_minus3
@ eBlast4_frame_type_notset
@ eBlast4_frame_type_minus1
@ eBlast4_residue_type_nucleotide
@ eBlast4_residue_type_unknown
@ eBlast4_residue_type_protein
Tdata & Set(void)
Assign a value to data member.
list< CRef< CSeq_align > > Tdata
const Tdata & Get(void) const
Get the member data.
list< CRef< CSeq_interval > > Tdata
const Tdata & Get(void) const
Get the member data.
bool IsPacked_int(void) const
Check if variant Packed_int is selected.
Definition: Seq_loc_.hpp:534
const TPacked_int & GetPacked_int(void) const
Get the variant data.
Definition: Seq_loc_.cpp:216
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
const TSeq & GetSeq(void) const
Get the variant data.
Definition: Seq_entry_.cpp:102
bool CanGetSeq_set(void) const
Check if it is safe to call GetSeq_set method.
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
bool IsSeq(void) const
Check if variant Seq is selected.
Definition: Seq_entry_.hpp:257
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
const TSeq_set & GetSeq_set(void) const
Get the Seq_set member data.
list< CRef< CSeq_entry > > TSeq_set
const TId & GetId(void) const
Get the Id member data.
Definition: Bioseq_.hpp:290
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
static CStopWatch sw
int i
Names used in blast4 network communications.
@ eBlastOpt_EntrezQuery
Definition: names.hpp:130
@ eBlastOpt_Web_StepNumber
Definition: names.hpp:154
@ eBlastOpt_RequiredEnd
Definition: names.hpp:141
@ eBlastOpt_DbFilteringAlgorithmKey
Definition: names.hpp:135
@ eBlastOpt_LCaseMask
Definition: names.hpp:138
@ eBlastOpt_NegativeGiList
Definition: names.hpp:140
@ eBlastOpt_DbFilteringAlgorithmId
Definition: names.hpp:134
@ eBlastOpt_GiList
Definition: names.hpp:133
@ eBlastOpt_RequiredStart
Definition: names.hpp:142
@ eBlastOpt_SubjectMaskingType
Definition: names.hpp:136
string Blast4SearchInfo_BuildReplyName(const string &name, const string &value)
This function builds the reply name token in the get-search-info reply objects, provided a pair of st...
Definition: names.cpp:448
const char * kBlast4SearchInfoReqValue_Title
Used to retrieve the BLAST search title.
const char * kBlast4SearchInfoReqValue_Subjects
Used to retrieve the BLAST search subjects.
const char * kBlast4SearchInfoReqValue_PsiIterationNum
Used to retrieve the PSI-BLAST iteration number.
const char * kBlast4SearchInfoReqName_Search
Used to retrieve information about the BLAST search.
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
#define TRUE
bool replacment for C indicating true.
Definition: ncbi_std.h:97
void SleepSec(unsigned long sec, EInterruptOnSignal onsignal=eRestartOnSignal)
Sleep.
Defines: CTimeFormat - storage class for time format.
const double E
std::istream & in(std::istream &in_, double &x_)
Format
Definition: njn_ioutil.hpp:52
void abort()
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
NOTE: This file contains work in progress and the APIs are likely to change, please do not rely on th...
Declarations of auxiliary functions/classes for PSI-BLAST.
Declares the CRemoteBlast class.
Declares the CImportStrategy and CExportStrategy.
vector< TMaskedQueryRegions > TSeqLocInfoVector
Collection of masked regions for all queries in a BLAST search.
Definition: seqlocinfo.hpp:139
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
#define _TROUBLE
#define _ASSERT
static string kStart("Start")
done
Definition: token1.c:1
#define W
Definition: crc32.c:85
Modified on Fri Sep 20 14:57:26 2024 by modify_doxy.py rev. 669887