NCBI Home IEB Home C++ Toolkit docs C Toolkit source browser C Toolkit source browser (2) |
NCBI C++ Toolkit Cross ReferenceC++/src/algo/ms/omssa/omssamerge.cpp |
source navigation diff markup identifier search freetext search file search |
1 /* 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 * Author: Lewis Y. Geer 27 * 28 * File Description: 29 * program for splitting omssa files 30 * 31 * 32 * =========================================================================== 33 */ 34 35 #include <ncbi_pch.hpp> 36 #include <corelib/ncbistl.hpp> 37 #include <corelib/ncbiargs.hpp> 38 #include <corelib/ncbiapp.hpp> 39 #include <corelib/ncbienv.hpp> 40 #include <corelib/ncbistre.hpp> 41 #include <corelib/ncbifile.hpp> 42 #include <connect/ncbi_memory_connector.h> 43 #include <connect/ncbi_conn_stream.hpp> 44 #include <serial/serial.hpp> 45 #include <serial/objistrasn.hpp> 46 #include <serial/objistrasnb.hpp> 47 #include <serial/objostrasn.hpp> 48 #include <serial/objostrasnb.hpp> 49 #include <serial/iterator.hpp> 50 #include <serial/objostrxml.hpp> 51 #include <objects/omssa/omssa__.hpp> 52 #include <util/compress/bzip2.hpp> 53 54 #include "omssa.hpp" 55 #include "msmerge.hpp" 56 57 #include <fstream> 58 #include <string> 59 #include <list> 60 61 62 USING_NCBI_SCOPE; 63 USING_SCOPE(objects); 64 USING_SCOPE(omssa); 65 66 ///////////////////////////////////////////////////////////////////////////// 67 // 68 // COMSSAMerge 69 // 70 // Main application 71 // 72 73 class COMSSAMerge : public CNcbiApplication { 74 public: 75 COMSSAMerge(); 76 private: 77 virtual int Run(); 78 virtual void Init(); 79 80 }; 81 82 COMSSAMerge::COMSSAMerge() 83 { 84 SetVersion(CVersionInfo(2, 1, 4)); 85 } 86 87 88 89 90 91 void COMSSAMerge::Init() 92 { 93 94 auto_ptr<CArgDescriptions> argDesc(new CArgDescriptions); 95 96 argDesc->AddDefaultKey("i", "infiles", 97 "file containing list of input files on separate lines", 98 CArgDescriptions::eString, 99 ""); 100 101 argDesc->AddFlag("sw", "output search results without spectra"); 102 103 argDesc->AddFlag("it", "input as text asn.1 formatted search results"); 104 argDesc->AddFlag("ib", "input as binary asn.1 formatted search results"); 105 argDesc->AddFlag("ix", "input as xml formatted search results"); 106 argDesc->AddFlag("ibz2", "input as xml formatted search results compressed by bzip2"); 107 108 argDesc->AddPositional("o", "output file name", CArgDescriptions::eString); 109 110 111 argDesc->AddFlag("ot", "output as text asn.1 formatted search results"); 112 argDesc->AddFlag("ob", "output as binary asn.1 formatted search results"); 113 argDesc->AddFlag("ox", "output as xml formatted search results"); 114 argDesc->AddFlag("obz2", "output as xml formatted search results compressed by bzip2"); 115 116 argDesc->AddExtra(0,10000, "input file names", CArgDescriptions::eString); 117 118 119 SetupArgDescriptions(argDesc.release()); 120 121 // allow info posts to be seen 122 SetDiagPostLevel(eDiag_Info); 123 } 124 125 int main(int argc, const char* argv[]) 126 { 127 COMSSAMerge theTestApp; 128 return theTestApp.AppMain(argc, argv, 0, eDS_Default, 0); 129 } 130 131 132 133 134 int COMSSAMerge::Run() 135 { 136 137 try { 138 139 CArgs args = GetArgs(); 140 141 142 CRef <COMSSASearch> MySearch(new COMSSASearch); 143 144 ESerialDataFormat InFileType(eSerial_Xml), OutFileType(eSerial_Xml); 145 146 bool obz2(false); // output bzip2 compressed? 147 bool ibz2(false); // input bzip2 compressed? 148 149 if(args["ox"]) OutFileType = eSerial_Xml; 150 else if(args["ob"]) OutFileType = eSerial_AsnBinary; 151 else if(args["ot"]) OutFileType = eSerial_AsnText; 152 else if(args["obz2"]) { 153 OutFileType = eSerial_Xml; 154 obz2 = true; 155 } 156 else ERR_POST(Fatal << "output file type not given"); 157 158 if(args["ix"]) InFileType = eSerial_Xml; 159 else if(args["ib"]) InFileType = eSerial_AsnBinary; 160 else if(args["it"]) InFileType = eSerial_AsnText; 161 else if(args["ibz2"]) { 162 InFileType = eSerial_Xml; 163 ibz2 = true; 164 } 165 else ERR_POST(Fatal << "input file type not given"); 166 167 168 // loop thru input files 169 if ( args["i"].AsString() != "") { 170 ifstream is(args["i"].AsString().c_str()); 171 bool Begin(true); 172 if(!is) 173 ERR_POST(Fatal << "unable to open input file list " << args["i"].AsString()); 174 while(!is.eof()) { 175 string iFileName; 176 NcbiGetline(is, iFileName, "\x0d\x0a"); 177 if(iFileName == "" || is.eof()) continue; 178 try { 179 CRef <COMSSASearch> InSearch(new COMSSASearch); 180 CSearchHelper::ReadCompleteSearch(iFileName, InFileType, ibz2, *InSearch); 181 // InSearch->ReadCompleteSearch(iFileName, InFileType, ibz2); 182 if(Begin) { 183 Begin = false; 184 MySearch->CopyCMSSearch(InSearch); 185 } 186 else { 187 // add 188 MySearch->AppendSearch(InSearch); 189 } 190 } 191 catch(CException& e) { 192 ERR_POST(Fatal << "exception: " << e.what()); 193 return 1; 194 } 195 } 196 } 197 else if ( args.GetNExtra() ) { 198 for (size_t extra = 1; extra <= args.GetNExtra(); extra++) { 199 CRef <COMSSASearch> InSearch(new COMSSASearch); 200 CSearchHelper::ReadCompleteSearch(args[extra].AsString(), InFileType, ibz2, *InSearch); 201 //InSearch->ReadCompleteSearch(args[extra].AsString(), InFileType, ibz2); 202 try { 203 if(extra == 1) { 204 // copy 205 MySearch->CopyCMSSearch(InSearch); 206 } 207 else { 208 // add 209 MySearch->AppendSearch(InSearch); 210 } 211 } 212 catch(CException& e) { 213 ERR_POST(Fatal << "exception: " << e.what()); 214 return 1; 215 } 216 } 217 } 218 219 // write out the new search 220 221 auto_ptr <CNcbiOfstream> raw_out; 222 auto_ptr <CCompressionOStream> compress_out; 223 auto_ptr <CObjectOStream> txt_out; 224 225 if( obz2 ) { 226 raw_out.reset(new CNcbiOfstream(args["o"].AsString().c_str())); 227 compress_out.reset( new CCompressionOStream (*raw_out, 228 new CBZip2StreamCompressor(), 229 CCompressionStream::fOwnProcessor)); 230 txt_out.reset(CObjectOStream::Open(OutFileType, *compress_out)); 231 } 232 else { 233 txt_out.reset(CObjectOStream::Open(args["o"].AsString().c_str(), OutFileType)); 234 } 235 236 237 // auto_ptr <CObjectOStream> txt_out( 238 // CObjectOStream::Open(args["o"].AsString(), OutFileType)); 239 240 if(txt_out.get()) { 241 SetUpOutputFile(txt_out.get(), OutFileType); 242 if (args["sw"]) { 243 txt_out->Write(ObjectInfo(*(*MySearch->SetResponse().begin()))); 244 } 245 else { 246 txt_out->Write(ObjectInfo(*MySearch)); 247 } 248 txt_out->Flush(); 249 txt_out->Close(); 250 } 251 252 253 } catch (NCBI_NS_STD::exception& e) { 254 ERR_POST(Fatal << "Exception in COMSSAMerge::Run: " << e.what()); 255 } 256 257 return 0; 258 } 259 260
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |