dlg_blastpoll.cpp

来自「ncbi源码」· C++ 代码 · 共 422 行

CPP
422
字号
/* * =========================================================================== * PRODUCTION $Log: dlg_blastpoll.cpp,v $ * PRODUCTION Revision 1000.6  2004/06/01 20:54:21  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13 * PRODUCTION * =========================================================================== *//*  $Id: dlg_blastpoll.cpp,v 1000.6 2004/06/01 20:54:21 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:  Cliff Clausen, Michael DiCuccio** File Description:*   !!! PUT YOUR DESCRIPTION HERE !!!** ===========================================================================*/#include <ncbi_pch.hpp>#include "dlg_blastpoll.hpp"#include "blast_poll_table.hpp"#include <gui/core/plugin_utils.hpp>#include <gui/utils/fltk_utils.hpp>#include <algo/blast/api/remote_blast.hpp>#include <objects/seq/Seq_annot.hpp>#include <objects/seqalign/Seq_align_set.hpp>#include <objects/seqalign/Seq_align.hpp>#include <objects/seqalign/Dense_seg.hpp>#include "blast_rid_cache.hpp"BEGIN_NCBI_SCOPEUSING_SCOPE(objects);#include "dlg_blastpoll_.cpp"CBlastPollDlg::CBlastPollDlg(){    m_Window.reset(x_CreateWindow());    m_PollPending = false;    m_RidCache.Reset(new CBlastRidCache());}void CBlastPollDlg::x_OnPollNow(){    // Loop through poll list    for (size_t i = 0;  i < m_Table->GetRows();  ++i) {        CBlastPollItem& item = *m_Table->SetData(i);        if ( !item.m_Active ) {            continue;        }        CTime now(CTime::eCurrent);        // Get blast results for this rid, if ready        string msg;        item.m_Errors = !x_Poll(item);        item.m_LastPollTime = now;        m_Table->UpdateItem(i, item);    }}void CBlastPollDlg::x_OnActiveToggle(){    for (size_t i = 0;  i < m_Table->GetRows();  ++i) {        if ( !m_Table->IsRowSelected(i) ) {            continue;        }        if (m_Table->GetData(i)->m_Active) {            m_Table->DeactivateItem(i);        } else {            m_Table->ActivateItem(i);        }    }}void CBlastPollDlg::x_OnRemove(){    m_Table->RemoveSelected();}void CBlastPollDlg::x_OnUp(){    for (size_t i = 0;  i < m_Table->GetRows();  ++i) {        if ( !m_Table->IsRowSelected(i) ) {            continue;        }        m_Table->MoveUp(i);    }}void CBlastPollDlg::x_OnDown(){    for (size_t i = 0;  i < m_Table->GetRows();  ++i) {        if ( !m_Table->IsRowSelected(i) ) {            continue;        }        m_Table->MoveDown(i);        // we need to increment as the next item is the one we just moved.        ++i;    }}static void s_pollTimeout(void *data){    CBlastPollDlg *dlg = static_cast<CBlastPollDlg*>(data);    if (dlg) {        dlg->Poll();        Fl::repeat_timeout(1.0f, s_pollTimeout, data);    }}void CBlastPollDlg::StartPoll(){    if (!m_PollPending) {        Fl::add_timeout(1.0f, s_pollTimeout, this);        m_PollPending = true;    }}void CBlastPollDlg::StopPoll(){    Fl::remove_timeout(s_pollTimeout);    m_PollPending = false;}void CBlastPollDlg::Poll(){    // Loop through poll list    for (size_t i = 0;  i < m_Table->GetRows();  ++i) {        CBlastPollItem& item = *m_Table->SetData(i);        if ( !item.m_Active ) {            continue;        }        CTime now(CTime::eCurrent);        size_t secs = now.DiffSecond(item.m_LastPollTime);        if (secs < 30) {            continue;        }        // Get blast results for this rid, if ready        string msg;        item.m_Errors = !x_Poll(item);        item.m_LastPollTime = now;        m_Table->UpdateItem(i, item);    }    CTime now(CTime::eCurrent);    m_CurrTimeStr = now.AsString("h:m:s");    m_CurrTime->label(m_CurrTimeStr.c_str());}bool CBlastPollDlg::x_Poll(CBlastPollItem& item){    CFltkCursorGuard WAIT;    string rid = item.m_Rid;    CRef<CSeq_annot> annot;    // check our cache first    annot = m_RidCache->GetRID(rid);    if ( !annot ) {        blast::CRemoteBlast rb(rid);        if (rb.CheckDone()) {            // Get the alignment, remap, and wrap it in a CSeq_annot            CRef<CSeq_align_set> results(rb.GetAlignments());            // Remap the alignments            if ( item.m_QueryLoc ) {                CTypeIterator<CDense_seg> ds_iter(*results);                for ( ;  ds_iter;  ++ds_iter) {                    ds_iter->RemapToLoc(0, *item.m_QueryLoc);                }            }            annot.Reset(new CSeq_annot);            annot->SetData().SetAlign() = results->Set();                // name defines how the object manager sees this annotation            annot->AddName("NetBLAST Results");            // 'title' defines how the user sees this            annot->AddTitle("NetBLAST Results, RID: " + rid);            // set our creation date            annot->SetCreateDate(CTime(CTime::eCurrent));            // save our results in the cache            m_RidCache->AddRID(rid, *annot);        }    }    if (annot) {        //        // got results        //        item.m_Active = false;        item.m_Status = "Retrieved";        // save the annot        item.m_Results = annot;        // Attach seq_annot to document        if ( item.m_Document ) {            const IDocument &cdoc =                 dynamic_cast<const IDocument&>(*item.m_Document);            const_cast<IDocument&>(cdoc).AttachAnnot(*annot);            const_cast<IDocument&>(cdoc).UpdateAllViews();        } else {            CRef<CScope> scope(new CScope(CDocManager::GetObjectManager()));            scope->AddDefaults();            item.m_Document = CDocManager::CreateDocument(*scope, *annot);            CDocManager::UpdateAllViews();        }    }        return true;}    void CBlastPollDlg::Add(const CPluginCommand& args){    string rid;    if (!args.HasArgument("RID")) {        return;    }    rid = args["RID"].AsString();    if ( !rid.empty()  &&  !m_Table->HasRid(rid)) {        CRef<CBlastPollItem> item(new CBlastPollItem());        if ( !args.HasArgument("query_loc")  ||             !CPluginUtils::IsValid(args["query_loc"])) {            item->m_Document.Reset();            item->m_Descr = rid;        } else {            item->m_Document = args["query_loc"].GetDocument();            item->m_QueryLoc = dynamic_cast<const CSeq_loc*>                (args["query_loc"].GetObject());            if (!item->m_Document.IsNull()) {                item->m_Descr = item->m_Document->GetShortTitle();            } else {                item->m_Descr = rid;            }        }        if ( args.HasArgument("prog") ) {            item->m_Descr += " - " + args["prog"].AsString();        }        item->m_Rid = rid;        item->m_Active = true;        item->m_Errors = false;        item->m_Status = "Polling";        item->m_Errors = !x_Poll(*item);        item->m_SubmitTime   = CTime(CTime::eCurrent);        item->m_LastPollTime = item->m_SubmitTime;        // Add rid to poll list        m_Table->AddItem(*item);        m_InputRid->value("");    }}void CBlastPollDlg::x_OnAdd(){    const char *rid = m_InputRid->value();    CRef<CBlastPollItem> item(new CBlastPollItem());    item->m_Document = NULL;    item->m_Descr = rid;    item->m_Rid = rid;    item->m_Active = true;    item->m_Errors = false;    item->m_Status = "Polling";    m_Table->AddItem(*item);}END_NCBI_SCOPE/** ===========================================================================** $Log: dlg_blastpoll.cpp,v $* Revision 1000.6  2004/06/01 20:54:21  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13** Revision 1.13  2004/05/21 22:27:46  gorelenk* Added PCH ncbi_pch.hpp** Revision 1.12  2004/04/22 12:22:08  dicuccio* Added BLAST RID caching.  Added better formatting for BLAST results** Revision 1.11  2004/04/16 14:41:55  dicuccio* Use CRemoteBlast to poll for results** Revision 1.10  2004/04/07 12:53:11  dicuccio* m_document -> m_Document.  Store CSeq_align_set in results** Revision 1.9  2004/03/05 17:32:14  dicuccio* Large-scale clean-up to blast code.  Reorganized blast polling dialog to be* multi-column; standardized options for BLAST network submissions; changed* plugin to accept multiple locations for submission and create a submission for* each** Revision 1.8  2004/02/18 19:02:36  jcherry* Query is now a Seq-loc, to which alignments get remapped** Revision 1.7  2003/11/18 13:20:11  clausen* Fixes to remove g++ warnings** Revision 1.6  2003/11/17 16:24:19  clausen* Added m_Descr** Revision 1.5  2003/11/04 17:49:22  dicuccio* Changed calling parameters for plugins - pass CPluginMessage instead of paired* CPluginCommand/CPluginReply** Revision 1.4  2003/10/31 22:56:36  ucko* Move include of idocument.hpp to header to precede use in CConstRef<>** Revision 1.3  2003/10/31 17:32:08  clausen* Switched from passing scope to passing document** Revision 1.2  2003/10/27 17:47:04  dicuccio* Removed dead #includes** Revision 1.1  2003/10/24 12:49:21  dicuccio* Moved files from algo/net_blast** Revision 1.12  2003/10/24 12:23:41  clausen* Fixed fltk blocking** Revision 1.11  2003/10/17 16:35:40  dicuccio* Better handling of optional scope parameter** Revision 1.10  2003/10/07 13:47:04  dicuccio* Renamed CPluginURL* to CPluginValue*** Revision 1.9  2003/09/04 14:05:25  dicuccio* Use IDocument instead of IDocument** Revision 1.8  2003/07/23 19:14:09  dicuccio* Moved logic for validating plugin arguments into CPluginUtils.** Revision 1.7  2003/07/14 11:14:11  shomrat* Plugin messageing system related changes** Revision 1.6  2003/07/10 13:06:20  dicuccio* Fixed compilation issues for gcc-3.3: restructured callback mechanism, replaced* multiple parallel arrays with an array of classes.** Revision 1.5  2003/06/25 17:02:57  dicuccio* Split CPluginHandle into a handle (pointer-to-implementation) and* implementation file.  Lots of #include file clean-ups.** Revision 1.4  2003/06/20 19:45:19  dicuccio* Fixed bizarre compile error related to namespaces on MSVC** Revision 1.3  2003/06/13 12:07:41  clausen* GUI changes** Revision 1.2  2003/06/04 19:39:56  ucko* Use new paths to OM headers (the forwarding headers break on WorkShop);* add missing public domain notice and CVS log.*** ===========================================================================*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?