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

Go to the SVN repository for this file.

00001 /*  $Id: demo_score_builder.cpp 44952 2010-03-01 18:11:44Z dicuccio $
00002  * ===========================================================================
00003  *
00004  *                            PUBLIC DOMAIN NOTICE
00005  *               National Center for Biotechnology Information
00006  *
00007  *  This software/database is a "United States Government Work" under the
00008  *  terms of the United States Copyright Act.  It was written as part of
00009  *  the author's official duties as a United States Government employee and
00010  *  thus cannot be copyrighted.  This software/database is freely available
00011  *  to the public for use. The National Library of Medicine and the U.S.
00012  *  Government have not placed any restriction on its use or reproduction.
00013  *
00014  *  Although all reasonable efforts have been taken to ensure the accuracy
00015  *  and reliability of the software and data, the NLM and the U.S.
00016  *  Government do not and cannot warrant the performance or results that
00017  *  may be obtained by using this software or data. The NLM and the U.S.
00018  *  Government disclaim all warranties, express or implied, including
00019  *  warranties of performance, merchantability or fitness for any particular
00020  *  purpose.
00021  *
00022  *  Please cite the author in any work or product based on this material.
00023  *
00024  * ===========================================================================
00025  *
00026  * Authors:  Mike DiCuccio
00027  *
00028  * File Description:
00029  *   Sample for the command-line arguments' processing ("ncbiargs.[ch]pp"):
00030  *
00031  */
00032 
00033 #include <ncbi_pch.hpp>
00034 #include <corelib/ncbiapp.hpp>
00035 #include <corelib/ncbienv.hpp>
00036 #include <corelib/ncbiargs.hpp>
00037 
00038 #include <objmgr/object_manager.hpp>
00039 #include <objmgr/scope.hpp>
00040 #include <objtools/data_loaders/genbank/gbloader.hpp>
00041 #include <algo/align/util/score_builder.hpp>
00042 
00043 USING_NCBI_SCOPE;
00044 USING_SCOPE(objects);
00045 
00046 
00047 /////////////////////////////////////////////////////////////////////////////
00048 //  CDemoApplication::
00049 
00050 
00051 class CDemoApplication : public CNcbiApplication
00052 {
00053 private:
00054     virtual void Init(void);
00055     virtual int  Run(void);
00056     virtual void Exit(void);
00057 };
00058 
00059 
00060 /////////////////////////////////////////////////////////////////////////////
00061 //  Init test for all different types of arguments
00062 
00063 
00064 void CDemoApplication::Init(void)
00065 {
00066     // Create command-line argument descriptions class
00067     auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
00068 
00069     arg_desc->AddDefaultKey("i", "InputFile",
00070                             "Seq-align to evaluate",
00071                             CArgDescriptions::eInputFile,
00072                             "-");
00073 
00074     arg_desc->AddDefaultKey("o", "OutputFile",
00075                             "Seq-align report",
00076                             CArgDescriptions::eOutputFile,
00077                             "-");
00078 
00079     // Setup arg.descriptions for this application
00080     SetupArgDescriptions(arg_desc.release());
00081 }
00082 
00083 
00084 
00085 /////////////////////////////////////////////////////////////////////////////
00086 //  Run test (printout arguments obtained from command-line)
00087 
00088 
00089 int CDemoApplication::Run(void)
00090 {
00091     // Get arguments
00092     const CArgs& args = GetArgs();
00093 
00094     CRef<CObjectManager> om(CObjectManager::GetInstance());
00095     CGBDataLoader::RegisterInObjectManager(*om);
00096     CRef<CScope> scope(new CScope(*om));
00097     scope->AddDefaults();
00098 
00099     CSeq_align align;
00100     args["i"].AsInputFile() >> MSerial_AsnText >> align;
00101 
00102     CNcbiOstream& ostr = args["o"].AsOutputFile();
00103     CScoreBuilder sb;
00104 
00105     ostr << "alignment length: " << sb.GetAlignLength(align) << endl;
00106     ostr << "identities: " << sb.GetIdentityCount(*scope, align) << endl;
00107     ostr << "mismatches: " << sb.GetMismatchCount(*scope, align) << endl;
00108 
00109     {{
00110          int mismatches;// = 0;
00111          int identities;// = 0;
00112          sb.GetMismatchCount(*scope, align, identities, mismatches);
00113          ostr << "identities + mismatches: "
00114              << identities << " / " << mismatches << endl;
00115      }}
00116 
00117 
00118     return 0;
00119 }
00120 
00121 
00122 /////////////////////////////////////////////////////////////////////////////
00123 //  Cleanup
00124 
00125 
00126 void CDemoApplication::Exit(void)
00127 {
00128     SetDiagStream(0);
00129 }
00130 
00131 
00132 /////////////////////////////////////////////////////////////////////////////
00133 //  MAIN
00134 
00135 
00136 int main(int argc, const char* argv[])
00137 {
00138     // Execute main application function
00139     return CDemoApplication().AppMain(argc, argv);
00140 }
Modified on Sun Dec 21 10:35:58 2014 by modify_doxy.py rev. 426318