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

Go to the SVN repository for this file.

1 /* $Id: demo_score_builder.cpp 66823 2015-03-26 16:08:56Z boukn $
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  * Sample for the command-line arguments' processing ("ncbiargs.[ch]pp"):
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbiapp.hpp>
35 #include <corelib/ncbienv.hpp>
36 #include <corelib/ncbiargs.hpp>
37 
39 #include <objmgr/scope.hpp>
42 
45 
46 
47 /////////////////////////////////////////////////////////////////////////////
48 // CDemoApplication::
49 
50 
52 {
53 private:
54  virtual void Init(void);
55  virtual int Run(void);
56  virtual void Exit(void);
57 };
58 
59 
60 /////////////////////////////////////////////////////////////////////////////
61 // Init test for all different types of arguments
62 
63 
65 {
66  // Create command-line argument descriptions class
68 
69  arg_desc->AddDefaultKey("i", "InputFile",
70  "Seq-align to evaluate",
72  "-");
73 
74  arg_desc->AddDefaultKey("o", "OutputFile",
75  "Seq-align report",
77  "-");
78 
79  // Setup arg.descriptions for this application
80  SetupArgDescriptions(arg_desc.release());
81 }
82 
83 
84 
85 /////////////////////////////////////////////////////////////////////////////
86 // Run test (printout arguments obtained from command-line)
87 
88 
90 {
91  // Get arguments
92  const CArgs& args = GetArgs();
93 
96  CRef<CScope> scope(new CScope(*om));
97  scope->AddDefaults();
98 
99  CSeq_align align;
100  args["i"].AsInputFile() >> MSerial_AsnText >> align;
101 
102  CNcbiOstream& ostr = args["o"].AsOutputFile();
103  CScoreBuilder sb;
104 
105  ostr << "alignment length: " << sb.GetAlignLength(align) << endl;
106  ostr << "identities: " << sb.GetIdentityCount(*scope, align) << endl;
107  ostr << "mismatches: " << sb.GetMismatchCount(*scope, align) << endl;
108 
109  {{
110  int mismatches;// = 0;
111  int identities;// = 0;
112  sb.GetMismatchCount(*scope, align, identities, mismatches);
113  ostr << "identities + mismatches: "
114  << identities << " / " << mismatches << endl;
115  }}
116 
117  ostr << "tiebreaker: " << sb.ComputeTieBreaker(align) << endl;
118 
119  return 0;
120 }
121 
122 
123 /////////////////////////////////////////////////////////////////////////////
124 // Cleanup
125 
126 
128 {
129  SetDiagStream(0);
130 }
131 
132 
133 /////////////////////////////////////////////////////////////////////////////
134 // MAIN
135 
136 
137 int main(int argc, const char* argv[])
138 {
139  // Execute main application function
140  return CDemoApplication().AppMain(argc, argv);
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
int ComputeTieBreaker(const CSeq_align &align)
Defines command line argument related classes.
virtual void Exit(void)
Cleanup on application exit.
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
virtual int Run(void)
Run the application.
int main(int argc, const char *argv[])
Defines unified interface to application:
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
int GetIdentityCount(CScope &scope, const CSeq_align &align)
Compute the number of identities in the alignment.
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:225
void SetDiagStream(CNcbiOstream *os, bool quick_flush=true, FDiagCleanup cleanup=0, void *cleanup_data=0, const string &stream_name="")
Set diagnostic stream.
Definition: ncbidiag.cpp:7290
USING_NCBI_SCOPE
auto_ptr –
Definition: ncbimisc.hpp:336
TSeqPos GetAlignLength(const CSeq_align &align, bool ungapped=false)
Compute the length of the alignment (= length of all segments, gaps + aligned)
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:150
CRef< objects::CObjectManager > om
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
Definition: ncbiapp.cpp:185
The Object manager core.
CArgDescriptions –.
Definition: ncbiargs.hpp:509
virtual void Init(void)
Initialize the application.
CScope –.
Definition: scope.hpp:90
CArgs –.
Definition: ncbiargs.hpp:356
Name of file (must be writable)
Definition: ncbiargs.hpp:564
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CNcbiApplication –.
Definition: ncbiapp.hpp:120
int GetMismatchCount(CScope &scope, const CSeq_align &align)
Compute the number of mismatches in the alignment.
USING_SCOPE(objects)
Modified on Fri Apr 29 18:25:48 2016 by modify_doxy.py rev. 426318