📄 remote_blast.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: remote_blast.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 18:06:16 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13 * PRODUCTION * =========================================================================== *//* $Id: remote_blast.cpp,v 1000.1 2004/06/01 18:06:16 gouriano Exp $* ===========================================================================** PUBLIC DOMAIN NOTICE* National Center for Biotechnology Information** This software/database is a "United States Government Work" under the* terms of the United States Copyright Act. It was written as part of* the author's official duties as a United States Government employee and* thus cannot be copyrighted. This software/database is freely available* to the public for use. The National Library of Medicine and the U.S.* Government have not placed any restriction on its use or reproduction.** Although all reasonable efforts have been taken to ensure the accuracy* and reliability of the software and data, the NLM and the U.S.* Government do not and cannot warrant the performance or results that* may be obtained by using this software or data. The NLM and the U.S.* Government disclaim all warranties, express or implied, including* warranties of performance, merchantability or fitness for any particular* purpose.** Please cite the author in any work or product based on this material.** ===========================================================================** Author: Kevin Bealer** ===========================================================================*//// @file remote_blast.cpp/// Queueing and Polling code for Remote Blast API.#include <ncbi_pch.hpp>#include <corelib/ncbi_system.hpp>#include <algo/blast/api/remote_blast.hpp>#include <objects/blast/blastclient.hpp>#include <objects/blast/blast__.hpp>#include <objects/scoremat/scoremat__.hpp>#if defined(NCBI_OS_UNIX)#include <unistd.h>#endif/** @addtogroup AlgoBlast * * @{ */BEGIN_NCBI_SCOPEUSING_SCOPE(objects);BEGIN_SCOPE(blast)// Static functionstemplate <class T>voids_Output(CNcbiOstream & os, CRef<T> t){ auto_ptr<CObjectOStream> x(CObjectOStream::Open(eSerial_AsnText, os)); *x << *t; os.flush();}typedef list< CRef<CBlast4_error> > TErrorList;static bools_SearchPending(CRef<CBlast4_reply> reply){ const list< CRef<CBlast4_error> > & errors = reply->GetErrors(); TErrorList::const_iterator i; for(i = errors.begin(); i != errors.end(); i++) { if ((*i)->GetCode() == eBlast4_error_code_search_pending) { return true; } } return false;}void CRemoteBlast::x_SearchErrors(CRef<CBlast4_reply> reply){ const list< CRef<CBlast4_error> > & errors = reply->GetErrors(); TErrorList::const_iterator i; for(i = errors.begin(); i != errors.end(); i++) { string msg; if ((*i)->CanGetMessage() && (! (*i)->GetMessage().empty())) { msg = ": "; msg += (*i)->GetMessage(); } switch((*i)->GetCode()) { case eBlast4_error_code_conversion_warning: m_Warn.push_back(string("Warning: conversion_warning") + msg); break; case eBlast4_error_code_internal_error: m_Errs.push_back(string("Error: internal_error") + msg); break; case eBlast4_error_code_not_implemented: m_Errs.push_back(string("Error: not_implemented") + msg); break; case eBlast4_error_code_not_allowed: m_Errs.push_back(string("Error: not_allowed") + msg); break; case eBlast4_error_code_bad_request: m_Errs.push_back(string("Error: bad_request") + msg); break; case eBlast4_error_code_bad_request_id: m_Errs.push_back(string("Error: bad_request_id") + msg); break; } }}// CBlast4Option methodsvoid CRemoteBlast::x_CheckConfig(void){ // If not configured, throw an exception - the associated string // will contain a list of the missing pieces. if (0 != m_NeedConfig) { string cfg("Configuration required:"); if (eProgram & m_NeedConfig) { cfg += " <program>"; } if (eService & m_NeedConfig) { cfg += " <service>"; } if (eQueries & m_NeedConfig) { cfg += " <queries>"; } if (eSubject & m_NeedConfig) { cfg += " <subject>"; } NCBI_THROW(CBlastException, eInternal, cfg.c_str()); }}CRef<CBlast4_reply>CRemoteBlast::x_SendRequest(CRef<CBlast4_request_body> body){ // If not configured, throw. x_CheckConfig(); // Create the request; optionally echo it CRef<CBlast4_request> request(new CBlast4_request); request->SetBody(*body); if (eDebug == m_Verbose) { s_Output(NcbiCout, request); } // submit to server, get reply; optionally echo it CRef<CBlast4_reply> reply(new CBlast4_reply); try { //throw some_kind_of_nothing(); CBlast4Client().Ask(*request, *reply); } catch(const CEofException&) { ERR_POST(Error << "No response from server, cannot " "complete request."); #if defined(NCBI_OS_UNIX) // Use _exit() to avoid coredump. _exit(-1);#else exit(-1);#endif } if (eDebug == m_Verbose) { s_Output(NcbiCout, reply); } return reply;}CRef<CBlast4_reply>CRemoteBlast::x_GetSearchResults(void){ CRef<CBlast4_get_search_results_request> gsrr(new CBlast4_get_search_results_request); gsrr->SetRequest_id(m_RID); CRef<CBlast4_request_body> body(new CBlast4_request_body); body->SetGet_search_results(*gsrr); return x_SendRequest(body);}// Pre: start, wait, or done// Post: failed or done// Returns: true if donebool CRemoteBlast::SubmitSync(int seconds){ // eFailed: no work to do, already an error. // eDone: already done, just return. EImmediacy immed = ePollAsync; switch(x_GetState()) { case eStart: x_SubmitSearch(); if (! m_Errs.empty()) { break; } immed = ePollImmed; // fall through case eWait: x_PollUntilDone(immed, seconds); break; } return (x_GetState() == eDone);}// Pre: start// Post: failed, wait or done// Returns: true if no error so farbool CRemoteBlast::Submit(void){ switch(x_GetState()) { case eStart: x_SubmitSearch(); } return m_Errs.empty();}// Pre: start, wait or done// Post: wait or done// Returns: true if donebool CRemoteBlast::CheckDone(void){ switch(x_GetState()) { case eFailed: case eDone: break; case eStart: Submit(); break; case eWait: x_CheckResults(); } return (x_GetState() == eDone);}CRemoteBlast::TGSRR * CRemoteBlast::x_GetGSRR(void){ TGSRR* rv = NULL; if (SubmitSync() && m_Reply.NotEmpty() && m_Reply->CanGetBody() && m_Reply->GetBody().IsGet_search_results()) { rv = & (m_Reply->SetBody().SetGet_search_results()); } return rv;}CRef<objects::CSeq_align_set> CRemoteBlast::GetAlignments(void){ CRef<objects::CSeq_align_set> rv; TGSRR * gsrr = x_GetGSRR(); if (gsrr && gsrr->CanGetAlignments()) { rv = & (gsrr->SetAlignments()); } return rv;}CRef<objects::CBlast4_phi_alignments> CRemoteBlast::GetPhiAlignments(void){ CRef<objects::CBlast4_phi_alignments> rv; TGSRR * gsrr = x_GetGSRR(); if (gsrr && gsrr->CanGetPhi_alignments()) { rv = & (gsrr->SetPhi_alignments()); } return rv;}CRef<objects::CBlast4_mask> CRemoteBlast::GetMask(void){ CRef<objects::CBlast4_mask> rv; TGSRR * gsrr = x_GetGSRR(); if (gsrr && gsrr->CanGetMask()) { rv = & (gsrr->SetMask()); } return rv;}list< CRef<objects::CBlast4_ka_block > > CRemoteBlast::GetKABlocks(void){ list< CRef<objects::CBlast4_ka_block > > rv; TGSRR * gsrr = x_GetGSRR(); if (gsrr && gsrr->CanGetKa_blocks()) { rv = (gsrr->SetKa_blocks()); } return rv;}list< string > CRemoteBlast::GetSearchStats(void){ list< string > rv; TGSRR * gsrr = x_GetGSRR(); if (gsrr && gsrr->CanGetSearch_stats()) { rv = (gsrr->SetSearch_stats()); } return rv;}CRef<objects::CScore_matrix_parameters> CRemoteBlast::GetPSSM(void){ CRef<objects::CScore_matrix_parameters> rv; TGSRR * gsrr = x_GetGSRR(); if (gsrr && gsrr->CanGetPssm()) { rv = & (gsrr->SetPssm()); } return rv;}// Internal CRemoteBlast methodsint CRemoteBlast::x_GetState(void){ // CBlast4Option states: // 0. start (no rid, no errors) // 1. failed (errors) // 2. wait (has rid, no errors, still pending) // 3. done (has rid, no errors, not pending) int rv = 0; if (! m_Errs.empty()) { rv = eFailed; } else if (m_RID.empty()) { rv = eStart; } else if (m_Pending) { rv = eWait; } else { rv = eDone; } return rv;}void CRemoteBlast::x_SubmitSearch(void){ if (m_QSR.Empty()) { m_Errs.push_back("No request exists and no RID was specified."); return; } x_SetAlgoOpts(); CRef<CBlast4_request_body> body(new CBlast4_request_body); body->SetQueue_search(*m_QSR); CRef<CBlast4_reply> reply; try { reply = x_SendRequest(body); } catch(const CEofException&) { m_Errs.push_back("No response from server, cannot complete request."); return; } if (reply->CanGetBody() && reply->GetBody().GetQueue_search().CanGetRequest_id()) { m_RID = reply->GetBody().GetQueue_search().GetRequest_id(); } x_SearchErrors(reply); if (m_Errs.empty()) { m_Pending = true; }}void CRemoteBlast::x_CheckResults(void){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -