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 52670 2012-01-17 19:20:37Z dicuccio $
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 {
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 }
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:641
void AddDefaultKey(const string &name, const string &synopsis, const string &comment, EType type, const string &default_value, TFlags flags=0, const string &env_var=kEmptyStr, const char *display_value=nullptr)
Add description for optional key with default value.
Definition: ncbiargs.cpp:2256
Defines command line argument related classes.
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
Definition: ncbiapp.cpp:789
Name of file (must exist and be readable)
Definition: ncbiargs.hpp:563
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:461
Defines unified interface to application:
#define NULL
Definition: ncbistd.hpp:225
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:492
X * release(void)
Release pointer.
Definition: ncbimisc.hpp:400
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:893
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:225
CRef< objects::CSeq_feat > ConvertAlignToAnnot(const objects::CSeq_align &align, objects::CSeq_annot &annot, objects::CBioseq_set &seqs, Int8 gene_id=0, const objects::CSeq_feat *cdregion_on_mrna=NULL)
Convert an alignment to an annotation.
auto_ptr –
Definition: ncbimisc.hpp:336
void SetConstraint(const string &name, const CArgAllow *constraint, EConstraintNegate negate=eConstraint)
Set additional user defined constraint on argument value.
Definition: ncbiargs.cpp:2404
User-defined methods of the data storage class.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:150
CRef< objects::CObjectManager > om
Try standard log file (app.name + ".log") in /log/, use stderr on failure.
Definition: ncbidiag.hpp:1757
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
Definition: ncbiapp.cpp:185
The Object manager core.
virtual int Run(void)
Run the application.
list< CRef< CSeq_feat > > TFtable
Definition: Seq_annot_.hpp:193
const TFtable & GetFtable(void) const
Get the variant data.
Definition: Seq_annot_.hpp:609
CArgDescriptions –.
Definition: ncbiargs.hpp:509
An arbitrary string.
Definition: ncbiargs.hpp:558
CScope –.
Definition: scope.hpp:90
CArgs –.
Definition: ncbiargs.hpp:356
void SetNameDesc(const string &name)
Definition: Seq_annot.cpp:66
Name of file (must be writable)
Definition: ncbiargs.hpp:564
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
USING_NCBI_SCOPE
void SetTitleDesc(const string &title)
Definition: Seq_annot.cpp:96
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CNcbiApplication –.
Definition: ncbiapp.hpp:120
virtual void Init(void)
Initialize the application.
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_annot_.hpp:854
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:147
CArgAllow_Strings –.
Definition: ncbiargs.hpp:1565
int main(int argc, char **argv)
USING_SCOPE(objects)
void DisableArgDescriptions(TDisableArgDesc disable=fDisableStdArgs)
Definition: ncbiapp.cpp:918
Modified on Sat Jul 23 19:21:17 2016 by modify_doxy.py rev. 506947