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

Go to the SVN repository for this file.

00001 /*  $Id: cpg_search_tool.cpp 27848 2013-04-12 18:51:49Z kuznets $
00002  * ===========================================================================
00003  *
00004  *                            PUBLIC DOMAIN NOTICE
00005  *               National Center for Biotechnology Information
00006  *
00007  *  This software/database is a "United States Government Work" under the
00008  *  terms of the United States Copyright Act.  It was written as part of
00009  *  the author's official duties as a United States Government employee and
00010  *  thus cannot be copyrighted.  This software/database is freely available
00011  *  to the public for use. The National Library of Medicine and the U.S.
00012  *  Government have not placed any restriction on its use or reproduction.
00013  *
00014  *  Although all reasonable efforts have been taken to ensure the accuracy
00015  *  and reliability of the software and data, the NLM and the U.S.
00016  *  Government do not and cannot warrant the performance or results that
00017  *  may be obtained by using this software or data. The NLM and the U.S.
00018  *  Government disclaim all warranties, express or implied, including
00019  *  warranties of performance, merchantability or fitness for any particular
00020  *  purpose.
00021  *
00022  *  Please cite the author in any work or product based on this material.
00023  *
00024  * ===========================================================================
00025  *
00026  * Authors:  Andrey Yazhuk
00027  *
00028  * File Description:
00029  *
00030  */
00031 
00032 #include <ncbi_pch.hpp>
00033 
00034 #include <gui/core/data_mining_service.hpp>
00035 
00036 #include "cpg_search_tool.hpp"
00037 
00038 
00039 #include <algo/sequence/cpg.hpp>
00040 #include <corelib/ncbiapp.hpp>
00041 #include <corelib/ncbifile.hpp>
00042 #include <corelib/ncbireg.hpp>
00043 #include <gui/utils/system_path.hpp>
00044 
00045 #include <gui/widgets/wx/message_box.hpp>
00046 #include <gui/widgets/wx/wx_utils.hpp>
00047 
00048 #include <objects/seqfeat/Cdregion.hpp>
00049 #include <objects/seqfeat/Seq_feat.hpp>
00050 #include <objects/seq/Seq_annot.hpp>
00051 
00052 #include <gui/objutils/label.hpp>
00053 #include <gui/objutils/utils.hpp>
00054 #include <gui/widgets/wx/ui_tool_registry.hpp>
00055 
00056 #include <gui/utils/app_job_dispatcher.hpp>
00057 #include <gui/utils/extension_impl.hpp>
00058 
00059 #include <objmgr/util/sequence.hpp>
00060 
00061 #include <objects/seqfeat/Genetic_code.hpp>
00062 #include <objects/seqfeat/Genetic_code_table.hpp>
00063 #include <algo/sequence/orf.hpp>
00064 
00065 
00066 #include <wx/sizer.h>
00067 #include <wx/stattext.h>
00068 #include <wx/choice.h>
00069 #include <wx/srchctrl.h>
00070 
00071 
00072 #define ID_COMBOBOX 10003
00073 #define ID_TEXT             11414
00074 #define ID_COMBOBOX_UPDATE  10111
00075 
00076 BEGIN_NCBI_SCOPE
00077 USING_SCOPE(objects);
00078 
00079 static const char* kCpgSizeOfSlidingWindow = "CpgSizeOfSlidingWindow";
00080 static const char* kCpgMinLenOfIsland      = "CpgMinLenOfIsland";
00081 static const char* kCpgMinGC               = "CpgMInGC";
00082 static const char* kCpgMinPercentage       = "CpgMinPercentage";
00083 static const char* kCpgAdjMergeTHreshold   = "CpgAdjMergeThreshold";
00084 
00085 /*
00086 class CCpgSearchTableModel : public CObjectListTableModel
00087 {
00088     virtual int GetNumExtraColumns() const;
00089 };
00090 
00091 int CCpgSearchTableModel::GetNumExtraColumns() const
00092 {
00093     // we can use just the first column from the set of standard ones
00094     // ie "Label"
00095     return 1;
00096 }
00097 */
00098 
00099 /*
00100 class CCpgSearchColumnHandler : public IObjectColumnHandler
00101 {
00102 public:
00103     virtual int         GetColumnsCount();
00104     virtual void        SetObjectList(CObjectList& obj_list);
00105     virtual wxString    GetColumnName(int col);
00106     virtual wxString    GetImageAlias(int row);
00107     virtual void        GetValue(wxString* str, int col, int row);
00108 
00109     static int      GetColumnsCountStatic();
00110     //static void     GetValueStatic(string* str, CNetBlastJobDescriptor& descr, int col);
00111 protected:
00112     CRef<CObjectList>   m_ObjectList;
00113 };
00114 
00115 
00116 static string s_Columns[] = {"Label", "Start", "Stop", "ORF Length",
00117                              "Begining Codon", "Terminal Codon", "Translated Sequence",
00118                              "Nucleotide Sequence", "Context"};
00119 
00120 
00121 void CCpgSearchColumnHandler::SetObjectList(CObjectList& obj_list)
00122 {
00123     m_ObjectList.Reset(&obj_list);
00124 }
00125 
00126 
00127 int CCpgSearchColumnHandler::GetColumnsCount()
00128 {
00129    return GetColumnsCountStatic();
00130 }
00131 
00132 
00133 wxString CCpgSearchColumnHandler::GetColumnName(int col)
00134 {
00135     return s_Columns[col];
00136 }
00137 
00138 wxString CCpgSearchColumnHandler::GetImageAlias(int row)
00139 {
00140     return "";   //TODO
00141 }
00142 
00143 void CCpgSearchColumnHandler::GetValue(wxString * str, int col, int row)
00144 {
00145     if(col < 0  ||  col >= GetColumnsCount())  {
00146         _ASSERT(false);
00147         NCBI_THROW(CException, eUnknown, "Invalid column index");
00148     }
00149     if (str) {
00150         switch (col) {
00151         case 0:
00152             {{
00153                 CObject* obj = m_ObjectList->GetObject(row);
00154                 CScope* scope = m_ObjectList->GetScope(row);
00155 
00156                 string label;
00157                 CLabel::GetLabel( *obj, &label, CLabel::eContent, scope );
00158                 *str = label;
00159             }}
00160             break;
00161 
00162         case 1: // start
00163         case 2: // stop
00164         case 3: // length
00165             /// treat as int
00166             *str = NStr::IntToString(m_ObjectList->GetInteger(col+2, row),
00167                                      NStr::fWithCommas);
00168             break;
00169 
00170         default:
00171             /// treat as string
00172             *str = m_ObjectList->GetString(col+2, row);
00173             break;
00174         }
00175     }
00176 }
00177 
00178 int CCpgSearchColumnHandler::GetColumnsCountStatic()
00179 {
00180     return sizeof(s_Columns) / sizeof(string);
00181 }
00182 */
00183 
00184 
00185 ///////////////////////////////////////////////////////////////////////////////
00186 /// CCpgSearchTool
00187 CCpgSearchTool::CCpgSearchTool()
00188 {
00189     m_Conversions.options.clear();
00190     m_Conversions.options.push_back(CSeqFeatData::eSubtype_region);
00191     m_Conversions.selected = CSeqFeatData::eSubtype_region;
00192 }
00193 
00194 
00195 string CCpgSearchTool::GetName() const
00196 {
00197     static string name("CpG Islands Search");
00198     return name;
00199 }
00200 
00201 
00202 IUITool* CCpgSearchTool::Clone() const
00203 {
00204     return new CCpgSearchTool();
00205 }
00206 
00207 
00208 string CCpgSearchTool::GetDescription() const
00209 {
00210     return "";
00211 }
00212 
00213 
00214 CIRef<IDMSearchForm> CCpgSearchTool::CreateSearchForm()
00215 {
00216     CIRef<IDMSearchForm> form(new CCpgSearchForm(*this));
00217     return form;
00218 }
00219 
00220 
00221 bool CCpgSearchTool::IsCompatible(IDataMiningContext* context)
00222 {
00223     ISeqLocSearchContext* sl_ctx =
00224         dynamic_cast<ISeqLocSearchContext*>(context);
00225     return sl_ctx != NULL;
00226 }
00227 
00228 
00229 CRef<CSearchJobBase> CCpgSearchTool::x_CreateJob(IDMSearchQuery& query)
00230 {
00231     CRef<CSearchJobBase> job;
00232     CCpgSearchQuery* f_query = dynamic_cast<CCpgSearchQuery*>(&query);
00233     if(f_query) {
00234         job.Reset(new CCpgSearchJob(*f_query));
00235     }
00236     return job;
00237 }
00238 
00239 
00240 
00241 string  CCpgSearchTool::GetExtensionIdentifier() const
00242 {
00243     return "search_tool::cpg_search_tool";
00244 }
00245 
00246 string  CCpgSearchTool::GetExtensionLabel() const
00247 {
00248     return "Datamining Tool - CpG Islands search";
00249 }
00250 
00251 
00252 ///////////////////////////////////////////////////////////////////////////////
00253 /// CCpgSearchQuery
00254 
00255 CCpgSearchQuery::CCpgSearchQuery(TScopedLocs& locs,
00256                         const string&  xSizeOfSlidingWindow,
00257                         const string&  xMinLenOfIsland,
00258                         const string&  xMinGC,
00259                         const string&  xMinPercentage,
00260                         const string&  xAdjMergeThreshold)
00261 :   CSearchQueryBase(locs),
00262     m_SizeOfSlidingWindow(xSizeOfSlidingWindow),
00263     m_MinLenOfIsland(xMinLenOfIsland),
00264     m_MinGC(xMinGC),
00265     m_MinPercentage(xMinPercentage),
00266     m_AdjMergeThreshold(xAdjMergeThreshold)
00267 {
00268 }
00269 
00270 string CCpgSearchQuery::ToString() const
00271 {
00272     string s;
00273 
00274     s.append(" SizeOfSlidingWindow=");
00275     s.append(m_SizeOfSlidingWindow);
00276     s.append(" MinLenOfIsland=");
00277     s.append(m_MinLenOfIsland);
00278     s.append(" MinGC=");
00279     s.append(m_MinGC);
00280     s.append(" MinPercentage=");
00281     s.append(m_MinPercentage);
00282     s.append(" AdjMergeThreshold=");
00283     s.append(m_AdjMergeThreshold);
00284 
00285     return s;
00286 }
00287 
00288 
00289 ///////////////////////////////////////////////////////////////////////////////
00290 /// CCpgSearchForm
00291 
00292 
00293 CCpgSearchForm::CCpgSearchForm(CCpgSearchTool& tool)
00294 :   m_Tool(&tool),
00295     m_DbCombo(NULL),
00296     m_SizeOfSlidingWindowCtl(NULL),
00297     m_MinLenOfIslandCtl(NULL),
00298     m_MinGCCtl(NULL),
00299     m_MinPercentageCtl(NULL),
00300     m_AdjMergeThresholdCtl(NULL)
00301 {
00302 }
00303 
00304 
00305 CCpgSearchForm::~CCpgSearchForm()
00306 {
00307 }
00308 
00309 void CCpgSearchForm::Create()
00310 {
00311 }
00312 
00313 void CCpgSearchForm::Init()
00314 {
00315     CSearchFormBase::Init();
00316 }
00317 
00318 
00319 void CCpgSearchForm::x_LoadSettings(CGuiRegistry::TReadView& view)
00320 {
00321     CSearchFormBase::x_LoadSettings(view);
00322 
00323     m_SizeOfSlidingWindow   = view.GetString(kCpgSizeOfSlidingWindow);
00324     m_MinLenOfIsland        = view.GetString(kCpgMinLenOfIsland);
00325     m_MinGC                 = view.GetString(kCpgMinGC);
00326     m_MinPercentage         = view.GetString(kCpgMinPercentage);
00327     m_AdjMergeThreshold     = view.GetString(kCpgAdjMergeTHreshold);
00328 
00329 }
00330 
00331 
00332 void CCpgSearchForm::x_SaveSettings(CGuiRegistry::TReadWriteView& view) const
00333 {
00334     CSearchFormBase::x_SaveSettings(view);
00335 
00336 
00337     if (m_SizeOfSlidingWindowCtl) {
00338         view.Set(kCpgSizeOfSlidingWindow, ToStdString( m_SizeOfSlidingWindowCtl->GetValue() ));
00339     }
00340     if (m_MinLenOfIslandCtl) {
00341         view.Set(kCpgMinLenOfIsland, ToStdString( m_MinLenOfIslandCtl->GetValue() ));
00342     }
00343     if (m_MinGCCtl) {
00344         view.Set(kCpgMinGC, ToStdString( m_MinGCCtl->GetValue() ));
00345     }
00346     if (m_MinPercentageCtl) {
00347         view.Set(kCpgMinPercentage, ToStdString( m_MinPercentageCtl->GetValue() ));
00348     }
00349     if (m_AdjMergeThresholdCtl) {
00350         view.Set(kCpgAdjMergeTHreshold, ToStdString( m_AdjMergeThresholdCtl->GetValue() ));
00351     }
00352 }
00353 
00354 
00355 IDMSearchTool* CCpgSearchForm::x_GetTool()
00356 {
00357     return m_Tool.GetPointer();
00358 }
00359 
00360 
00361 wxSizer *  CCpgSearchForm::GetWidget(wxWindow * parent)
00362 {
00363     if (!m_Sizer) {
00364         wxBoxSizer * vSz = new wxBoxSizer(wxVERTICAL);
00365         m_Sizer = vSz;
00366 
00367         wxFlexGridSizer * sz = new wxFlexGridSizer(3, 4, 0, 0);
00368         sz->AddGrowableCol(1);
00369         sz->AddGrowableCol(3);
00370 
00371         m_Sizer->Add(sz, 0, wxGROW|wxALL, 0);
00372 
00373 
00374         sz->Add(new wxStaticText( parent, wxID_STATIC, wxT("Search Context:"),
00375                                   wxDefaultPosition, wxDefaultSize, 0 ),
00376                 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00377 
00378         m_DbCombo = new wxChoice(parent, ID_COMBOBOX,
00379                                    wxDefaultPosition, wxDefaultSize,
00380                                    0, (const wxString*)NULL);
00381 
00382         sz->Add(m_DbCombo,1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00383 
00384         // 1-st param
00385         sz->Add(new wxStaticText( parent, wxID_STATIC,
00386                                   wxT("Size of sliding window:"),
00387                                   wxDefaultPosition, wxDefaultSize, 0 ),
00388                 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00389         m_SizeOfSlidingWindowCtl =
00390             new wxTextCtrl(parent, wxID_STATIC, wxT("100"),
00391                            wxDefaultPosition, wxDefaultSize, 0 );
00392         if (!m_SizeOfSlidingWindow.empty()) {
00393             m_SizeOfSlidingWindowCtl->SetValue(ToWxString(m_SizeOfSlidingWindow));
00394         } else {
00395             m_SizeOfSlidingWindowCtl->SetValue(wxT("200"));
00396         }
00397         sz->Add(m_SizeOfSlidingWindowCtl, 1,
00398                 wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00399 
00400         // 2-nd param
00401         sz->Add(new wxStaticText( parent, wxID_STATIC,
00402                                   wxT("Minimum length of island:"),
00403                                   wxDefaultPosition, wxDefaultSize, 0 ),
00404                 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00405         m_MinLenOfIslandCtl = new wxTextCtrl(parent, wxID_STATIC, wxT("500"),
00406                                              wxDefaultPosition, wxDefaultSize,
00407                                              0 );
00408         if (!m_MinLenOfIsland.empty()) {
00409             m_MinLenOfIslandCtl->SetValue(ToWxString(m_MinLenOfIsland));
00410         } else {
00411             m_MinLenOfIslandCtl->SetValue(wxT("500"));
00412         }
00413         sz->Add(m_MinLenOfIslandCtl, 1,
00414                 wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00415 
00416         // 3-rd param
00417         sz->Add(new wxStaticText( parent, wxID_STATIC,
00418                                   wxT("Minimum /%G + /%C:"),
00419                                   wxDefaultPosition, wxDefaultSize, 0 ),
00420                 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00421         m_MinGCCtl = new wxTextCtrl(parent, wxID_STATIC, wxT("100"),
00422                                     wxDefaultPosition, wxDefaultSize, 0 );
00423         if (!m_MinGC.empty()) {
00424             m_MinGCCtl->SetValue(ToWxString(m_MinGC));
00425         } else {
00426             m_MinGCCtl->SetValue(wxT("50"));
00427         }
00428         sz->Add(m_MinGCCtl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00429 
00430         // 4-th param
00431         sz->Add(new wxStaticText( parent, wxID_STATIC,
00432                                   wxT("Minimum CpG percentage:"),
00433                                   wxDefaultPosition, wxDefaultSize, 0 ),
00434                 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00435         m_MinPercentageCtl = new wxTextCtrl(parent, wxID_STATIC, wxT("60"),
00436                                             wxDefaultPosition, wxDefaultSize,
00437                                             0 );
00438         if (!m_MinPercentage.empty()) {
00439             m_MinPercentageCtl->SetValue(ToWxString(m_MinPercentage));
00440         } else {
00441             m_MinPercentageCtl->SetValue(wxT("60"));
00442         }
00443         sz->Add(m_MinPercentageCtl, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00444 
00445         // 5-th param
00446         sz->Add(new wxStaticText( parent, wxID_STATIC,
00447                                   wxT("Adjacency merge threshold:"),
00448                                   wxDefaultPosition, wxDefaultSize, 0 ),
00449                 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00450         m_AdjMergeThresholdCtl =
00451             new wxTextCtrl(parent, wxID_STATIC, wxT(""),
00452                            wxDefaultPosition, wxDefaultSize, 0 );
00453         if (!m_AdjMergeThreshold.empty()) {
00454             m_AdjMergeThresholdCtl->SetValue(ToWxString(m_AdjMergeThreshold));
00455         } else {
00456             m_AdjMergeThresholdCtl->SetValue(wxT(""));
00457         }
00458         sz->Add(m_AdjMergeThresholdCtl, 1,
00459                 wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00460     }
00461     return m_Sizer;
00462 }
00463 
00464 
00465 void CCpgSearchForm::Update()
00466 {
00467     UpdateContextCombo(m_DbCombo);
00468 }
00469 
00470 
00471 void CCpgSearchForm::UpdateContexts()
00472 {
00473     CSearchFormBase::UpdateContexts();
00474 }
00475  
00476 CIRef<IDMSearchQuery> CCpgSearchForm::ConstructQuery()
00477 {
00478      m_SeqLocContexts.clear();
00479      for( size_t i = 0;  i < m_Contexts.size();  i++ )   {
00480          if (m_DbCombo->GetSelection() != 0  &&
00481              m_DbCombo->GetSelection() != int(i + 1)) {
00482              continue;
00483          }
00484          ISeqLocSearchContext* seq_ctx =
00485             dynamic_cast<ISeqLocSearchContext*>(m_Contexts[i]);
00486          m_SeqLocContexts.push_back(seq_ctx);
00487       }
00488 
00489     _ASSERT(m_SeqLocContexts.size());
00490 
00491     /// accumulate locations from all selected contexts
00492     TScopedLocs sc_locs;
00493     for( size_t i = 0;  i < m_SeqLocContexts.size();  i++ ) {
00494         ISeqLocSearchContext* sl_ctx = m_SeqLocContexts[i];
00495         _ASSERT(sl_ctx);
00496 
00497          // tereshko: skip context if it can't participate in search anymore (selection loss, etc) 
00498         if (sl_ctx->GetSearchLoc().IsNull()) continue;
00499 
00500         CRef<CSeq_loc> loc(new CSeq_loc());
00501         if (m_bRange) {
00502             loc = sl_ctx->GetSearchLoc();
00503         }
00504         else {
00505             CRef<CSeq_id> id(new CSeq_id());
00506             id->Assign(*(sl_ctx->GetSearchLoc()->GetId()));
00507             loc->SetWhole(*id);
00508         }
00509 
00510         CSearchQueryBase::SScopedLoc sl;
00511         sl.m_Loc = loc;       
00512         sl.m_Scope = sl_ctx->GetSearchScope();
00513         sl.m_ContextName = sl_ctx->GetDMContextName();
00514         sc_locs.push_back(sl);
00515     }
00516 
00517     CIRef<IDMSearchQuery> ref
00518         (new CCpgSearchQuery(sc_locs,
00519                              ToStdString(m_SizeOfSlidingWindowCtl->GetValue()),
00520                              ToStdString(m_MinLenOfIslandCtl->GetValue()),
00521                              ToStdString(m_MinGCCtl->GetValue()),
00522                              ToStdString(m_MinPercentageCtl->GetValue()),
00523                              ToStdString(m_AdjMergeThresholdCtl->GetValue())));
00524     return ref;
00525 }
00526 
00527 
00528 
00529 ///////////////////////////////////////////////////////////////////////////////
00530 /// CCpgSearchJob
00531 
00532 CCpgSearchJob::CCpgSearchJob(CCpgSearchQuery& query)
00533 :   m_Query(&query)
00534 {
00535 }
00536 
00537 
00538 bool CCpgSearchJob::x_ValidateParams()
00539 {
00540     m_Error.Reset();
00541 
00542     if( m_Query->GetScopedLocs().empty()) {
00543         m_Error = new CAppJobError("Invalid input parameters - no search context specified.");
00544     }
00545 
00546     return m_Error ? false : true;
00547 }
00548 
00549 
00550 IAppJob::EJobState CCpgSearchJob::x_DoSearch()
00551 {
00552     EJobState res_state = IAppJob::eFailed;
00553     TScopedLocs& locs   = m_Query->GetScopedLocs();
00554     size_t sum_isles = 0;
00555     size_t row = 0;
00556 
00557 
00558      ITERATE (TScopedLocs, iter, locs) {
00559         TScopedLoc& sc_loc = const_cast<TScopedLoc&>(*iter);
00560         CSeq_loc& loc = *sc_loc.m_Loc;
00561         CScope& scope = *sc_loc.m_Scope;
00562 
00563         CBioseq_Handle handle = scope.GetBioseqHandle(loc);
00564         CSeqVector sv(loc, scope, CBioseq_Handle::eCoding_Iupac);
00565 
00566         string data;
00567         sv.GetSeqData(0, sv.size(), data);
00568 
00569         //find islands
00570         CCpGIslands isles(data.data(), data.size(),
00571                           NStr::StringToInt(m_Query->GetSizeOfSlidingWindow()),
00572                           NStr::StringToInt(m_Query->GetMinLenOfIsland()),
00573                           NStr::StringToInt(m_Query->GetMinGC()),
00574                           NStr::StringToInt(m_Query->GetMinPercentage()));
00575 
00576         // if requested, merge sufficiently close islands
00577         if (!m_Query->GetAdjMergeThreshold().empty()) {
00578             isles.MergeIslesWithin( NStr::StringToInt(m_Query->GetAdjMergeThreshold()));
00579         }
00580 
00581          //report islands
00582         if (!isles.GetIsles().empty()) {
00583             sum_isles += isles.GetIsles().size();
00584 
00585             string title("CpG islands on ");
00586             CLabel::GetLabel(loc, &title,
00587                              CLabel::eDefault, &scope);
00588 
00589             CRef<CSeq_annot> sa(new CSeq_annot);
00590             sa->SetNameDesc(title);
00591             sa->SetCreateDate(CTime(CTime::eCurrent));
00592             CNcbiOstrstream oss;
00593             oss << "windowsize: " << m_Query->GetSizeOfSlidingWindow()
00594                 << ", minlen: " << m_Query->GetMinLenOfIsland()
00595                 << ", min %gc: " << m_Query->GetMinGC()
00596                 << ", min observed/expected CpG: "
00597                 << m_Query->GetMinPercentage();
00598             sa->AddComment(CNcbiOstrstreamToString(oss));
00599 
00600             CSeq_annot::C_Data::TFtable &feats = sa->SetData().SetFtable();
00601             ITERATE (CCpGIslands::TIsles, i, isles.GetIsles()) {
00602                 CRef<CSeq_feat> feat(new CSeq_feat);
00603                 CSeq_interval &seqInt = feat->SetLocation().SetInt();
00604                 seqInt.SetFrom(i->m_Start);
00605                 seqInt.SetTo(i->m_Stop);
00606                 seqInt.SetId().Assign(sequence::GetId(loc, &scope));
00607 
00608                 CRef<CSeq_loc> new_loc =
00609                     CSeqUtils::RemapChildToParent(loc, feat->GetLocation());
00610                 feat->SetLocation(*new_loc);
00611 
00612                 size_t size = (i->m_Stop - i->m_Start);
00613                 size_t pct_gc = (i->m_C + i->m_G) * 100 / size;
00614                 string gc_str = NStr::SizetToString(pct_gc);
00615 
00616                 string& label = feat->SetData().SetRegion();
00617                 label = "CpG island: " + gc_str;
00618                 label += "% GC, ";
00619                 label += NStr::SizetToString(size);
00620                 label += " bases";
00621 
00622                 feats.push_back(feat);
00623 
00624                 ++row;
00625 
00626                 x_AddToResults(*new_loc,
00627                            scope,
00628                            label,
00629                            new_loc->GetTotalRange().GetFrom()+1,
00630                            new_loc->GetTotalRange().GetTo()+1,
00631                            new_loc->GetTotalRange().GetLength(),
00632                            pct_gc,
00633                            sc_loc.m_ContextName);
00634 
00635             }
00636 
00637             /*
00638             x_AddToResults(*sa,
00639                            scope,
00640                            title,
00641                            sc_loc.m_ContextName);
00642                            */
00643         }
00644         res_state = IAppJob::eCompleted;
00645     }
00646 
00647     return res_state;
00648 }
00649 
00650 
00651 void CCpgSearchJob::x_SetupColumns(CObjectList& obj_list)
00652 {   
00653     obj_list.ClearObjectLabels();
00654     obj_list.AddObjectLabel( "Label", CLabel::eContent );
00655 
00656     obj_list.AddColumn( CObjectList::eInteger, "Start" );
00657     obj_list.AddColumn( CObjectList::eInteger, "Stop" );
00658     obj_list.AddColumn( CObjectList::eInteger, "Length" );
00659     obj_list.AddColumn( CObjectList::eInteger, "% GC" );
00660     obj_list.AddColumn(CObjectList::eString, "Context");
00661     
00662 }
00663 
00664 void CCpgSearchJob::x_AddToResults(CObject& obj, objects::CScope& scope,
00665                            const string& loc_name,
00666                            int   start,
00667                            int   stop,
00668                            int   length,
00669                            int   gc,                                  
00670                            const string& ctx_name)
00671 {
00672     static const int kUpdateIncrement = 250;
00673 
00674     /// adding the result to the Accumulator
00675     int row = m_AccList.AddRow(&obj, &scope);
00676     int col = 0;
00677     m_AccList.SetInteger(col++, row, start);
00678     m_AccList.SetInteger(col++, row, stop);
00679     m_AccList.SetInteger(col++, row, length);
00680     m_AccList.SetInteger(col++, row, gc);
00681     m_AccList.SetString(col++, row, ctx_name);
00682 
00683     int count = m_AccList.GetNumRows();
00684     if(count >= kUpdateIncrement)   {
00685         // time to update the Result
00686         CMutexGuard Guard(m_Mutex);
00687 
00688         /// transfer results from Accumulator to m_TempResult
00689         m_TempResult->GetObjectList()->Append(m_AccList);
00690         m_AccList.ClearRows();
00691 
00692         /// update progress string
00693         m_ProgressStr = NStr::IntToString(count, NStr::fWithCommas) + " CPG";
00694         if (count != 1) {
00695             m_ProgressStr += "'s";
00696         }
00697         m_ProgressStr += " found.";
00698     }
00699 }
00700 
00701 CObjectListTableModel* CCpgSearchJob::x_GetNewOLTModel() const
00702 {
00703     return new CObjectListTableModel();
00704 }
00705 
00706 
00707 END_NCBI_SCOPE
Modified on Sat Mar 28 10:16:31 2015 by modify_doxy.py rev. 426318