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 100101 2023-06-15 14:10:29Z 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  m_Warn.push_back(string("conversion_warning") + msg);
117  break;
118 
120  m_Errs.push_back(string("internal_error") + msg);
121  break;
122 
124  m_Errs.push_back(string("not_implemented") + msg);
125  break;
126 
128  m_Errs.push_back(string("not_allowed") + msg);
129  break;
130 
132  m_Errs.push_back(string("bad_request") + msg);
133  break;
134 
136  m_Errs.push_back(string("Invalid/unknown RID (bad_request_id)") +
137  msg);
138  break;
139  }
140  }
141 }
142 
143 
144 
145 // CBlast4Option methods
146 
148 {
149  // If not configured, throw an exception - the associated string
150  // will contain a list of the missing pieces.
151 
152  if (0 != m_NeedConfig) {
153  string cfg("Configuration required:");
154 
155  if (eProgram & m_NeedConfig) {
156  cfg += " <program>";
157  }
158 
159  if (eService & m_NeedConfig) {
160  cfg += " <service>";
161  }
162 
163  if (eQueries & m_NeedConfig) {
164  cfg += " <queries>";
165  }
166 
167  if (eSubject & m_NeedConfig) {
168  cfg += " <subject>";
169  }
170 
171  NCBI_THROW(CRemoteBlastException, eIncompleteConfig, cfg);
172  }
173 }
174 
177 {
179  x_CheckConfig();
180  string errors(GetErrors());
181  if ( !errors.empty() ) {
182  NCBI_THROW(CRemoteBlastException, eIncompleteConfig, errors);
183  }
185  if ( !m_ClientId.empty() ) {
186  retval->SetIdent(m_ClientId);
187  }
188  retval->SetBody(*body);
189  return retval;
190 }
191 
194 {
195  // If not configured, throw.
196  x_CheckConfig();
197 
198  // Create the request; optionally echo it
199 
201  if ( !m_ClientId.empty() ) {
202  request->SetIdent(m_ClientId);
203  }
204  request->SetBody(*body);
205 
206  if (eDebug == m_Verbose) {
207  NcbiCout << MSerial_AsnText << *request << endl;
208  }
209 
210  // submit to server, get reply; optionally echo it
211 
213 
214  try {
216 
217  if (eDebug == m_Verbose) {
218  NcbiCout << "Starting network transaction (" << sw.Elapsed() << ")" << endl;
219  }
220 
221  CBlast4Client().Ask(*request, *reply);
222 
223  if (eDebug == m_Verbose) {
224  NcbiCout << "Done network transaction (" << sw.Elapsed() << ")" << endl;
225  }
226  }
227  catch(const CEofException&) {
228  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
229  "No response from server, cannot complete request.");
230  }
231 
232  if (eDebug == m_Verbose) {
233  NcbiCout << MSerial_AsnText << *reply << endl;
234  }
235 
236  return reply;
237 }
238 
241 {
244 
245  gsrr->SetRequest_id(m_RID);
246 
248  body->SetGet_search_results(*gsrr);
249 
250  return x_SendRequest(body);
251 }
252 
253 // Pre: start, wait, or done
254 // Post: failed or done
255 
256 // Returns: true if done
257 
258 bool CRemoteBlast::SubmitSync(int seconds)
259 {
260  // eFailed: no work to do, already an error.
261  // eDone: already done, just return.
262 
263  EImmediacy immed = ePollAsync;
264 
265  switch(x_GetState()) {
266  case eStart:
267  x_SubmitSearch();
268  if (! m_Errs.empty()) {
269  break;
270  }
271  immed = ePollImmed;
272  // fall through
273 
274  case eWait:
275  x_PollUntilDone(immed, seconds);
276  break;
277  default:
278  break;
279  }
280 
281  return (x_GetState() == eDone);
282 }
283 
284 
285 
286 // Pre: start
287 // Post: failed, wait or done
288 
289 // Returns: true if no error so far
290 
292 {
293  switch(x_GetState()) {
294  case eStart:
295  x_SubmitSearch();
296  default: break;
297  }
298 
299  return m_Errs.empty();
300 }
301 
302 //
303 // The following table summarizes how to determine the status of a given
304 // RID/search submission:
305 //
306 // | CheckDone() | CheckDone()
307 // | returns true | returns false
308 // ------------------------------------------------------------
309 // GetErrors() == kEmptyStr | DONE | PENDING
310 // ------------------------------------------------------------
311 // GetErrors() != kEmptyStr | FAILED | UNKNOWN RID
312 // ------------------------------------------------------------
313 //
316 {
318 
319  bool done = CheckDone();
320  string errors = GetErrors();
321 
322  if (done && errors == kEmptyStr) {
323  retval = eStatus_Done;
324  } else if (!done && errors == kEmptyStr) {
325  retval = eStatus_Pending;
326  } else if (!done && errors.find("bad_request_id") != NPOS) {
327  retval = eStatus_Unknown;
328  } else if (done && errors != kEmptyStr) {
329  retval = eStatus_Failed;
330  }
331  return retval;
332 }
333 
335 {
336  bool retval = false;
337  if (NStr::Find(GetErrors(), "bad_request_id") != NPOS) {
338  retval = true;
339  }
340  return retval;
341 }
342 
343 // Pre: start, wait or done
344 // Post: wait, done, or failed
345 
346 // Returns: true if done
347 
349 {
350  switch(x_GetState()) {
351  case eFailed:
352  case eDone:
353  break;
354 
355  case eStart:
356  Submit();
357  break;
358 
359  case eWait:
361  }
362 
363  int state = x_GetState();
364  return (state == eDone || (state == eFailed && !x_IsUnknownRID()));
365 }
366 
368 {
369  TGSRR* rv = NULL;
370 
371  if (m_ReadFile)
372  {
373  rv = &(m_Archive->SetResults());
374  }
375  else if (SubmitSync() &&
376  m_Reply.NotEmpty() &&
377  m_Reply->CanGetBody() &&
378  m_Reply->GetBody().IsGet_search_results()) {
379 
380  rv = & (m_Reply->SetBody().SetGet_search_results());
381  }
382 
383  return rv;
384 }
385 
387 {
389 
390  TGSRR * gsrr = x_GetGSRR();
391 
392  if (gsrr && gsrr->CanGetAlignments()) {
393  rv = & (gsrr->SetAlignments());
394  }
395 
396  return rv;
397 }
398 
400 {
402 
403  TSeqAlignVector rv;
404 
405  CRef<CSeq_align_set> cur_set;
406  CConstRef<CSeq_id> current_id;
407 
408  // this loop groups all matches to one target sequences in one vector element.
409  TSeqAlignVector temp;
410 
411  if (al.NotEmpty())
412  {
413  ITERATE(CSeq_align_set::Tdata, it, al->Get()) {
414  // index 0 = query, index 1 = subject
415  const int query_index = 0;
416  CConstRef<CSeq_id> this_id( & (*it)->GetSeq_id(query_index) );
417 
418  if (current_id.Empty() || (CSeq_id::e_YES != this_id->Compare(*current_id))) {
419  if (cur_set.NotEmpty()) {
420  temp.push_back(cur_set);
421  }
422  cur_set.Reset(new CSeq_align_set);
423  current_id = this_id;
424  }
425  cur_set->Set().push_back(*it);
426  }
427  }
428 
429  if (cur_set.NotEmpty()) {
430  temp.push_back(cur_set);
431  }
432 
434  x_ExtractQueryIds(query_ids);
435 
436  // Fill out the return value, with empty Seq-align-set if not match for a query.
437  TSeqAlignVector::size_type sap_index = 0;
438  ITERATE(CSearchResultSet::TQueryIdVector, it, query_ids) {
439  const int query_index = 0;
440  if (sap_index < temp.size())
441  {
442  list< CRef< CSeq_align > > sal = temp[sap_index]->Get();
443  CConstRef<CSeq_id> this_id( & (sal.front()->GetSeq_id(query_index) ));
444  if (CSeq_id::e_YES == (*it)->Compare(sal.front()->GetSeq_id(query_index) ))
445  {
446  rv.push_back(temp[sap_index]);
447  sap_index++;
448  }
449  else
450  {
451  cur_set.Reset(new CSeq_align_set);
452  rv.push_back(cur_set);
453  }
454  }
455  else
456  {
457  cur_set.Reset(new CSeq_align_set);
458  rv.push_back(cur_set);
459  }
460  }
461 
462  return rv;
463 }
464 
466 {
468 
469  TGSRR * gsrr = x_GetGSRR();
470 
471  if (gsrr && gsrr->CanGetPhi_alignments()) {
472  rv = & (gsrr->SetPhi_alignments());
473  }
474 
475  return rv;
476 }
477 
478 // N.B.: this function assumes that the BLAST 4 server sends the query masked
479 // locations for each query adjacent to one another in the list of masks (i.e.:
480 // masks-for-query1-frameA, masks-for-query1-frameB, ...,
481 // masks-for-query2-frameA, masks-for-query2-frameB, ... etc).
484 {
485  TSeqLocInfoVector retval;
486  retval.resize(GetQueries()->GetNumQueries());
487 
488  TGSRR::TMasks network_masks = x_GetMasks();
489  if (network_masks.empty()) {
490  return retval;
491  }
492 
494  m_Service);
495  CConstRef<CSeq_id> previous_seqid;
496  size_t query_index = 0;
497 
498  ITERATE(TGSRR::TMasks, masks_for_frame, network_masks) {
499 
500  _ASSERT(masks_for_frame->NotEmpty());
501 
502  CConstRef<CSeq_id> current_seqid
503  ((*masks_for_frame)->GetLocations().front()->GetId());
504  if (previous_seqid.Empty()) {
505  previous_seqid = current_seqid;
506  }
507 
508  // determine which query are we setting the masks for...
509  TMaskedQueryRegions* mqr = NULL;
510  if (CSeq_id::e_YES == current_seqid->Compare(*previous_seqid)) {
511  mqr = &retval[query_index];
512  } else {
513  mqr = &retval[++query_index];
514  previous_seqid = current_seqid;
515  }
516 
517  // all the masks for a given query and frame are in a single
518  // Packed-seqint
519  _ASSERT((*masks_for_frame)->GetLocations().size() == (size_t) 1);
520  _ASSERT((*masks_for_frame)->GetLocations().front().NotEmpty());
521  CRef<CSeq_loc> masks =
522  (*masks_for_frame)->GetLocations().front();
523  _ASSERT(masks->IsPacked_int());
524 
525  const CPacked_seqint& packed_int = masks->GetPacked_int();
526  const EBlast4_frame_type frame = (*masks_for_frame)->GetFrame();
527  ITERATE(CPacked_seqint::Tdata, mask, packed_int.Get()) {
529  (new CSeq_interval(const_cast<CSeq_id&>((*mask)->GetId()),
530  (*mask)->GetFrom(), (*mask)->GetTo()));
532  (new CSeqLocInfo(si, NetworkFrame2FrameNumber(frame, program)));
533  mqr->push_back(sli);
534  }
535  }
536 
537  // _ASSERT(query_index == GetQueries()->GetNumQueries() - 1);
538 
539  return retval;
540 }
541 
542 CRemoteBlast::TGSRR::TMasks CRemoteBlast::x_GetMasks(void)
543 {
544  TGSRR::TMasks rv;
545 
546  TGSRR * gsrr = x_GetGSRR();
547 
548  if (gsrr && gsrr->CanGetMasks()) {
549  rv = gsrr->SetMasks();
550  }
551 
552  return rv;
553 }
554 
555 list< CRef<objects::CBlast4_ka_block > > CRemoteBlast::GetKABlocks(void)
556 {
557  list< CRef<CBlast4_ka_block > > rv;
558 
559  TGSRR * gsrr = x_GetGSRR();
560 
561  if (gsrr && gsrr->CanGetKa_blocks()) {
562  rv = (gsrr->SetKa_blocks());
563  }
564 
565  return rv;
566 }
567 
568 list< string > CRemoteBlast::GetSearchStats(void)
569 {
570  list< string > rv;
571 
572  TGSRR * gsrr = x_GetGSRR();
573 
574  if (gsrr && gsrr->CanGetSearch_stats()) {
575  rv = (gsrr->SetSearch_stats());
576  }
577 
578  return rv;
579 }
580 
582 {
584 
585  TGSRR * gsrr = x_GetGSRR();
586 
587  if (gsrr && gsrr->CanGetPssm()) {
588  rv = & (gsrr->SetPssm());
589  }
590 
591  return rv;
592 }
593 
594 
595 // Internal CRemoteBlast methods
596 
598 {
599  // CBlast4Option states:
600 
601  // 0. start (no rid, no errors)
602  // 1. failed (errors)
603  // 2. wait (has rid, no errors, still pending)
604  // 3. done (has rid, no errors, not pending)
605 
606  EState rv = eDone;
607 
608  if (! m_Errs.empty()) {
609  rv = eFailed;
610  } else if (m_RID.empty()) {
611  rv = eStart;
612  } else if (m_Pending) {
613  rv = eWait;
614  }
615 
616  return rv;
617 }
618 
621 {
623 
624  if (m_QSR.Empty()) {
625  m_Errs.push_back("No request exists and no RID was specified.");
626  return retval;
627  }
628 
629  x_SetAlgoOpts();
631 
632  retval.Reset(new CBlast4_request_body);
633  retval->SetQueue_search(*m_QSR);
634  return retval;
635 }
636 
638 {
640  CRef<CBlast4_reply> reply;
641 
642  try {
643  reply = x_SendRequest(body);
644  }
645  catch(const CEofException&) {
646  m_Errs.push_back("No response from server, cannot complete request.");
647  return;
648  }
649 
650  if (reply->CanGetBody() &&
651  reply->GetBody().GetQueue_search().CanGetRequest_id()) {
652 
653  m_RID = reply->GetBody().GetQueue_search().GetRequest_id();
654  }
655 
656  x_SearchErrors(reply);
657 
658  if (m_Errs.empty()) {
659  m_Pending = true;
660  }
661 }
662 
664 {
665  if (! m_Errs.empty()) {
666  m_Pending = false;
667  }
668 
669  if (! m_Pending) {
670  return;
671  }
672 
674 
675  bool try_again = true;
676 
677  while(try_again) {
678  try {
679  r = x_GetSearchResults();
681  try_again = false;
682  }
683  catch(const CEofException&) {
684  --m_ErrIgn;
685 
686  if (m_ErrIgn == 0) {
687  m_Errs.push_back("No response from server, "
688  "cannot complete request.");
689  return;
690  }
691 
692  SleepSec(10);
693  }
694  }
695 
696  if (! m_Pending) {
697  x_SearchErrors(r);
698 
699  if (! m_Errs.empty()) {
700  return;
701  } else if (r->CanGetBody() && r->GetBody().IsGet_search_results()) {
702  m_Reply = r;
703  } else {
704  m_Errs.push_back("Results were not a get-search-results reply");
705  }
706  }
707 }
708 
709 // The input here is a hint as to whether the request might be ready.
710 // If the flag is true, then we are polling immediately after
711 // submission. In this case, the results will not be ready, and so we
712 // skip the first results check to reduce net traffic. If the flag is
713 // false, then the user is using the asynchronous interface, and we do
714 // not know how long it has been since the request was submitted. In
715 // this case, we check the results before sleeping.
716 //
717 // If this was always set to 'true' then async mode would -always-
718 // sleep. This is undesireable in the case where (for example) 100
719 // requests are batched together - the mandatory sleeps would add to a
720 // total of 1000 seconds, more than a quarter hour.
721 //
722 // If it were always specified as 'false', then synchronous mode would
723 // shoot off an immediate 'check results' as soon as the "submit"
724 // returned, which creates unnecessary traffic.
725 //
726 // Futher optimizations are no doubt possible.
727 
729 {
730  if (eDebug == m_Verbose)
731  cout << "polling " << 0 << endl;
732 
733  // Configuration - internal for now
734 
735  double start_sec = 10.0;
736  double increment = 1.30;
737  double max_sleep = 300.0;
738  double max_time = timeout;
739 
740  if (eDebug == m_Verbose)
741  cout << "polling " << start_sec << "/" << increment << "/" << max_sleep << "/" << max_time << "/" << endl;
742 
743  // End config
744 
745  double sleep_next = start_sec;
746  double sleep_totl = 0.0;
747 
748  if (eDebug == m_Verbose)
749  cout << "line " << __LINE__ << " sleep next " << sleep_next << " sleep totl " << sleep_totl << endl;
750 
751  if (ePollAsync == immed) {
753  }
754 
755  while (m_Pending && (sleep_totl < max_time)) {
756  if (eDebug == m_Verbose)
757  cout << " about to sleep " << sleep_next << endl;
758 
759  double max_left = max_time - sleep_totl;
760 
761  // Don't oversleep
762  if (sleep_next > max_left) {
763  sleep_next = max_left;
764 
765  // But never sleep less than 2
766  if (sleep_next < 2.0)
767  sleep_next = 2.0;
768  }
769 
770  SleepSec(int(sleep_next));
771  sleep_totl += sleep_next;
772 
773  if (eDebug == m_Verbose)
774  cout << " done, total = " << sleep_totl << endl;
775 
776  if (sleep_next < max_sleep) {
777  sleep_next *= increment;
778  if (sleep_next > max_sleep) {
779  sleep_next = max_sleep;
780  }
781  }
782 
783  if (eDebug == m_Verbose)
784  cout << " next sleep time = " << sleep_next << endl;
785 
787  }
788 }
789 
791 {
792 
793  // m_Archive.Reset(new CBlast4_archive);
794  CFormatGuess::EFormat fmt_type = ncbi::CFormatGuess().Format(f);
795  switch (fmt_type) {
798  break;
799 
801  m_ObjectStream.reset(new CObjectIStreamAsn(f));
802  break;
803 
804  case CFormatGuess::eXml:
806  break;
807 
808  default:
809  NCBI_THROW(CBlastException, eInvalidArgument,
810  "BLAST archive must be one of text ASN.1, binary ASN.1 or XML.");
811  }
812  m_ReadFile = true;
813  m_ObjectType = fmt_type;
814  m_ErrIgn = 5;
815  m_Verbose = eSilent;
818 }
819 
821 {
822  string p;
823  string s;
825 
826  x_Init(opts, p, s);
827 }
828 
830  const string & program,
831  const string & service)
832 {
833  if ((! opts_handle) || program.empty() || service.empty()) {
834  if (! opts_handle) {
835  NCBI_THROW(CBlastException, eInvalidArgument,
836  "NULL argument specified: options handle");
837  }
838  if (program.empty()) {
839  NCBI_THROW(CBlastException, eInvalidArgument,
840  "NULL argument specified: program");
841  }
842  NCBI_THROW(CBlastException, eInvalidArgument,
843  "NULL argument specified: service");
844  }
845 
846  m_CBOH.Reset( opts_handle );
847  m_ErrIgn = 5;
848  m_Pending = false;
849  m_Verbose = eSilent;
851  m_QueryMaskingLocations.clear();
852  m_ReadFile = false;
855 
857 
858  m_QSR->SetProgram(m_Program = program);
859  m_QSR->SetService(m_Service = service);
860 
862 
863  if (! (opts_handle && opts_handle->SetOptions().GetBlast4AlgoOpts())) {
864  // This happens if you do not specify eRemote for the
865  // CBlastOptions subclass constructor.
866 
867  NCBI_THROW(CBlastException, eInvalidArgument,
868  "CRemoteBlast: No remote API options.");
869  }
871 }
872 
873 void CRemoteBlast::x_Init(const string & RID)
874 {
875  if (RID.empty()) {
876  NCBI_THROW(CBlastException, eInvalidArgument,
877  "Empty RID string specified");
878  }
879 
880  m_RID = RID;
881  m_ErrIgn = 5;
882  m_Pending = true;
883  m_Verbose = eSilent;
885  m_QueryMaskingLocations.clear();
886  m_ReadFile = false;
889 }
890 
892 {
893  CBlast4_parameters * algo_opts =
894  m_CBOH->SetOptions().GetBlast4AlgoOpts();
895 
896  string user_ipv6_address;
898  if( env.Get("HTTP_X_FORWARDED_FOR_IPV6") != kEmptyStr )
899  user_ipv6_address = env.Get("HTTP_X_FORWARDED_FOR_IPV6");
900  if( !user_ipv6_address.empty() ){
901  algo_opts->Add( string("HTTP_X_FORWARDED_FOR_IPV6"), user_ipv6_address );
902  }
903 
904  m_QSR->SetAlgorithm_options().Set() = *algo_opts;
905 }
906 
907 // the "int" version is not actually used (no program options need it.)
908 void CRemoteBlast::x_SetOneParam(objects::CBlast4Field & field,
909  const int * x)
910 {
912  v->SetInteger(*x);
913 
915  p->SetName(field.GetName());
916  p->SetValue(*v);
917  _ASSERT(field.Match(*p));
918 
919  m_QSR->SetProgram_options().Set().push_back(p);
920 }
921 
922 void CRemoteBlast::x_SetOneParam(objects::CBlast4Field & field,
924 {
926  v->SetQuery_mask(*mask);
927 
929  // as dictated by internal/blast/interfaces/blast4/params.hpp
930  p->SetName(field.GetName());
931  p->SetValue(*v);
932  _ASSERT(field.Match(*p));
933 
934  m_QSR->SetProgram_options().Set().push_back(p);
935 }
936 
937 void CRemoteBlast::x_SetOneParam(objects::CBlast4Field & field,
938  const list<int> * x)
939 {
941  v->SetInteger_list() = *x;
942 
944  p->SetName(field.GetName());
945  p->SetValue(*v);
946  _ASSERT(field.Match(*p));
947 
948  m_QSR->SetProgram_options().Set().push_back(p);
949 }
950 
951 void CRemoteBlast::x_SetOneParam(objects::CBlast4Field & field,
952  const list<Int8> * x)
953 {
955  v->SetBig_integer_list() = *x;
956 
958  p->SetName(field.GetName());
959  p->SetValue(*v);
960  _ASSERT(field.Match(*p));
961 
962  m_QSR->SetProgram_options().Set().push_back(p);
963 }
964 
965 
966 void CRemoteBlast::x_SetOneParam(objects::CBlast4Field & field,
967  const char ** x)
968 {
970  v->SetString().assign((x && (*x)) ? (*x) : "");
971 
973  p->SetName(field.GetName());
974  p->SetValue(*v);
975  _ASSERT(field.Match(*p));
976 
977  m_QSR->SetProgram_options().Set().push_back(p);
978 }
979 
981 {
982  if (bioseqs.Empty()) {
983  NCBI_THROW(CBlastException, eInvalidArgument,
984  "Empty reference for query.");
985  }
986 
988  m_Queries->SetBioseq_set(*bioseqs);
989 
990  m_QSR->SetQueries(*m_Queries);
992 }
993 
995  const TSeqLocInfoVector& masking_locations)
996 {
997  SetQueries(bioseqs);
998  x_SetMaskingLocationsForQueries(masking_locations);
999 }
1000 
1001 void CRemoteBlast::SetQueryMasks(const TSeqLocInfoVector& masking_locations)
1002 {
1003  if (!m_QSR->IsSetQueries())
1004  {
1005  NCBI_THROW(CBlastException, eInvalidArgument,
1006  "Queries must be set before setting the masks.");
1007  }
1008  x_SetMaskingLocationsForQueries(masking_locations);
1009 }
1010 
1012 {
1013  if (seqlocs.empty()) {
1014  NCBI_THROW(CBlastException, eInvalidArgument,
1015  "Empty list for query.");
1016  }
1017 
1019  m_Queries->SetSeq_loc_list() = seqlocs;
1020 
1021  m_QSR->SetQueries(*m_Queries);
1023 }
1024 
1026  const TSeqLocInfoVector& masking_locations)
1027 {
1028  SetQueries(seqlocs);
1029  x_SetMaskingLocationsForQueries(masking_locations);
1030 }
1031 
1032 void
1034  masking_locations)
1035 {
1036  _ASSERT(m_QSR->CanGetQueries());
1037  if (masking_locations.empty()) {
1038  return;
1039  }
1040 
1041  if (m_QSR->GetQueries().GetNumQueries() != masking_locations.size()) {
1042  CNcbiOstrstream oss;
1043  oss << "Mismatched number of queries ("
1044  << m_QSR->GetQueries().GetNumQueries()
1045  << ") and masking locations (" << masking_locations.size() << ")";
1046  NCBI_THROW(CBlastException, eInvalidArgument,
1048  }
1049 
1050  m_QueryMaskingLocations = const_cast<TSeqLocInfoVector&>(masking_locations);
1051 }
1052 
1053 /** Creates a Blast4-mask which is supposed to contain all masked locations for
1054  * a given query sequence and frame, all of which are in the packed_int
1055  * argument.
1056  */
1057 static CRef<CBlast4_mask>
1059 {
1060  CRef<CBlast4_mask> retval(new CBlast4_mask);
1061 
1062  CRef<CSeq_loc> seqloc(new CSeq_loc);
1063  ITERATE(CPacked_seqint::Tdata, masked_region, packed_int.Get()) {
1064  CRef<CSeq_interval> seqint
1065  (new CSeq_interval(const_cast<CSeq_id&>((*masked_region)->GetId()),
1066  (*masked_region)->GetFrom(),
1067  (*masked_region)->GetTo()));
1068  if ((*masked_region)->CanGetStrand() &&
1069  (*masked_region)->GetStrand() == eNa_strand_minus) {
1070  // skip this as locations on the negative strand are not
1071  // represented in the remote masking locations
1072  continue;
1073  }
1074  seqloc->SetPacked_int().Set().push_back(seqint);
1075  }
1076  retval->SetLocations().push_back(seqloc);
1077 
1078  /// The frame can only be notset for protein queries or plus1 for
1079  /// nucleotide queries
1080  EBlast4_frame_type frame =
1081  (Blast_QueryIsNucleotide(program) || Blast_QueryIsTranslated(program))
1084  retval->SetFrame(frame);
1085 
1086  return retval;
1087 }
1088 
1091  EBlastProgramType program,
1092  vector<string>* warnings /* = NULL */)
1093 {
1095 
1096  ITERATE(TSeqLocInfoVector, query_masks, masking_locations) {
1097  CRef<CPacked_seqint> packed_seqint(new CPacked_seqint);
1098 
1099  if (query_masks->empty()) {
1100  continue;
1101  }
1102 
1103  int current_frame = query_masks->front()->GetFrame();
1104  ITERATE(TMaskedQueryRegions, mask_locs, *query_masks) {
1105  if (Blast_QueryIsTranslated(program) && current_frame != (*mask_locs)->GetFrame())
1106  {
1107  if (!packed_seqint.Empty())
1108  {
1109  CRef<CBlast4_mask> network_mask = s_CreateBlastMask(*packed_seqint, program);
1110  network_mask->SetFrame(FrameNumber2NetworkFrame(current_frame, program));
1111  retval.push_back(network_mask);
1112  }
1113  current_frame = (*mask_locs)->GetFrame();
1114  packed_seqint.Reset(new CPacked_seqint);
1115  }
1116 
1117  packed_seqint->AddInterval((*mask_locs)->GetSeqId(),
1118  (*mask_locs)->GetInterval().GetFrom(),
1119  (*mask_locs)->GetInterval().GetTo());
1120  }
1121 
1122  if (!packed_seqint.Empty())
1123  {
1124  CRef<CBlast4_mask> network_mask = s_CreateBlastMask(*packed_seqint, program);
1125  if (Blast_QueryIsTranslated(program))
1126  network_mask->SetFrame(FrameNumber2NetworkFrame(current_frame, program));
1127  retval.push_back(network_mask);
1128  }
1129  packed_seqint.Reset();
1130  }
1131  return retval;
1132 }
1133 // Puts in each Blast4-mask all the masks that correspond to the same query
1134 // and the same frame.
1135 void
1137 {
1138  if (m_QueryMaskingLocations.empty()) {
1139  return;
1140  }
1141 
1142  m_CBOH->GetOptions().GetRemoteProgramAndService_Blast3(m_Program,
1143  m_Service);
1145  m_Service);
1146 
1147  const CBlast4_get_search_results_reply::TMasks& network_masks =
1149  program, &m_Warn);
1150  ITERATE(CBlast4_get_search_results_reply::TMasks, itr, network_masks) {
1152  }
1153 
1154 }
1155 
1157 {
1158  if (pssm.Empty()) {
1159  NCBI_THROW(CBlastException, eInvalidArgument,
1160  "Empty reference for query pssm.");
1161  }
1162 
1163  CPsiBlastValidate::Pssm(*pssm);
1164 
1165  string psi_program("blastp");
1166  string old_service("plain");
1167  string new_service("psi");
1168  string delta_service("delta_blast");
1169 
1170  if (m_QSR->GetProgram() != psi_program) {
1171  NCBI_THROW(CBlastException, eNotSupported,
1172  "PSI-Blast is only supported for blastp.");
1173  }
1174 
1175  if (m_QSR->GetService().empty()) {
1176  NCBI_THROW(CBlastException, eInvalidArgument,
1177  "Internal error: service is not set.");
1178  }
1179 
1180  if ((m_QSR->GetService() != old_service) &&
1181  (m_QSR->GetService() != new_service) &&
1182  (m_QSR->GetService() != delta_service)) {
1183 
1184  // Allowing "psi" allows the matrix to be set, then replaced.
1185 
1186  NCBI_THROW(CBlastException, eInvalidArgument,
1187  string("PSI-Blast cannot also be ") +
1188  m_QSR->GetService() + ".");
1189  }
1190 
1191  CRef<CBlast4_queries> queries_p(new CBlast4_queries);
1192  queries_p->SetPssm(*pssm);
1193 
1194  m_QSR->SetQueries(*queries_p);
1196 
1197  if(m_QSR->GetService() != delta_service) {
1198  m_QSR->SetService(new_service);
1199  }
1200 }
1201 
1203 {
1204  if (m_Errs.empty()) {
1205  return string();
1206  }
1207 
1208  string rvalue = m_Errs[0];
1209 
1210  for(unsigned i = 1; i<m_Errs.size(); i++) {
1211  rvalue += "\n";
1212  rvalue += m_Errs[i];
1213  }
1214 
1215  return rvalue;
1216 }
1217 
1219 {
1220  if (m_Warn.empty()) {
1221  return string();
1222  }
1223 
1224  string rvalue = m_Warn[0];
1225 
1226  for(unsigned i = 1; i<m_Warn.size(); i++) {
1227  rvalue += "\n";
1228  rvalue += m_Warn[i];
1229  }
1230 
1231  return rvalue;
1232 }
1233 
1234 const vector<string> & CRemoteBlast::GetWarningVector()
1235 {
1236  return m_Warn;
1237 }
1238 
1239 const vector<string> & CRemoteBlast::GetErrorVector()
1240 {
1241  return m_Errs;
1242 }
1243 
1245 {
1246  x_Init(f);
1247  x_InitDiskCache();
1248 }
1249 
1250 CRemoteBlast::CRemoteBlast(const string & RID)
1251 {
1252  x_Init(RID);
1253  x_InitDiskCache();
1254 }
1255 
1257 {
1258  x_Init(algo_opts);
1259  x_InitDiskCache();
1260 }
1261 
1263  CRef<CBlastOptionsHandle> opts_handle,
1264  const CSearchDatabase & db)
1265 {
1266  x_Init(opts_handle, db);
1267  x_InitQueries(queries);
1268  x_InitDiskCache();
1269 }
1270 
1271 void
1272 FlattenBioseqSet(const CBioseq_set & bss, list< CRef<CBioseq> > & seqs)
1273 {
1274  if (bss.CanGetSeq_set()) {
1275  ITERATE(CBioseq_set::TSeq_set, iter, bss.GetSeq_set()) {
1276  if (iter->NotEmpty()) {
1277  const CSeq_entry & entry = **iter;
1278 
1279  if (entry.IsSeq()) {
1280  CBioseq & bs = const_cast<CBioseq &>(entry.GetSeq());
1281  seqs.push_back(CRef<CBioseq>(& bs));
1282  } else {
1283  _ASSERT(entry.IsSet());
1284  FlattenBioseqSet(entry.GetSet(), seqs);
1285  }
1286  }
1287  }
1288  }
1289 }
1290 
1292  CRef<CBlastOptionsHandle> opts_handle,
1293  CRef<IQueryFactory> subjects)
1294 {
1295  x_Init(&* opts_handle);
1296  x_InitQueries(queries);
1297  SetSubjectSequences(subjects);
1298  x_InitDiskCache();
1299 }
1300 
1302 {
1303  if (queries.Empty()) {
1305  eInvalidArgument,
1306  "Error: No queries specified");
1307  }
1308 
1310  CRef<CBioseq_set> bss = Q->GetBioseqSet();
1312 
1313  if (bss.Empty() && sll.empty()) {
1315  eInvalidArgument,
1316  "Error: No query data.");
1317  }
1318 
1319  // Check if there are any range restrictions applied and if local IDs are
1320  // being used to determine how to specify the query sequence(s)
1321 
1322  bool has_local_ids = false;
1323 
1324  if ( !sll.empty() ) {
1325  // Only one range restriction can be sent in this protocol
1326  if (sll.front()->IsInt()) {
1327  const int kStart((int)sll.front()->GetStart(eExtreme_Positional));
1328  const int kStop((int)sll.front()->GetStop(eExtreme_Positional));
1329  const int kRangeLength = kStop - kStart + 1;
1330 
1331  _ASSERT(bss->CanGetSeq_set());
1332  _ASSERT( !bss->GetSeq_set().empty() );
1333  _ASSERT(bss->GetSeq_set().front()->IsSeq());
1334  _ASSERT(bss->GetSeq_set().front()->GetSeq().CanGetInst());
1335  const int kFullLength =
1336  bss->GetSeq_set().front()->GetSeq().GetInst().GetLength();
1337 
1338  if (kFullLength != kRangeLength) {
1341  }
1342  }
1343 
1344  ITERATE(IRemoteQueryData::TSeqLocs, itr, sll) {
1345  if (IsLocalId((*itr)->GetId())) {
1346  has_local_ids = true;
1347  break;
1348  }
1349  }
1350  }
1351 
1352  TSeqLocInfoVector user_specified_masks;
1353  x_ExtractUserSpecifiedMasks(queries, user_specified_masks);
1354 
1355  if (has_local_ids) {
1356  SetQueries(bss, user_specified_masks);
1357  } else {
1358  SetQueries(sll, user_specified_masks);
1359  }
1360 }
1361 
1362 void
1364  TSeqLocInfoVector& masks)
1365 {
1366  masks.clear();
1367  CObjMgr_QueryFactory* objmgrqf = NULL;
1368  if ( (objmgrqf = dynamic_cast<CObjMgr_QueryFactory*>(&*query_factory))) {
1369  masks = objmgrqf->ExtractUserSpecifiedMasks();
1370  }
1371 }
1372 
1374  CRef<CBlastOptionsHandle> opts_handle,
1375  const CSearchDatabase & db)
1376 {
1377  if (pssm.Empty()) {
1379  eInvalidArgument,
1380  "Error: No PSSM specified");
1381  }
1382 
1383  x_Init(opts_handle, db);
1384 
1385  SetQueries(pssm);
1386 }
1387 
1389  const CSearchDatabase & db)
1390 {
1391  if (opts_handle.Empty()) {
1393  eInvalidArgument,
1394  "Error: No options specified");
1395  }
1396 
1397  if (db.GetDatabaseName().empty()) {
1399  eInvalidArgument,
1400  "Error: No database specified");
1401  }
1402 
1403  x_Init(&* opts_handle);
1404 
1407  // Set the GI list restriction
1408  {{
1409  const CSearchDatabase::TGiList& tmplist = db.GetGiListLimitation();
1410  if ( !tmplist.empty() ) {
1411  list<TGi> gilist;
1412  copy(tmplist.begin(), tmplist.end(), back_inserter(gilist));
1413  SetGIList(gilist);
1414  }
1415  }}
1416 
1417  // Set the negative GI list
1418  {{
1419  const CSearchDatabase::TGiList& tmplist =
1421  if ( !tmplist.empty() ) {
1422  list<TGi> gilist;
1423  copy(tmplist.begin(), tmplist.end(), back_inserter(gilist));
1424  SetNegativeGIList(gilist);
1425  }
1426  }}
1427 
1428  // Set the filtering algorithms
1431 }
1432 // initialize disk cache support variables
1434 {
1435  m_use_disk_cache = false;
1436  m_disk_cache_error_flag = false;
1437  m_disk_cache_error_msg.clear();
1439  if( env.Get("BLAST4_DISK_CACHE") != kEmptyStr )
1440  {
1441  string l_disk_cache_flag = env.Get("BLAST4_DISK_CACHE");
1442  if( !NStr::CompareNocase(l_disk_cache_flag,"ON") )
1443  {
1444  m_use_disk_cache = true;
1445  LOG_POST(Info << "CRemoteBlast: DISK CACHE IS ON" );
1446  }
1447  }
1448 }
1449 
1451 {
1452 }
1453 
1454 void CRemoteBlast::SetGIList(const list<TGi> & gi_list)
1455 {
1456  if (gi_list.empty()) {
1457  return;
1458  } else {
1459  NCBI_THROW(CBlastException, eNotSupported,
1460  "Submitting gi lists remotely is currently not supported");
1461  }
1462 
1463  #ifdef NCBI_STRICT_GI
1464  list<int> int_gi_list;
1465  ITERATE ( list<TGi>, it, gi_list ) {
1466  int_gi_list.push_back(GI_TO( int, *it));
1467  }
1469  #else
1471  #endif
1472  m_GiList.clear();
1473  copy(gi_list.begin(), gi_list.end(), back_inserter(m_GiList));
1474 }
1475 
1477 {
1478  if (algo_id == -1)
1479  return;
1480 
1482  m_DbFilteringAlgorithmId = algo_id;
1483  int mask = (int) mask_type;
1485  m_SubjectMaskingType = mask_type;
1486 }
1487 
1489 {
1490  if (algo_key == kEmptyStr)
1491  return;
1492 
1493  const char * key = algo_key.c_str();
1495  m_DbFilteringAlgorithmKey = algo_key;
1496  int mask = (int) mask_type;
1498  m_SubjectMaskingType = mask_type;
1499 }
1500 
1503 {
1504  return m_SubjectMaskingType;
1505 }
1506 
1507 void CRemoteBlast::SetNegativeGIList(const list<TGi> & gi_list)
1508 {
1509  if (gi_list.empty()) {
1510  return;
1511  } else {
1512  NCBI_THROW(CBlastException, eNotSupported,
1513  "Submitting negative gi lists remotely is currently not supported");
1514  }
1515  #ifdef NCBI_STRICT_GI
1516  list<int> int_gi_list;
1517  ITERATE ( list<TGi>, it, gi_list ) {
1518  int_gi_list.push_back(GI_TO( int, *it));
1519  }
1521  #else
1523  #endif
1524 
1525  m_NegativeGiList.clear();
1526  copy(gi_list.begin(), gi_list.end(), back_inserter(m_NegativeGiList));
1527 }
1528 
1529 void CRemoteBlast::x_SetDatabase(const string & x)
1530 {
1532 
1533  if (m_Program == "blastp" ||
1534  m_Program == "blastx" ||
1535  (m_Program == "tblastn" && m_Service == "rpsblast")) {
1536 
1538  } else {
1540  }
1541 
1543  m_Dbs->SetName(x);
1544  m_Dbs->SetType(rtype);
1545 
1546  m_SubjectSequences.clear();
1547 }
1548 
1549 void CRemoteBlast::SetDatabase(const string & x)
1550 {
1551  if (x.empty()) {
1552  NCBI_THROW(CBlastException, eInvalidArgument,
1553  "NULL specified for database.");
1554  }
1555 
1556  CRef<CBlast4_subject> subject_p(new CBlast4_subject);
1557  subject_p->SetDatabase(x);
1558  m_QSR->SetSubject(*subject_p);
1560 
1561  x_SetDatabase(x);
1562 }
1563 
1565 {
1567  CRef<CBioseq_set> bss = Q->GetBioseqSet();
1568 
1569  if (bss.Empty()) {
1571  eInvalidArgument,
1572  "Error: No query data.");
1573  }
1574 
1575  list< CRef<CBioseq> > seqs;
1576  FlattenBioseqSet(*bss, seqs);
1577 
1578  SetSubjectSequences(seqs);
1579 }
1580 
1581 void
1583 {
1584  CRef<CBlast4_subject> subject_p(new CBlast4_subject);
1585  subject_p->SetSequences() = subj;
1586 
1587  m_QSR->SetSubject(*subject_p);
1589 
1590  x_SetSubjectSequences(subj);
1591 }
1592 
1593 void
1595 {
1596  m_SubjectSequences = subj;
1597  m_Dbs.Reset();
1598 }
1599 
1600 void CRemoteBlast::SetEntrezQuery(const char * x)
1601 {
1602  if (!x) {
1603  NCBI_THROW(CBlastException, eInvalidArgument,
1604  "NULL specified for entrez query.");
1605  }
1606 
1607  if (*x) { // Ignore empty strings.
1609  m_EntrezQuery.assign(x);
1610  }
1611 }
1612 
1614 {
1615  return SubmitSync( x_DefaultTimeout() );
1616 }
1617 
1618 const string & CRemoteBlast::GetRID(void)
1619 {
1620  return m_RID;
1621 }
1622 
1624 {
1625  m_Verbose = verb;
1626 }
1627 
1628 /// The default timeout is 3.5 hours.
1630 {
1631  return int(3600*3.5);
1632 }
1633 
1634 static const string
1635  kNoRIDSpecified("Cannot fetch query info: No RID was specified.");
1636 
1637 static const string
1638  kNoArchiveFile("Cannot fetch query info: No archive file.");
1639 
1640 void
1642 {
1643  if(m_ReadFile == true){
1645  }
1646  else{
1648  }
1649 }
1650 
1651 bool
1653 {
1654  if (m_ObjectStream->EndOfData())
1655  return false;
1656 
1659 
1660  m_Errs.empty();
1661  if(m_Archive->IsSetMessages()) {
1662  const list< CRef< CBlast4_error > > & msgs = m_Archive->GetMessages();
1663  ITERATE(list< CRef< CBlast4_error > >, itr, msgs) {
1664  if((*itr)->IsSetMessage()) {
1665  string msg = (*itr)->GetMessage();
1666  if((*itr)->IsSetCode()) {
1667  switch ((*itr)->GetCode()) {
1668  case EDiagSev::eDiag_Info :
1669  LOG_POST(Info << msg);
1670  break;
1672  LOG_POST(Warning << msg);
1673  break;
1674  case EDiagSev::eDiag_Error :
1675  LOG_POST(Error << msg);
1676  break;
1678  LOG_POST(Critical << msg);
1679  break;
1680  case EDiagSev::eDiag_Fatal :
1681  LOG_POST(Fatal << msg);
1682  break;
1683  case EDiagSev::eDiag_Trace :
1684  LOG_POST(Trace << msg);
1685  break;
1686  default :
1687  LOG_POST(Error <<"Unknown Error Code: " << msg);
1688  break;
1689  }
1690  }
1691  }
1692  }
1693  }
1694 
1695  if (!IsErrMsgArchive()) {
1696  x_GetRequestInfoFromFile(); // update info.
1697  }
1698  return true;
1699 }
1700 
1701 
1702 void
1704 {
1705  // Archive file must be present to fetch.
1706  if (!m_Archive || m_Archive.Empty()) {
1707  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1708  kNoArchiveFile);
1709  }
1710 
1711  if (m_Archive->CanGetRequest())
1712  {
1713  CRef<objects::CBlast4_request> request(&m_Archive->SetRequest());
1714  CImportStrategy strategy(request);
1715  m_Program = strategy.GetProgram();
1716  m_Service = strategy.GetService();
1717  m_CreatedBy = strategy.GetCreatedBy();
1718  m_Queries = strategy.GetQueries();
1719  m_AlgoOpts.Reset( strategy.GetAlgoOptions() );
1720  m_ProgramOpts.Reset( strategy.GetProgramOptions() );
1721 
1722  if (strategy.GetSubject()->IsDatabase())
1723  x_SetDatabase(strategy.GetSubject()->GetDatabase());
1724  else
1725  m_SubjectSequences = strategy.GetSubject()->SetSequences();
1726 
1727  if(m_Service == "psi")
1728  {
1729  // Would have errored out in CImportStrategy if we can't get queue search
1730  m_FormatOpts.Reset( strategy.GetWebFormatOptions());
1731  }
1732  // Ignore return value, want side effect of setting fields.
1733  GetSearchOptions();
1734  return;
1735  }
1736 
1737  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1738  "Could not get information from archive file.");
1739 }
1740 
1741 void
1743 {
1744  // Must have an RID to do this.
1745 
1746  if (m_RID.empty()) {
1747  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1748  kNoRIDSpecified);
1749  }
1750 
1751  // First... poll until done.
1752 
1754 
1755  if (x_GetState() != eDone) {
1756  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1757  "Polling terminated, but search is in incomplete state.");
1758  }
1759 
1760  // Build the request
1761 
1764  if ( !m_ClientId.empty() ) {
1765  request->SetIdent(m_ClientId);
1766  }
1767 
1769  request->SetBody(*body);
1770 
1772 
1773  if (eDebug == m_Verbose) {
1774  NcbiCout << MSerial_AsnText << *request << endl;
1775  }
1776 
1777  try {
1779 
1780  if (eDebug == m_Verbose) {
1781  NcbiCout << "Starting network transaction (" << sw.Elapsed() << ")" << endl;
1782  }
1783 
1784  // Send request.
1785  CBlast4Client().Ask(*request, *reply);
1786 
1787  if (eDebug == m_Verbose) {
1788  NcbiCout << "Done network transaction (" << sw.Elapsed() << ")" << endl;
1789  }
1790  }
1791  catch(const CEofException&) {
1792  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1793  "No response from server, cannot complete request.");
1794  }
1795 
1796  if (eDebug == m_Verbose) {
1797  NcbiCout << MSerial_AsnText << *reply << endl;
1798  }
1799 
1800  if (reply->CanGetBody()) {
1801  if (reply->GetBody().IsGet_request_info()) {
1803  (& reply->SetBody().SetGet_request_info());
1804 
1805  if (grir->GetDatabase().GetName() != "n/a") {
1806  m_Dbs.Reset( & grir->SetDatabase() );
1807  } else {
1808  x_GetSubjects();
1809  }
1810 
1811  m_Program = grir->GetProgram();
1812  m_Service = grir->GetService();
1813  m_CreatedBy = grir->GetCreated_by();
1814 
1815  m_Queries .Reset( & grir->SetQueries() );
1816  m_AlgoOpts .Reset( & grir->SetAlgorithm_options() );
1817  m_ProgramOpts.Reset( & grir->SetProgram_options() );
1818  if( grir->IsSetFormat_options() )
1819  m_FormatOpts.Reset( & grir->SetFormat_options() );
1820 
1821  return;
1822  }
1823  }
1824 
1825  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
1826  "Could not get information from search.");
1827 }
1828 
1829 
1832 {
1833  if (! m_Dbs.Empty()) {
1834  return m_Dbs;
1835  }
1836 
1837  x_GetRequestInfo();
1838 
1839  return m_Dbs;
1840 }
1841 
1842 bool
1844 {
1845  if (m_Dbs.Empty() && m_SubjectSequences.empty() && m_SubjectSeqLocs.empty())
1846  x_GetRequestInfo();
1847 
1848  if (! m_Dbs.Empty()) {
1849  return true;
1850  }
1851  return false;
1852 }
1853 
1854 list< CRef<objects::CBioseq> >
1856 {
1857  if (x_HasRetrievedSubjects()) {
1858  return m_SubjectSequences;
1859  }
1860 
1861  x_GetRequestInfo();
1862 
1863  return m_SubjectSequences;
1864 }
1865 
1868 {
1869  if (x_HasRetrievedSubjects()) {
1870  return m_SubjectSeqLocs;
1871  }
1872 
1873  x_GetRequestInfo();
1874 
1875  return m_SubjectSeqLocs;
1876 }
1877 
1878 string
1880 {
1881  if (! m_Program.empty()) {
1882  return m_Program;
1883  }
1884 
1885  x_GetRequestInfo();
1886 
1887  return m_Program;
1888 }
1889 
1890 string
1892 {
1893  if (! m_Service.empty()) {
1894  return m_Service;
1895  }
1896 
1897  x_GetRequestInfo();
1898 
1899  return m_Service;
1900 }
1901 
1902 string
1904 {
1905  if (! m_CreatedBy.empty()) {
1906  return m_CreatedBy;
1907  }
1908 
1909  x_GetRequestInfo();
1910 
1911  return m_CreatedBy;
1912 }
1913 
1916 {
1917  if (! m_Queries.Empty()) {
1918  return m_Queries;
1919  }
1920 
1921  x_GetRequestInfo();
1922 
1923  return m_Queries;
1924 }
1925 
1927 NetworkProgram2BlastProgramType(const string& program, const string& service)
1928 {
1929  _ASSERT(!program.empty());
1930  _ASSERT(!service.empty());
1931 
1933  Int2 rv = BlastProgram2Number(program.c_str(), &retval);
1934  _ASSERT(rv == 0);
1935  rv += 0; // to eliminate compiler warning
1936  _ASSERT(retval != eBlastTypeUndefined);
1937 
1938  if (service == "rpsblast") {
1939 
1940  if (program == "blastp") {
1941  retval = eBlastTypeRpsBlast;
1942  } else if (program == "tblastn" || program == "blastx") {
1943  retval = eBlastTypeRpsTblastn;
1944  } else {
1945  abort();
1946  }
1947 
1948  }
1949 
1950  if (service == "psi") {
1951  _ASSERT(program == "blastp");
1952  retval = eBlastTypePsiBlast;
1953  }
1954 
1955  return retval;
1956 }
1957 
1958 
1961 {
1962  if (Blast_QueryIsTranslated(program)) {
1963  switch (frame) {
1964  case 1: return eBlast4_frame_type_plus1;
1965  case 2: return eBlast4_frame_type_plus2;
1966  case 3: return eBlast4_frame_type_plus3;
1967  case -1: return eBlast4_frame_type_minus1;
1968  case -2: return eBlast4_frame_type_minus2;
1969  case -3: return eBlast4_frame_type_minus3;
1970  default: abort();
1971  }
1972  _TROUBLE;
1973  }
1974 
1975  if (Blast_QueryIsNucleotide(program)) {
1976  _ASSERT(frame == -1 || frame == 1);
1977  // For some reason, the return value here is not set...
1979  }
1980 
1982 }
1983 
1986  EBlastProgramType program)
1987 {
1988  if (Blast_QueryIsTranslated(program)) {
1989  switch (frame) {
1996  default: abort();
1997  }
1998  _TROUBLE;
1999  }
2000 
2001  // The BLAST formatter expects nucleotide masks to have a 'not-set' strand,
2002  // which implies that they're on the plus strand. If they're set to
2003  // anything else, it won't display them.
2004  //if (Blast_QueryIsNucleotide(program)) {
2005  // _ASSERT(frame == eBlast4_frame_type_plus1);
2006  // return CSeqLocInfo::eFramePlus1;
2007  //}
2008 
2010 }
2011 
2013 {
2014  if (m_CBOH.Empty()) {
2015  string program_s = GetProgram();
2016  string service_s = GetService();
2017 
2018  CBlastOptionsBuilder bob(program_s, service_s, CBlastOptions::eRemote );
2019 
2021  &m_Task);
2022 
2023  if (bob.HaveEntrezQuery()) {
2024  m_EntrezQuery = bob.GetEntrezQuery();
2025  }
2026 
2027  if (bob.HaveFirstDbSeq()) {
2028  m_FirstDbSeq = bob.GetFirstDbSeq();
2029  }
2030 
2031  if (bob.HaveFinalDbSeq()) {
2032  m_FinalDbSeq = bob.GetFinalDbSeq();
2033  }
2034 
2035  if (bob.HaveGiList()) {
2036  m_GiList = bob.GetGiList();
2037  }
2038 
2039  if(bob.HaveTaxidList()){
2040  list<TTaxId> list = bob.GetTaxidList();
2041  m_TaxidList.clear();
2042  m_TaxidList.insert(list.begin(), list.end());
2043  }
2044 
2045  if(bob.HaveNegativeTaxidList()){
2046  list<TTaxId> list = bob.GetNegativeTaxidList();
2048  m_NegativeTaxidList.insert(list.begin(), list.end());
2049  }
2050 
2051  if (bob.HasDbFilteringAlgorithmId() &&
2052  bob.GetDbFilteringAlgorithmId() != -1) {
2054  }
2055 
2056  if (bob.HasDbFilteringAlgorithmKey() &&
2059  }
2060 
2061  if (bob.HaveNegativeGiList()) {
2063  }
2064  }
2065 
2066  return m_CBOH;
2067 }
2068 
2069 /// Extract the query IDs from a CBioseq_set
2070 /// @param bss CBioseq_set object used as source [in]
2071 /// @param query_ids where the query_ids will be added [in|out]
2074  query_ids)
2075 {
2076  // sacrifice speed for protection against infinite loops
2078  for (; itr; ++itr) {
2079  query_ids.push_back(FindBestChoice(itr->GetId(), CSeq_id::BestRank));
2080  }
2081 }
2082 
2083 void
2085 {
2086  query_ids.clear();
2087  CRef<CBlast4_queries> queries = GetQueries();
2088  query_ids.reserve(queries->GetNumQueries());
2089  _ASSERT(queries);
2090 
2091  if (queries->IsPssm()) {
2092  const CSeq_entry& seq_entry = queries->GetPssm().GetQuery();
2093  if (seq_entry.IsSeq()) {
2094  query_ids.push_back(FindBestChoice(seq_entry.GetSeq().GetId(),
2096  } else {
2097  _ASSERT(seq_entry.IsSet());
2098  s_ExtractQueryIdsFromBioseqSet(seq_entry.GetSet(), query_ids);
2099  }
2100  } else if (queries->IsSeq_loc_list()) {
2101  query_ids.reserve(queries->GetSeq_loc_list().size());
2103  CConstRef<CSeq_id> id((*i)->GetId());
2104  query_ids.push_back(id);
2105  }
2106  } else {
2107  _ASSERT(queries->IsBioseq_set());
2108  s_ExtractQueryIdsFromBioseqSet(queries->GetBioseq_set(), query_ids);
2109  }
2110 }
2111 
2112 /// Submit the search and return the results.
2113 /// @return Search results.
2115 {
2116  CRef<CSearchResultSet> retval;
2117  if (m_ReadFile == false)
2118  SubmitSync();
2119 
2120  TSeqAlignVector alignments = GetSeqAlignSets();
2121 
2122  /* Process errors and warnings */
2123  TSearchMessages search_messages;
2124  {
2125  const vector<string> & W = GetWarningVector();
2126  const vector<string> & E = GetErrorVector();
2127 
2128  TQueryMessages query_messages;
2129 
2130  // Represents the context of the error, not the error id.
2131  int err = kBlastMessageNoContext;
2132 
2133  ITERATE(vector<string>, itw, W) {
2135  sm(new CSearchMessage(eBlastSevWarning, err, *itw));
2136 
2137  query_messages.push_back(sm);
2138  }
2139 
2140  ITERATE(vector<string>, ite, E) {
2141  err = kBlastMessageNoContext;
2142 
2144  sm(new CSearchMessage(eBlastSevError, err, *ite));
2145 
2146  query_messages.push_back(sm);
2147  }
2148 
2149  // Since there is no way to report per-query messages, all
2150  // warnings and errors are applied to all queries.
2151  search_messages.insert(search_messages.end(),
2152  alignments.empty() ? 1 : alignments.size(),
2153  query_messages);
2154 
2155  if (eDebug == m_Verbose) {
2156  NcbiCout << "Error/Warning messages: '"
2157  << search_messages.ToString() << "'" << endl;
2158  }
2159  }
2160 
2162  x_ExtractQueryIds(query_ids);
2163 
2164  if (alignments.empty()) {
2165  // this is required by the CSearchResultSet ctor
2166  alignments.resize(1);
2167  try { x_ExtractQueryIds(query_ids); }
2168  catch (const CRemoteBlastException& e) {
2169  if (e.GetMsg() == kNoRIDSpecified) {
2170  retval.Reset(new CSearchResultSet(alignments, search_messages));
2171  return retval;
2172  }
2173  throw;
2174  }
2175  }
2176 
2177  /* Build the ancillary data structure */
2178  CSearchResultSet::TAncillaryVector ancill_vector;
2179  {
2180  /* Get the effective search space */
2181  const string kTarget("Effective search space used: ");
2182  const string kLength_Adj("Length adjustment: ");
2183  list<string> search_stats = GetSearchStats();
2184  Int8 effective_search_space = 0;
2185  Int8 length_adjustment = 0;
2186  NON_CONST_ITERATE(list<string>, itr, search_stats) {
2187  if (NStr::Find(*itr, kTarget) != NPOS) {
2188  NStr::ReplaceInPlace(*itr, kTarget, kEmptyStr);
2189  effective_search_space =
2191  }
2192  if (NStr::Find(*itr, kLength_Adj) != NPOS) {
2193  NStr::ReplaceInPlace(*itr, kLength_Adj, kEmptyStr);
2194  length_adjustment =
2196  }
2197  }
2198 
2199  if((m_Service == "rpsblast") || (m_Service == "rpstblastn") )
2200  {
2201  const string kTmp("Matrix: ");
2202  NON_CONST_ITERATE(list<string>, itr, search_stats) {
2203  if (NStr::Find(*itr, kTmp) != NPOS) {
2204  NStr::ReplaceInPlace(*itr, kTmp, kEmptyStr);
2205  m_CBOH->SetOptions().SetMatrixName((*itr).c_str());
2206  break;
2207  }
2208  }
2209  }
2210 
2211  /* Get the Karlin-Altschul parameters */
2212  bool found_gapped = false, found_ungapped = false;
2213  pair<double, double> lambdas, Ks, Hs;
2214  TKarlinAltschulBlocks ka_blocks = GetKABlocks();
2215 
2216  ITERATE(TKarlinAltschulBlocks, itr, ka_blocks) {
2217  if ((*itr)->GetGapped()) {
2218  lambdas.second = (*itr)->GetLambda();
2219  Ks.second = (*itr)->GetK();
2220  Hs.second = (*itr)->GetH();
2221  found_gapped = true;
2222  } else {
2223  lambdas.first = (*itr)->GetLambda();
2224  Ks.first = (*itr)->GetK();
2225  Hs.first = (*itr)->GetH();
2226  found_ungapped = true;
2227  }
2228 
2229  if (found_gapped && found_ungapped) {
2230  break;
2231  }
2232  }
2233 
2234  // N.B.: apparently the BLAST3 protocol doesn't send PSI-BLAST Karlin &
2235  // Altschul parameters, so we don't set the is_psiblast
2236  // CBlastAncillaryData constructor argument
2237  CRef<CBlastAncillaryData> ancillary_data
2238  (new CBlastAncillaryData(lambdas, Ks, Hs, effective_search_space, m_Task == "psiblast"));
2239  ancillary_data->SetLengthAdjustment(length_adjustment);
2240  ancill_vector.insert(ancill_vector.end(), alignments.size(),
2241  ancillary_data);
2242  }
2243 
2244  TSeqLocInfoVector masks = GetMasks();
2245  retval.Reset(new CSearchResultSet(query_ids, alignments, search_messages,
2246  ancill_vector, &masks));
2247  retval->SetRID(GetRID());
2248  return retval;
2249 }
2250 
2253 {
2254  // First try to read a Blast4-get-search-strategy-reply...
2256  bool succeeded = false;
2257  try {
2258  switch (CFormatGuess().Format(in)) {
2260  b4_ss_reply.Reset(new CBlast4_get_search_strategy_reply);
2261  in >> MSerial_AsnBinary >> *b4_ss_reply;
2262  succeeded = true;
2263  break;
2264 
2266  b4_ss_reply.Reset(new CBlast4_get_search_strategy_reply);
2267  in >> MSerial_AsnText >> *b4_ss_reply;
2268  succeeded = true;
2269  break;
2270 
2271  case CFormatGuess::eXml:
2272  {
2273  unique_ptr<CObjectIStream> is(
2275  dynamic_cast<CObjectIStreamXml*>
2276  (is.get())->SetEnforcedStdXml(true);
2277  b4_ss_reply.Reset(new CBlast4_get_search_strategy_reply);
2278  *is >> *b4_ss_reply;
2279  succeeded = true;
2280  }
2281  break;
2282 
2283  default:
2284  _ASSERT(b4_ss_reply.Empty());
2285  }
2286  } catch (const CException&) {
2287  succeeded = false;
2288  }
2289 
2290  CRef<CBlast4_request> retval;
2291  if (succeeded) {
2292  retval.Reset(&b4_ss_reply->Set());
2293  return retval;
2294  }
2295  b4_ss_reply.Reset();
2296  in.seekg(0);
2297 
2298  // Go for broke and try the Blast4-request...
2299  retval.Reset(new CBlast4_request);
2300  switch (CFormatGuess().Format(in)) {
2302  in >> MSerial_AsnBinary >> *retval;
2303  break;
2304 
2306  in >> MSerial_AsnText >> *retval;
2307  break;
2308 
2309  case CFormatGuess::eXml:
2310  {
2311  unique_ptr<CObjectIStream> is(
2313  dynamic_cast<CObjectIStreamXml*>
2314  (is.get())->SetEnforcedStdXml(true);
2315  *is >> *retval;
2316  }
2317  break;
2318 
2319  default:
2320  NCBI_THROW(CSerialException, eInvalidData,
2321  "Unrecognized input format ");
2322  }
2323 
2324  return retval;
2325 }
2326 
2328 s_BuildSearchInfoRequest(const string& rid,
2329  const string& name,
2330  const string& value)
2331 {
2333  info_request->SetRequest_id(rid);
2334  info_request->SetInfo().Add(name, value);
2336  retval->SetGet_search_info(*info_request);
2337  return retval;
2338 }
2339 
2340 string
2342  const string& name,
2343  const string& value)
2344 {
2345  string retval;
2346  if (reply.Empty() || !reply->CanGetBody()) {
2347  return retval;
2348  }
2349  if (reply->GetBody().IsGet_search_info()) {
2350  const CBlast4_get_search_info_reply &info_reply = reply->GetBody().GetGet_search_info();
2351  if (info_reply.CanGetRequest_id() && (info_reply.GetRequest_id() == m_RID)) {
2352  if( info_reply.CanGetInfo() ){
2353  const CBlast4_parameters &params = info_reply.GetInfo();
2354  const string reply_name =
2356  CRef< CBlast4_parameter > search_param =
2357  params.GetParamByName(reply_name);
2358  if( search_param.NotEmpty() && search_param->GetValue().IsString()) {
2359  retval = search_param->GetValue().GetString();
2360  }
2361  } // get info
2362  } // request id == m_RID
2363  } // search info reply
2364  return retval;
2365 }
2366 
2367 
2368 //
2369 // based on a new request
2370 //
2372 {
2373  // Build the request
2374  CRef<CBlast4_request_body> request_body =
2378  CRef<CBlast4_reply> reply = x_SendRequest(request_body);
2379  return x_GetStringFromSearchInfoReply(reply,
2382 
2383 }
2384 // Disk Cache version: x_CheckResults
2385 // only difference is that if search finished,
2386 // different approach to call and get results will be orchestrated
2387 // to fist get data from services as-is an deserialize them
2388 // later. This steps will minimize time OM is working.
2389 //
2391 {
2392  LOG_POST(Info << "CRemoteBlast::x_CheckResultsDC");
2393  if (! m_Errs.empty()) {
2394  m_Pending = false;
2395  }
2396 
2397  if (! m_Pending) {
2398  return;
2399  }
2400 
2402 
2403  bool try_again = true;
2404 
2405  while(try_again) {
2406  try {
2407  // asking for search statistics
2408  r = x_GetSearchStatsOnly();
2410  try_again = false;
2411  }
2412  catch(const CEofException&) {
2413  --m_ErrIgn;
2414 
2415  if (m_ErrIgn == 0) {
2416  m_Errs.push_back("No response from server, "
2417  "cannot complete request.");
2418  return;
2419  }
2420 
2421  SleepSec(10);
2422  }
2423  }
2424 
2425  if (! m_Pending) {
2426  // search finishedi check for errors
2427  x_SearchErrors(r);
2428 
2429  if (! m_Errs.empty()) {
2430  return;
2431  }
2432 
2433  if( !r->CanGetBody() ) {
2434  m_Errs.push_back("Results were not a get-search-results reply 2");
2435  return;
2436  }
2437  if( r->CanGetBody() && !r->GetBody().IsGet_search_results()) {
2438  m_Errs.push_back("Results were not a get-search-results reply");
2439  return;
2440  }
2441  //ATTENTION: fullscale get results call
2442  // search finished, retriev results
2444  if( r.Empty() ){
2445  m_Errs.push_back("Results were not a get-search-results reply 3");
2446  return;
2447  }
2448  if( r->CanGetBody() && !r->GetBody().IsGet_search_results()) {
2449  m_Errs.push_back("Results were not a get-search-results reply 4");
2450  return;
2451  }
2453  m_Reply = r;
2454  }
2455 
2456 }
2457 // disk cache support.
2458 // ask for search statistics to check status w/o polling results.
2461 {
2464 
2465  gsrr->SetRequest_id(m_RID);
2466  // result-types
2467  gsrr->ResetResult_types();
2468  gsrr->SetResult_types( 16) ;
2469 
2471  body->SetGet_search_results(*gsrr);
2472 
2473  return x_SendRequest(body);
2474 }
2475 //
2476 // get search results caching first on a file system.
2477 // TODO: check for errors and disable disk caching
2480 {
2482  CStopWatch swatch;
2484  string BLAST4_CONN_SERVICE_NAME = "blast4";
2485  if( env.Get("BLAST4_CONN_SERVICE_NAME") != kEmptyStr )
2486  BLAST4_CONN_SERVICE_NAME = env.Get("BLAST4_CONN_SERVICE_NAME");
2487 
2488  // construct request
2490  gsrr->SetRequest_id( m_RID);
2491 
2493  body->SetGet_search_results(*gsrr);
2494 
2495  CRef<CBlast4_request> request( new CBlast4_request );
2496  request->SetBody(*body );
2497  // call service
2498  swatch.Start();
2499  CConn_ServiceStream ios( BLAST4_CONN_SERVICE_NAME , fSERV_HttpPost, 0);
2500  ios << MSerial_AsnBinary << *request;
2501  ios.flush();
2502  // cache answer to the file
2503  char incoming_buffer[8192];
2504  int read_max = 8192;
2505  int l_total_bytes=0, n_read;
2506  bool l_cached_ok = true;
2507 
2508  unique_ptr<fstream> tmp_stream( CDirEntry::CreateTmpFile() );
2509  do{
2510  n_read = static_cast<int>( CStreamUtils::Readsome(ios,incoming_buffer, read_max) );
2511  if( n_read > 0 ){
2512  l_total_bytes += n_read;
2513  try{
2514  tmp_stream->write(incoming_buffer,n_read);
2515  if( tmp_stream->bad() || tmp_stream->fail() )
2516  {
2517  l_cached_ok = false;
2518  LOG_POST(Error << "CRemoteBlast::x_GetSearchResultsHTTP CAN'T WRITE CACHED DATA: BAD/FAIL STATE" );
2519  m_disk_cache_error_msg = "bad/fail fstream state on write";
2520  break;
2521  }
2522  }
2523  catch ( ios_base::failure &err){
2524  LOG_POST(Error << "CRemoteBlast::x_GetSearchResultsHTTP CAN'T WRITE CACHED DATA: "<<err.what() );
2525  l_cached_ok = false;
2526  m_disk_cache_error_msg = err.what();
2527  break;
2528  }
2529  }
2530  }
2531  while( ios );
2532  swatch.Stop();
2533 
2534  if(!l_cached_ok ){
2535  // Attention: in case of caching error, disable it and re-read w/o caching
2536  LOG_POST(Info << "CRemoteBlast::x_GetSearchResultsHTTP: DISABLE CACHE, RE-READ");
2537  m_use_disk_cache = false;
2538  m_disk_cache_error_flag = true;
2539  return x_GetSearchResults();
2540  }
2541 
2542  tmp_stream->seekg(0);
2543  // read cached answer
2544  swatch.Restart();
2545  try {
2546  unique_ptr<CObjectIStream>
2547  in_stream( CObjectIStream::Open(eSerial_AsnBinary, *tmp_stream) );
2548  in_stream->Read(ObjectInfo(*one_reply), CObjectIStream::eNoFileHeader);
2549 
2550  }
2551  catch(...){
2552  LOG_POST(Info << "CRemoteBlast::x_GetSearchResultsHTTP: DISABLE CACHE, CAN'T READ CACHED FILE, RE-READ");
2553  m_use_disk_cache = false;
2554  m_disk_cache_error_flag = true;
2555  return x_GetSearchResults();
2556  }
2557  swatch.Stop();
2558 
2559  return one_reply ;
2560 }
2561 //
2562 // Get search subject and set
2563 // m_SubjectSeqLocs or m_SubjectSequences
2564 //
2566 {
2567  if( !m_SubjectSequences.empty() && !m_SubjectSeqLocs.empty() )
2568  return; // already got data
2569 
2570  // Build the request
2573  request->SetBody(*body);
2574 
2576 
2577  if (eDebug == m_Verbose) {
2578  NcbiCout << MSerial_AsnText << *request << endl;
2579  }
2580 
2581  try {
2583 
2584  if (eDebug == m_Verbose) {
2585  NcbiCout << "Starting network transaction (" << sw.Elapsed() << ")" << endl;
2586  }
2587 
2588  // Send request.
2589  CBlast4Client().Ask(*request, *reply);
2590 
2591  if (eDebug == m_Verbose) {
2592  NcbiCout << "Done network transaction (" << sw.Elapsed() << ")" << endl;
2593  }
2594  }
2595  catch(const CEofException&) {
2596  NCBI_THROW(CRemoteBlastException, eServiceNotAvailable,
2597  "No response from server, cannot complete request.");
2598  }
2599 
2600  if (eDebug == m_Verbose) {
2601  NcbiCout << MSerial_AsnText << *reply << endl;
2602  }
2603 
2604  // get reply. it will be status and subjects
2605  if (reply->CanGetBody()) {
2606  if (reply->GetBody().IsGet_search_info()) {
2607  const CBlast4_get_search_info_reply &info_reply = reply->GetBody().GetGet_search_info();
2608  if( info_reply.CanGetRequest_id() && ( info_reply.GetRequest_id() == m_RID ) ){
2609  if( info_reply.CanGetInfo() ){
2610  const CBlast4_parameters &params = info_reply.GetInfo();
2611  string reply_name =
2614  CRef< CBlast4_parameter > search_param = params.GetParamByName (reply_name);
2615  // reply could have string, seq-loc-list or
2616  // bioseq-list, but we don't care about string result for bl2seq
2617  if( search_param.NotEmpty() && search_param->GetValue().IsSeq_loc_list())
2618  {
2619  m_SubjectSeqLocs = search_param->GetValue().GetSeq_loc_list();
2620  }
2621  // bioseq-list // SEQUENCE OF Bioseq
2622  else if( search_param.NotEmpty() && search_param->GetValue().IsBioseq_list())
2623  {
2624  x_SetSubjectSequences( search_param->GetValue().GetBioseq_list() );
2625 
2626  }
2627  else
2628  {
2629  NCBI_THROW(CRemoteBlastException, eIncompleteConfig,
2630  "Obtained database name for remote bl2seq search");
2631  }
2632 
2633  } // get info
2634  } // request id == m_RID
2635  } // search info reply
2636  } // get body
2637 }
2638 
2640 {
2641  unsigned int iter_num = 0;
2642  if(!m_FormatOpts.Empty())
2643  {
2645  if( param.NotEmpty())
2646  {
2647  iter_num = param->GetValue().GetInteger();
2648  }
2649  }
2650  else if(!m_RID.empty())
2651  {
2652  iter_num = x_GetPsiIterationsFromServer();
2653  }
2654 
2655  return iter_num;
2656 }
2657 
2659 {
2660  unsigned int retval=0;
2661 
2662  CRef<CBlast4_request_body> request_body =
2666  CRef<CBlast4_reply> reply = x_SendRequest(request_body);
2667  string num = x_GetStringFromSearchInfoReply(reply,
2670  if ( !num.empty() ) {
2671  try { retval = NStr::StringToUInt(num); }
2672  catch (...) {} // ignore errors and leave as unset
2673  }
2674  return retval;
2675 }
2676 
2678 {
2679  if((m_Archive) != NULL && m_Archive->IsSetRequest() && m_Archive->GetRequest().CanGetBody() &&
2680  m_Archive->GetRequest().GetBody().IsGet_request_info() &&
2681  m_Archive->GetRequest().GetBody().GetGet_request_info().IsSetRequest_id() &&
2682  (m_Archive->GetRequest().GetBody().GetGet_request_info().GetRequest_id() == "Error")) {
2683  return true;
2684  }
2685  return false;
2686 }
2687 
2688 
2689 END_SCOPE(blast)
2691 
2692 /* @} */
#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:355
static CBlast4Field & Get(EBlastOptIdx opt)
Definition: names.cpp:44
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:104
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:1938
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
char value[7]
Definition: config.c:431
static const char si[8][64]
Definition: des.c:146
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:687
#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:742
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:551
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
#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:2887
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:3401
@ fConvErr_NoThrow
Do not throw an exception on error.
Definition: ncbistr.hpp:285
double Restart(void)
Return time elapsed since first Start() or last Restart() call (in seconds).
Definition: ncbitime.hpp:2817
double Elapsed(void) const
Return time elapsed since first Start() or last Restart() call (in seconds).
Definition: ncbitime.hpp:2776
void Stop(void)
Suspend the timer.
Definition: ncbitime.hpp:2793
void Start(void)
Start the timer.
Definition: ncbitime.hpp:2765
@ eStart
Start timer immediately after creating.
Definition: ncbitime.hpp:1942
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:128
@ eBlastOpt_Web_StepNumber
Definition: names.hpp:152
@ eBlastOpt_RequiredEnd
Definition: names.hpp:139
@ eBlastOpt_DbFilteringAlgorithmKey
Definition: names.hpp:133
@ eBlastOpt_LCaseMask
Definition: names.hpp:136
@ eBlastOpt_NegativeGiList
Definition: names.hpp:138
@ eBlastOpt_DbFilteringAlgorithmId
Definition: names.hpp:132
@ eBlastOpt_GiList
Definition: names.hpp:131
@ eBlastOpt_RequiredStart
Definition: names.hpp:140
@ eBlastOpt_SubjectMaskingType
Definition: names.hpp:134
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:446
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
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
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
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 int failure
Definition: t0019.c:11
#define _TROUBLE
#define _ASSERT
static string kStart("Start")
done
Definition: token1.c:1
static HENV env
Definition: transaction2.c:38
#define W
Definition: crc32.c:85
Modified on Tue Nov 28 02:16:57 2023 by modify_doxy.py rev. 669887