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

Go to the SVN repository for this file.

1 /* $Id: export_table.cpp 47479 2023-05-02 13:24:02Z ucko $
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: Igor Filippov
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 ////@begin includes
33 ////@end includes
35 #include <objmgr/feat_ci.hpp>
36 #include <objmgr/seqdesc_ci.hpp>
37 #include <objmgr/util/sequence.hpp>
41 #include <gui/objutils/utils.hpp>
47 
48 
52 
53 #ifdef NCBI_OS_MSWIN
54 #include <wx/msw/ole/automtn.h>
55 #endif
56 
57 #include <wx/filename.h>
58 #include <wx/button.h>
59 #include <wx/statbox.h>
60 #include <wx/stattext.h>
61 #include <wx/msgdlg.h>
62 #include <wx/filedlg.h>
63 
64 ////@begin XPM images
65 ////@end XPM images
66 
68 
69 
70 
71 IMPLEMENT_DYNAMIC_CLASS( CExportTableDlg, wxDialog )
72 
73 
74 BEGIN_EVENT_TABLE( CExportTableDlg, wxDialog )
75 
76 
78 
80 {
81  Init();
82 }
83 
84 CExportTableDlg::CExportTableDlg( wxWindow* parent, objects::CSeq_entry_Handle seh,
85  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
86 : m_TopSeqEntry(seh)
87 {
88  Init();
90  Create(parent, id, caption, pos, size, style);
91 }
92 
93 
94 bool CExportTableDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
95 {
96  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
97  wxDialog::Create( parent, id, caption, pos, size, style );
98 
100  if (GetSizer())
101  {
102  GetSizer()->SetSizeHints(this);
103  }
104  Centre();
105 
106  return true;
107 }
108 
109 
111 {
112 }
113 
114 
115 /*!
116  * Member initialisation
117  */
118 
120 {
121  m_ExcelCheck = NULL;
122 }
123 
125 {
126  CExportTableDlg* itemDialog1 = this;
127 
128  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
129  itemDialog1->SetSizer(itemBoxSizer1);
130 
131  m_SourceCheck = new wxCheckBox(itemDialog1, ID_EXPTABLE_CHKBOX1, _("Source Qualifiers"));
132  itemBoxSizer1->Add(m_SourceCheck, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
133  m_SourceCheck->SetValue(true);
134 
135  wxArrayString source_quals;
136  source_quals.Add(ToWxString("All"));
137  for (set<string>::iterator qual = m_source_choices.begin(); qual != m_source_choices.end(); ++qual)
138  source_quals.Add(ToWxString(*qual));
139 
140  m_SourceChoice = new wxListBox(itemDialog1, ID_EXPTABLE_LISTBOX, wxDefaultPosition, wxDefaultSize, source_quals, wxLB_MULTIPLE, wxDefaultValidator);
141  m_SourceChoice->SetSelection(0);
142  itemBoxSizer1->Add(m_SourceChoice, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
143 
144  wxStaticBox* itemStaticBoxSizer2Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Other Qualifiers"));
145  wxStaticBoxSizer* itemBoxSizer2 = new wxStaticBoxSizer(itemStaticBoxSizer2Static, wxVERTICAL);
146  itemBoxSizer1->Add(itemBoxSizer2, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
147 
148  m_NoneRB = new wxRadioButton(itemDialog1, ID_EXPTABLE_RADBTN1, _("None"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
149  m_NoneRB->SetValue(true);
150  itemBoxSizer2->Add(m_NoneRB, 0, wxALIGN_LEFT|wxALL, 5);
151 
152  m_FeatureRB = new wxRadioButton(itemDialog1, ID_EXPTABLE_RADBTN2, _("Feature Qualifiers"));
153  itemBoxSizer2->Add(m_FeatureRB, 0, wxALIGN_LEFT|wxALL, 5);
154 
155  m_CdsGeneProtRB = new wxRadioButton(itemDialog1, ID_EXPTABLE_RADBTN3, _("CDS-Gene-Prot Qualifiers"));
156  itemBoxSizer2->Add(m_CdsGeneProtRB, 0, wxALIGN_LEFT|wxALL, 5);
157 
158  m_RnaRB = new wxRadioButton(itemDialog1, ID_EXPTABLE_RADBTN4, _("RNA Qualifiers"));
159  itemBoxSizer2->Add(m_RnaRB, 0, wxALIGN_LEFT|wxALL, 5);
160 
161  m_DeflineRB = new wxRadioButton(itemDialog1, ID_EXPTABLE_RADBTN5, _("Definition Line"));
162  itemBoxSizer2->Add(m_DeflineRB, 0, wxALIGN_LEFT|wxALL, 5);
163 
164  m_PubRB = new wxRadioButton(itemDialog1, ID_EXPTABLE_RADBTN6, _("Publication Titles"));
165  itemBoxSizer2->Add(m_PubRB, 0, wxALIGN_LEFT|wxALL, 5);
166 
167  m_DbLinkRB = new wxRadioButton(itemDialog1, ID_EXPTABLE_RADBTN7, _("DBLink"));
168  itemBoxSizer2->Add(m_DbLinkRB, 0, wxALIGN_LEFT|wxALL, 5);
169 
170 #ifdef NCBI_OS_MSWIN
171  m_ExcelCheck = new wxCheckBox(itemDialog1, ID_EXPTABLE_CHKBOX2, _("Launch Excel"));
172  itemBoxSizer1->Add(m_ExcelCheck, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
173 #endif
174 
175  wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
176  itemBoxSizer1->Add(itemBoxSizer11, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
177  wxButton* itemButton1 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
178  itemBoxSizer11->Add(itemButton1, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
179  wxButton* itemButton2 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
180  itemBoxSizer11->Add(itemButton2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
181 
182 }
183 
184 
185 /*!
186  * Should we show tooltips?
187  */
188 
190 {
191  return true;
192 }
193 
194 /*!
195  * Get bitmap resources
196  */
197 
198 wxBitmap CExportTableDlg::GetBitmapResource( const wxString& name )
199 {
200  // Bitmap retrieval
201  wxUnusedVar(name);
202  return wxNullBitmap;
203 }
204 
205 /*!
206  * Get icon resources
207  */
208 
209 wxIcon CExportTableDlg::GetIconResource( const wxString& name )
210 {
211  // Icon retrieval
212  wxUnusedVar(name);
213  return wxNullIcon;
214 }
215 
217 {
218  FOR_EACH_ORGMOD_ON_BIOSOURCE(orgmod,biosource)
219  {
220  try {
221  string qual_name = objects::COrgMod::GetSubtypeName ((*orgmod)->GetSubtype());
222  if (!NStr::IsBlank(qual_name) && !objects::COrgMod::IsDiscouraged((*orgmod)->GetSubtype(), true)) {
223  // special case for nat-host
224  if (NStr::EqualNocase(qual_name, kNatHost)) {
226  } else if (NStr::EqualNocase(qual_name, "note")) {
228  } else {
229  m_source_choices.insert(qual_name);
230  if ( (*orgmod)->GetSubtype() == COrgMod::eSubtype_bio_material ||
231  (*orgmod)->GetSubtype() == COrgMod::eSubtype_culture_collection ||
232  (*orgmod)->GetSubtype() == COrgMod::eSubtype_specimen_voucher) {
233  m_source_choices.insert(qual_name + "-coll");
234  m_source_choices.insert(qual_name + "-inst");
235  m_source_choices.insert(qual_name + "-specid");
236  }
237  }
238  }
239 
240  } catch(const CException&) {} catch (const exception&) {}
241  }
242 
243  FOR_EACH_SUBSOURCE_ON_BIOSOURCE(subsource,biosource)
244  {
245  try {
246  string qual_name = objects::CSubSource::GetSubtypeName ((*subsource)->GetSubtype());
247  if (!NStr::IsBlank(qual_name) && !objects::CSubSource::IsDiscouraged((*subsource)->GetSubtype())) {
248  if (NStr::EqualNocase(qual_name, "note")) {
250  } else {
251  m_source_choices.insert(qual_name);
252  }
253  }
254 
255  } catch(const CException&) {} catch (const exception&) {}
256  }
257 
258  if (biosource.IsSetTaxname() && !biosource.GetTaxname().empty())
259  m_source_choices.insert("taxname");
260 }
261 
263 {
264 
266  if ((*it)->IsSource()) {
267  AddBioSource ((*it)->GetSource());
268  }
269  }
270 
271  if (se.IsSet()) {
273  GetDesc (**it);
274  }
275  }
276 }
277 
278 
279 void CExportTableDlg::FindBioSource(objects::CSeq_entry_Handle tse)
280 {
281  GetDesc (*(tse.GetCompleteSeq_entry()));
283  while (feat) {
284  AddBioSource (feat->GetData().GetBiosrc());
285  ++feat;
286  }
287 }
288 
289 void CExportTableDlg::SaveTable(const wxString& workDir)
290 {
291  m_SaveFileDir = workDir;
292  list< map<string, string> > table;
294  if (m_CdsGeneProtRB->GetValue())
295  {
297  }
298  if (m_DeflineRB->GetValue())
299  {
301  }
302  if (m_FeatureRB->GetValue())
303  {
305  }
306  if (m_PubRB->GetValue())
307  {
309  }
310  if (m_DbLinkRB->GetValue())
311  {
313  }
314  if (m_RnaRB->GetValue())
315  {
317  }
318  if (m_SourceCheck->GetValue())
319  {
321  }
323  wxFileName fname;
324  fname.Assign(m_SaveFileDir, m_SaveFileName);
325 
326  if (m_ExcelCheck && m_ExcelCheck->GetValue())
327  {
328  RunExcel(fname.GetFullPath());
329  }
330 }
331 
333 {
334  vector<pair<string, CIRef<IEditingAction> > > cds_gene_mrna_actions;
335  IEditingActionFeat* cds_gene_mrna_feat_action(NULL);
336 
337  vector<string> cds_gene_mrna_fields;
338  cds_gene_mrna_fields.push_back("protein name");
339  cds_gene_mrna_fields.push_back("protein description");
340  cds_gene_mrna_fields.push_back("CDS comment");
341  cds_gene_mrna_fields.push_back("gene locus");
342  cds_gene_mrna_fields.push_back("gene description");
343  cds_gene_mrna_fields.push_back("gene comment");
344  cds_gene_mrna_fields.push_back("gene allele");
345  cds_gene_mrna_fields.push_back("gene maploc");
346  cds_gene_mrna_fields.push_back("gene locus tag");
347  cds_gene_mrna_fields.push_back("gene synonym");
348  cds_gene_mrna_fields.push_back("mRNA product");
349  cds_gene_mrna_fields.push_back("mRNA comment");
350  cds_gene_mrna_fields.push_back("protein name");
351  cds_gene_mrna_fields.push_back("protein description");
352  cds_gene_mrna_fields.push_back("protein EC number");
353  cds_gene_mrna_fields.push_back("protein activity");
354  cds_gene_mrna_fields.push_back("protein comment");
355  cds_gene_mrna_fields.push_back("codon-start");
356 
357  for (auto field : cds_gene_mrna_fields)
358  {
359  int subtype = -1;
360  if (field == "protein name" || field == "protein description" || field == "protein EC number"
361  || field == "protein activity" || field == "protein comment")
362  {
363  subtype = CSeqFeatData::eSubtype_prot;
364  }
365  else if (field == "CDS comment" || field == "CDS inference" || field == "codon-start")
366  {
368  }
369  else if ( field == "gene description" || field == "gene comment"
370  || field == "gene inference" || field == "gene allele" || field == "gene maploc"
371  || field == "gene locus tag" || field == "gene synonym" || field == "gene old_locus_tag"
372  || field == "gene locus")
373  {
374  subtype = CSeqFeatData::eSubtype_gene;
375  }
376  else if (field == "mRNA product" || field == "mRNA comment")
377  {
378  subtype = CSeqFeatData::eSubtype_mRNA;
379  }
380 /* else if (field == "mat_peptide name" || field == "mat_peptide description" || field == "mat_peptide EC number"
381  || field == "mat_peptide activity" || field == "mat_peptide comment")
382  {
383  subtype = CSeqFeatData::eSubtype_mat_peptide_aa;
384  }
385 */
386  cds_gene_mrna_actions.push_back(make_pair(field, CreateAction(m_TopSeqEntry, field, CFieldNamePanel::eFieldType_CDSGeneProt, subtype)));
387  if (cds_gene_mrna_actions.back().second && !cds_gene_mrna_feat_action)
388  cds_gene_mrna_feat_action = dynamic_cast<IEditingActionFeat*>(cds_gene_mrna_actions.back().second.GetPointer());
389  }
390 
391 
393  CScope &scope = m_TopSeqEntry.GetScope();
394  for( CFeat_CI feat (m_TopSeqEntry); feat; ++feat)
395  {
396  CSeq_feat_Handle fh = feat->GetSeq_feat_Handle();
397  if (seen.find(fh) != seen.end())
398  continue;
399  seen.insert(fh);
401  if (cds_gene_mrna_feat_action)
402  {
403  CSeq_feat_Handle cds, gene, mrna, prot;
405  {
406  cds = fh;
407  gene = cds_gene_mrna_feat_action->x_FindGeneForFeature(fh.GetLocation(), scope, CSeqFeatData::eSubtype_gene);
408  mrna = cds_gene_mrna_feat_action->x_FindGeneForFeature(fh.GetLocation(), scope, CSeqFeatData::eSubtype_mRNA);
409  }
411  {
412  gene = fh;
413  cds = cds_gene_mrna_feat_action->x_FindGeneForFeature(fh.GetLocation(), scope, CSeqFeatData::eSubtype_cdregion);
414  mrna = cds_gene_mrna_feat_action->x_FindGeneForFeature(fh.GetLocation(), scope, CSeqFeatData::eSubtype_mRNA);
415  }
417  {
418  mrna = fh;
419  gene = cds_gene_mrna_feat_action->x_FindGeneForFeature(fh.GetLocation(), scope, CSeqFeatData::eSubtype_gene);
420  cds = cds_gene_mrna_feat_action->x_FindGeneForFeature(fh.GetLocation(), scope, CSeqFeatData::eSubtype_cdregion);
421  }
422  if (cds && cds.IsSetProduct())
423  {
424  const CSeq_loc& prot_loc = cds.GetProduct();
425  CBioseq_Handle prot_bsh = scope.GetBioseqHandle(prot_loc);
426  if (prot_bsh)
427  {
428  CFeat_CI prot_feat_ci(prot_bsh, SAnnotSelector(CSeqFeatData::eSubtype_prot));
429  if( prot_feat_ci)
430  {
431  prot = prot_feat_ci->GetSeq_feat_Handle();
432  }
433  }
434  }
435  seen.insert(cds);
436  seen.insert(gene);
437  seen.insert(mrna);
438  seen.insert(prot);
439  for (auto field_action : cds_gene_mrna_actions)
440  {
441  string field = field_action.first;
442  string value;
443  IEditingActionFeat* feat_action = dynamic_cast<IEditingActionFeat*>(field_action.second.GetPointer());
444  if (feat_action)
445  {
446  bool is_feat_set(false);
447  if (feat_action->GetActionFeatSubtype() == CSeqFeatData::eSubtype_cdregion && cds)
448  {
449  feat_action->SetFeat(cds);
450  is_feat_set = true;
451  }
452  if (feat_action->GetActionFeatSubtype() == CSeqFeatData::eSubtype_gene && gene)
453  {
454  feat_action->SetFeat(gene);
455  is_feat_set = true;
456  }
457  if (feat_action->GetActionFeatSubtype() == CSeqFeatData::eSubtype_mRNA && mrna)
458  {
459  feat_action->SetFeat(mrna);
460  is_feat_set = true;
461  }
462  if (feat_action->GetActionFeatSubtype() == CSeqFeatData::eSubtype_prot && prot)
463  {
464  feat_action->SetFeat(prot);
465  is_feat_set = true;
466  }
467 
468  if (is_feat_set)
469  {
470  const vector<string>& values = feat_action->GetValues();
471  if (!values.empty())
472  value = values.front();
473  }
474  }
475  if (!value.empty())
476  {
477  row[field] = value;
478  columns.insert(field);
479  }
480  }
481  }
482 
483  if (!row.empty())
484  {
485  string seqid;
486  for (CSeq_loc_CI subloc(fh.GetLocation(), objects::CSeq_loc_CI::eEmpty_Skip); subloc; ++subloc)
487  {
488  CBioseq_Handle bsh = scope.GetBioseqHandle(subloc.GetSeq_id());
489  if (!bsh)
490  continue;
492  if (!seqid.empty())
493  break;
494  }
495  row["Seq-ID"] = seqid;
496  table.push_back(row);
497  }
498  }
499 }
500 
502 {
503  vector<pair<string, CIRef<IEditingAction> > > actions;
504  IEditingActionFeat* rna_feat_action(NULL);
505  vector<string> fields;
506 
507  fields.push_back("product");
508  fields.push_back("comment");
509  fields.push_back("ncRNA class"); // ncRNA
510  fields.push_back("gene locus");
511  fields.push_back("gene description");
512  fields.push_back("gene maploc");
513  fields.push_back("gene locus tag");
514  fields.push_back("gene synonym");
515  fields.push_back("gene comment");
516  fields.push_back("codons recognized"); // tRNA
517  fields.push_back("anticodon"); // tRNA
518  fields.push_back("tag_peptide"); // tmRNA
519 
520 
521 
522  for (auto field : fields)
523  {
524  int subtype = -1;
525  if ( field == "gene description" || field == "gene comment" || field == "gene maploc"
526  || field == "gene locus tag" || field == "gene synonym" || field == "gene locus")
527  {
528  subtype = CSeqFeatData::eSubtype_gene;
529  }
530  else if (field == "ncRNA class")
531  {
533  }
534  else if (field == "codons recognized" || field == "anticodon")
535  {
536  subtype = CSeqFeatData::eSubtype_tRNA;
537  }
538  else if (field == "tag_peptide")
539  {
541  }
542 
543  actions.push_back(make_pair(field, CreateAction(m_TopSeqEntry, field, CFieldNamePanel::eFieldType_RNA, subtype)));
544  if (actions.back().second && !rna_feat_action)
545  rna_feat_action = dynamic_cast<IEditingActionFeat*>(actions.back().second.GetPointer());
546  }
547 
548  CScope &scope = m_TopSeqEntry.GetScope();
549  for( CFeat_CI feat (m_TopSeqEntry, CSeqFeatData::e_Rna); feat; ++feat)
550  {
551  CSeq_feat_Handle rna = feat->GetSeq_feat_Handle();
553  if (rna_feat_action)
554  {
555  CSeq_feat_Handle gene = rna_feat_action->x_FindGeneForFeature(rna.GetLocation(), scope, CSeqFeatData::eSubtype_gene);
556 
557  for (auto field_action : actions)
558  {
559  string field = field_action.first;
560  string value;
561  IEditingActionFeat* feat_action = dynamic_cast<IEditingActionFeat*>(field_action.second.GetPointer());
562  if (feat_action)
563  {
564  bool is_feat_set(false);
565  if (feat_action->GetActionFeatSubtype() == CSeqFeatData::eSubtype_gene && gene)
566  {
567  feat_action->SetFeat(gene);
568  is_feat_set = true;
569  }
570  else if (feat_action->GetActionFeatSubtype() == rna.GetFeatSubtype())
571  {
572  feat_action->SetFeat(rna);
573  is_feat_set = true;
574  }
575  else if (feat_action->GetActionFeatSubtype() == CSeqFeatData::eSubtype_any)
576  {
577  feat_action->SetFeat(rna);
578  is_feat_set = true;
579  }
580 
581  if (is_feat_set)
582  {
583  const vector<string>& values = feat_action->GetValues();
584  if (!values.empty())
585  value = values.front();
586  }
587  }
588  if (!value.empty())
589  {
590  row[field] = value;
591  columns.insert(field);
592  }
593  }
594  }
595 
596  if (!row.empty())
597  {
598  string seqid;
599  for (CSeq_loc_CI subloc(rna.GetLocation(), objects::CSeq_loc_CI::eEmpty_Skip); subloc; ++subloc)
600  {
601  CBioseq_Handle bsh = scope.GetBioseqHandle(subloc.GetSeq_id());
602  if (!bsh)
603  continue;
605  if (!seqid.empty())
606  break;
607  }
608  row["Seq-ID"] = seqid;
609  table.push_back(row);
610  }
611  }
612 }
613 
614 
616 {
617  auto table_it = table.begin();
618  vector<string> fields;
619  wxArrayInt selections;
620  int num = m_SourceChoice->GetSelections (selections);
621  for (size_t j = 0; j < num; j++)
622  {
623  int i = selections[j];
624  string sel = m_SourceChoice->GetString(i).ToStdString();
625  if (sel == "All")
626  {
627  fields.clear();
629  fields.push_back(*s);
630  break;
631  }
632  else
633  fields.push_back(sel);
634  }
635  vector<pair<string, CIRef<IEditingAction> > > actions;
636  for (auto &field : fields)
637  {
638  actions.push_back(make_pair(field, CreateAction(m_TopSeqEntry, field, CFieldNamePanel::eFieldType_Source, -1)));
639  }
640  for (CBioseq_CI b_iter(m_TopSeqEntry, objects::CSeq_inst::eMol_na); b_iter; ++b_iter)
641  {
642  CBioseq_Handle bsh = *b_iter;
644  for (CSeqdesc_CI desc_ci( bsh, CSeqdesc::e_Source); desc_ci; ++desc_ci)
645  {
646  const CSeqdesc* desc = &*desc_ci;
647  for (auto field_action : actions)
648  {
649  string field = field_action.first;
650  string value;
651  IEditingActionBiosource* action = dynamic_cast<IEditingActionBiosource*>(field_action.second.GetPointer());
652  if (action)
653  {
654  action->SetDesc(desc);
655  const vector<string>& values = action->GetValues();
656  if (!values.empty())
657  value = values.front();
658  }
659  if (!value.empty())
660  {
661  row[field] = value;
662  columns.insert(field);
663  }
664  }
665  }
666 
667  for (CFeat_CI feat_ci(bsh, CSeqFeatData::e_Biosrc); feat_ci; ++feat_ci)
668  {
669  CSeq_feat_Handle fh = feat_ci->GetSeq_feat_Handle();
670  for (auto field_action : actions)
671  {
672  string field = field_action.first;
673  string value;
674  IEditingActionBiosource* action = dynamic_cast<IEditingActionBiosource*>(field_action.second.GetPointer());
675  if (action)
676  {
677  action->SetFeat(fh);
678  const vector<string>& values = action->GetValues();
679  if (!values.empty())
680  value = values.front();
681  }
682  if (!value.empty())
683  {
684  row[field] = value;
685  columns.insert(field);
686  }
687  }
688  }
689 
690 
691  string seqid;
693  bool found(false);
694  while (table_it != table.end() && (*table_it)["Seq-ID"] == seqid)
695  {
696  found = true;
697  if (!row.empty())
698  table_it->insert(row.begin(), row.end());
699  ++table_it;
700  }
701  if (!found && !row.empty())
702  {
703  row["Seq-ID"] = seqid;
704  table_it = table.insert(table_it, row);
705  ++table_it;
706  }
707  }
708 }
709 
710 
712 {
713  size_t num_rows = values_table->GetNum_rows();
714  CSeq_table::TColumns::iterator col = values_table->SetColumns().begin();
715  while (col != values_table->SetColumns().end())
716  {
717  bool do_remove = false;
718  if ((*col)->IsSetData())
719  {
720  if ((*col)->GetData().IsString())
721  {
722  bool empty_col = true;
723  for (size_t row = 0; row < (*col)->GetData().GetString().size() && empty_col; row++)
724  {
725  empty_col = empty_col && (*col)->GetData().GetString()[row].empty();
726  }
727  if (empty_col)
728  {
729  do_remove = true;
730  }
731  }
732  }
733  if (do_remove)
734  {
735  col = values_table->SetColumns().erase(col);
736  }
737  else
738  {
739  ++col;
740  }
741  }
742 
743  vector<size_t> erase_rows;
744  for (size_t row = 0; row < num_rows; row++)
745  {
746  bool empty_row = true;
747  for (CSeq_table::TColumns::iterator col = values_table->SetColumns().begin(); col != values_table->SetColumns().end(); ++col)
748  if ((*col)->IsSetData() && (*col)->GetData().IsString() && row < (*col)->GetData().GetString().size())
749  empty_row = empty_row && (*col)->GetData().GetString()[row].empty();
750  if (empty_row)
751  {
752  erase_rows.push_back(row);
753  }
754 
755  }
756  for (long i = erase_rows.size()-1; i >= 0; i--)
757  {
758  for (CSeq_table::TColumns::iterator col = values_table->SetColumns().begin(); col != values_table->SetColumns().end(); ++col)
759  if ((*col)->IsSetData() && (*col)->GetData().IsString() && erase_rows[i] < (*col)->GetData().GetString().size())
760  {
761  (*col)->SetData().SetString().erase((*col)->SetData().SetString().begin()+erase_rows[i]);
762  }
763  else if ((*col)->IsSetData() && (*col)->GetData().IsId() && erase_rows[i] < (*col)->GetData().GetId().size())
764  {
765  (*col)->SetData().SetId().erase((*col)->SetData().SetId().begin()+erase_rows[i]);
766  }
767  }
768  values_table->SetNum_rows(static_cast<CSeq_table::TNum_rows>(num_rows-erase_rows.size()));
769 }
770 
771 
773 {
774  string field("Definition Line");
775 
776  for (CBioseq_CI b_iter(m_TopSeqEntry, objects::CSeq_inst::eMol_na); b_iter; ++b_iter)
777  {
778  CBioseq_Handle bsh = *b_iter;
779 
781  CSeqdesc_CI title(bsh, CSeqdesc::e_Title, 1);
782  string value;
783  if ( title )
784  {
785  value = title->GetTitle();
786  }
787 
788  row[field] = value;
789  if (!value.empty())
790  {
791  columns.insert(field);
792  string seqid;
794  row["Seq-ID"] = seqid;
795  table.push_back(row);
796  }
797  }
798 }
799 
801 {
802  CScope &scope = m_TopSeqEntry.GetScope();
803  for( CFeat_CI feat (m_TopSeqEntry); feat; ++feat)
804  {
806  string feat_name = CSeqFeatData::SubtypeValueToName(feat->GetOriginalFeature().GetData().GetSubtype());
807  FOR_EACH_GBQUAL_ON_SEQFEAT(qual,feat->GetOriginalFeature())
808  {
809  if ((*qual)->IsSetQual() && (*qual)->IsSetVal() && !(*qual)->GetQual().empty() && !(*qual)->GetVal().empty())
810  {
811  string field = feat_name + " " + (*qual)->GetQual();
812  string value = (*qual)->GetVal();
813  row[field] = value;
814  columns.insert(field);
815  }
816  }
817  if (!row.empty())
818  {
819  string seqid;
820  for (CSeq_loc_CI subloc(feat->GetLocation(), objects::CSeq_loc_CI::eEmpty_Skip); subloc; ++subloc)
821  {
822  CBioseq_Handle bsh = scope.GetBioseqHandle(subloc.GetSeq_id());
823  if (!bsh)
824  continue;
826  if (!seqid.empty())
827  break;
828  }
829  row["Seq-ID"] = seqid;
830  table.push_back(row);
831  }
832  }
833 }
834 
836 {
837  vector<pair<string, CIRef<IEditingAction> > > actions;
838  vector<string> pubs = CPubFieldType::GetFieldNames();
839  for (auto &field : pubs)
840  {
841  actions.push_back(make_pair("publication " + field, CreateAction(m_TopSeqEntry, field, CFieldNamePanel::eFieldType_Pub, -1)));
842  }
843  for (CBioseq_CI b_iter(m_TopSeqEntry, objects::CSeq_inst::eMol_na); b_iter; ++b_iter)
844  {
845  CBioseq_Handle bsh = *b_iter;
846  for (CSeqdesc_CI desc_ci( bsh, CSeqdesc::e_Pub); desc_ci; ++desc_ci)
847  {
849  const CSeqdesc* desc = &*desc_ci;
850  for (auto field_action : actions)
851  {
852  string field = field_action.first;
853  string value;
854  IEditingActionDesc* action = dynamic_cast<IEditingActionDesc*>(field_action.second.GetPointer());
855  if (action)
856  {
857  action->SetDesc(desc);
858  const vector<string>& values = action->GetValues();
859  if (!values.empty())
860  value = values.front();
861  }
862  if (!value.empty())
863  {
864  row[field] = value;
865  columns.insert(field);
866  }
867  }
868 
869  if (!row.empty())
870  {
871  string seqid;
873  row["Seq-ID"] = seqid;
874  table.push_back(row);
875  }
876  }
877  }
878 }
879 
881 {
882  vector<string> dbs = CDBLinkFieldType::GetFieldNames();
883  vector<pair<string, CIRef<IEditingAction> > > actions;
884  for (auto &field : dbs)
885  {
886  actions.push_back(make_pair("DBLink " + field, CreateAction(m_TopSeqEntry, field, CFieldNamePanel::eFieldType_DBLink, -1)));
887  }
888  for (CBioseq_CI b_iter(m_TopSeqEntry, objects::CSeq_inst::eMol_na); b_iter; ++b_iter)
889  {
890  CBioseq_Handle bsh = *b_iter;
891  for (CSeqdesc_CI desc_ci( bsh, CSeqdesc::e_User); desc_ci; ++desc_ci)
892  {
893  if (desc_ci->GetUser().IsSetType() && desc_ci->GetUser().GetType().IsStr()
894  && NStr::EqualNocase(desc_ci->GetUser().GetType().GetStr(), "DBLink") )
895  {
897  const CSeqdesc* desc = &*desc_ci;
898  for (auto field_action : actions)
899  {
900  string field = field_action.first;
901  string value;
902  IEditingActionDesc* action = dynamic_cast<IEditingActionDesc*>(field_action.second.GetPointer());
903  if (action)
904  {
905  action->SetDesc(desc);
906  const vector<string>& values = action->GetValues();
907  if (!values.empty())
908  value = values.front();
909  }
910  if (!value.empty())
911  {
912  row[field] = value;
913  columns.insert(field);
914  }
915  }
916 
917  if (!row.empty())
918  {
919  string seqid;
921  row["Seq-ID"] = seqid;
922  table.push_back(row);
923  }
924  }
925  }
926  }
927 }
928 
929 void CExportTableDlg::SaveTableFile (wxWindow *parent, wxString& save_file_dir, wxString& save_file_name, const list< map<string, string> > &table, const set<string> &columns)
930 
931 {
932  if (columns.empty() || table.empty())
933  {
934  wxMessageBox(wxT("Empty table"), wxT("Error"),
935  wxOK | wxICON_ERROR, parent);
936  return;
937  }
938  wxFileDialog table_save_file(parent, wxT("Select a file"), save_file_dir, save_file_name,
939  _("TAB files(*.tab) | *.tab | All files(*.*) | *.*"),
940  wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
941 
942  if (table_save_file.ShowModal() == wxID_OK)
943  {
944  wxString path = table_save_file.GetPath();
945  wxString name = table_save_file.GetFilename();
946 
947  name.Trim(false);
948  name.Trim(true);
949 
950  if (name.IsEmpty())
951  {
952  wxMessageBox(wxT("Please, select file name"), wxT("Error"),
953  wxOK | wxICON_ERROR, parent);
954  return;
955  }
956  ios::openmode mode = ios::out;
957 
958  CNcbiOfstream os(path.fn_str(), mode);
959  if (!os)
960  {
961  wxMessageBox(wxT("Cannot open file ")+name, wxT("Error"),
962  wxOK | wxICON_ERROR, parent);
963  return;
964  }
965 
966  CCSVExporter exporter(os, '\t', '"');
967  exporter.Field(string("Seq-ID"));
968  for (auto col : columns)
969  exporter.Field(col);
970  exporter.NewRow();
971  for (auto row : table)
972  {
973  string seqid = row["Seq-ID"];
974  row.erase("Seq-ID");
975  exporter.Field(seqid);
976  for (auto col : columns)
977  {
978  exporter.Field(row[col]);
979  }
980  exporter.NewRow();
981  }
982 
983  save_file_dir = table_save_file.GetDirectory();
984  save_file_name = table_save_file.GetFilename();
985  }
986 }
987 
988 void CExportTableDlg::RunExcel(wxString FileName)
989 {
990 #ifdef NCBI_OS_MSWIN
991  wxAutomationObject ExcelObject;
992  if (ExcelObject.GetInstance(wxT("Excel.Application")))
993  {
994  ExcelObject.CallMethod("Workbooks.Open", FileName);
995  ExcelObject.PutProperty("Visible", true);
996  }
997 #endif
998 }
999 
static string GetSubtypeName(const CSubSource &qual)
const string & GetTaxname(void) const
Definition: BioSource.cpp:340
bool IsSetTaxname(void) const
Definition: BioSource.cpp:335
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_Handle –.
void Field(const string &value)
static vector< string > GetFieldNames()
void CreateControls()
Creates the controls and sizers.
wxString m_SaveFileName
void SaveTableFile(wxWindow *parent, wxString &save_file_dir, wxString &save_file_name, const list< map< string, string > > &table, const set< string > &columns)
set< string > m_source_choices
void Init()
Initialises member variables.
wxRadioButton * m_PubRB
bool Create(wxWindow *parent, wxWindowID id=ID_EXPORT_TABLE_DLG, const wxString &caption=_("Export Table"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
wxListBox * m_SourceChoice
void AddRnaToTable(list< map< string, string > > &table, set< string > &columns)
wxRadioButton * m_NoneRB
static bool ShowToolTips()
Should we show tooltips?
wxRadioButton * m_CdsGeneProtRB
void GetDesc(const CSeq_entry &se)
void AddSourceToTable(list< map< string, string > > &table, set< string > &columns)
void FindBioSource(objects::CSeq_entry_Handle tse)
wxRadioButton * m_FeatureRB
objects::CSeq_entry_Handle m_TopSeqEntry
wxString m_SaveFileDir
wxRadioButton * m_RnaRB
CExportTableDlg()
Constructors.
void AddFeaturesToTable(list< map< string, string > > &table, set< string > &columns)
void AddDeflinesToTable(list< map< string, string > > &table, set< string > &columns)
void RunExcel(wxString FileName)
wxCheckBox * m_SourceCheck
void AddPubsToTable(list< map< string, string > > &table, set< string > &columns)
void AddBioSource(const CBioSource &biosource)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void SaveTable(const wxString &workDir=wxEmptyString)
wxRadioButton * m_DbLinkRB
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxCheckBox * m_ExcelCheck
~CExportTableDlg()
Destructor.
wxRadioButton * m_DeflineRB
void AddDblinkToTable(list< map< string, string > > &table, set< string > &columns)
static void RemoveEmptyColsAndRows(CRef< CSeq_table > values_table)
void AddCdsGeneMrnaTable(list< map< string, string > > &table, set< string > &columns)
CFeat_CI –.
Definition: feat_ci.hpp:64
static vector< string > GetFieldNames(bool extended=false)
CScope –.
Definition: scope.hpp:92
static CTempString SubtypeValueToName(ESubtype eSubtype)
Turns a ESubtype into its string value which is NOT necessarily related to the identifier of the enum...
Definition: Seq_entry.hpp:56
CSeq_feat_Handle –.
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
void SetFeat(CSeq_feat_Handle fh)
void SetDesc(const CSeqdesc *desc)
void SetDesc(const CSeqdesc *desc)
CSeq_feat_Handle x_FindGeneForFeature(const CSeq_loc &loc, CScope &scope, CSeqFeatData::ESubtype subtype)
virtual void SetFeat(CSeq_feat_Handle fh)
CSeqFeatData::ESubtype GetActionFeatSubtype()
const vector< string > & GetValues(void)
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
#define _(proto)
Definition: ct_nlmzip_i.h:78
CIRef< IEditingAction > CreateAction(CSeq_entry_Handle seh, const string &field, CFieldNamePanel::EFieldType field_type, int subtype, const string &ncRNA_class=kEmptyStr, CConstRef< objects::CSeq_submit > submit=CConstRef< objects::CSeq_submit >(NULL))
std::ofstream out("events_result.xml")
main entry point for tests
const char * kOrgModNote
const char * kSubSourceNote
const char * kNatHost
const char * kHost
static void Init(void)
Definition: cursor6.c:76
static const column_t columns[]
Definition: utf8_2.c:22
#define NULL
Definition: ncbistd.hpp:225
void GetLabel(string *label, ELabelType type=eDefault, TLabelFlags flags=fLabel_Default) const
Append a label for this Seq-id to the supplied string.
Definition: Seq_id.cpp:2040
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:605
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
@ eGetId_Best
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function
Definition: sequence.hpp:101
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
const CSeqFeatData & GetData(void) const
virtual const CSeq_loc & GetProduct(void) const
bool IsSetProduct(void) const
virtual const CSeq_loc & GetLocation(void) const
CSeqFeatData::ESubtype GetFeatSubtype(void) const
const CSeq_feat_Handle & GetSeq_feat_Handle(void) const
Get original feature handle.
Definition: mapped_feat.hpp:71
#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::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
@ eSubtype_specimen_voucher
Definition: OrgMod_.hpp:106
@ eSubtype_bio_material
Definition: OrgMod_.hpp:119
@ eSubtype_culture_collection
Definition: OrgMod_.hpp:118
void SetNum_rows(TNum_rows value)
Assign a value to Num_rows data member.
Definition: Seq_table_.hpp:402
TNum_rows GetNum_rows(void) const
Get the Num_rows member data.
Definition: Seq_table_.hpp:393
TColumns & SetColumns(void)
Assign a value to Columns data member.
Definition: Seq_table_.hpp:439
const TBiosrc & GetBiosrc(void) const
Get the variant data.
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
const TTitle & GetTitle(void) const
Get the variant data.
Definition: Seqdesc_.hpp:1032
@ e_User
user defined object
Definition: Seqdesc_.hpp:124
@ e_Pub
a reference to the publication
Definition: Seqdesc_.hpp:122
@ e_Title
a title for this sequence
Definition: Seqdesc_.hpp:115
@ e_Source
source of materials, includes Org-ref
Definition: Seqdesc_.hpp:133
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
END_EVENT_TABLE()
int i
#define wxT(x)
Definition: muParser.cpp:41
mdb_mode_t mode
Definition: lmdb++.h:38
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Utility macros and typedefs for exploring NCBI objects from seqfeat.asn.
#define FOR_EACH_ORGMOD_ON_BIOSOURCE(Itr, Var)
FOR_EACH_ORGMOD_ON_BIOSOURCE EDIT_EACH_ORGMOD_ON_BIOSOURCE.
#define FOR_EACH_GBQUAL_ON_SEQFEAT(Itr, Var)
FOR_EACH_GBQUAL_ON_SEQFEAT EDIT_EACH_GBQUAL_ON_SEQFEAT.
#define FOR_EACH_SUBSOURCE_ON_BIOSOURCE(Itr, Var)
FOR_EACH_SUBSOURCE_ON_BIOSOURCE EDIT_EACH_SUBSOURCE_ON_BIOSOURCE.
static static static wxID_ANY
Utility macros and typedefs for exploring NCBI objects from seqset.asn.
#define FOR_EACH_SEQENTRY_ON_SEQSET(Itr, Var)
FOR_EACH_SEQENTRY_ON_SEQSET EDIT_EACH_SEQENTRY_ON_SEQSET.
#define FOR_EACH_SEQDESC_ON_SEQENTRY(Itr, Var)
FOR_EACH_SEQDESC_ON_SEQENTRY EDIT_EACH_SEQDESC_ON_SEQENTRY.
#define row(bind, expected)
Definition: string_bind.c:73
SAnnotSelector –.
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Thu Apr 25 08:17:43 2024 by modify_doxy.py rev. 669887