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

Go to the SVN repository for this file.

1 /* $Id: blast_sample.cpp 90001 2020-05-04 12:53:02Z ivanov $
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: Christiam Camacho
27  *
28  * File Description:
29  * Demo of using the CBl2Seq class to compare two sequences using the BLAST
30  * algorithm
31  *
32  */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbiapp.hpp>
36 
37 // Objects includes
39 
40 // Object Manager includes
42 
43 // BLAST includes
46 
49 
50 
51 /////////////////////////////////////////////////////////////////////////////
52 // CBlastSampleApplication::
53 
55 {
56 private:
57  virtual void Init(void);
58  virtual int Run(void);
59  virtual void Exit(void);
60 
61  enum ESeqType {
63  eSubject
64  };
65  blast::SSeqLoc* x_CreateSSeqLoc(ESeqType st);
66 };
67 
68 
69 blast::SSeqLoc*
71 {
72  // Get the gi
73  TGi gi;
74  if (st == eQuery) {
75  gi = GI_FROM(TIntId, GetArgs()["query"].AsIntId());
76  } else {
77  gi = GI_FROM(TIntId, GetArgs()["subject"].AsIntId());
78  }
79  CRef<CSeq_loc> seqloc(new CSeq_loc);
80  seqloc->SetWhole().SetGi(gi);
81 
82  // Setup the scope
84 
85  return new blast::SSeqLoc(seqloc, scope);
86 }
87 
88 
89 /////////////////////////////////////////////////////////////////////////////
90 // Init test for all different types of arguments
91 
93 {
95 
96  // Create command-line argument descriptions class
97  unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
98 
99  // Specify USAGE context
100  arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
101  "CBl2Seq demo to compare 2 sequences using BLAST");
102 
103  // Program type
104  arg_desc->AddKey("program", "p", "Type of BLAST program", CArgDescriptions::eString);
105  arg_desc->SetConstraint
106  ("program", &(*new CArgAllow_Strings,
107  "blastp", "blastn", "blastx", "tblastn", "tblastx"));
108 
109  // Identifier for the query sequence
110  arg_desc->AddKey("query", "QuerySequenceID",
111  "GI of the query sequence",
113 
114  // Identifier for the subject sequence
115  arg_desc->AddKey("subject", "SubjectSequenceID",
116  "GI of the subject sequence",
118 
119  // Output file
120  arg_desc->AddDefaultKey("out", "OutputFile",
121  "File name for writing the Seq-align results in ASN.1 form",
123 
124  // Setup arg.descriptions for this application
125  SetupArgDescriptions(arg_desc.release());
126 }
127 
128 
129 
130 /////////////////////////////////////////////////////////////////////////////
131 // Run demo
132 
134 {
135  int retval = 0;
136  try {
137  // Obtain the query, subject, and program from command line
138  // arguments...
139  unique_ptr<blast::SSeqLoc> query(x_CreateSSeqLoc(eQuery));
140  unique_ptr<blast::SSeqLoc> subject(x_CreateSSeqLoc(eSubject));
141  blast::EProgram program = blast::ProgramNameToEnum(GetArgs()["program"].AsString());
142 
143  /// ... and BLAST the sequences!
144  blast::CBl2Seq blaster(*query, *subject, program);
145  blast::TSeqAlignVector alignments = blaster.Run();
146 
147  /// Display the alignments in text ASN.1
148  CNcbiOstream& out = GetArgs()["out"].AsOutputFile();
149  for (const auto& it : alignments)
150  out << MSerial_AsnText << *it;
151 
152  } catch (const CException& e) {
153  ERR_POST(e);
154  retval = 1;
155  }
156 
157  return retval;
158 }
159 
160 
161 /////////////////////////////////////////////////////////////////////////////
162 // Cleanup
163 
165 {
166  // Do your after-Run() cleanup here
167 }
168 
169 
170 /////////////////////////////////////////////////////////////////////////////
171 // MAIN
172 
173 #ifndef SKIP_DOXYGEN_PROCESSING
174 int NcbiSys_main(int argc, ncbi::TXChar* argv[])
175 {
176  // Execute main application function
177  return CBlastSampleApplication().AppMain(argc, argv);
178 }
179 #endif /* SKIP_DOXYGEN_PROCESSING */
Declares the CBl2Seq (BLAST 2 Sequences) class.
USING_SCOPE(objects)
int NcbiSys_main(int argc, ncbi::TXChar *argv[])
USING_NCBI_SCOPE
vector< CRef< objects::CSeq_align_set > > TSeqAlignVector
Vector of Seq-align-sets.
EProgram
This enumeration is to evolve into a task/program specific list that specifies sets of default parame...
Definition: blast_types.hpp:56
CArgAllow_Strings –.
Definition: ncbiargs.hpp:1641
CArgDescriptions –.
Definition: ncbiargs.hpp:541
virtual int Run(void)
Run the application.
blast::SSeqLoc * x_CreateSSeqLoc(ESeqType st)
virtual void Init(void)
Initialize the application.
virtual void Exit(void)
Cleanup on application exit.
static CRef< CScope > NewScope(bool with_defaults=true)
Return a new scope, possibly (by default) with default loaders, which will include the Genbank loader...
Definition: simple_om.cpp:202
std::ofstream out("events_result.xml")
main entry point for tests
EProgram ProgramNameToEnum(const std::string &program_name)
Map a string into an element of the ncbi::blast::EProgram enumeration (except eBlastProgramMax).
Definition: blast_aux.cpp:757
void HideStdArgs(THideStdArgs hide_mask)
Set the hide mask for the Hide Std Flags.
Definition: ncbiapp.cpp:1325
#define GI_FROM(T, value)
Definition: ncbimisc.hpp:1086
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:832
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
Definition: ncbiapp.cpp:1208
Int8 TIntId
Definition: ncbimisc.hpp:999
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ fHideXmlHelp
Hide XML help description.
@ fHideLogfile
Hide log file description.
@ fHideFullVersion
Hide full version description.
@ fHideConffile
Hide configuration file description.
@ fHideVersion
Hide version description.
@ fPreOpen
Open file right away; for eInputFile, eOutputFile, eIOFile.
Definition: ncbiargs.hpp:618
@ eIntId
Convertible to TIntId (int or Int8 depending on NCBI_INT8_GI)
Definition: ncbiargs.hpp:593
@ eString
An arbitrary string.
Definition: ncbiargs.hpp:589
@ eOutputFile
Name of file (must be writable)
Definition: ncbiargs.hpp:596
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
void SetWhole(TWhole &v)
Definition: Seq_loc.hpp:982
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
char TXChar
Definition: ncbistr.hpp:172
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
static SLJIT_INLINE sljit_ins st(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Definition of SSeqLoc structure.
static string subject
static string query
Modified on Wed Sep 04 14:58:55 2024 by modify_doxy.py rev. 669887