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

Go to the SVN repository for this file.

1 /* $Id: gbproject_tool.cpp 34680 2016-02-01 22:06:08Z katargir $
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: Mike DiCuccio
27  *
28  * File Description:
29  * Application for manipulating GBench projects.
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbifile.hpp>
34 #include <corelib/ncbiapp.hpp>
35 #include <corelib/ncbienv.hpp>
36 #include <corelib/ncbiargs.hpp>
37 #include <serial/objistr.hpp>
38 #include <serial/objostr.hpp>
39 #include <serial/serial.hpp>
51 #include <gui/objutils/label.hpp>
52 #include <objects/general/Date.hpp>
53 #include <objmgr/scope.hpp>
56 
57 #include "fileloader.hpp"
58 #include "projectfilewriter.hpp"
59 
62 
64 auto_ptr<CProjectFileWriter> Writer;
65 
67 {
68 private:
69  void Init();
70  int Run();
71 
74  CNcbiIstream& istr);
75 
76  void x_LoadGffData(CProjectItem& item,
77  CNcbiIstream& istr);
78 
79 
80  void x_AddItem(CGBProjectHandle& project,
81  CNcbiIstream& istr,
82  const string& fmt_str,
83  const string& in_folder);
84 };
85 
86 
88 {
91 
92  auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions());
93  arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
94  "Application for manipulating GBench projects");
95 
96  arg_desc->AddDefaultKey("i", "InputFile",
97  "Input project file",
99  "-");
100 
101  arg_desc->AddDefaultKey("o", "OutputFile",
102  "Output project file",
104  "-");
105 
106  arg_desc->AddFlag("noid", "disable access to genbank or id and id2");
107  arg_desc->AddFlag("list", "List the contents of a project file");
108  arg_desc->AddFlag("create", "Create a new project file");
109 
110  arg_desc->AddOptionalKey("expand", "expand",
111  "Create a subdirectory tree from a project file",
113  arg_desc->AddDefaultKey("expand-fmt", "expand_format",
114  "Format to expand project file parts out in",
115  CArgDescriptions::eString, "asnb");
116  arg_desc->SetConstraint("expand-fmt", &((*new CArgAllow_Strings(NStr::eNocase)), "asnt", "asnb", "xml", "gtf"));
117 
118 
119  arg_desc->AddOptionalKey("collapse", "collapse",
120  "Create a project file from a directory tree",
122 
123 
124  arg_desc->AddOptionalKey("title", "Title",
125  "Title for new project",
127 
128  arg_desc->AddOptionalKey("add", "ItemToAdd",
129  "Add an item to a project file",
131  arg_desc->AddOptionalKey("fmt", "ItemFormat",
132  "Format of input item",
134  arg_desc->SetConstraint("fmt",
135  &(*new CArgAllow_Strings,
136  "gff", "asn", "asnb", "agp"));
137  arg_desc->AddOptionalKey("proj-folder", "FolderName",
138  "Add item into the named folder",
140  arg_desc->SetDependency("add", CArgDescriptions::eRequires, "fmt");
141 
142  arg_desc->AddOptionalKey("add-folder", "FolderToAdd",
143  "Create a folder in the existing project",
145 
146  arg_desc->AddOptionalKey("rm", "RemoveItem",
147  "Remove an item from an existing project",
149  arg_desc->AddOptionalKey("rmdir", "RemoveFolder",
150  "Remove a folder from an existing project",
152 
153  SetupArgDescriptions(arg_desc.release());
154 }
155 
156 
157 static void s_ListProjectFolder(const CProjectFolder& folder,
158  CNcbiOstream& ostr,
159  int level = 0)
160 {
161  const string kSpacer(level * 2, ' ');
162 
163  ostr << kSpacer << "[folder] " << folder.GetInfo().GetTitle()
164  << " (created: "
165  << folder.GetInfo().GetCreate_date().AsCTime().AsString("M/D/Y h:m:s")
166  << ")" << endl;
167 
168  if (folder.IsSetFolders()) {
169  ITERATE (CProjectFolder::TFolders, iter, folder.GetFolders()) {
170  s_ListProjectFolder(**iter, ostr, level + 1);
171  }
172  }
173 
174  if (folder.IsSetItems()) {
175  ITERATE (CProjectFolder::TItems, iter, folder.GetItems()) {
176  string s;
177  CLabel::GetLabel(**iter, &s);
178  ostr << kSpacer << " " << "[item:"
179  << (*iter)->GetId() << "] " << s << endl;
180  }
181  }
182 }
183 
184 
185 
187  const CProjectFolder& folder)
188 {
189  if (folder.IsSetFolders()) {
190  ITERATE (CProjectFolder::TFolders, iter, folder.GetFolders()) {
191  s_ScopeProjectFolder(Scope, **iter);
192  }
193  }
194 
195  if (folder.IsSetItems()) {
196  ITERATE (CProjectFolder::TItems, iter, folder.GetItems()) {
197  Writer->AddToScope(CConstRef<CSerialObject>(((*iter)->GetObject())));
198  }
199  }
200 }
201 
202 
204  const CProjectFolder& folder,
205  CDir& parentDir,
206  EFormat format,
207  int level = 0)
208 {
209  const string kSpacer(level * 2, ' ');
210 
211  string currentName = CDirEntry::ConcatPathEx(parentDir.GetPath(),
212  folder.GetInfo().GetTitle());
213  CDir currentDir(currentName);
214  if(level == 0) // get rid of the /Data/ dir thats always on the top when expanding
215  currentDir = parentDir;
216  currentDir.CreatePath();
217  cout << kSpacer << "[folder] " << folder.GetInfo().GetTitle()
218  << " (created: "
219  << folder.GetInfo().GetCreate_date().AsCTime().AsString("M/D/Y h:m:s")
220  << ")" << " " << currentName << endl;
221 
222  if (folder.IsSetFolders()) {
223  ITERATE (CProjectFolder::TFolders, iter, folder.GetFolders()) {
224  s_ExpandProjectFolder(scope, **iter, currentDir, format, level + 1);
225  }
226  }
227 
228  if (folder.IsSetItems()) {
229  ITERATE (CProjectFolder::TItems, iter, folder.GetItems()) {
230  string itemTitle;
231  CLabel::GetLabel(**iter, &itemTitle);
232  string itemFilename = CDirEntry::ConcatPathEx(currentDir.GetPath(), itemTitle);
233  cout << kSpacer << " " << "[item:"
234  << (*iter)->GetId() << "] " << itemTitle << " " << itemFilename << endl;
235 
236  Writer->WriteFile(itemFilename,
237  CConstRef<CSerialObject>(((*iter)->GetObject())),
238  format);
239  //auto_ptr<CObjectOStream> ObjS(CObjectOStream::Open(format, itemFilename));
240  //*ObjS << *((*iter)->GetObject());
241  }
242  }
243 }
244 
246 {
247  time_t mod_a, mod_b;
248  A->GetTimeT(&mod_a);
249  B->GetTimeT(&mod_b);
250  return (mod_a < mod_b);
251 }
252 
254  CGBProjectHandle& project,
255  CProjectFolder& folder,
256  CDir& dir)
257 {
258  list< AutoPtr< CDirEntry > > children =
260 
261  vector< CDirEntry* > children_vec;
262  ITERATE(list<AutoPtr<CDirEntry> >, childIter, children) {
263  CDirEntry* New = new CDirEntry(**childIter);
264  children_vec.push_back(New);
265  }
266  sort(children_vec.begin(), children_vec.end(), s_Compare_DirEntry_ModDate);
267 
268  typedef multimap<string, CRef<CProjectItem> > TItemMap;
269  TItemMap items;
270 
271  string CurrLabel;
272  NON_CONST_ITERATE(vector<CDirEntry*>, childIter, children_vec) {
273 
274  // Save the file name early, in case its actually a symbolic link.
275  CurrLabel = (*childIter)->GetName();
276 
277  // Then if its a link, dereference it
278  if( (*childIter)->IsLink() ) {
279  (*childIter)->DereferenceLink();
280  }
281 
282  if( (*childIter)->IsDir() ) {
283  CRef<CProjectFolder> childFolder(new CProjectFolder);
284  childFolder->SetInfo().SetCreateDate(CTime(CTime::eCurrent));
285  childFolder->SetInfo().SetTitle(CurrLabel);
286  cout << "Dir " << CurrLabel << endl;
287  folder.SetFolders().push_back(childFolder);
288  CDir childDir(**childIter);
289  s_CollapseProjectFolder(scope, project, *childFolder, childDir);
290  }
291  else if( (*childIter)->IsFile() ) {
292 
293  cout << "File " << CurrLabel << endl;
295  CFileLoader::LoadFile( (*childIter)->GetPath(), Objects);
296 
297  if(Objects.empty())
298  continue;
299 
300  ITERATE(CFileLoader::TSerialObjectList, ObjIter, Objects) {
301 
302  CRef<CSerialObject> Object = *ObjIter;
303  string label = CurrLabel;
304 
305  if(Object->GetThisTypeInfo() != NULL &&
306  Object->GetThisTypeInfo()->GetName() == "Seq-annot") {
307  CRef<CSeq_annot> Annot(static_cast<CSeq_annot*>(Object.GetPointer()));
308  if (Annot->CanGetDesc()) {
310  CConstRef<CAnnotdesc> title;
311  ITERATE(CSeq_annot::TDesc::Tdata, desciter, Annot->GetDesc().Get()) {
312  if((*desciter)->IsName()) {
313  name = *desciter;
314  } else if ((*desciter)->IsTitle()) {
315  title = *desciter;
316  }
317  }
318  if (title) {
319  label = title->GetTitle();
320  } else if (name) {
321  label = name->GetName();
322  }
323  }
324  else{
325  Annot->SetNameDesc(CurrLabel);
326  Annot->SetTitleDesc(CurrLabel);
327  }
328  } else if(Object->GetThisTypeInfo() != NULL &&
329  Object->GetThisTypeInfo()->GetName() == "Seq-align") {
330  CRef<CSeq_align> Align(static_cast<CSeq_align*>(Object.GetPointer()));
331  string AlignTitle;
332  CSeq_id_Handle Id1, Id2;
333  string Id1Str, Id2Str;
334  Id1 = scope->GetAccVer(CSeq_id_Handle::GetHandle(Align->GetSeq_id(0)));
335  Id2 = scope->GetAccVer(CSeq_id_Handle::GetHandle(Align->GetSeq_id(1)));
336  if(Id1.GetSeqIdOrNull().IsNull())
337  Id1Str = Align->GetSeq_id(0).GetSeqIdString(true);
338  else
339  Id1Str = Id1.GetSeqId()->GetSeqIdString(true);
340  if(Id2.GetSeqIdOrNull().IsNull())
341  Id2Str = Align->GetSeq_id(1).GetSeqIdString(true);
342  else
343  Id2Str = Id2.GetSeqId()->GetSeqIdString(true);
344  AlignTitle = Id1Str + " x " + Id2Str;
345  label = AlignTitle;
346  } else if(Object->GetThisTypeInfo() != NULL &&
347  Object->GetThisTypeInfo()->GetName() == "Project-item") {
348  CRef<CProjectItem> Item(static_cast<CProjectItem*>(Object.GetPointer()));
349  items.insert(TItemMap::value_type(Item->GetLabel(), Item));
350  continue;
351  }
352 
353  CRef<CProjectItem> childItem(new CProjectItem);
354  CTime CreateTime;
355  (*childIter)->GetTime(&CreateTime);
356  childItem->SetCreateDate(CreateTime);
357 
358  if (Object->GetThisTypeInfo() == CProjectItem::GetTypeInfo()) {
359  childItem.Reset(dynamic_cast<CProjectItem*>(Object.GetPointer()));
360  } else {
361  childItem->SetLabel(label);
362  childItem->SetObject(*Object);
363  cout << " Title: " << label << endl;
364  }
365  items.insert(TItemMap::value_type(label, childItem));
366  }
367  }
368 
369  delete *childIter;
370  *childIter = NULL;
371  }
372 
373  NON_CONST_ITERATE(TItemMap, it, items) {
374  project.AddItem(*it->second, folder);
375  }
376 
377 }
378 
379 
380 static void s_RemoveItem(CGBProjectHandle& project,
381  CProjectFolder& folder,
382  const string& label)
383 {
384  if (folder.IsSetFolders()) {
386  s_RemoveItem(project, **iter, label);
387  }
388  }
389 
390  if (folder.IsSetItems()) {
392  string s;
393  CLabel::GetLabel(**iter, &s);
394 
395  if(s == label) {
397  "FIXME: CGBProjectHandle::RemoveItem() not supported");
398  //project.RemoveItem(**iter);
399  return;
400  //iter = folder.SetItems().erase(iter);
401  }
402  }
403  }
404 }
405 
406 
407 static void s_RemoveFolder(CGBProjectHandle& project,
408  CProjectFolder& folder,
409  const string& label)
410 {
411  if (folder.IsSetFolders()) {
413  if( (*iter)->GetInfo().GetTitle() == label)
414  iter = folder.SetFolders().erase(iter);
415  else
416  s_RemoveFolder(project, **iter, label);
417  }
418  }
419 }
420 
421 
422 CRef<CProjectFolder> s_GetOrCreateFolder(CGBProjectHandle& project,
423  CProjectFolder& parent_folder,
424  const string& folder_name,
425  bool top = true)
426 {
427  if (parent_folder.IsSetFolders()) {
428  NON_CONST_ITERATE(CProjectFolder::TFolders, iter, parent_folder.SetFolders()) {
429  if( (*iter)->GetInfo().GetTitle() == folder_name) {
430  return (*iter); // iter = folder.SetFolders().erase(iter);
431  }
432  else
433  s_GetOrCreateFolder(project, **iter, folder_name, false);
434  }
435  }
436 
437  if(top) {
439  folder->SetInfo().SetCreateDate(CTime(CTime::eCurrent));
440  folder->SetInfo().SetTitle(folder_name);
441  parent_folder.SetFolders().push_back(folder);
442  return folder;
443  }
444  return CRef<CProjectFolder>();
445 }
446 
447 
449  ESerialDataFormat fmt,
450  CNcbiIstream& istr)
451 {
452  auto_ptr<CObjectIStream> os(CObjectIStream::Open(fmt, istr));
453  string obj_type = os->ReadFileHeader();
454  os->SetStreamPos(0);
455 
456  if (obj_type == "Seq-annot") {
457  CRef<CSeq_annot> obj(new CSeq_annot);
458  *os >> *obj;
459  item.SetObject(*obj);
460  } else if (obj_type == "Seq-loc") {
461  CRef<CSeq_loc> obj(new CSeq_loc);
462  *os >> *obj;
463  item.SetObject(*obj);
464  } else if (obj_type == "Seq-id") {
465  CRef<CSeq_id> obj(new CSeq_id);
466  *os >> *obj;
467  item.SetObject(*obj);
468  } else {
469  NCBI_THROW(CException, eUnknown, "The data type is not supported!");
470  }
471 }
472 
473 
475  CNcbiIstream& istr)
476 {
477  // always treat it as a seq-entry
478  CGFFReader reader;
479  CRef<CSeq_entry> obj = reader.Read(istr);
480  item.SetObject(*obj);
481 }
482 
483 
484 void CGBProjectTool::x_AddItem(CGBProjectHandle& project,
485  CNcbiIstream& istr,
486  const string& fmt_str,
487  const string& in_folder)
488 {
490 
491  if (fmt_str == "gff") {
492  x_LoadGffData(*item, istr);
493  } else {
494  if (fmt_str == "asn") {
495  x_LoadGeneralData(*item, eSerial_AsnText, istr);
496  } else if (fmt_str == "asnb") {
497  x_LoadGeneralData(*item, eSerial_AsnBinary, istr);
498  } else {
499  NCBI_THROW(CException, eUnknown, "The file format is not currently supported!");
500  }
501  }
502 
503  // add the new item into the project (under a folder if given)
504  if (!in_folder.empty()) {
505  CProjectFolder& root = project.SetProject().SetData();
506 
507  // check if there is a folder named 'in_folder'
508  bool folder_found = false;
509  if (root.IsSetFolders()) {
511  if ((*iter)->GetInfo().GetTitle() == in_folder) {
512  project.AddItem(*item, **iter);
513  folder_found = true;
514  break;
515  }
516  }
517  }
518 
519  // otherwise add a new folder
520  if (!folder_found) {
522  folder->SetInfo().SetCreateDate(CTime(CTime::eCurrent));
523  folder->SetInfo().SetTitle(in_folder);
524  root.SetFolders().push_back(folder);
525  project.AddItem(*item, *folder);
526  }
527  } else {
528  project.AddItem(*item, project.SetData());
529  }
530 }
531 
532 
534 {
535  CArgs args = GetArgs();
536 
537  bool EnableID = true;
538  if(args["noid"].HasValue() && args["noid"].AsBoolean())
539  EnableID = false;
540 
541 
543  CRef<CScope> scope(new CScope(*object_manager));
544  scope->ResetDataAndHistory();
545 
546  if(EnableID) {
549  }
550 
551  Writer.reset(new CProjectFileWriter(scope));
552 
553 
555 
556  if (args["create"]) {
557 
558  //
559  // create a new project
560  //
561  CGBProject_ver2 projObj;
562  CGBProjectHandle project(projObj);
563 
564  CTime create_time(CTime::eCurrent);
565 
566  /// set the project's basic descriptors
567  CProjectDescr& descr = project.SetProject().SetDescr();
568  descr.SetCreate_date().SetToTime(create_time);
569  if (args["title"].HasValue()) {
570  descr.SetTitle(args["title"].AsString());
571  } else {
572  descr.SetTitle("Default");
573  }
574 
575  /// set the data descriptors
576  CProjectFolder& data = project.SetProject().SetData();
577  data.SetInfo().SetTitle("Data");
578  data.SetInfo().SetCreate_date().SetToTime(create_time);
579 
580  /// serialize
581  CNcbiOstream& ostr = args["o"].AsOutputFile();
582  project.Save(ostr, saveformat);
583 
584  } else if (args["add-folder"].HasValue()) {
585  ///
586  /// add a folder to an existing project
587  ///
588  CGBProjectHandle project;
589  {{
590  CNcbiIstream& istr = args["i"].AsInputFile();
591  if ( !project.Load(istr,0) ) {
592  NCBI_THROW(CException, eUnknown, "failed to read project");
593  }
594  }}
595 
596  string folder_name = args["add-folder"].AsString();
597 
599  folder->SetInfo().SetCreateDate(CTime(CTime::eCurrent));
600  folder->SetInfo().SetTitle(folder_name);
601 
602  CProjectFolder& root = project.SetProject().SetData();
603  root.SetFolders().push_back(folder);
604 
605  /// serialize
606  CNcbiOstream& ostr = args["o"].AsOutputFile();
607  project.Save(ostr, saveformat);
608 
609  } else if (args["list"]) {
610  /// lists the folders of an existing project
611  CGBProjectHandle project;
612  {{
613  CNcbiIstream& istr = args["i"].AsInputFile();
614  if ( !project.Load(istr,0) ) {
615  NCBI_THROW(CException, eUnknown, "failed to read project");
616  }
617  }}
618 
619  const CProjectFolder& folder = project.GetProject().GetData();
620  CNcbiOstream& ostr = args["o"].AsOutputFile();
621  s_ListProjectFolder(folder, ostr);
622  } else if (args["expand"].HasValue()) {
623  /// Expands (saves the folders to directories and items to files)
624  // of an existing project
625  CGBProjectHandle project;
626  {{
627  CNcbiIstream& istr = args["i"].AsInputFile();
628  if ( !project.Load(istr,0) ) {
629  NCBI_THROW(CException, eUnknown, "failed to read project");
630  }
631  }}
632 
633  EFormat format = CFormatGuess::eBinaryASN;//eSerial_AsnBinary;
634  string formatstr = args["expand-fmt"].AsString();
635  if(formatstr == "asnb")
636  format = CFormatGuess::eBinaryASN;
637  else if(formatstr == "asnt")
638  format = CFormatGuess::eTextASN;
639  else if(formatstr == "xml")
640  format = CFormatGuess::eXml;
641  //else if(formatstr == "json")
642  // format = eSerial_Json;
643  else if(formatstr == "gtf")
644  format = CFormatGuess::eGtf;
645 
646  const CProjectFolder& folder = project.GetProject().GetData();
647  CDir parent(args["expand"].AsString());
648  s_ScopeProjectFolder(scope, folder);
649  s_ExpandProjectFolder(scope, folder, parent, format);
650  } else if (args["collapse"].HasValue()) {
651  /// Expands (saves the folders to directories and items to files)
652  // of an existing project
653  CGBProjectHandle project(*new CGBProject_ver2);
654  {{
655  CNcbiIstream& istr = args["i"].AsInputFile();
656  if ( !project.Load(istr,0) ) {
657  //cerr << "Failed to load, making new proj" << endl;
658  // NCBI_THROW(CException, eUnknown, "failed to read project");
659  }
660  }}
661 
662 
663  CDir parent(args["collapse"].AsString());
664  CRef<CProjectFolder> folder = CRef<CProjectFolder>(&project.SetProject().SetData());
665  if(args["proj-folder"].HasValue()) {
666  string ProjFolder = args["proj-folder"].AsString();
667  folder = s_GetOrCreateFolder(project, *folder, ProjFolder);
668  }
669 
670  if(args["i"].AsString() == "-")
671  project.SetDescr().SetTitle(parent.GetBase());
672 
673  if(args["title"].HasValue())
674  project.SetDescr().SetTitle(args["title"].AsString());
675 
676  project.SetDescr().SetCreateDate(CTime(CTime::eCurrent));
677  project.SetDescr().SetModifiedDate(CTime(CTime::eCurrent));
678  s_CollapseProjectFolder(scope, project, *folder, parent);
679  CNcbiOstream& ostr = args["o"].AsOutputFile();
680  project.Save(ostr, saveformat);
681  } else if (args["add"].HasValue()) {
682  ///
683  /// add an item to the project
684  ///
685  CGBProjectHandle project;
686  {{
687  CNcbiIstream& istr = args["i"].AsInputFile();
688  if ( !project.Load(istr,0) ) {
689  NCBI_THROW(CException, eUnknown, "failed to read project");
690  }
691  }}
692 
693  string folder;
694  if (args["proj-folder"].HasValue()) {
695  folder = args["proj-folder"].AsString();
696  }
697  x_AddItem(project, args["add"].AsInputFile(),
698  args["fmt"].AsString(), folder);
699  /// serialize
700  CNcbiOstream& ostr = args["o"].AsOutputFile();
701  project.Save(ostr, saveformat);
702 
703  } else if (args["rm"].HasValue()) {
704 
705  // remove an item from the project
706  CGBProjectHandle project;
707  {{
708  CNcbiIstream& istr = args["i"].AsInputFile();
709  if ( !project.Load(istr,0) ) {
710  NCBI_THROW(CException, eUnknown, "failed to read project");
711  }
712  }}
713 
714  CProjectFolder& folder = project.SetProject().SetData();
715  string label = args["rm"].AsString();
716  s_RemoveItem(project, folder, label);
717 
718  /// serialize
719  CNcbiOstream& ostr = args["o"].AsOutputFile();
720  project.Save(ostr, saveformat);
721 
722  } else if (args["rmdir"].HasValue()) {
723 
724  // remove an item from the project
725  CGBProjectHandle project;
726  {{
727  CNcbiIstream& istr = args["i"].AsInputFile();
728  if ( !project.Load(istr,0) ) {
729  NCBI_THROW(CException, eUnknown, "failed to read project");
730  }
731  }}
732 
733  CProjectFolder& folder = project.SetProject().SetData();
734  string label = args["rmdir"].AsString();
735  s_RemoveFolder(project, folder, label);
736 
737  /// serialize
738  CNcbiOstream& ostr = args["o"].AsOutputFile();
739  project.Save(ostr, saveformat);
740 
741  } else {
742  NCBI_THROW(CException, eUnknown, "command not yet implemented");
743  }
744 
745  return 0;
746 }
747 
748 
751 
752 
753 int NcbiSys_main(int argc, ncbi::TXChar* argv[])
754 {
755  return CGBProjectTool().AppMain(argc, argv);
756 }
void x_LoadGffData(CProjectItem &item, CNcbiIstream &istr)
void AddDataLoader(const string &loader_name, TPriority pri=kPriority_Default)
Add data loader by name.
Definition: scope.cpp:467
list< CRef< CProjectItem > > TItems
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:783
static void s_RemoveFolder(CGBProjectHandle &project, CProjectFolder &folder, const string &label)
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
static string GetLoaderNameFromArgs(CReader *reader=0)
Definition: gbloader.cpp:256
void SetCreate_date(TCreate_date &value)
Assign a value to Create_date data member.
static void s_ScopeProjectFolder(CRef< CScope > Scope, const CProjectFolder &folder)
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
void x_AddItem(CGBProjectHandle &project, CNcbiIstream &istr, const string &fmt_str, const string &in_folder)
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:970
static void s_RemoveItem(CGBProjectHandle &project, CProjectFolder &folder, const string &label)
void SetCreateDate(const CTime &time)
SetCreateDate() will add a descriptor for creation date, and insure that only one such descriptor exi...
Definition: ProjectItem.cpp:73
Defines command line argument related classes.
list< CRef< CSerialObject > > TSerialObjectList
Definition: fileloader.hpp:55
User-defined methods of the data storage class.
auto_ptr< CProjectFileWriter > Writer
Case insensitive compare.
Definition: ncbistr.hpp:1177
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
Definition: ncbiapp.cpp:941
Name of file (must exist and be readable)
Definition: ncbiargs.hpp:568
ASN.1 text.
Definition: serialdef.hpp:73
bool IsSetItems(void) const
Check if a value has been assigned to Items data member.
static string ConcatPathEx(const string &first, const string &second)
Concatenate two parts of the path for any OS.
Definition: ncbifile.cpp:786
CDirEntry –.
Definition: ncbifile.hpp:263
string GetBase(void) const
Get the base entry name without extension.
Definition: ncbifile.hpp:3863
User-defined methods of the data storage class.
const TTitle & GetTitle(void) const
Get the variant data.
Definition: Annotdesc_.hpp:521
static void s_ListProjectFolder(const CProjectFolder &folder, CNcbiOstream &ostr, int level=0)
Defines unified interface to application:
bool GetTimeT(time_t *modification, time_t *last_access=0, time_t *creation=0) const
Get time stamp(s) of a directory entry (time_t version).
Definition: ncbifile.cpp:2009
const string & GetPath(void) const
Get entry path.
Definition: ncbifile.hpp:3849
#define NULL
Definition: ncbistd.hpp:225
const TInfo & GetInfo(void) const
Get the Info member data.
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
Definition: ncbiapp.cpp:626
#define kEmptyStr
Definition: ncbistr.hpp:120
bool s_Compare_DirEntry_ModDate(CDirEntry *A, CDirEntry *B)
bool CreatePath(TCreateFlags flags=fCreate_Default) const
Create the directory path recursively possibly more than one at a time.
Definition: ncbifile.cpp:4039
TItems & SetItems(void)
Assign a value to Items data member.
const TItems & GetItems(void) const
Get the Items member data.
ESerialDataFormat format
const Tdata & Get(void) const
Get the member data.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:776
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:185
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:243
void SetLabel(const TLabel &value)
Assign a value to Label data member.
void NCBI_SeqTable_RegisterModuleClasses(void)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
static void s_CollapseProjectFolder(CRef< CScope > scope, CGBProjectHandle &project, CProjectFolder &folder, CDir &dir)
string GetSeqIdString(bool with_version=false) const
Return seqid string with optional version for text seqid type.
Definition: Seq_id.cpp:1528
User-defined methods of the data storage class.
static void LoadFile(const string &Filename, TSerialObjectList &Objects, EFormat Format=CFormatGuess::eUnknown)
Definition: fileloader.cpp:97
CDir –.
Definition: ncbifile.hpp:1665
User-defined methods of the data storage class.
void SetTitle(const TTitle &value)
Assign a value to Title data member.
const TDesc & GetDesc(void) const
Get the Desc member data.
Definition: Seq_annot_.hpp:833
list< CRef< CProjectFolder > > TFolders
char TXChar
Definition: ncbistr.hpp:169
User-defined methods of the data storage class.
CRef< CSeq_entry > Read(CNcbiIstream &in, TFlags flags=fDefaults)
Definition: gff_reader.cpp:112
static void s_ExpandProjectFolder(CRef< CScope > scope, const CProjectFolder &folder, CDir &parentDir, EFormat format, int level=0)
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:1305
#define A(i)
Definition: ecp_curves.c:882
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:142
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
Definition: ncbitime.cpp:1515
CRef< CProjectFolder > s_GetOrCreateFolder(CGBProjectHandle &project, CProjectFolder &parent_folder, const string &folder_name, bool top=true)
CSeq_id_Handle GetAccVer(const CSeq_id_Handle &idh, TGetFlags flags=0)
Get accession.version Seq-id Returns null CSeq_id_Handle if the sequence is not found or if it doesn'...
Definition: scope.cpp:380
CTime AsCTime(CTime::ETimeZone tz=CTime::eLocal) const
Definition: Date.cpp:70
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
Definition: ncbiapp.cpp:198
void Init()
Initialize the application.
list< CRef< CAnnotdesc > > Tdata
void SetInfo(TInfo &value)
Assign a value to Info data member.
CTime –.
Definition: ncbitime.hpp:290
CArgDescriptions –.
Definition: ncbiargs.hpp:514
One argument requires another.
Definition: ncbiargs.hpp:928
Magic spell ;-) needed for some weird compilers... very empiric.
TEntries GetEntries(const string &mask=kEmptyStr, TGetEntriesFlags flags=0) const
Get directory entries based on the specified "mask".
Definition: ncbifile.cpp:3786
CConstRef< CSeq_id > GetSeqId(void) const
An arbitrary string.
Definition: ncbiargs.hpp:563
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
Definition: ncbiapp.hpp:681
CScope –.
Definition: scope.hpp:90
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock, CFileIO, CFileReader, CFileWriter, CFileReaderWriter, CFileException.
CArgs –.
Definition: ncbiargs.hpp:356
void SetNameDesc(const string &name)
Definition: Seq_annot.cpp:66
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
AutoPtr –.
Definition: ncbimisc.hpp:384
Name of file (must be writable)
Definition: ncbiargs.hpp:569
bool CanGetDesc(void) const
Check if it is safe to call GetDesc method.
Definition: Seq_annot_.hpp:827
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
int NcbiSys_main(int argc, ncbi::TXChar *argv[])
const CSeq_id & GetSeq_id(TDim row) const
Get seq-id (the first one if segments have different ids).
Definition: Seq_align.cpp:317
void SetTitleDesc(const string &title)
Definition: Seq_annot.cpp:96
const TLabel & GetLabel(void) const
Get the Label member data.
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CNcbiApplication –.
Definition: ncbiapp.hpp:120
CFormatGuess::EFormat EFormat
User-defined methods of the data storage class.
Suppress "self recursive" elements (the directories "." and "..").
Definition: ncbifile.hpp:1726
int Run()
Run the application.
Use current time.
Definition: ncbitime.hpp:295
#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:546
virtual const CTypeInfo * GetThisTypeInfo(void) const =0
Reader for GFF (including GTF) files.
User-defined methods of the data storage class.
void x_LoadGeneralData(CProjectItem &item, ESerialDataFormat fmt, CNcbiIstream &istr)
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:139
const string & GetName(void) const
Get name of this type.
Definition: typeinfo.cpp:231
void NCBI_Sequence_RegisterModuleClasses(void)
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
USING_SCOPE(objects)
New GTF, CGtfReader.
const TCreate_date & GetCreate_date(void) const
Get the Create_date member data.
CArgAllow_Strings –.
Definition: ncbiargs.hpp:1566
User-defined methods of the data storage class.
const TName & GetName(void) const
Get the variant data.
Definition: Annotdesc_.hpp:501
void SetObject(CSerialObject &object)
wrapper for setting the object pointed to by this item
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:756
const TFolders & GetFolders(void) const
Get the Folders member data.
const TTitle & GetTitle(void) const
Get the Title member data.
TFolders & SetFolders(void)
Assign a value to Folders data member.
EFormat
The formats are checked in the same order as declared here.
void ResetDataAndHistory(void)
Clear all information in the scope except added data loaders.
Definition: scope.cpp:319
ASN.1 binary.
Definition: serialdef.hpp:74
CConstRef< CSeq_id > GetSeqIdOrNull(void) const
bool IsSetFolders(void) const
Check if a value has been assigned to Folders data member.
Modified on Sat Sep 23 14:27:49 2017 by modify_doxy.py rev. 546573