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

Go to the SVN repository for this file.

1 /* $Id: omssacl.cpp 67418 2015-05-15 15:50:53Z vasilche $
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 authors in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Lewis Y. Geer, Douglas J. Slotta
27  *
28  * File Description:
29  * command line OMSSA search
30  *
31  *
32  * ===========================================================================
33  */
34 
35 #include <ncbi_pch.hpp>
36 #include <corelib/ncbiargs.hpp>
37 #include <corelib/ncbiapp.hpp>
38 #include <corelib/ncbienv.hpp>
39 #include <corelib/ncbistre.hpp>
40 #include <corelib/ncbi_system.hpp>
41 #include <serial/serial.hpp>
42 #include <serial/objistrasn.hpp>
43 #include <serial/objistrasnb.hpp>
44 #include <serial/objostrasn.hpp>
45 #include <serial/objostrasnb.hpp>
46 #include <serial/iterator.hpp>
48 #include <serial/objostrxml.hpp>
49 #include <corelib/ncbifile.hpp>
50 
51 #include <fstream>
52 #include <string>
53 #include <list>
54 #include <stdio.h>
55 
56 #include "omssa.hpp"
57 #include "SpectrumSet.hpp"
58 #include "Mod.hpp"
59 #include "omssaapp.hpp"
60 
61 
64 USING_SCOPE(omssa);
65 
66 /////////////////////////////////////////////////////////////////////////////
67 //
68 // COMSSA
69 //
70 // Main application
71 //
72 
73 
74 class COMSSA : public COMSSABase {
75 public:
76  virtual int Run();
77  virtual void AppInit(CArgDescriptions *argDesc);
78 };
79 
80 
82 {
83  if(!argDesc) return;
84  argDesc->AddFlag("ns", "depreciated flag"); // to be deprecated
85  argDesc->AddFlag("os", "use omssa 1.0 scoring"); // to be deprecated
86  argDesc->AddFlag("nrs", "turn off rank score"); // experimental
87  argDesc->SetUsageContext(GetArguments().GetProgramBasename(),
88  "Search engine for identifying MS/MS peptide spectra");
89 }
90 
91 
92 int main(int argc, const char* argv[])
93 {
94  COMSSA theTestApp;
95  return theTestApp.AppMain(argc, argv, 0, eDS_Default, 0);
96 }
97 
98 
99 /** progress callback */
100 static void OMSSACallback(int TotalSeq, int Completed, void* Anything)
101 {
102  ERR_POST(Info << "Sequence=" << Completed << " Percent=" << (double)Completed/TotalSeq*100.0 <<
103  "%");
104 }
105 
107 {
108 
109  try {
110 
111  const CArgs& args = GetArgs();
113 
114  // turn off informational messages if requested
115  if(args["ni"])
117 
118  // read in modifications
119  if(CSearchHelper::ReadModFiles(args["mx"].AsString(), args["mux"].AsString(),
120  GetProgramExecutablePath(), Modset))
121  return 1;
122  Modset->CreateArrays();
123 
124  // print out the modification list
125  if(args["ml"]) {
126  PrintMods(Modset);
127  return 0;
128  }
129 
130  // print out the enzymes list
131  if(args["el"]) {
132  PrintEnzymes();
133  return 0;
134  }
135 
136  // print out the ions list
137  if(args["il"]) {
138  PrintIons();
139  return 0;
140  }
141 
142  CMSSearch MySearch;
143 
144  // which search settings to use
145  CRef <CMSSearchSettings> SearchSettings;
146 
147  // if search settings to be loaded from param file, create and load
148  if(args["pm"].AsString().size() != 0) {
149  SearchSettings.Reset(new CMSSearchSettings);
150  CSearchHelper::CreateSearchSettings(args["pm"].AsString(),
151  SearchSettings);
152  }
153  else if (args["fxml"].AsString().size() != 0) {
154  // load in MSRequest
155  CSearchHelper::ReadSearchRequest(args["fxml"].AsString(),
156  eSerial_Xml,
157  MySearch);
158  // todo: SearchSettings needs to be set or will be overwritten!
159  SearchSettings.Reset(&((*(MySearch.SetRequest().begin()))->SetSettings()));
160  }
161  else {
162  // use command line to set up search settings if no param file
163  SearchSettings.Reset(new CMSSearchSettings);
164  SetSearchSettings(args, SearchSettings);
165  }
166 
168 
169  SetThreadCount(args["nt"].AsInteger());
170 
171  CRef <CSearch> SearchEngine (new CSearch(0));
172  SetsearchThreads().push_back(SearchEngine);
173 
174  //CSearch* SearchEngine = new CSearch();
175 
176  // set up rank scoring
177  if(args["os"]) SearchEngine->SetRankScore() = false;
178  else SearchEngine->SetRankScore() = true;
179  if(args["nrs"]) SearchEngine->SetPoissonOnly() = true;
180  else SearchEngine->SetPoissonOnly() = false;
181 
182  int FileRetVal(1);
183 
184  if(args["fxml"].AsString().size() == 0) {
185  // load in files only if infile specified and not a loaded MSRequest
186  if(SearchSettings->GetInfiles().size() == 1) {
187  FileRetVal =
189  *(SearchSettings->GetInfiles().begin()),
190  &(SearchEngine->SetIterative()));
191  if(FileRetVal == -1) {
192  ERR_POST(Fatal << "omssacl: too many spectra in input file");
193  return 1;
194  }
195  else if(FileRetVal == 1) {
196  ERR_POST(Fatal << "omssacl: unable to read spectrum file -- incorrect file type?");
197  return 1;
198  }
199  }
200  else {
201  ERR_POST(Fatal << "omssacl: input file not given or too many input files given.");
202  return 1;
203  }
204 
205  // place search settings in search object
206  MySearch.SetUpSearchSettings(SearchSettings,
207  SearchEngine->GetIterative());
208  }
209 
210  try {
211  SearchEngine->InitBlast(SearchSettings->GetDb().c_str(),
212  args["umm"]);
213  }
214  catch (const NCBI_NS_STD::exception &e) {
215  ERR_POST(Fatal << "Unable to open blast library " << SearchSettings->GetDb() << " with error:" <<
216  e.what());
217  }
218  catch (...) {
219  ERR_POST(Fatal << "Unable to open blast library " << SearchSettings->GetDb());
220  }
221 
222  // set up the response object
223  if(MySearch.SetResponse().empty()) {
224  CRef <CMSResponse> Response (new CMSResponse);
225  MySearch.SetResponse().push_back(Response);
226  }
227 
228  // Used to be a call to SearchEngine.Search(...)
229  SearchEngine->SetupSearch(*MySearch.SetRequest().begin(),
230  *MySearch.SetResponse().begin(),
231  Modset,
232  SearchSettings,
233  &OMSSACallback);
234 
235  RunSearch(SearchEngine);
236  _TRACE("omssa: search end");
237 
238 
239 #if _DEBUG
240  // read out hits
241  CMSResponse::THitsets::const_iterator iHits;
242  iHits = (*MySearch.SetResponse().begin())->GetHitsets().begin();
243  for(; iHits != (*MySearch.SetResponse().begin())->GetHitsets().end(); iHits++) {
244  CRef< CMSHitSet > HitSet = *iHits;
245  ERR_POST(Info << "Hitset: " << HitSet->GetNumber());
246  if( HitSet-> CanGetError() && HitSet->GetError() ==
248  ERR_POST(Info << "Hitset Empty");
249  continue;
250  }
251  CRef< CMSHits > Hit;
252  CMSHitSet::THits::const_iterator iHit;
253  CMSHits::TPephits::const_iterator iPephit;
254  for(iHit = HitSet->GetHits().begin();
255  iHit != HitSet->GetHits().end(); iHit++) {
256  ERR_POST(Info << (*iHit)->GetPepstring() << ": " << "P = " <<
257  (*iHit)->GetPvalue() << " E = " <<
258  (*iHit)->GetEvalue());
259  for(iPephit = (*iHit)->GetPephits().begin();
260  iPephit != (*iHit)->GetPephits().end();
261  iPephit++) {
262  ERR_POST(Info << ((*iPephit)->CanGetGi()?(*iPephit)->GetGi():ZERO_GI) <<
263  ": " << (*iPephit)->GetStart() << "-" << (*iPephit)->GetStop() <<
264  ":" << (*iPephit)->GetDefline());
265  }
266 
267  }
268  }
269 #endif
270 
271  // Check to see if there is a hitset
272 
273  if(!(*MySearch.SetResponse().begin())->CanGetHitsets()) {
274  ERR_POST(Fatal << "No results found");
275  }
276 
277  CSearchHelper::SaveAnyFile(MySearch,
278  SearchSettings->GetOutfiles(),
279  Modset);
280 
281  } catch (NCBI_NS_STD::exception& e) {
282  ERR_POST(Fatal << "Exception in COMSSA::Run: " << e.what());
283  }
284 
285  return 0;
286 }
287 
288 
289 
CArgDescriptions –.
Definition: ncbiargs.hpp:541
CArgs –.
Definition: ncbiargs.hpp:379
@MSModSpecSet.hpp User-defined methods of the data storage class.
void CreateArrays(void)
creates arrays for the existing set
@MSSearchSettings.hpp User-defined methods of the data storage class.
int SetUpSearchSettings(CRef< CMSSearchSettings > &SearchSettings, bool IsIterative)
take a search settings object, give it an id, and put it in the right place
Definition: MSSearch.cpp:50
void SetThreadCount(int NumThreads)
set up number of threads
Definition: omssaapp.cpp:515
void RunSearch(CRef< CSearch > SearchEngine)
run multithreaded search
Definition: omssaapp.cpp:528
void PrintEnzymes(void)
print out a list of enzymes that can be used in OMSSA
Definition: omssaapp.cpp:89
void PrintMods(CRef< CMSModSpecSet > Modset)
print out a list of modification that can be used in OMSSA
Definition: omssaapp.cpp:69
void PrintIons(void)
print out a list of ions that can be used in OMSSA
Definition: omssaapp.cpp:99
TSearchThreads & SetsearchThreads(void)
return a settable list of search engine threads
Definition: omssaapp.hpp:167
void SetSearchSettings(const CArgs &args, CRef< CMSSearchSettings > Settings)
Set search settings given args.
Definition: omssaapp.cpp:375
virtual int Run()
Run the application.
Definition: omssacl.cpp:106
virtual void AppInit(CArgDescriptions *argDesc)
application specific initialization
Definition: omssacl.cpp:81
static int SaveAnyFile(CMSSearch &MySearch, CMSSearchSettings::TOutfiles OutFiles, CRef< CMSModSpecSet > Modset)
Write out a complete search.
Definition: omssa.cpp:298
static int ReadSearchRequest(const string &Filename, const ESerialDataFormat DataFormat, CMSSearch &MySearch)
Read in an MSRequest.
Definition: omssa.cpp:169
static void ValidateSearchSettings(CRef< CMSSearchSettings > &Settings)
Validates Search Settings.
Definition: omssa.cpp:366
static void CreateSearchSettings(string FileName, CRef< CMSSearchSettings > &Settings)
create search setting object from file or brand new
Definition: omssa.cpp:379
static int LoadAnyFile(CMSSearch &MySearch, CConstRef< CMSInFile > InFile, bool *SearchEngineIterative=0)
Read in any input file.
Definition: omssa.cpp:224
static int ReadModFiles(const string &ModFileName, const string &UserModFileName, const string &Path, CRef< CMSModSpecSet > Modset)
read in modification files.
Definition: omssa.cpp:61
CSearch –.
Definition: Search.hpp:68
bool & SetRankScore(void)
Sets the scoring to use rank statistics.
Definition: omssa.hpp:790
bool & SetIterative(void)
Sets iterate search.
Definition: omssa.hpp:808
const bool GetIterative(void) const
Gets iterate search.
Definition: omssa.hpp:814
int InitBlast(const char *blastdb, bool use_mmap=false)
init blast databases.
Definition: omssa.cpp:429
void SetupSearch(CRef< CMSRequest > MyRequestIn, CRef< CMSResponse > MyResponseIn, CRef< CMSModSpecSet > Modset, CRef< CMSSearchSettings > SettingsIn, TOMSSACallback Callback=0, void *CallbackData=0)
Setup the ms/ms search.
Definition: omssa.cpp:940
bool & SetPoissonOnly(void)
Sets the scoring to use rank statistics only with Poisson.
Definition: omssa.hpp:796
const string & GetProgramExecutablePath(EFollowLinks follow_links=eIgnoreLinks) const
Get the application's executable path.
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
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
#define ZERO_GI
Definition: ncbimisc.hpp:1088
void AddFlag(const string &name, const string &comment, CBoolEnum< EFlagValue > set_value=eFlagHasValueIfSet, TFlags flags=0)
Add description for flag argument.
Definition: ncbiargs.cpp:2459
void SetUsageContext(const string &usage_name, const string &usage_description, bool usage_sort_args=false, SIZE_TYPE usage_width=78)
Set extra info to be used by PrintUsage().
Definition: ncbiargs.cpp:3304
#define _TRACE(message)
Definition: ncbidbg.hpp:122
EDiagSev SetDiagPostLevel(EDiagSev post_sev=eDiag_Error)
Set the threshold severity for posting the messages.
Definition: ncbidiag.cpp:6132
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
@ eDS_Default
Try standard log file (app.name + ".log") in /log/, use stderr on failure.
Definition: ncbidiag.hpp:1790
@ eDiag_Warning
Warning message.
Definition: ncbidiag.hpp:652
void Fatal(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1209
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
@ eSerial_Xml
XML.
Definition: serialdef.hpp:75
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
const TDb & GetDb(void) const
Get the Db member data.
const TInfiles & GetInfiles(void) const
Get the Infiles member data.
TResponse & SetResponse(void)
Assign a value to Response data member.
Definition: MSSearch_.hpp:235
TRequest & SetRequest(void)
Assign a value to Request data member.
Definition: MSSearch_.hpp:210
const TOutfiles & GetOutfiles(void) const
Get the Outfiles member data.
@ eMSHitError_notenuffpeaks
not enough peaks to search
Definition: MSHitError_.hpp:68
const struct ncbi::grid::netcache::search::fields::SIZE size
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines command line argument related classes.
Defines unified interface to application:
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
USING_SCOPE(objects)
static void OMSSACallback(int TotalSeq, int Completed, void *Anything)
progress callback
Definition: omssacl.cpp:100
int main(int argc, const char *argv[])
Definition: omssacl.cpp:92
USING_NCBI_SCOPE
Definition: omssacl.cpp:62
Modified on Fri Sep 20 14:57:50 2024 by modify_doxy.py rev. 669887