DoubleVectorVector QuanMSMSXMLData::getFormulaPurityCoefficients ( const string& name ) const
{
	DoubleVectorVector dvv;
	StringVector f = getQuanMSMSInfo ( name ).formulae;
	DoubleVector m = getQuanMSMSInfo ( name ).masses;
	for ( int i = 0 ; i < f.size () ; i++ ) {
		DoubleVector dv;
		if ( f [i] != "" ) {
			IsotopePeakStats ips ( f [i], 1 );
			int index = ips.getProbabilityIndexForMass ( m [i] );
			if ( index >= 2 ) dv.push_back ( ips.getProbability ( index - 2 ) );
			else dv.push_back ( 0.0 );
			if ( index >= 1 ) dv.push_back ( ips.getProbability ( index - 1 ) );
			else dv.push_back ( 0.0 );
			dv.push_back ( ips.getProbability ( index + 1 ) );
			dv.push_back ( ips.getProbability ( index + 2 ) );
		}
		else {									// No formulae so assume no correction
			for ( int j = 0 ; j < 4 ; j++ ) {
				dv.push_back ( 0.0 );
			}
		}
		dvv.push_back ( dv );
	}
	return dvv;
}
Beispiel #2
0
pair<DoubleVectorVector,IntVector> readJF(string filename) {
  igzstream is; is.open(filename.c_str());

  if(!is.good()) {
    ERR << "Reading from " << filename << endl;
    exit(20);
  }
  
  DoubleVectorVector resultData;
  IntVector resultClasses;
  int maxCls;
  uint dim;
  int cls=0;
  DoubleVector *tmpDblVec;
  if(is.good() && is) {
    is >> maxCls >> dim;
    while(cls != -1) {
      double tmpDbl;
      tmpDblVec=new DoubleVector(dim);
      is >> cls;
      if(cls !=-1) {
        for(uint i=0;i<dim;++i) {
          is >> tmpDbl;
          (*tmpDblVec)[i]=tmpDbl;
        }
        resultClasses.push_back(cls);
        resultData.push_back(tmpDblVec);
      }
    }
    is.close();
  }  
ResultVector cluster(vector<LocalFeatures*> &locfeat, bool clusterWithPositions, string splitMode, uint maxSplit, uint stopWithNClusters, string disturbMode, string poolMode, uint dontSplitBelow, uint iterationsBetweenSplits, uint minObservationsPerCluster, double epsilon, string distanceMaker, string saveModelTo, bool saveBeforeSplits, string loadModelFrom)
{

  BaseClusterer *clusterer = new EM();

  if(loadModelFrom!="")
  {
    clusterer->loadModel(loadModelFrom);
  }
  setupClusterer(dynamic_cast<EM*>(clusterer), splitMode, maxSplit, stopWithNClusters, disturbMode, poolMode, dontSplitBelow,
                 iterationsBetweenSplits, minObservationsPerCluster, epsilon, distanceMaker, saveBeforeSplits);


  ResultVector clusterinformation;

  if (clusterWithPositions)
  {
    DBG(10) << "clustering with position information included" << endl;
  }

  DoubleVectorVector localFeaturesData;
  for (uint j = 0; j < locfeat.size(); j++)
  {
    LocalFeatures* localFeatures = locfeat[j];
    int xSize = localFeatures->imageSizeX();
    int ySize = localFeatures->imageSizeY();
    for (uint i = 0; i < localFeatures->numberOfFeatures(); i++)
    {
      DoubleVector* lfvector = &((*localFeatures)[i]);
      if (clusterWithPositions)
      {
        pair<double, double> pos = localFeatures->relativePosition(i);
        lfvector->push_back((double) localFeatures->position(i).x / (double) xSize);
        lfvector->push_back((double) localFeatures->position(i).y / (double) ySize);
      }
      localFeaturesData.push_back( lfvector );
    }
  }


  if(saveModelTo!="")
  {
    dynamic_cast<EM*>(clusterer)->run(localFeaturesData, clusterinformation, saveModelTo);
    clusterer->saveModel(saveModelTo);
  }
  else
  {
    clusterer->run(localFeaturesData, clusterinformation);
  }

  delete clusterer;
  return clusterinformation;
}
static void initialiseIndexScore ()
{
	int numEntries;
	char* info = getFileInfo ( MsparamsDir::instance ().getParamPath ( "indicies.txt" ), '>', 1, true, &numEntries );

	for ( int i = 0 ; i < numEntries ; i++ ) {
		names.push_back ( ( i == 0 ) ? strtok ( info, "\n" ) : strtok ( NULL, "\n" ) );
		DoubleVector dv (52);
		indexV.push_back ( dv );
		fill ( dv.begin (), dv.end (), 0.0 );
		for ( ; ; ) {
			char aa;
			double value;
			char* line = strtok ( NULL, "\n" );

			if ( !strcmp ( line, ">" ) ) break;
			sscanf ( line, "%c %lf", &aa, &value );
			indexV [i][aa-'A'] = value;
		}
	}
	initialised = true;
}