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

Go to the SVN repository for this file.

1 /* $Id: bam_ui_data_source.cpp 47130 2022-08-29 22:09:43Z evgeniev $
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  * Authors: Liangshou Wu
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <corelib/ncbiexec.hpp>
33 #include <corelib/ncbi_process.hpp>
34 #include <corelib/ncbi_system.hpp>
35 #include <corelib/ncbifile.hpp>
36 #include <serial/iterator.hpp>
37 
39 
44 
47 #include <gui/core/app_dialogs.hpp>
50 
54 
59 
61 #include <gui/objutils/label.hpp>
64 #include <gui/objutils/utils.hpp>
65 
67 
68 #include <wx/menu.h>
69 
78 
79 #include <serial/objistr.hpp>
80 #include <serial/objostr.hpp>
81 #include <serial/serial.hpp>
82 
88 
90 
91 #include <util/format_guess.hpp>
92 #include <corelib/ncbi_system.hpp>
93 #include <corelib/ncbiexec.hpp>
94 
95 #include <sstream>
96 
97 #include <mutex>
98 #include <util/thread_pool.hpp>
99 
102 
103 static const char* kLoaderDataType_File = "BAM file";
104 static const char* kLoaderDataType_SRZ = "BAM SRZ";
105 static const char* kLoaderDataType_SRA = "SRA ACC";
106 static const char* kLoaderDataType_CSra_File = "CSRA file";
107 static const char* kBamLoadOption = "BAM/CSRA files";
108 static const char* kBamPath = "path";
109 static const char* kBamFile = "files";
110 static const char* kCSraFile = "file";
111 static const char* kBamIndexFile = "index";
112 static const char* kTargetAssm = "context";
113 static const char* kSrzAccession = "SRZ";
114 static const char* kSraAccession = "SRA";
115 static const int kLoaderPriority = 90;
116 
117 
118 ///////////////////////////////////////////////////////////////////////////////
119 /// CBamLoadingJob
121 {
122 public:
123  struct SBamFile
124  {
125  string m_BamFile;
126  string m_IndexFile;
128  };
129 
130  typedef vector<SBamFile> TBamFiles;
136 
137  CBamLoadingJob();
138 
139  void SetSrzAccs(const TSrzAccs& accs) { m_SrzAccs = accs; }
140  void SetSraAccs(const TSraAccs& accs) { m_SraAccs = accs; }
141  void SetBamFiles(const TBamFiles& files) { m_BamFiles = files; }
142  void SetCSraFiles(const TCSraFiles& files) { m_CSraFiles = files; }
145  void SetSamtoolsPath(const string& samtools) { m_SamtoolsPath = samtools; }
147 
148  const string& GetTargetAssembly() const { return m_TargetAssm; }
149  void SetTargetAssembly(const string& assm) { m_TargetAssm = assm; }
150 
151 protected:
152  virtual void x_CreateProjectItems();
153 
154 private:
155  TLoaderRef x_CreateDataLoader(SBamFile& bam_input);
156 
157 private:
158  TSrzAccs m_SrzAccs; // SRZ accessions
159  TSraAccs m_SraAccs; // SRA accessions
164  string m_TargetAssm;
167 };
168 
169 
170 ///////////////////////////////////////////////////////////////////////////////
171 /// CBamDSEvtHandler - wxEvtHandler-derived adapter for Bam data source.
172 
173 class CBamDSEvtHandler : public wxEvtHandler
174 {
176 public:
178  : m_Workbench(workbench) {
179  }
180  void OnLoadBamFile(wxCommandEvent& event)
181  {
182  if(m_Workbench) {
184  }
185  }
186 protected:
188 };
189 
190 static
191 CRef<CSeq_id> s_GetRefSeq_id(const string& id_str)
192 {
193  CRef<CSeq_id> seq_id;
194  try {
195  seq_id = new CSeq_id(id_str);
196  } catch ( CException&) {
197  // ignored
198  }
199 
200  if ( !seq_id && id_str.find('|') != NPOS ) {
201  try {
202  CBioseq::TId ids;
203  CSeq_id::ParseIDs(ids, id_str);
204  if ( !ids.empty() ) {
205  seq_id = *ids.begin();
206  }
207  } catch ( CException& /*ignored*/ ) {
208  }
209  }
210 
211  if ( !seq_id || (seq_id->IsGi() && seq_id->GetGi() < GI_CONST(1000)) ) {
212  seq_id = new CSeq_id(CSeq_id::e_Local, id_str);
213  }
214  return seq_id;
215 }
216 
217 BEGIN_EVENT_TABLE(CBamDSEvtHandler, wxEvtHandler)
220 
221 
222 ///////////////////////////////////////////////////////////////////////////////
223 /// CBamUIDataSource
224 
225 static const char* kBAM_DS_Icon = "icon::bam_data_source";
226 
228 : m_Type(&type),
229  m_Descr("BAM", kBAM_DS_Icon),
230  m_SrvLocator(NULL),
231  m_Open(false)
232 {
233 }
234 
236 {
237 }
238 
239 
241 {
242  return "bam_data_source";
243 }
244 
245 
247 {
248  return "Bam Data Source";
249 }
250 
251 
253 {
254  m_SrvLocator = locator;
255 }
256 
257 
259 {
261 
262  /// this is not a good solution, but simple
263  IWorkbench* workbench = dynamic_cast<IWorkbench*>(m_SrvLocator);
264 
265  if(items.size() != 1 || workbench == NULL) {
266  return contrib; // return empty object - nothin to contribute
267  }
268 
270 
271  PT::CItem* item = items[0];
272  int type = item->GetType();
273 
274  if(type == PT::eDataSource) {
275  PT::CDataSource* ds_item = dynamic_cast<PT::CDataSource*>(item);
276 
277  if(ds_item) {
278  CIRef<IUIDataSource> ds = ds_item->GetData();
279  CBamUIDataSource* bam_ds = dynamic_cast<CBamUIDataSource*>(ds.GetPointer());
280 
281  if(bam_ds) {
282  wxMenu* menu = new wxMenu;
283  menu->Append(wxID_SEPARATOR, wxT("Top Actions"));
284  cmd_reg.AppendMenuItem(*menu, eCmdLoadBamFile);
285 
286  contrib.first = menu;
287  contrib.second = new CBamDSEvtHandler(workbench);
288  }
289  }
290  }
291  return contrib;
292 }
293 
294 
296 {
297  return *m_Type;
298 }
299 
300 
302 {
303  return m_Descr;
304 }
305 
306 
308 {
309  return m_Open;
310 }
311 
312 //static const char* kCmdExtPoint = "scoped_objects::cmd_contributor";
313 static const char* kAppExpCmdExtPoint = "project_tree_view::context_menu::item_cmd_contributor";
314 
316 {
317  if (m_Open) {
318  LOG_POST(Error << "CBamUIDataSource::Open(): "
319  "attempt to open already open data source");
320  return false;
321  }
322 
323  CStopWatch sw;
324  sw.Start();
325 
326  /// register itself as menu contributor
328  reg->AddExtension(kAppExpCmdExtPoint, *this);
329 
330  m_Open = true;
331  return true;
332 }
333 
334 
336 {
337  if (m_Open) {
338  /// remove itself from menu contribution points
340  reg->RemoveExtension(kAppExpCmdExtPoint, *this);
341 
342  m_Open = false;
343  return true;
344  }
345 
346  return false;
347 }
348 
349 
351 {
352  //TODO
353 }
354 
355 
357 {
358  // TODO may need to link the manager to this particular datasource
359  return new CBamUILoadManager();
360 }
361 
363  return eCmdLoadBamFile;
364 }
365 
367 
368 
369  IWorkbench* workbench = dynamic_cast<IWorkbench*>(m_SrvLocator);
370 
371  return new CBamDSEvtHandler( workbench );
372 }
373 
374 
375 string CBamUIDataSource::AddDataLoader(const objects::CUser_object& obj)
376 {
377  string loader_name = kEmptyStr;
378 
379  // figure out the loader name and data from object
380  if (obj.GetType().IsStr()) {
381  const string& loader_type = obj.GetType().GetStr();
382  if (loader_type == kLoaderDataType_File) {
383  string path, file, index, target_assm;
384  if (x_GetBamInputs(obj, path, file, index, target_assm)) {
385  // make sure the given BAM file and it's index exist
386  // if they are local
387  if (!NStr::StartsWith(path, "http:", NStr::eNocase) &&
388  !NStr::StartsWith(path, "https:", NStr::eNocase))
389  {
390  if (!CFile(path + file).Exists()) {
391  string msg = "Can't find the bam file: " + path + file;
393  }
394 
395  if (!CFile(path + index).Exists()) {
396  string msg = "Can't find the bam index file: " + path + index;
398  }
399  }
400 
402  params.m_DirPath = path;
403  params.m_BamFiles.push_back(CBAMDataLoader::SBamFileName(file, index));
404 
406  if ( !target_assm.empty() ) {
407  // assembly used for remapping, so a full assembly is needed
408  // this is used only by Gbench, so using seqconfig as assembly service should be safe
409  CRef<CGC_Assembly> assm = CGencollSvc::GetInstance()->GetGCAssembly(target_assm, true, "Gbench", nullptr, true);
410  if (assm)
412  }
417  loader_name = info.GetLoader()->GetName();
418  }
419  } else if (loader_type == kLoaderDataType_CSra_File) {
420  string file;
421  if (x_GetCSraInputs(obj, file)) {
422  // make sure the given CSRA file exists, if it's local
423  if (!NStr::StartsWith(file, "http:", NStr::eNocase) &&
424  !NStr::StartsWith(file, "https:", NStr::eNocase))
425  {
426  if (!CFile(file).Exists()) {
427  string msg = "Can't find the CSRA file: " + file;
429  }
430  }
431 
435  (*obj_mgr, "", file,
437  loader_name = info.GetLoader()->GetName();
438  }
439  } else if (loader_type == kLoaderDataType_SRZ) {
440  string srz;
441  if (x_GetSrzAccession(obj, srz)) {
447  loader_name = info.GetLoader()->GetName();
448  }
449  } else if (loader_type == kLoaderDataType_SRA) {
450  string sra;
451  if (x_GetSraAccession(obj, sra)) {
453  objects::CCSRADataLoader::TRegisterLoaderInfo info;
454  info = objects::CCSRADataLoader::RegisterInObjectManager(*obj_mgr, sra,
455  objects::CObjectManager::eNonDefault, kLoaderPriority);
456  loader_name = info.GetLoader()->GetName();
457  }
458  }
459  }
460 
461  return loader_name;
462 }
463 
464 
465 string CBamUIDataSource::GetLoaderName(const objects::CUser_object& obj) const
466 {
467  string loader_name;
468 
469  if (obj.GetType().IsStr()) {
470  const string& loader_type = obj.GetType().GetStr();
471  if (loader_type == kLoaderDataType_File) {
472  string path, file, index, target_assm;
473  if (x_GetBamInputs(obj, path, file, index, target_assm)) {
474  vector<CBAMDataLoader::SBamFileName> bam_files;
475  bam_files.push_back(CBAMDataLoader::SBamFileName(file, index));
476  loader_name =
477  CBAMDataLoader::GetLoaderNameFromArgs(path, bam_files);
478  }
479  } else if (loader_type == kLoaderDataType_CSra_File) {
480  string file;
481  if (x_GetCSraInputs(obj, file)) {
482  loader_name =
484  }
485  } else if (loader_type == kLoaderDataType_SRZ) {
486  string srz;
487  if (x_GetSrzAccession(obj, srz)) {
488  loader_name = CBAMDataLoader::GetLoaderNameFromArgs(srz);
489  }
490  } else if (loader_type == kLoaderDataType_SRA) {
491  string sra;
492  if (x_GetSraAccession(obj, sra)) {
493  loader_name = CCSRADataLoader::GetLoaderNameFromArgs(sra);
494  }
495  }
496  }
497 
498  return loader_name;
499 }
500 
501 
502 bool CBamUIDataSource::x_GetBamInputs(const objects::CUser_object& obj,
503  string& path, string& file,
504  string& idx, string& target_assm) const
505 {
506  CConstRef<CUser_field> field_path = obj.GetFieldRef(kBamPath);
507  CConstRef<CUser_field> field_file = obj.GetFieldRef(kBamFile);
508  CConstRef<CUser_field> field_index = obj.GetFieldRef(kBamIndexFile);
509  CConstRef<CUser_field> field_target_assm = obj.GetFieldRef(kTargetAssm);
510 
511  if (field_path && field_file && field_index && field_target_assm) {
512  path = field_path->GetData().GetStr();
513  file = field_file->GetData().GetStr();
514  idx = field_index->GetData().GetStr();
515  target_assm = field_target_assm->GetData().GetStr();
516 
517  return true;
518  }
519 
520  return false;
521 }
522 
523 
524 bool CBamUIDataSource::x_GetSrzAccession(const objects::CUser_object& obj,
525  string& srz) const
526 {
527  CConstRef<CUser_field> field_srz = obj.GetFieldRef(kSrzAccession);
528  if (field_srz) {
529  srz = field_srz->GetData().GetStr();
530  return true;
531  }
532  return false;
533 }
534 
535 
536 bool CBamUIDataSource::x_GetCSraInputs(const objects::CUser_object& obj,
537  string& file) const
538 {
539  CConstRef<CUser_field> field_file = obj.GetFieldRef(kCSraFile);
540 
541  if (field_file) {
542  file = field_file->GetData().GetStr();
543 
544  return true;
545  }
546 
547  return false;
548 }
549 
550 
551 bool CBamUIDataSource::x_GetSraAccession(const objects::CUser_object& obj,
552  string& sra) const
553 {
554  CConstRef<CUser_field> field_sra = obj.GetFieldRef(kSraAccession);
555  if (field_sra) {
556  sra = field_sra->GetData().GetStr();
557  return true;
558  }
559  return false;
560 }
561 
562 ///////////////////////////////////////////////////////////////////////////////
563 /// CBamUIDataSourceType
565  : m_Descr("Bam File data Loader", "")
566 {
569  wxT("bam_data_source.png"));
570 }
571 
572 
574 {
575  return m_Descr;
576 }
577 
578 
580 {
581  return new CBamUIDataSource(*this);
582 }
583 
584 
586 {
587  return true; // we want to create default "Bam" datasource
588 }
589 
590 
592 {
593  static string ext_id("bam_data_source_type");
594  return ext_id;
595 }
596 
597 
599 {
600  return m_Descr.GetLabel();
601 }
602 
603 
604 
605 ///////////////////////////////////////////////////////////////////////////////
606 /// CBamUILoadManager
608 : m_SrvLocator(NULL),
609  m_ParentWindow(NULL),
610  m_Descriptor(kBamLoadOption, ""),
611  m_State(eInvalid),
612  m_OptionPanel(NULL),
613  m_IndexingPanel(NULL),
614  m_RefSequencesPanel(NULL),
615  m_GraphPanel(NULL),
616  m_ProjectSelPanel(NULL)
617 {
619  m_Descriptor.SetLogEvent("loaders");
620 }
621 
622 
624 {
625  m_SrvLocator = srv_locator;
626 }
627 
628 
630 {
631  m_ParentWindow = parent;
632 }
633 
634 
636 {
637  return m_Descriptor;
638 }
639 
640 
642 {
644 }
645 
646 
648 {
649  m_State = eInvalid;
650  if(m_OptionPanel) {
652  m_OptionPanel = NULL; // window is destroyed by its parent
653  }
654  if (m_IndexingPanel) {
656  m_IndexingPanel = NULL; // window is destroyed by its parent
657  }
658  m_GraphPanel = NULL; // window is destroyed by its parent
659  m_ProjectSelPanel = NULL; // window is destroyed by its parent
660  m_RefSequencesPanel = NULL; // window is destroyed by its parent
661 }
662 
663 
665 {
666  switch (m_State) {
667  case eSelectBam :
668  if (m_OptionPanel == NULL) {
671  }
672  return m_OptionPanel;
673  case eBamIndex:
674  if (m_IndexingPanel == NULL) {
677  }
679  return m_IndexingPanel;
680  case eCoverageGraph:
681  if (m_GraphPanel == NULL) {
683  if (!m_RegPath.empty()) {
684  m_GraphPanel->SetRegistryPath(m_RegPath + ".CoverageGraphPanel");
686  }
687  }
688  m_GraphPanel->TransferDataToWindow();
690  return m_GraphPanel;
691  case eRefSequences:
692  {
693  if (m_RefSequencesPanel == NULL) {
695  }
697  return m_RefSequencesPanel;
698  }
699  case eSelectProject:
700  if(m_ProjectSelPanel == NULL) {
706  }
707  return m_ProjectSelPanel;
708  default:
709  return NULL;
710  }
711  return NULL;
712 }
713 
714 
716 {
717  switch(m_State) {
718  case eSelectBam:
719  return action == eNext;
720  case eBamIndex:
721  case eCoverageGraph:
722  case eRefSequences:
723  case eSelectProject:
724  return action == eBack || action == eNext;
725  case eCompleted:
726  return false; // nothing left to do
727  default:
728  _ASSERT(false);
729  return false;
730  }
731 }
732 
733 
735 {
736  return m_State == eSelectProject;
737 }
738 
739 
741 {
742  return m_State == eCompleted;
743 }
744 
745 
747 {
748  if (m_State == eSelectBam && action == eNext) {
749  if (m_OptionPanel->IsInputValid()) {
750  if (m_OptionPanel->HasBamFile()) {
751  if (m_OptionPanel->SetIndexFiles()) {
753  } else {
754  m_State = eBamIndex;
755  }
756  return true;
757  } else {
758  m_RefSeqIds.clear();
763  return true;
764  }
765  }
766  return false;
767  } else if (m_State == eBamIndex) {
768  if (action == eBack) {
770  return true;
771  } else if (action == eNext) {
772  if (m_IndexingPanel->IsInputValid()) {
774  return true;
775  }
776  return false;
777  }
778  } else if (m_State == eCoverageGraph) {
779  if (action == eBack) {
780  if (m_OptionPanel->SetIndexFiles()) {
782  } else {
783  m_State = eBamIndex;
784  }
785  return true;
786  } else if (action == eNext) {
787  if (m_GraphPanel->IsInputValid()) {
788  const CMapAssemblyParams& map_params = m_GraphPanel->m_AssemblyPanel->GetData();
789  if (map_params.GetUseMapping())
790  m_AssmAcc = map_params.GetAssemblyAcc();
791  else
792  m_AssmAcc.clear();
793  if (m_OptionPanel->HasBamFile()) {
794  m_RefSeqIds.clear();
795  wxBusyCursor wait;
797  }
798 
800  return true;
801  }
802  return false;
803  }
804  } else if (m_State == eRefSequences) {
805  if (action == eBack) {
806  if (m_OptionPanel->HasBamFile()) {
808  } else {
810  }
811  return true;
812  } else if (action == eNext) {
813 
814 
816  return true;
817  }
818  } else if (m_State == eSelectProject) {
819  if (action == eBack) {
821  return true;
822  } else if (action == eNext) {
825  return true;
826  }
827  return false;
828  }
829  }
830  _ASSERT(false);
831  return false;
832 }
833 
834 
836 {
837  // create loading Job
839 
841  CBamLoadingJob* job = new CBamLoadingJob();
842  // create a wrapper task
843 
844  CSelectProjectOptions options;
846 
847  unique_ptr<CDataLoadingAppTask> task(new CDataLoadingAppTask(srv, options, *job));
848  task->SetReportErrors(false); // we handle errors ourselves
849 
850  CBamLoadingJob::TBamFiles bam_files;
851  for (const auto& iter : m_OptionPanel->GetBamFiles()) {
852  CBamLoadingJob::SBamFile bam_input;
853  bam_input.m_BamFile = iter.first;
854  bam_input.m_IndexFile = iter.second;
855  bam_files.push_back(bam_input);
856  }
857 
858  job->SetSrzAccs(m_OptionPanel->GetSrzAccs());
859  job->SetSraAccs(m_OptionPanel->GetSraAccs());
860  job->SetBamFiles(bam_files);
861  job->SetCSraFiles(m_OptionPanel->GetCSraFiles());
862  job->SetRefSeqs() = m_RefSeqIds;
863 
865  m_RefSequencesPanel->GetSelectedReferenceSeqIds(job->SetSeqIdsToLoad());
866  if (m_IndexingPanel) {
867  job->SetSamtoolsPath(m_IndexingPanel->GetSamtoolsPath());
868  }
869 
870  job->SetTargetAssembly(m_AssmAcc);
871 
872  return task.release();
873 }
874 
875 
876 void CBamUILoadManager::SetRegistryPath(const string& path)
877 {
878  m_RegPath = path; // store for later use
879 }
880 
881 
882 static const char* kBamInputTag = "BamInput2";
883 static const char* kBamInputListTag = "BamInputList";
884 static const char* kSamtoolsPathTag = "SamtoolsPath";
885 static const char* kProjectParamsTag = "ProjectParams";
886 
887 
889 {
890  if ( !m_RegPath.empty() ) {
892  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath);
893 
894  /// remember the selected Format (only if m_OptionPanel exists)
895  if (m_OptionPanel) {
897  }
898  // do not save large texts
899  if (m_SavedInput.size() < 10000) {
900  list<string> input_list;
901  NStr::Split(m_SavedInput, "\n", input_list);
902  view.Set(kBamInputListTag, input_list);
903  }
904 
905  if (m_IndexingPanel) {
907  }
908 
909  if ( !m_SamtoolsPath.empty() ) {
911  }
912  /// save Project Panel settings
914 
915  if (m_GraphPanel)
917  }
918 }
919 
920 
922 {
923  if (!m_RegPath.empty()) {
925  CRegistryReadView view = gui_reg.GetReadView(m_RegPath);
926  list<string> input_list;
927  view.GetStringList(kBamInputListTag, input_list);
928  if (!input_list.empty()) {
929  m_SavedInput = NStr::Join(input_list, "\n");
930  } else {
931  m_SavedInput = view.GetString(kBamInputTag, "");
932  }
933 
935 
936  /// load Project Panel settings
938 
939  if (m_GraphPanel)
941  }
942 }
943 
944 
946 {
947  unique_ptr<IIdMapper> idMapper;
948  if (!mappedAcc.empty()) {
949  // this is used only by Gbench, so using seqconfig as assembly service should be safe
950  CRef<CGC_Assembly> assm = CGencollSvc::GetInstance()->GetGCAssembly(mappedAcc, true, "Gbench", nullptr, true);
951  if (assm)
952  idMapper.reset(CGencollIdMapperAdapter::GetIdMapper(assm));
953  }
954  set<string> added_ids;
955  CBamMgr mgr;
956  for (const auto& itFile : files) {
957  CBamDb db(mgr, itFile.first);
958  if (idMapper.get())
959  db.SetIdMapper(idMapper.get(), eNoOwnership);
960  // Get the list of referenced sequences
961  for ( CBamRefSeqIterator itRefSeq(db); itRefSeq; ++itRefSeq ) {
962  CRef< CSeq_id > seqId = db.GetRefSeq_id(itRefSeq.GetRefSeqId());
963  if (seqId.Empty())
964  continue;
965  auto id_str = seqId->GetSeqIdString(true);
966  // if we have multiple bams in the input they might map to the same id
967  // in this case we don't need to add this id to m_RefSeqIds twice
968  if (added_ids.insert(id_str).second == true) {
969  m_RefSeqIds.push_back(seqId);
970  }
971  }
972  }
973 }
974 
976 {
977  CVDBMgr mgr;
978  ITERATE(CBamLoadOptionPanel::TBamFiles, itAcc, accessions) {
979  CCSraDb csra_db(mgr, *itAcc);
980  for ( CCSraRefSeqIterator it(csra_db); it; ++it ) {
981  CRef<CSeq_id> seqId = s_GetRefSeq_id(it.GetRefSeqId());
982  if (seqId.Empty())
983  continue;
984  m_RefSeqIds.push_back(seqId);
985  }
986  }
987 }
988 
990 {
991  CSrzPath srz_path;
992  ITERATE(CBamLoadOptionPanel::TBamFiles, itAcc, accessions) {
993  try {
994  string def_name =
995  CDirEntry::MakePath(srz_path.FindAccPath(*itAcc),
997  CNcbiIfstream in(def_name.c_str());
998  if (!in) {
999  continue;
1000  }
1001  string line;
1002  vector<string> tokens;
1003  while (getline(in, line)) {
1004  tokens.clear();
1005  NStr::Split(line, "\t", tokens);
1006  if (tokens.size() < 4) {
1007  break;
1008  }
1009  string str_id = tokens[2];
1010  if (str_id.empty()) {
1011  str_id = tokens[1];
1012  }
1013  CRef<CSeq_id> seqId;
1014  try {
1015  seqId = new CSeq_id(str_id);
1016  }
1017  catch (CException& /*ignored*/) {
1018  seqId = new CSeq_id(CSeq_id::e_Local, str_id);
1019  }
1020  m_RefSeqIds.push_back(seqId);
1021  }
1022  }
1023  catch (exception&) {
1024  }
1025  }
1026 }
1027 
1028 /// CBamLoadingJob
1029 
1031 {
1032  m_Descr = "Loading BAM file";
1033 }
1034 
1035 inline string s_QuotedPath(const string& path)
1036 {
1037  // We dont need quoting anymore (since SC-13)
1038 //#if defined __WXMSW__
1039 // return "\"" + path + "\"";
1040 //#else
1041  return path;
1042 //#endif
1043 }
1044 
1045 string s_GetTempSortedBamFile(const string& sorted_file, int file_i)
1046 {
1047  string i_str = NStr::IntToString(file_i);
1048  if (i_str.length() < 4) {
1049  i_str.insert((size_t)0, size_t(4 - i_str.length()), '0');
1050  }
1051  return sorted_file + "." + i_str + ".bam";
1052 }
1053 
1054 string s_GetTempSortedBamFileNew(const string& sorted_file, int file_i)
1055 {
1056  string i_str = NStr::IntToString(file_i);
1057  if (i_str.length() < 4) {
1058  i_str.insert((size_t)0, size_t(4 - i_str.length()), '0');
1059  }
1060  return sorted_file + ".tmp." + i_str + ".bam";
1061 }
1062 
1063 string s_GetAnnotName(const CSeq_annot& annot)
1064 {
1065  if (annot.IsSetDesc()) {
1066  ITERATE (CSeq_annot::TDesc::Tdata, iter, annot.GetDesc().Get()) {
1067  if ((*iter)->IsName()) {
1068  return (*iter)->GetName();
1069  }
1070  }
1071  }
1072 
1073  return "";
1074 }
1075 
1076 
1077 CRef<CSeq_annot> s_LoadSeqAnnot(const string& file, const string& annot_name)
1078 {
1079  // Currently, only ASN.1, Binary ASN.1 or XML files are acceptible
1080  CNcbiIfstream istr(file.c_str(), ios::binary);
1082  CFormatGuess fg;
1083  CFormatGuess::EFormat f = fg.Format(istr);
1084  switch (f) {
1086  sfmt = eSerial_AsnBinary;
1087  break;
1089  sfmt = eSerial_AsnText;
1090  break;
1091  case CFormatGuess::eXml:
1092  sfmt = eSerial_Xml;
1093  break;
1094  default:
1095  {{
1096  string msg("File format could not be determined:\n");
1097  msg += file;
1098  LOG_POST(Info << msg);
1099  }}
1100  break;
1101  }
1102  if (sfmt == eSerial_None) {
1103  string msg = "The graph file format is not supported!";
1104  msg += "\nGraph file: " + file;
1106  }
1107 
1108  istr.seekg(0);
1109  unique_ptr<CObjectIStream> obj_str(CObjectIStream::Open(sfmt, istr));
1110  CRef<CSeq_annot> annot(new CSeq_annot);
1111  try {
1112  // We only consider seq-annot
1113  *obj_str >> *annot;
1114  } catch (CException& e) {
1115  string msg = "Can't deserialize the graph file. A seq-annot is expected. ";
1116  msg += "Error: " + e.GetMsg();
1117  msg += "\nGraph file: " + file;
1119  }
1120 
1121  if ( !annot->IsSetData() || !annot->IsGraph()) {
1122  string msg = "The input graph file doesn't cotain a graph!";
1123  msg += "\nGraph file: " + file;
1125  }
1126 
1127  if ( s_GetAnnotName(*annot) != annot_name) {
1128  string msg = "The graph annotatin name (" + s_GetAnnotName(*annot);
1129  msg += ") needs to match with BAM file: " + annot_name;
1130  msg += "\nGraph file: " + file;
1132  }
1133 
1134  return annot;
1135 }
1136 
1137 
1139 {
1141  const string& bam_file = iter->m_BamFile;
1142  LOG_POST(Info << "Importing BAM file: " << bam_file);
1143  TLoaderRef bam_loader = x_CreateDataLoader(*iter);
1144  if (IsCanceled())
1145  return;
1146  if (!bam_loader)
1147  continue;
1148  // skip the one that doesn't have an index file
1149  if (iter->m_IndexFile.empty())
1150  continue;
1151  AddDataLoader(*bam_loader);
1152  }
1153 
1154  // add data loader from SRZ accessions
1155  ITERATE (TSrzAccs, iter, m_SrzAccs) {
1156  if (IsCanceled()) {
1157  return;
1158  }
1159 
1160  LOG_POST(Info << "Importing SRZ accession: " << *iter);
1161 
1163  CBamUIDataSourceType data_source_type;
1164 
1165  loader->SetLabel(*iter);
1166  loader->SetPriority(kLoaderPriority);
1167  loader->SetLoader_type(data_source_type.GetExtensionIdentifier());
1168 
1170  bam_data->SetType().SetStr(kLoaderDataType_SRZ);
1171  bam_data->AddField(kSrzAccession, *iter);
1172 
1173  loader->SetData(*bam_data);
1174  AddDataLoader(*loader);
1175  }
1176 
1177  // add data loader from CSRA files
1178  ITERATE (TCSraFiles, iter, m_CSraFiles) {
1179  if (IsCanceled()) {
1180  return;
1181  }
1182 
1183  LOG_POST(Info << "Importing cSRA file: " << *iter);
1184 
1186  CBamUIDataSourceType data_source_type;
1187 
1188  loader->SetLabel(*iter);
1189  loader->SetPriority(kLoaderPriority);
1190  loader->SetLoader_type(data_source_type.GetExtensionIdentifier());
1191 
1193  bam_data->SetType().SetStr(kLoaderDataType_CSra_File);
1194  bam_data->AddField(kCSraFile, *iter);
1195 
1196  loader->SetData(*bam_data);
1197  AddDataLoader(*loader);
1198  }
1199 
1200  // add data loader from SRA accessions
1201  ITERATE (TSraAccs, iter, m_SraAccs) {
1202  if (IsCanceled()) {
1203  return;
1204  }
1205 
1206  LOG_POST(Info << "Importing SRA accession: " << *iter);
1207 
1209  CBamUIDataSourceType data_source_type;
1210 
1211  loader->SetLabel(*iter);
1212  loader->SetPriority(kLoaderPriority);
1213  loader->SetLoader_type(data_source_type.GetExtensionIdentifier());
1214 
1216  bam_data->SetType().SetStr(kLoaderDataType_SRA);
1217  bam_data->AddField(kSraAccession, *iter);
1218 
1219  loader->SetData(*bam_data);
1220  AddDataLoader(*loader);
1221  }
1222 
1223  // add data loader from reference sequences
1224  for (auto& id : m_SeqIdsToLoad) {
1225  CRef<CProjectItem> item(new CProjectItem());
1226  CRef<CSeq_id> seqId(new CSeq_id());
1227  seqId->Assign(*id);
1228  item->SetObject(*seqId);
1230  // add item to a list
1231  AddProjectItem(*item);
1232  }
1233 }
1234 
1235 
1238 {
1239  TLoaderRef bam_loader;
1240  const string& bam_file = bam_input.m_BamFile;
1241  if (bam_file.empty()) {
1242  LOG_POST(Error << "CBamLoadingJob::x_CreateDataLoader(): "
1243  "Invalid (empty) bam file.");
1244  return bam_loader;
1245  }
1246 
1247  // bam file
1248  string path, file_name, ext;
1249  CDirEntry::SplitPath(bam_file, &path, &file_name, &ext);
1250 
1251  if (path.empty() || file_name.empty()) {
1252  return bam_loader;
1253  }
1254 
1255  auto GenerateIndex = [this](const string& bam_file, const string& index_file, bool generate_csi = false)
1256  {
1258  try {
1259  if (generate_csi)
1260  result = CExec::SpawnL(CExec::eNoWait, m_SamtoolsPath.c_str(), "index", "-c", s_QuotedPath(bam_file).c_str(), NULL);
1261  else
1262  result = CExec::SpawnL(CExec::eNoWait, m_SamtoolsPath.c_str(), "index", s_QuotedPath(bam_file).c_str(), NULL);
1263 
1264  // wait here until it finishes
1265  CProcess proc(result.GetProcessHandle());
1266  while (proc.IsAlive()) {
1267  if (IsCanceled() && proc.Kill()) {
1268  // need clean up the possible generated index file?
1269  CFile t_file(index_file);
1270  if (t_file.Exists()) {
1271  t_file.Remove();
1272  }
1273  return false;
1274  }
1275  proc.Wait(500);
1276  }
1277  return true;
1278  }
1279  catch (exception&) {
1280  string msg = "Failed to generate the index file for " + bam_file;
1281  msg += " with the provided Samtools executable: " + m_SamtoolsPath;
1283  }
1284  };
1285 
1286  if (bam_input.m_IndexFile.empty()) {
1287  LOG_POST(Info << "Generating BAI index file for " << bam_file);
1288  x_SetStatusText("Generating BAI index file");
1289 
1290  // need to create an index file
1291  if (m_SamtoolsPath.empty()) {
1292  return bam_loader;
1293  }
1294 
1295  string index_file = bam_file + ".bai";
1296 
1297  if (!GenerateIndex(bam_file, index_file))
1298  return bam_loader;
1299 
1300  do {
1301  if (CFile(index_file).Exists())
1302  break;
1303 
1304  // if failed, try generating CSI index
1305  {
1306  LOG_POST(Info << "Generating CSI index file for " << bam_file);
1307  x_SetStatusText("Generating CSI index file");
1308 
1309  string index_file = bam_file + ".csi";
1310 
1311  if (!GenerateIndex(bam_file, index_file, true))
1312  return bam_loader;
1313  }
1314 
1315  // if failed, try sorting the Bam file, and do it again
1316  if (CFile(index_file).Exists())
1317  break;
1318 
1319  LOG_POST(Warning << "Maybe the input Bam file is not sorted. Try sorting it and do indexing again ...");
1320 
1321  x_SetStatusText("Sorting Bam file");
1322  // sorting BAM file
1323  file_name += ".sorted";
1324  string sorted_file = path + file_name;
1325 
1327  // wait here until it finishes
1328  try {
1330  m_SamtoolsPath.c_str(), "sort",
1331  s_QuotedPath(bam_file).c_str(),
1332  s_QuotedPath(sorted_file).c_str(), NULL);
1333  CProcess sort_proc(result.GetProcessHandle());
1334 
1335  while (sort_proc.IsAlive()) {
1336  if (IsCanceled() && sort_proc.Kill()) {
1337  // need clean up the possible generated index file?
1338  int file_i = 0;
1339  string t_file = s_GetTempSortedBamFile(sorted_file, file_i);
1340  while (file_i < 10000 && CFile(t_file).Exists()) {
1341  CFile(t_file).Remove();
1342  ++file_i;
1343  t_file = s_GetTempSortedBamFile(sorted_file, file_i);
1344  }
1345  return bam_loader;
1346  }
1347  sort_proc.Wait(2000);
1348  }
1349  }
1350  catch (exception&) {
1351  string msg = "Failed to sort the BAM file: " + bam_file;
1352  msg += " with the provided Samtools executable: " + m_SamtoolsPath;
1354  }
1355 
1356  // samtools automatically append '.bam' to the given sorted file name.
1357  // so we need to adjust it
1358  sorted_file += ".bam";
1359 
1360  if (!CFile(sorted_file).Exists()) {
1361 
1362  // Newer versions of samtools use different input parameters try it on failure
1363  try {
1365  m_SamtoolsPath.c_str(), "sort",
1366  "-o",
1367  s_QuotedPath(sorted_file).c_str(),
1368  s_QuotedPath(bam_file).c_str(),
1369  NULL);
1370 
1371  CProcess sort_proc(result.GetProcessHandle());
1372 
1373  while (sort_proc.IsAlive()) {
1374  if (IsCanceled() && sort_proc.Kill()) {
1375  // need clean up the possible generated index file?
1376  int file_i = 0;
1377  string t_file = s_GetTempSortedBamFileNew(sorted_file, file_i);
1378  while (file_i < 10000 && CFile(t_file).Exists()) {
1379  CFile(t_file).Remove();
1380  ++file_i;
1381  t_file = s_GetTempSortedBamFileNew(sorted_file, file_i);
1382  }
1383  return bam_loader;
1384  }
1385  sort_proc.Wait(2000);
1386  }
1387  }
1388  catch (exception&) {
1389  string msg = "Failed to sort the BAM file: " + bam_file;
1390  msg += " with the provided Samtools executable: " + m_SamtoolsPath;
1392  }
1393  }
1394 
1395 
1396  if (CFile(sorted_file).Exists()) {
1397  x_SetStatusText("Generating BAI index file");
1398 
1399  // use the sorted Bam file instead of the original user-provided one
1400  index_file = sorted_file + ".bai";
1401  if (!GenerateIndex(sorted_file, index_file))
1402  return bam_loader;
1403 
1404  if (CFile(index_file).Exists()) {
1405  bam_input.m_BamFile = sorted_file;
1406  }
1407  else {
1408  x_SetStatusText("Generating CSI index file");
1409 
1410  // use the sorted Bam file instead of the original user-provided one
1411  index_file = sorted_file + ".csi";
1412  if (!GenerateIndex(sorted_file, index_file, true))
1413  return bam_loader;
1414 
1415  if (CFile(index_file).Exists()) {
1416  bam_input.m_BamFile = sorted_file;
1417  }
1418  else {
1419  string msg = "Failed to generate index file for " + bam_file;
1421  }
1422  }
1423  }
1424  else {
1425  string msg = "Failed to sort the Bam file: " + bam_file;
1427  }
1428  } while (false);
1429 
1430  string ind_file_name, ind_ext;
1431  CDirEntry::SplitPath(index_file, &path, &ind_file_name, &ind_ext);
1432  bam_input.m_IndexFile = ind_file_name + ind_ext;
1433  }
1434 
1435  x_SetStatusText("Creating Bam data loader");
1436  file_name += ext;
1437  bam_loader.Reset(new CLoaderDescriptor());
1438  CBamUIDataSourceType data_source_type;
1439 
1440  bam_loader->SetLabel(file_name);
1441  bam_loader->SetPriority(kLoaderPriority);
1442  bam_loader->SetLoader_type(data_source_type.GetExtensionIdentifier());
1443 
1445  bam_data->SetType().SetStr(kLoaderDataType_File);
1446 
1447  bam_data->AddField(kBamFile, file_name);
1448  bam_data->AddField(kBamPath, path);
1449 
1450  string index_path, index_file_name, index_ext;
1451  CDirEntry::SplitPath(bam_input.m_IndexFile, &index_path, &index_file_name, &index_ext);
1452  bam_data->AddField(kBamIndexFile, index_file_name + index_ext);
1453 
1454  bam_data->AddField(kTargetAssm, GetTargetAssembly());
1455 
1456  bam_loader->SetData(*bam_data);
1457  return bam_loader;
1458 }
1459 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
#define static
User-defined methods of the data storage class.
User-defined methods of the data storage class.
static const char * kSraAccession
USING_SCOPE(objects)
static const char * kProjectParamsTag
static const char * kBamIndexFile
static CRef< CSeq_id > s_GetRefSeq_id(const string &id_str)
CRef< CSeq_annot > s_LoadSeqAnnot(const string &file, const string &annot_name)
static const char * kBamInputTag
static const char * kSamtoolsPathTag
static const char * kSrzAccession
string s_GetTempSortedBamFileNew(const string &sorted_file, int file_i)
static const char * kLoaderDataType_SRA
static const char * kLoaderDataType_File
string s_QuotedPath(const string &path)
string s_GetTempSortedBamFile(const string &sorted_file, int file_i)
string s_GetAnnotName(const CSeq_annot &annot)
static const char * kBamLoadOption
END_EVENT_TABLE()
static const int kLoaderPriority
static const char * kBAM_DS_Icon
CBamUIDataSource.
static const char * kLoaderDataType_SRZ
static const char * kBamPath
static const char * kTargetAssm
static const char * kLoaderDataType_CSra_File
static const char * kAppExpCmdExtPoint
static const char * kCSraFile
static const char * kBamInputListTag
static const char * kBamFile
#define SRZ_CONFIG_NAME
Definition: bamread.hpp:108
static void COpenDialog(IWorkbench *workbench, const string &loader_label=NcbiEmptyString, const vector< wxString > &filenames=vector< wxString >())
CMapAssemblyParams & GetData()
Data access.
static string GetLoaderNameFromArgs(void)
Definition: bamloader.cpp:153
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, const SLoaderParams &params, CObjectManager::EIsDefault is_default=CObjectManager::eNonDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: bamloader.cpp:98
static void SetSkipEmptyPileupGraphsParamDefault(bool param)
void SetBamFiles(const vector< pair< string, string >> &bam_files)
virtual void SetRegistryPath(const string &path)
CBamDSEvtHandler - wxEvtHandler-derived adapter for Bam data source.
CBamDSEvtHandler(IWorkbench *workbench)
void OnLoadBamFile(wxCommandEvent &event)
CRef< CSeq_id > GetRefSeq_id(const string &label) const
Definition: bamread.cpp:995
void SetIdMapper(IIdMapper *idmapper, EOwnership ownership)
Definition: bamread.hpp:236
string GetSamtoolsPath() const
void SetBamFilePath(const string &file)
void SetSamtoolsPath(const string &path)
CBamLoadOptionPanel.
CBamLoadingJob.
CRef< objects::CLoaderDescriptor > TLoaderRef
vector< SBamFile > TBamFiles
TLoaderRef x_CreateDataLoader(SBamFile &bam_input)
set< string > TSraAccs
CBamUtils::TSeqIdsVector TSeqIdsVector
void SetTargetAssembly(const string &assm)
TSeqIdsVector m_SeqIdsToLoad
set< string > TSrzAccs
TSeqIdsVector & SetSeqIdsToLoad()
TSeqIdsVector & SetRefSeqs()
set< string > TCSraFiles
void SetSraAccs(const TSraAccs &accs)
void SetBamFiles(const TBamFiles &files)
void SetSamtoolsPath(const string &samtools)
void SetCSraFiles(const TCSraFiles &files)
TSeqIdsVector m_RefSeqIds
void SetGraphBinSize(int size)
void SetSrzAccs(const TSrzAccs &accs)
CBamLoadingJob()
CBamLoadingJob.
const string & GetTargetAssembly() const
virtual void x_CreateProjectItems()
override this function in derived classes and populate m_Items.
void GetSelectedReferenceSeqIds(vector< CConstRef< objects::CSeq_id > > &selSeqIds) const
void SetReferenceSeqIds(const vector< CConstRef< objects::CSeq_id > > &refSeqIds)
CBamUIDataSourceType.
CBamUIDataSource.
vector< CConstRef< objects::CSeq_id > > TSeqIdsVector
Definition: bam_utils.hpp:44
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, const SLoaderParams &params, CObjectManager::EIsDefault is_default=CObjectManager::eNonDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: csraloader.cpp:254
static string GetLoaderNameFromArgs(void)
Definition: csraloader.cpp:326
CDataLoadingAppJob - a base class for Jobs loading data into projects.
void AddProjectItem(objects::CProjectItem &item)
void AddDataLoader(objects::CLoaderDescriptor &loader)
CRef< objects::CScope > m_Scope
CDataLoadingAppTask - a task that executes CDataLoadingAppJob.
The result type for Spawn methods.
Definition: ncbiexec.hpp:120
CFile –.
Definition: ncbifile.hpp:1604
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.
static CRef< CGencollSvc > GetInstance(void)
Definition: gencoll_svc.cpp:54
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
CLoaderDescriptor –.
string GetAssemblyAcc() const
CProcess –.
void SetObject(CSerialObject &object)
wrapper for setting the object pointed to by this item
CProjectSelectorPanel - a panel that allows the user to specify how the project items created by a pl...
void SetProjectService(CProjectService *service)
void GetParams(SProjectSelectorParams &params) const
void SetParams(const SProjectSelectorParams &params)
CProjectService - a service providing API for operations with Workspaces and Projects.
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
string GetString(const string &key, const string &default_val=kEmptyStr) const
Definition: reg_view.cpp:246
void GetStringList(const string &key, list< string > &val) const
Definition: reg_view.cpp:268
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
CProjectSelectOptions - describes how new Project Items shall be added to a workspace.
bool IsGraph(void) const
Definition: Seq_annot.cpp:187
string FindAccPath(const string &acc, EMissing mising)
Definition: bamread.cpp:305
CStopWatch –.
Definition: ncbitime.hpp:1938
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
static CUICommandRegistry & GetInstance()
the main instance associated with the application
Definition: ui_command.cpp:176
wxMenuItem * AppendMenuItem(wxMenu &menu, TCmdID cmd_id) const
Definition: ui_command.cpp:300
IAppTask.
Definition: app_task.hpp:83
pair< wxMenu *, wxEvtHandler * > TContribution
Contribution consists of a Menu object and event handler.
Definition: pt_item.hpp:152
IServiceLocator - an abstract mechanism for locating services.
Definition: service.hpp:71
IUIDataSourceType - defines a type of a Data Source, can serve as a Data Source factory.
IUIDataSource - an interface representing a Data Source.
IUIObject - object that provides basic properties often required in a UI object.
Definition: ui_object.hpp:63
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
virtual int GetType() const =0
const TData & GetData() const
Definition: pt_item.hpp:135
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
const char * file_name[]
#define false
Definition: bool.h:36
static const char * proc
Definition: stats.c:21
void reset(element_type *p=0, EOwnership ownership=eTakeOwnership)
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
Definition: ncbimisc.hpp:480
#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_CONST(gi)
Definition: ncbimisc.hpp:1087
@ eNoOwnership
No ownership is assumed.
Definition: ncbi_types.h:135
#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
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 Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
static CResult SpawnL(EMode mode, const char *cmdname, const char *argv,...)
Spawn a new process with specified command-line arguments.
Definition: ncbiexec.cpp:532
@ eNoWait
Continues to execute calling process concurrently with new process (asynchronous process).
Definition: ncbiexec.hpp:96
virtual bool Remove(TRemoveFlags flags=eRecursive) const
Remove a directory entry.
Definition: ncbifile.cpp:2595
static string MakePath(const string &dir=kEmptyStr, const string &base=kEmptyStr, const string &ext=kEmptyStr)
Assemble a path from basic components.
Definition: ncbifile.cpp:413
virtual bool Exists(void) const
Check existence of file.
Definition: ncbifile.hpp:4038
static void SplitPath(const string &path, string *dir=0, string *base=0, string *ext=0)
Split a path string into its basic components.
Definition: ncbifile.cpp:358
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
Definition: service.hpp:91
static IIdMapper * GetIdMapper(CRef< objects::CGC_Assembly > assm)
Definition: utils.cpp:2826
void x_GetSrzRefSeqs(const CBamLoadOptionPanel::TBamFiles &accessions)
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual bool IsCompletedState()
Manager goes into "Complete" state when "Finish" button is pressed and all input data is gatherred an...
void SetInput(const string &input)
bool x_GetCSraInputs(const objects::CUser_object &obj, string &file) const
virtual bool DoTransition(EAction action)
Performs transition if possible and returns true, otherwise the function shall warn the user about th...
bool x_GetSraAccession(const objects::CUser_object &obj, string &sra) const
virtual bool Open()
Prepares Data Source for use, any initialization that can be potentially time-consuming or may requir...
IServiceLocator * m_SrvLocator
virtual void SetServiceLocator(IServiceLocator *locator)
virtual int GetDefaultCommand()
virtual bool AutoCreateDefaultDataSource()
returns "true" if this type needs to create a default instance of the Data Source at start-up
virtual IUIDataSource * CreateDataSource()
factory method; create an Data Source instance
virtual wxPanel * GetCurrentPanel()
Return the panel corresponding to the current state of Tool Manager.
virtual bool IsFinalState()
True if Tool Manager has reached its final state, i.e.
CProjectSelectorPanel * m_ProjectSelPanel
SProjectSelectorParams m_ProjectParams
CBamLoadOptionPanel * m_OptionPanel
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
const TBamFiles & GetSraAccs() const
CBamUIDataSourceType()
CBamUIDataSourceType.
CBamRefSequencesPanel * m_RefSequencesPanel
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual void InitUI()
Initializes the Manager before using it in UI.
virtual string GetLoaderName(const objects::CUser_object &obj) const
Get the data loader's name based on input object.
CBamUILoadManager()
CBamUILoadManager.
virtual void CleanUI()
CleanUI() is called after the host finished using the manager.
virtual void SetParentWindow(wxWindow *parent)
CBamIndexingPanel * m_IndexingPanel
virtual const IUIObject & GetDescriptor() const
Returns the object describing this tool (UI meta data).
virtual void EditProperties()
const TBamWithIndexFiles & GetBamFiles() const
virtual IExplorerItemCmdContributor::TContribution GetMenu(wxTreeCtrl &treeCtrl, PT::TItems &items)
for the given set of items returns a contribution
virtual IAppTask * GetTask()
Once parameters are gathered and validated this function is called to produce the final Task object t...
virtual IUIToolManager * GetLoadManager()
virtual void LoadSettings()
virtual bool IsOpen()
a Data source needs to be open before use and closed after.
virtual IUIDataSourceType & GetType() const
vector< pair< string, string > > TBamWithIndexFiles
virtual bool CanDo(EAction action)
Indicates whether given transition is possible in the current state.
CBamCoverageGraphPanel * m_GraphPanel
CRef< CBamUIDataSourceType > m_Type
vector< CConstRef< objects::CSeq_id > > m_RefSeqIds
IServiceLocator * m_SrvLocator
void x_GetCSraRefSeqs(const CBamLoadOptionPanel::TBamFiles &accessions)
virtual void SaveSettings() const
virtual const IUIObject & GetDescr()
returns UI description of the object (label, icon etc.)
virtual void SetRegistryPath(const string &path)
virtual string AddDataLoader(const objects::CUser_object &obj)
Add a new data loader to object manager.
virtual wxEvtHandler * CreateEvtHandler()
bool x_GetSrzAccession(const objects::CUser_object &obj, string &srz) const
const TBamFiles & GetCSraFiles() const
virtual void SetServiceLocator(IServiceLocator *srv_locator)
Sets / unsets Service Locator.
void x_GetBamRefSeqs(const CBamLoadOptionPanel::TBamWithIndexFiles &files, const string &mappedAcc)
const TBamFiles & GetSrzAccs() const
virtual const IUIObject & GetDescr()
returns UI description of the type (label, icon etc.)
bool x_GetBamInputs(const objects::CUser_object &obj, string &path, string &files, string &idx, string &target_assm) const
@ eCmdLoadBamFile
string m_Descr
mutex to sync our internals
static CIRef< IExtensionRegistry > GetInstance()
provides access to the Singleton
virtual bool IsCanceled() const override
static void SetLabelByData(objects::CProjectItem &item, objects::CScope *scope=NULL)
Definition: label.cpp:121
virtual void x_SetStatusText(const string &text)
virtual void SetLogEvent(const string &log_event)
Definition: ui_object.cpp:118
virtual const string & GetLabel() const
Definition: ui_object.cpp:124
@ eUnknown
Definition: app_popup.hpp:72
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
@ eSerial_Xml
XML.
Definition: serialdef.hpp:75
@ eSerial_None
Definition: serialdef.hpp:72
@ eSerial_AsnBinary
ASN.1 binary.
Definition: serialdef.hpp:74
string GetSeqIdString(bool with_version=false) const
Return seqid string with optional version for text seqid type.
Definition: Seq_id.cpp:2145
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Optimized implementation of CSerialObject::Assign, which is not so efficient.
Definition: Seq_id.cpp:318
static SIZE_TYPE ParseIDs(CBioseq::TId &ids, const CTempString &s, TParseFlags flags=fParse_Default)
Parse a string representing one or more Seq-ids, appending the results to IDS.
Definition: Seq_id.cpp:2613
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
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
bool Kill(unsigned long timeout=kDefaultKillTimeout)
Terminate process.
int Wait(unsigned long timeout=kInfiniteTimeoutMs, CExitInfo *info=0) const
Wait until process terminates.
bool IsAlive(void) const
Check for process existence.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
#define kEmptyStr
Definition: ncbistr.hpp:123
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
#define NPOS
Definition: ncbistr.hpp:133
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
void Start(void)
Start the timer.
Definition: ncbitime.hpp:2765
const TStr & GetStr(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
TGi GetGi(void) const
Get the variant data.
Definition: Seq_id_.hpp:889
bool IsGi(void) const
Check if variant Gi is selected.
Definition: Seq_id_.hpp:883
@ e_Local
local use
Definition: Seq_id_.hpp:95
const Tdata & Get(void) const
Get the member data.
bool IsSetData(void) const
Check if a value has been assigned to Data data member.
Definition: Seq_annot_.hpp:861
const TDesc & GetDesc(void) const
Get the Desc member data.
Definition: Seq_annot_.hpp:852
list< CRef< CSeq_id > > TId
Definition: Bioseq_.hpp:94
bool IsSetDesc(void) const
used only for stand alone Seq-annots Check if a value has been assigned to Desc data member.
Definition: Seq_annot_.hpp:840
list< CRef< CAnnotdesc > > Tdata
static CStopWatch sw
FILE * file
static MDB_envinfo info
Definition: mdb_load.c:37
#define wxT(x)
Definition: muParser.cpp:41
@ eDataSource
Definition: pt_item.hpp:121
vector< CItem * > TItems
Definition: pt_item.hpp:113
const struct ncbi::grid::netcache::search::fields::SIZE size
Defines process management classes.
Defines a portable execute class.
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
std::istream & in(std::istream &in_, double &x_)
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
The Object manager core.
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
AutoPtr< IIdMapper > m_IdMapper
Definition: bamloader.hpp:72
vector< SBamFileName > m_BamFiles
Definition: bamloader.hpp:71
void LoadSettings(CRegistryReadView &view, const string &section)
void ToLoadingOptions(CSelectProjectOptions &options)
void SaveSettings(CRegistryWriteView &view, const string &section) const
SRegisterLoaderInfo –.
Definition: type.c:6
#define _ASSERT
Pool of generic task-executing threads.
else result
Definition: token2.c:20
wxFileArtProvider * GetDefaultFileArtProvider()
Definition: wx_utils.cpp:334
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
#define const
Definition: zconf.h:232
Modified on Wed Apr 17 13:08:43 2024 by modify_doxy.py rev. 669887