Beispiel #1
0
//#ifdef _MSC_VER 
//#ifndef MSSINGLESCAN_MAIN
//int mssinglescan_main(int argc, char * argv[] ) {
//#else
//int main(int argc, char *argv[]){
//#endif
//#else
int main(int argc, char *argv[]){
//#endif


	//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);
  };

	r.readFile(argv[2],s,atoi(argv[1]));
  if(s.getScanNumber()==0) exit(-1);
  printf("S\t%d\t%d\t%.*f\n",s.getScanNumber(),s.getScanNumber(),2,s.getMZ());
	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,2,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;

};
bool CPeptideDatabase::readMascot(char* mascotFile, char* dataFile){
  MSReader r;
  MascotParser p;
  Spectrum s;
  MascotLite m;

  int i;
  int percent=0;

  p.clear();
  p.readText(mascotFile);

  if(p.isDistiller()){
    cout << mascotFile << "\t" << p.size() << " peptides from Distiller, no need for RT lookup." << endl;
  } else if(p.hasRTime()){
    cout << mascotFile << "\t" << p.size() << " peptides have RT already, no need for lookup." << endl;
  } else {
    cout << mascotFile << "\tLooking up retention times for " << p.size() << " Mascot peptides..." << endl;
    cout << percent;
    r.readFile(dataFile,s);
  }

  for(i=0;i<p.size();i++){
    if(p.isDistiller()||p.hasRTime()){ 
      m.rTime=p[i].rTime;
    } else {
      if( (int)i*100/p.size() > percent){
        percent=(int)i*100/p.size();
        cout << "\b\b\b" << percent;
      }

      r.readFile(NULL,s,p[i].scanNum);
      if(s.getScanNumber()==0){
        cout << "Scan not found. Please check that correct data file is used. Stopping Mascot parsing." << endl;
        return false;
      }
      m.rTime=s.getRTime();
    }
    m.charge=p[i].charge;
    m.fileID=fileID;
    m.monoMass=p[i].zeroMass;
    m.scanNum=p[i].scanNum;
    strcpy(m.peptide,p[i].sequence_Long);
    strcpy(m.protein,p[i].gene);
    mascot.push_back(m);
  }
  cout << "  Done!" << endl;

  fileID++;

  return true;
}
Beispiel #3
0
bool CNoiseReduction::ScanAverage(Spectrum& sp, char* file, int width, float cutoff){
  
  Spectrum ts;
  Spectrum ps=sp;
  MSReader r;
 
  int i;
  int j;
  int k;
  int widthCount=0;
  int numScans=1;
  double dif;
  double prec;
  double dt;
  double c=CParam(ps,3);

  bool bLeft=true;
  int posLeft=ps.getScanNumber()-1;
  int posRight=ps.getScanNumber()+1;
  char cFilter1[256];
  char cFilter2[256];

  ps.getRawFilter(cFilter1,256);

  while(widthCount<(width*2)){

    //Alternate looking left and right
    if(bLeft){
      bLeft=false;
      widthCount++;
      while(posLeft>0){
        r.readFile(file,ts,posLeft);
        if(ts.getScanNumber()==0) break;
        ts.getRawFilter(cFilter2,256);
        if(strcmp(cFilter1,cFilter2)==0) break;
        posLeft--;
      }
    } else {
      bLeft=true;
      widthCount++;
      while(true){
        r.readFile(file,ts,posRight);
        if(ts.getScanNumber()==0) break;
        ts.getRawFilter(cFilter2,256);
        if(strcmp(cFilter1,cFilter2)==0) break;
        posRight++;
      }
    }
    if(ts.getScanNumber()==0) continue;

    numScans++;

    //Match peaks between pivot scan and temp scan
    k=0;
    for(i=0;i<ps.size();i++){
      dif=100000.0;
      prec = c * ps.at(i).mz * ps.at(i).mz / 2;

      for(j=k;j<ts.size();j++){
        dt=fabs(ps.at(i).mz-ts.at(j).mz);
        if(dt<=dif) {
          if(dt<prec) {
            ps.at(i).intensity+=ts.at(j).intensity;
            ts.at(j).mz=-1.0;
            k=j+1;
            break;
          }
          dif=dt;
        } else {
          k=j-1;
          break;
        }
      }
    }

    //Add unmatched peaks from temp scan
    for(i=0;i<ts.size();i++){
      if(ts.at(i).mz>-1.0) ps.add(ts.at(i));
    }

    //Sort pivot scan peaks for fast traversal against next temp scan
    ps.sortMZ();

  }

  //Average points and apply cutoff
  sp.clear();
  for(i=0;i<ps.size();i++) {
    ps.at(i).intensity/=numScans;
    if(ps.at(i).intensity>=cutoff) sp.add(ps.at(i));
  }

  sp.setScanNumber(ps.getScanNumber());
  sp.setScanNumber(ps.getScanNumber(true),true);
  sp.setRTime(ps.getRTime());

  return true;
}
// Function reads in the spectra from the data stored for each PSMClass object
void PepXMLClass::readInSpectra() {
	string curSpectrumFilePath;

	deque<PSMClass>::iterator curPSM;
        SpecStruct *spec = NULL;
        bool status;
        string spectrumFileName;
        int scanNum;
        int ctr = 0;
        int N = (signed) PSMvec->size();
        
        if(g_ext == "mgf") {
            parseMGF();
            return;
        }
        
        // mstoolkit to read MS2 spectra
        MSReader *reader = new MSReader();
        reader->setFilter(MS2);

       // mstoolkit spectrum object
       Spectrum *S = NULL;

	// Extract from each PSM, it's parent spectrum file and scan number
	for(curPSM = PSMvec->begin(); curPSM != PSMvec->end(); curPSM++) {
            spectrumFileName = curPSM->getSpectrumFileName();
            scanNum = curPSM->getScanNumber();
            
            
            // code to get the full path to the input spectrum file
            filesystem::path curFile( spectrumFileName.c_str() );
            filesystem::path spectral_dir( g_srcDir.c_str() );
            filesystem::path curFilePath( spectral_dir/curFile );
            curSpectrumFilePath = curFilePath.file_string();

            // if the source file is not located, drop the spectrum
            if( !boost::filesystem::exists(curSpectrumFilePath) ) {
                curPSM = PSMvec->erase(curPSM);
                continue;
            }
            
            
            // Read the spectrum for 'scanNum' into 'S'
            S = new Spectrum();
            status = reader->readFile(curSpectrumFilePath.c_str(), *S, scanNum);
            if(S->getScanNumber() == 0) {
                cerr << "Failed to get " << curSpectrumFilePath.c_str() << " scan#: " << scanNum << endl;
                exit(0);
            }
            
            spec = new SpecStruct();
            for(int j = 0; j < S->size(); j++) {
                spec->mz.push_back( S->at(j).mz );
                spec->intensity.push_back( S->at(j).intensity );
            }
            delete(S); S = NULL;
            
            // Assign the data in 'S' to curPSM
            curPSM->recordSpectrum(*spec);
            delete(spec); spec = NULL;
            ctr++;
            
            printProgress("Reading in spectra (please be patient)...", ctr, N);
	}
       delete(reader); reader = NULL;
       cerr << endl; // prettier stderr
}