jaybjenjs / mstoolkit

Automatically exported from code.google.com/p/mstoolkit
0 stars 0 forks source link

Using mstoolkit #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi.

This isn't an issue so much as a request for example code.
I just want to use mstoolkit to read spectra from mzXML, mzML and the other 
open XML file formats. 

Ideally I want a function where I provide the mzXML file name and a scan number 
(or index) and get back an STL map of the spectra.

So far I can't even open the file for reading.

This is my program so far. 
/*************************************************************************/
#include <iostream>
#include <string>
#include <map>

#include "MSReader.h"

using namespace std;

int main(int argc, char* argv[]) {

        if(argc < 2) {
                cerr << "\nUSAGE: mzMLreaderCPP.exe scan mzXML\n\n";
                return 0;
        }

        int scan = atoi(argv[1]); // index 69, scan 1260
        string mzXML_file = argv[2];

        cerr << "\nInput file: " << mzXML_file << "\nScan number: " << scan << endl << endl;

        // Open file for reading
        MSReader *reader = new MSReader();

        int status = reader->openFile(mzXML_file.c_str(), false);
        if(status == 1) {
                cerr << "Opened " << mzXML_file << endl;
        }

        delete(reader);

        return 0;
}
/***********************************************************************/

Any and all help would be greatly appreciated.

Thanks,
Damian

Original issue reported on code.google.com by damian.f...@gmail.com on 28 Jul 2013 at 2:35

GoogleCodeExporter commented 9 years ago
Okay. I have gotten a little further along.
This is my new main function. My current problem is that I cannot open the 
mzXML file for reading. No obvious reason why, but the code at least compiles 
and doesn't give errors. Any suggestions?
/******************************************************************************/
int main(int argc, char* argv[]) {

        if(argc < 2) {
                cerr << "\nUSAGE: mzMLreaderCPP.exe scan_index mzXML\n\n";
                return 0;
        }

        int scan = atoi(argv[1]); // provide scan number to retrieve from the mzXML file
        string mzXML_file = argv[2];

        cerr << "\nInput file: " << mzXML_file << "\nScan index: " << scan << endl << endl;

        Spectrum S;
        MSReader *reader = new MSReader();

        //bool status = reader->readFile(mzXML_file.c_str(), S, scan);
        bool status = reader->readFile(mzXML_file.c_str(), S);
        if(status) {
                cerr << "Opened " << mzXML_file << endl;
        }
        else cerr << "Unable to open " << mzXML_file << endl;

        delete(reader);

        return 0;
}

/******************************************************************************/

Original comment by damian.f...@gmail.com on 29 Jul 2013 at 1:34

GoogleCodeExporter commented 9 years ago
Hi Damian,
You're quite right that example code is needed. I only have a few minutes right 
now, so I'll copy a quick program that I usually use as an example. If I find 
time later, I will post the modifications to your code to get it to work. 
Pretty much you have it figured out, you're just stuck on some of the 
deprecated functions that I have to carry along for other people.
Cheers,
Mike

#include <iostream>
#include <iomanip>
#include "MSToolkitTypes.h"
#include "MSReader.h"
#include "MSObject.h"
#include "Spectrum.h"

using namespace std;

int main(int argc, char *argv[]){

  //Here are all the variable we are going to need
  MSReader r;
  Spectrum s;
  int j;

  if(argc==1){
    printf("DESCRIPTION: Reads an MS/MS spectrum from any MSToolkit supported file type and outputs to screen in MS2 format.\n\n");
    printf("USAGE: MSSingleScan [scan number] [file]\n");
    exit(0);
  }

  //Adding filters are necessary. At least one scan type must be specified.
  r.setFilter(MS1);
  r.addFilter(MS2);

  //This is where you grab a file. Specify the filename (or NULL to read from
  //the same file as the last read), a spectrum object, and (optionally) a scan
  //number. If you omit the scan number, the next scan after the last read is
  //extracted from the file.
  r.readFile(argv[2],s,atoi(argv[1]));

  //Your scan number will equal 0 if loading failed. Possible reason for failure
  //is end of file or requesting a non-existent scan number.
  if(s.getScanNumber()==0) exit(-1);

  printf("S\t%d\t%d",s.getScanNumber(),s.getScanNumber());

  for(j=0;j<s.sizeMZ();j++){
    printf("\t%.*lf",4,s.getMZ(j));
  }
  printf("\n");
  if(s.getRTime()>0) printf("I\tRTime\t%.*f\n",4,s.getRTime());
  for(j=0;j<s.sizeZ();j++){
    printf("Z\t%d\t%.*f\n",s.atZ(j).z,6,s.atZ(j).mz);
  }

  for(j=0;j<s.size();j++){
    printf("%.4f %.4f\n",s.at(j).mz,s.at(j).intensity); 
  }

  return 0;

}

Original comment by mhoopm...@systemsbiology.org on 29 Jul 2013 at 5:15

GoogleCodeExporter commented 9 years ago
I'll handle this one.

Original comment by mhoopm...@systemsbiology.org on 12 Aug 2014 at 4:16

GoogleCodeExporter commented 9 years ago

Original comment by mhoopm...@systemsbiology.org on 12 Aug 2014 at 4:16