Il main è questo
#include <iostream>
#include <fstream>
#include <list>
#include <string>
#include <cmath>
#include "LipidType.h"
using namespace std;
double findinten(string filename, double picco);
void sort(LipidType* &lip,int leng); // insertion sort decrescente
void resiz(LipidType* &lip,int leng,int maxsiz);
int main()
{
LipidType *lipid;
list<double> fraglist;
list<double>::iterator myIt;
string sdfname, namelip, lineflag;
string discard,classe, mod;
ifstream insdf,infrag;
ofstream out;
double frag, fragtemp, mz;
char ch;
int matches;
int maxsize = 20;
cout << "SDF file:";
getline(cin,sdfname);
cout << "Pos or neg(p/n):";
cin >> ch;
insdf.open(sdfname.c_str());
unsigned int len;
len = static_cast<unsigned int>(sdfname.length());
sdfname[len-3] = 't';
sdfname[len-2] = 'x';
sdfname[len-1] = 't';
out.open(sdfname.c_str());
int nlip=0;
lipid = new LipidType[maxsize];
while(insdf>>namelip)
{
if(nlip+1 > maxsize)
resiz(lipid,nlip,maxsize*2);
lipid[nlip].getname(namelip);
for(int i=0; i<20; i++) // ignora un po' di righe inutili
insdf.ignore(1000,'\n');
getline(insdf,lineflag);
size_t found = lineflag.find("FRAGMENT_MATCHES");
while(found == string::npos)
{
getline(insdf,lineflag);
found = lineflag.find("FRAGMENT_MATCHES");
}
// cominciano i frammenti
while(insdf >> frag)
fraglist.push_back(frag);
insdf.clear();
// ricerco matches count
getline(insdf,lineflag);
insdf >> matches;
lipid[nlip].getmatches(matches);
// ricerco picco parente
getline(insdf,lineflag);
found = lineflag.find("MSMS");
while(found == string::npos)
{
getline(insdf,lineflag);
found = lineflag.find("MSMS");
}
for(int i=0; i<3; i++)
insdf >> discard;
insdf >> mz; // picco parente
lipid[nlip].getmz(mz);
insdf >> discard; // legge $$$$
if(ch == 'p')
infrag.open("IN-POS.txt"); //apro file con i frammenti templato
else
infrag.open("IN-NEG.txt");
for(int i=0; i<5; i++)
{
infrag >> discard >> classe >> mod >> fragtemp;
if (namelip.find("LMGP") != string::npos)
if (mod.find("curs") != string::npos)
{
for(myIt=fraglist.begin(); myIt!=fraglist.end(); ++myIt)
if (fabs(*myIt-fragtemp)< 1)
{
lipid[nlip].getall(mod,classe,findinten(sdfname,*myIt),*myIt);
break;
}
}
else
{
for(myIt=fraglist.begin(); myIt!=fraglist.end(); ++myIt)
if (fabs((mz-(*myIt))-fragtemp)<1)
{
lipid[nlip].getall(mod,classe,findinten(sdfname,*myIt),*myIt);
break;
}
}
}
while(infrag)
{
infrag >> discard >> classe >> mod >> fragtemp;
if (mod.find("curs") != string::npos)
{
for(myIt=fraglist.begin(); myIt!=fraglist.end(); ++myIt)
if (fabs(*myIt-fragtemp)< 1)
{
lipid[nlip].getall(mod,classe,findinten(sdfname,*myIt),*myIt);
break;
}
}
else
{
for(myIt=fraglist.begin(); myIt!=fraglist.end(); ++myIt)
if (fabs((mz-(*myIt))-fragtemp)<1)
{
lipid[nlip].getall(mod,classe,findinten(sdfname,*myIt),*myIt);
break;
}
}
}
fraglist.clear();
infrag.close();
nlip++;
}
cout << "Fin qui tutto ok" << endl;
sort(lipid,nlip);
for(int i=0; i<nlip; i++)
out << lipid[i];
out.close();
return 0;
}
double findinten(string filename, double picco)
{
ifstream inn;
string mystr;
string discard;
double varx,vary;
unsigned int len;
len = static_cast<unsigned int>(filename.length());
filename[len-3] = 'C';
filename[len-2] = 'E';
filename[len-1] = 'F';
for(int i=0; i<len; i++)
if(filename[i] == '-')
filename[i] = '.';
inn.open(filename.c_str());
for(int i=0; i<5; i++) // ignora un po' di righe inutili dopo l'intestazione
inn.ignore(1000,'\n'); // relativa a quella d'interesse
mystr = " ";
int volte=0;
while(volte != 2)
{
getline(inn,mystr);
if (mystr.find("<MSPeaks>") != string::npos)
volte++;
}
char dischar;
inn >> discard;
for(int i=0; i<3; i++)
inn >> dischar;
inn >> varx;
while (discard.find("</MSPeaks>") == string::npos)
{
if(fabs(varx-picco)<0.05)
{
inn >> dischar;
for(int i=0; i<3; i++)
inn >> dischar;
inn >> vary;
inn.close();
return vary;
}
else
{
inn.ignore(1000,'\n');
inn >> discard;
for(int i=0; i<3; i++)
inn >> dischar;
inn >> varx;
}
}
inn.close();
return 1;
}
void sort(LipidType* &lip,int leng)
{
int location;
LipidType temp;
for(int i=0;i<leng-1;i++)
{
location=i+1;
temp = lip[location];
while(location>0 && temp>lip[location-1])
{
lip[location] = lip[location-1];
location--;
}
lip[location] = temp;
}
}
void resiz(LipidType* &lip,int leng,int maxsiz)
{
LipidType *temp= new LipidType[maxsiz];
for(int i=0;i<leng;i++)
temp[i]=lip[i];
delete [] lip;
lip = temp;
}
però ti servono i due file di input. Sono un po' lunghetti, te li riporto come testo sul forum o te li mando con uno zip(se mi spieghi come allegare i file su MP mi faresti un piacere )?