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

Go to the SVN repository for this file.

1 /* $Id: demo_gene_model.cpp 91963 2020-12-17 12:53:46Z grichenk $
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  * Author: Mike DiCuccio
27  *
28  * File Description:
29  *
30  * ===========================================================================
31  */
32 
33 #include <ncbi_pch.hpp>
34 
35 #include <corelib/ncbiapp.hpp>
36 #include <corelib/ncbiargs.hpp>
37 #include <corelib/ncbienv.hpp>
38 
43 #include <objmgr/scope.hpp>
44 
45 #include <serial/iterator.hpp>
46 
48 
51 
53 public:
55  virtual void Init(void);
56  virtual int Run(void);
57 };
58 
59 /*---------------------------------------------------------------------------*/
60 
62 {
63  unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
64 
65  arg_desc->AddDefaultKey("i", "InputFile",
66  "File containing seq-align to use",
68  "-");
69 
70  arg_desc->AddDefaultKey("o", "OutputFile",
71  "File containing seq-annot for gene model",
73  "-");
74  arg_desc->AddDefaultKey("ofmt", "OutputFormat",
75  "Format for output",
77  "seq-annot");
78  arg_desc->SetConstraint("ofmt",
79  &(*new CArgAllow_Strings,
80  "seq-annot", "seq-feat"));
81 
82  SetupArgDescriptions(arg_desc.release());
83 }
84 
85 
87 {
88  const CArgs& args = GetArgs();
89  CNcbiIstream& istr = args["i"].AsInputFile();
90  CNcbiOstream& ostr = args["o"].AsOutputFile();
91  string ofmt = args["ofmt"].AsString();
92 
95  CScope scope(*om);
96  scope.AddDefaults();
97 
98  while (istr) {
99  CSeq_align align;
100  try {
101  istr >> MSerial_AsnText >> align;
102  }
103  catch (CEofException&) {
104  break;
105  }
106 
107  CSeq_annot annot;
108  CBioseq_set seqs;
109  CFeatureGenerator gen(scope);
110  gen.ConvertAlignToAnnot(align, annot, seqs);
111 
112  annot.SetNameDesc("Demo Gene Models");
113  annot.SetTitleDesc("Demo Gene Models");
114 
115  /**
116  CTypeIterator<CSeq_feat> feat_it(annot);
117  for ( ; feat_it; ++feat_it) {
118  feat_it->SetId().SetLocal().SetId(++counter);
119  }
120  **/
121 
122  if (ofmt == "seq-annot") {
123  ostr << MSerial_AsnText << annot;
124  }
125  else if (ofmt == "seq-feat") {
127  annot.GetData().GetFtable()) {
128  ostr << MSerial_AsnText << **it;
129  }
130  }
131  }
132 
133  return 0;
134 }
135 
136 //---------------------------------------------------------------------------
137 int main(int argc, char** argv)
138 {
139  CGeneModelDemoApp theApp;
140  return theApp.AppMain(argc, argv, NULL, eDS_Default, 0);
141 }
User-defined methods of the data storage class.
CArgAllow_Strings –.
Definition: ncbiargs.hpp:1641
CArgDescriptions –.
Definition: ncbiargs.hpp:541
CArgs –.
Definition: ncbiargs.hpp:379
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:366
virtual int Run(void)
Run the application.
virtual void Init(void)
Initialize the application.
CScope –.
Definition: scope.hpp:92
void SetNameDesc(const string &name)
Definition: Seq_annot.cpp:66
void SetTitleDesc(const string &title)
Definition: Seq_annot.cpp:96
USING_SCOPE(objects)
int main(int argc, char **argv)
USING_NCBI_SCOPE
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
Definition: ncbiapp.cpp:305
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:819
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
Definition: ncbiapp.cpp:1195
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
void DisableArgDescriptions(TDisableArgDesc disable=fDisableStdArgs)
Definition: ncbiapp.cpp:1306
@ eInputFile
Name of file (must exist and be readable)
Definition: ncbiargs.hpp:595
@ eString
An arbitrary string.
Definition: ncbiargs.hpp:589
@ eOutputFile
Name of file (must be writable)
Definition: ncbiargs.hpp:596
#define NULL
Definition: ncbistd.hpp:225
@ eDS_Default
Try standard log file (app.name + ".log") in /log/, use stderr on failure.
Definition: ncbidiag.hpp:1790
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
const TFtable & GetFtable(void) const
Get the variant data.
Definition: Seq_annot_.hpp:621
list< CRef< CSeq_feat > > TFtable
Definition: Seq_annot_.hpp:193
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_annot_.hpp:873
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines command line argument related classes.
Defines unified interface to application:
The Object manager core.
CRef< objects::CObjectManager > om
Modified on Wed Apr 17 13:09:29 2024 by modify_doxy.py rev. 669887