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;
}
Exemple #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;
}
void QuantitationRatio::printDelimitedLine2 ( ostream& os, const DoubleVectorVector& dvv, DoubleVectorVectorSizeType peakNumber ) const
{
	for ( int i = 0 ; i < dvv.size () ; i++ ) {
		if ( ok [i][peakNumber] ) delimitedCell ( os, dvv [i][peakNumber], 0 );
		else delimitedEmptyCell ( os );
	}
}
void QuantitationRatio::printHTMLLine2 ( ostream& os, const DoubleVectorVector& dvv, DoubleVectorVectorSizeType peakNumber, const string& styleID ) const
{
	for ( int i = 0 ; i < dvv.size () ; i++ ) {
		if ( ok [i][peakNumber] ) tableCell ( os, dvv [i][peakNumber], 0, false, styleID );
		else tableEmptyCell ( os, styleID );
	}
}
void QuantitationRatio::printDelimitedLine4 ( ostream& os, const DoubleVectorVector& ratio, const CharVectorVector& ratioType, DoubleVectorVectorSizeType peakNumber ) const
{
	for ( int i = 0 ; i < ratio.size () ; i++ ) {
		if ( ok [0][peakNumber] && ok [i+1][peakNumber] && quanPep )
			printDelimitedRatio ( os, ratio [i][peakNumber], ratioType [i][peakNumber] );
		else
			delimitedEmptyCell ( os );
	}
}
void QuantitationRatio::printDelimitedLine3 ( ostream& os, const DoubleVectorVector& dvv, DoubleVectorVectorSizeType peakNumber ) const
{
	for ( int i = 0 ; i < dvv.size () ; i++ ) {
		if ( ok [0][peakNumber] && ok [i+1][peakNumber] && quanPep )
			delimitedCellSigFig ( os, dvv [i][peakNumber], 4 );
		else
			delimitedEmptyCell ( os );
	}
}
void QuantitationRatio::printHTMLLine4 ( ostream& os, const DoubleVectorVector& ratio, const CharVectorVector& ratioType, DoubleVectorVectorSizeType peakNumber, const string& styleID ) const
{
	for ( int i = 0 ; i < ratio.size () ; i++ ) {
		if ( ok [0][peakNumber] && ok [i+1][peakNumber] && quanPep )
			printHTMLRatio ( os, ratio [i][peakNumber], ratioType [i][peakNumber], styleID );
		else
			tableEmptyCell ( os, styleID );
	}
}
Exemple #9
0
set<uint> DBSCAN::neighborhood(const DoubleVectorVector& inputdata, uint startObjectID) {
  set<uint> result;
  uint nOfObjects=inputdata.size();
  for(uint i=0;i<nOfObjects;++i) {
    if(distance(inputdata,i,startObjectID)<=epsilon_) {
      result.insert(i);
    }
  }
  return result;
}
CosSimilarityList::CosSimilarityList ( const StringVector& formulaString, int charge, const DoubleVectorVector& intensity, const DoubleVectorVector& area, int numQuanStates ) :
	csi ( numQuanStates, -100.0 ),
	csa ( numQuanStates, -100.0 )
{
	for ( int i = 0 ; i < numQuanStates ; i++ ) {
		CosSimilarity cs ( formulaString [i], charge, i < intensity.size () ? intensity [i] : DoubleVector (), i < area.size () ? area [i] : DoubleVector () );
		csi [i] = cs.getIntensity ();
		csa [i] = cs.getArea ();
	}
}
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;
}
Exemple #12
0
void DBSCAN::run(const DoubleVectorVector& inputdata, ResultVector &clusterInformation){

  DBG(25) << "Init ...";
  uint nOfObservations=inputdata.size();
  distanceTable_=DoubleVectorVector(nOfObservations);
  for(uint i=0;i<nOfObservations;++i) {
    distanceTable_[i]=new DoubleVector(nOfObservations,-1);
  }
  clusterInformation=vector<int>(nOfObservations,UNCLASSIFIED); // all observations are unclassified
  uint tenpercent=nOfObservations/10;
  uint percent=0;
  BLINK(25) << "done" << endl;
  
  uint clusterId=0;
  for(uint i=0;i<nOfObservations;++i) {
    if(i%tenpercent==0) {DBG(10) << percent << "% done" << endl; percent+=10;}
    if(clusterInformation[i]==UNCLASSIFIED) {
      if(expandClusters(inputdata,clusterInformation,i,clusterId)) {
        ++clusterId;
        DBG(10) << "ClusterId=" << clusterId << endl;
      }
    }
  }
}