NCBI C++ Toolkit Cross Reference

C++/src/algo/ms/omssa/omssacl.cpp


  1 /* $Id: omssacl.cpp 127992 2008-05-19 16:21:50Z lewisg $
  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>
 47 #include <objects/omssa/omssa__.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 
 62 USING_NCBI_SCOPE;
 63 USING_SCOPE(objects);
 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 
 81 void COMSSA::AppInit(CArgDescriptions *argDesc)
 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->SetUsageContext(GetArguments().GetProgramBasename(),
 87                               "Search engine for identifying MS/MS peptide spectra");
 88 }
 89 
 90 
 91 int main(int argc, const char* argv[]) 
 92 {
 93     COMSSA theTestApp;
 94     return theTestApp.AppMain(argc, argv, 0, eDS_Default, 0);
 95 }
 96 
 97 
 98 /** progress callback */
 99 static void OMSSACallback(int TotalSeq, int Completed, void* Anything)
100 {
101     ERR_POST(Info << "Sequence=" << Completed << " Percent=" << (double)Completed/TotalSeq*100.0 <<
102              "%");
103 }
104 
105 int COMSSA::Run()
106 {    
107 
108     try {
109 
110         CArgs args = GetArgs();
111     CRef <CMSModSpecSet> Modset(new CMSModSpecSet);
112 
113     // turn off informational messages if requested
114     if(args["ni"])
115        SetDiagPostLevel(eDiag_Warning);
116 
117     // read in modifications
118     if(CSearchHelper::ReadModFiles(args["mx"].AsString(), args["mux"].AsString(),
119                             GetProgramExecutablePath(), Modset))
120         return 1;
121         Modset->CreateArrays();
122 
123         // print out the modification list
124         if(args["ml"]) {
125             PrintMods(Modset);
126             return 0;
127         }
128 
129         // print out the enzymes list
130         if(args["el"]) {
131             PrintEnzymes();
132             return 0;
133         }
134 
135     // print out the ions list
136     if(args["il"]) {
137         PrintIons();
138         return 0;
139     }
140 
141     CMSSearch MySearch;
142 
143     // which search settings to use
144     CRef <CMSSearchSettings> SearchSettings;
145 
146     // if search settings to be loaded from param file, create and load
147     if(args["pm"].AsString().size() != 0) {
148         SearchSettings.Reset(new CMSSearchSettings);
149         CSearchHelper::CreateSearchSettings(args["pm"].AsString(),
150                                             SearchSettings);
151     }
152     else if (args["fxml"].AsString().size() != 0) {
153         // load in MSRequest
154         CSearchHelper::ReadSearchRequest(args["fxml"].AsString(),
155                                          eSerial_Xml,
156                                          MySearch);
157         // todo: SearchSettings needs to be set or will be overwritten!
158         SearchSettings.Reset(&((*(MySearch.SetRequest().begin()))->SetSettings()));
159     }
160     else {
161         // use command line to set up search settings if no param file
162         SearchSettings.Reset(new CMSSearchSettings);
163         SetSearchSettings(args, SearchSettings);
164     }
165 
166     CSearchHelper::ValidateSearchSettings(SearchSettings);
167 
168         SetThreadCount(args["nt"].AsInteger());
169 
170     CRef <CSearch> SearchEngine (new CSearch(0));
171     SetsearchThreads().push_back(SearchEngine);
172     
173     //CSearch* SearchEngine = new CSearch();
174 
175     // set up rank scoring
176     if(args["os"]) SearchEngine->SetRankScore() = false;
177     else SearchEngine->SetRankScore() = true;
178 
179     int FileRetVal(1);
180 
181     if(args["fxml"].AsString().size() == 0) {
182         // load in files only if infile specified and not a loaded MSRequest
183         if(SearchSettings->GetInfiles().size() == 1) {
184             FileRetVal = 
185                 CSearchHelper::LoadAnyFile(MySearch,
186                                            *(SearchSettings->GetInfiles().begin()),
187                                             &(SearchEngine->SetIterative()));
188             if(FileRetVal == -1) {
189                 ERR_POST(Fatal << "omssacl: too many spectra in input file");
190                 return 1;
191             }
192             else if(FileRetVal == 1) {
193                 ERR_POST(Fatal << "omssacl: unable to read spectrum file -- incorrect file type?");
194                 return 1;
195             }
196         }
197         else {
198             ERR_POST(Fatal << "omssacl: input file not given or too many input files given.");
199             return 1;
200         }
201         
202         // place search settings in search object
203         MySearch.SetUpSearchSettings(SearchSettings, 
204                                      SearchEngine->GetIterative());
205     }
206 
207     try {
208         SearchEngine->InitBlast(SearchSettings->GetDb().c_str(),
209         args["umm"]);
210     }
211     catch (const NCBI_NS_STD::exception &e) {
212         ERR_POST(Fatal << "Unable to open blast library " << SearchSettings->GetDb() << " with error:" <<
213                  e.what());
214     }
215     catch (...) {
216         ERR_POST(Fatal << "Unable to open blast library " << SearchSettings->GetDb());
217     }
218 
219     // set up the response object
220     if(MySearch.SetResponse().empty()) {
221         CRef <CMSResponse> Response (new CMSResponse);
222         MySearch.SetResponse().push_back(Response);
223     }
224 
225     // Used to be a call to SearchEngine.Search(...)
226     SearchEngine->SetupSearch(*MySearch.SetRequest().begin(),
227                               *MySearch.SetResponse().begin(), 
228                               Modset,
229                               SearchSettings,
230                               &OMSSACallback);
231 
232         RunSearch(SearchEngine);
233     _TRACE("omssa: search end");
234     
235 
236 #if _DEBUG
237         // read out hits
238         CMSResponse::THitsets::const_iterator iHits;
239         iHits = (*MySearch.SetResponse().begin())->GetHitsets().begin();
240         for(; iHits != (*MySearch.SetResponse().begin())->GetHitsets().end(); iHits++) {
241             CRef< CMSHitSet > HitSet =  *iHits;
242             ERR_POST(Info << "Hitset: " << HitSet->GetNumber());
243             if( HitSet-> CanGetError() && HitSet->GetError() ==
244                 eMSHitError_notenuffpeaks) {
245                 ERR_POST(Info << "Hitset Empty");
246                 continue;
247             }
248             CRef< CMSHits > Hit;
249             CMSHitSet::THits::const_iterator iHit; 
250             CMSHits::TPephits::const_iterator iPephit;
251             for(iHit = HitSet->GetHits().begin();
252                 iHit != HitSet->GetHits().end(); iHit++) {
253                 ERR_POST(Info << (*iHit)->GetPepstring() << ": " << "P = " << 
254                          (*iHit)->GetPvalue() << " E = " <<
255                          (*iHit)->GetEvalue());    
256                 for(iPephit = (*iHit)->GetPephits().begin();
257                     iPephit != (*iHit)->GetPephits().end();
258                     iPephit++) {
259                     ERR_POST(Info << ((*iPephit)->CanGetGi()?(*iPephit)->GetGi():0) << 
260                      ": " << (*iPephit)->GetStart() << "-" << (*iPephit)->GetStop() << 
261                      ":" << (*iPephit)->GetDefline());
262                 }
263     
264             }
265         }
266 #endif
267 
268         // Check to see if there is a hitset
269 
270         if(!(*MySearch.SetResponse().begin())->CanGetHitsets()) {
271           ERR_POST(Fatal << "No results found");
272         }
273 
274     CSearchHelper::SaveAnyFile(MySearch, 
275                                SearchSettings->GetOutfiles(),
276                                Modset);
277     
278     } catch (NCBI_NS_STD::exception& e) {
279         ERR_POST(Fatal << "Exception in COMSSA::Run: " << e.what());
280     }
281 
282     return 0;
283 }
284 
285 
286 
287 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.