public
Created

  • Download Gist
test.cpp
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <stdlib.h>
 
using namespace std;
 
int main(int argc, char** argv) {
if(argc != 2) {
cout << "Usage: ./parse <filename.txt>" << endl;
return 255;
}
 
string line;
ifstream f(argv[1]);
if(!f.is_open()) {
cout << "The file you specified could not be read." << endl;
return 1;
}
 
while(!f.eof()) {
getline(f, line);
if(line == "" || line[0] == '#') continue;
 
char *ptr, *buf;
buf = new char[line.size() + 1];
strcpy(buf, line.c_str());
 
// Peptide values
double mass;
char* sequence;
int numK;
int numPTS;
int numM;
set<int> parents;
 
mass = strtod(strtok(buf, " "), NULL);
sequence = strtok(NULL, " ");
numK = strtol(strtok(NULL, " "), NULL, 10);
numPTS = strtol(strtok(NULL, " "), NULL, 10);
numM = strtol(strtok(NULL, " "), NULL, 10);
while(ptr = strtok(NULL, " "))
parents.insert(strtol(ptr, NULL, 10));
 
//cout << "mass: " << mass << endl
// << "sequence: " << sequence << endl
// << "numK: " << numK << endl
// << "numPTS: " << numPTS << endl
// << "numM: " << numM << endl
// << "parents:" << endl;
 
//set<int>::iterator it;
//for(it = parents.begin(); it != parents.end(); it++)
// cout << "\t- " << *it << endl;
}
f.close();
 
return 0;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.