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/omssa2pepXML.cpp |
source navigation diff markup identifier search freetext search file search |
1 /* $Id: omssa2pepXML.cpp 139701 2008-09-08 16:08:42Z slottad $ 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 * Authors: Douglas Slotta 27 * 28 * File Description: 29 * Command line utility to convert OMSSA output to the PepXML format 30 * 31 */ 32 33 #include <ncbi_pch.hpp> 34 #include <corelib/ncbiapp.hpp> 35 #include <corelib/ncbienv.hpp> 36 #include <corelib/ncbiargs.hpp> 37 #include <corelib/ncbifile.hpp> 38 #include <serial/serial.hpp> 39 #include <serial/objistr.hpp> 40 #include <serial/objostr.hpp> 41 #include <objects/omssa/omssa__.hpp> 42 #include <util/compress/bzip2.hpp> 43 44 #include "omssa.hpp" 45 #include "pepxml.hpp" 46 47 USING_SCOPE(ncbi); 48 USING_SCOPE(objects); 49 USING_SCOPE(omssa); 50 51 // Helper function for debugging, might need this again in the future 52 // void PrintModInfo(CRef <CMSModSpecSet> Modset) { 53 // for (unsigned int modNum = 0; modNum < Modset->Get().size(); modNum++) { 54 // cout << MSSCALE2DBL(Modset->GetModMass(modNum)) << "\t"; 55 // cout << MSSCALE2DBL(Modset->GetNeutralLoss(modNum)) << "\t"; 56 // cout << Modset->GetModNumChars(modNum) << "\t"; 57 // for (int i=0; i< Modset->GetModNumChars(modNum); i++) { 58 // cout << ConvertAA(Modset->GetModChar(modNum, i)) << " "; 59 // cout << MonoMass[static_cast <int> (Modset->GetModChar(modNum,i))] << " "; 60 // } 61 // cout << "\t" << Modset->GetModType(modNum) << "\t"; 62 // cout << Modset->GetModName(modNum) << endl; 63 // } 64 // } 65 66 ///////////////////////////////////////////////////////////////////////////// 67 // COmssa2pepxmlApplication:: 68 69 70 class COmssa2pepxmlApplication : public CNcbiApplication 71 { 72 public: 73 COmssa2pepxmlApplication(); 74 private: 75 virtual void Init(void); 76 virtual int Run(void); 77 virtual void Exit(void); 78 }; 79 80 81 COmssa2pepxmlApplication::COmssa2pepxmlApplication() { 82 SetVersion(CVersionInfo(2, 1, 4)); 83 } 84 85 ///////////////////////////////////////////////////////////////////////////// 86 // Init test for all different types of arguments 87 void COmssa2pepxmlApplication::Init(void) 88 { 89 // Create command-line argument descriptions class 90 auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); 91 arg_desc->PrintUsageIfNoArgs(); 92 93 // Specify USAGE context 94 arg_desc->SetUsageContext(GetArguments().GetProgramBasename(), 95 "Convert OMSSA ASN.1 and XML output files to PepXML"); 96 97 // Describe the expected command-line arguments 98 arg_desc->AddFlag("xml", "Input file is XML"); 99 arg_desc->AddFlag("bz2", "Input file is bzipped XML"); 100 arg_desc->AddFlag("asn", "Input file is ASN.1"); 101 arg_desc->AddFlag("asntext", "Input file is ASN.1 text"); 102 103 arg_desc->AddOptionalKey("o", "outfile", 104 "filename for pepXML formatted search results", 105 CArgDescriptions::eString); 106 107 arg_desc->AddPositional 108 ("filename", 109 "The name of the XML file to load", 110 CArgDescriptions::eString); 111 112 // Setup arg.descriptions for this application 113 SetupArgDescriptions(arg_desc.release()); 114 } 115 116 117 118 ///////////////////////////////////////////////////////////////////////////// 119 // Run test (printout arguments obtained from command-line) 120 int COmssa2pepxmlApplication::Run ( void ) 121 { 122 CMSSearch inOMSSA; 123 CPepXML outPepXML; 124 ESerialDataFormat format = eSerial_Xml; // assume xml 125 126 // Get arguments 127 const CArgs& args = GetArgs(); 128 129 string filename = args["filename"].AsString(); 130 CFile file(filename); 131 132 string fullpath, path, base, ext; 133 if (CFile::IsAbsolutePath(file.GetPath())) { 134 fullpath = file.GetPath(); 135 } else { 136 fullpath = CFile::CreateAbsolutePath(file.GetPath()); 137 } 138 CFile::SplitPath(fullpath, &path, &base, &ext); 139 string basename = path + base; 140 string newname; 141 if (args["o"].HasValue()) { 142 newname = args["o"].AsString(); 143 } else { 144 newname = basename + ".pep.xml"; 145 } 146 147 // figure out input file type 148 bool notSet = true; 149 if (args["xml"] || args["bz2"]) { 150 format = eSerial_Xml; 151 notSet = false; 152 } else if (args["asn"]) { 153 format = eSerial_AsnBinary; 154 notSet = false; 155 } else if (args["asntext"]) { 156 format = eSerial_AsnText; 157 notSet = false; 158 } 159 160 if (notSet) { // Not explict, maybe extension gives us a clue? 161 if (ext == ".oms") { 162 format = eSerial_AsnBinary; 163 } else if (ext == ".omx") { 164 format = eSerial_Xml; 165 } else if (ext == ".omt") { 166 format = eSerial_AsnText; 167 } 168 } 169 cout << "Reading " << filename << " as "; 170 switch (format) { 171 case eSerial_AsnBinary: 172 cout << "ASN" << endl; break; 173 case eSerial_Xml: 174 cout << "XML" << endl; break; 175 case eSerial_AsnText: 176 cout << "ASN text" << endl; break; 177 default: 178 cout << "Unable to determine type of file" << endl; 179 return 0; 180 } 181 182 CSearchHelper::ReadCompleteSearch(filename, format, args["bz2"], inOMSSA); 183 184 if (!inOMSSA.CanGetRequest()) { 185 cout << "Sorry, this file cannot be converted." << endl; 186 cout << "The original search needs to have been executed with the '-w' flag set." << endl; 187 cout << "The search settings are not availiable in this file. Aborting" << endl; 188 return 0; 189 } 190 191 CRef <CMSModSpecSet> Modset(new CMSModSpecSet); 192 CSearchHelper::ReadModFiles("mods.xml","usermods.xml",GetProgramExecutablePath(), Modset); 193 Modset->CreateArrays(); 194 //PrintModInfo(Modset); 195 196 outPepXML.ConvertFromOMSSA(inOMSSA, Modset, basename, newname); 197 198 //CNcbiOfstream out(newname.c_str()); 199 //out << MSerial_Xml << outPepXML; 200 201 auto_ptr<CObjectOStream> oStream(CObjectOStream::Open(newname, eSerial_Xml)); 202 CObjectOStreamXml *xml_out = dynamic_cast <CObjectOStreamXml *> (oStream.get()); 203 xml_out->SetDefaultSchemaNamespace("http://regis-web.systemsbiology.net/pepXML"); 204 xml_out->SetReferenceSchema(); 205 *xml_out << outPepXML; 206 207 return 0; 208 } 209 210 211 ///////////////////////////////////////////////////////////////////////////// 212 // Cleanup 213 214 215 void COmssa2pepxmlApplication::Exit ( void ) 216 { 217 SetDiagStream ( 0 ); 218 } 219 220 221 ///////////////////////////////////////////////////////////////////////////// 222 // MAIN 223 224 225 int main ( int argc, const char* argv[] ) 226 { 227 // Execute main application function 228 return COmssa2pepxmlApplication().AppMain ( argc, argv, 0, eDS_Default, 0 ); 229 } 230
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |