示例#1
0
 void set(DMat<RT>& A, MatrixWindow wA, const DMat<RT>& B, MatrixWindow wB)
 {
   M2_ASSERT(wA.sameSize(wB));
   long rA = wA.begin_row;
   long rB = wB.begin_row;
   for ( ; rA < wA.end_row; ++rA, ++rB)
     {
       long cA = wA.begin_column;
       long cB = wB.begin_column;
       for ( ; cA < wA.end_column; ++cA, ++cB)
         A.ring().set(A.entry(rA,cA), B.entry(rB,cB));
     }
 }
示例#2
0
   void scalarMultInPlace(DMat<RT>& A, MatrixWindow wA, const typename RT::ElementType& c)
 {
   M2_ASSERT(wA.sameSize(wB));
   long rA = wA.begin_row;
   for ( ; rA < wA.end_row; ++rA)
     {
       long cA = wA.begin_column;
       for ( ; cA < wA.end_column; ++cA)
         {
           auto& a = A.entry(rA,cA);
           A.ring().mult(a, a, c);
         }
     }
 }
示例#3
0
   void scalarMult(DMat<RT>& A, MatrixWindow wA, const typename RT::ElementType& c, const DMat<RT>& B, MatrixWindow wB)
 {
   M2_ASSERT(wA.sameSize(wB));
   long rA = wA.begin_row;
   long rB = wB.begin_row;
   for ( ; rA < wA.end_row; ++rA, ++rB)
     {
       long cA = wA.begin_column;
       long cB = wB.begin_column;
       for ( ; cA < wA.end_column; ++cA, ++cB)
         {
           A.ring().mult(A.entry(rA,cA), c, B.entry(rB,cB));
         }
     }
 }
示例#4
0
void addTo(DMat<RT>& A, MatrixWindow wA, const DMat<RT>& B, MatrixWindow wB)
{
  assert(wA.sameSize(wB));
  long rA = wA.begin_row;
  long rB = wB.begin_row;
  for (; rA < wA.end_row; ++rA, ++rB)
    {
      long cA = wA.begin_column;
      long cB = wB.begin_column;
      for (; cA < wA.end_column; ++cA, ++cB)
        {
          auto& a = A.entry(rA, cA);
          A.ring().add(a, a, B.entry(rB, cB));
        }
    }
}
示例#5
0
   void addMultipleTo(DMat<RT>& A, MatrixWindow wA, const typename RT::ElementType& c, const DMat<RT>& B, MatrixWindow wB)
 {
   M2_ASSERT(wA.sameSize(wB));
   typename RT::ElementType tmp;
   A.ring().init(tmp);
   long rA = wA.begin_row;
   long rB = wB.begin_row;
   for ( ; rA < wA.end_row; ++rA, ++rB)
     {
       long cA = wA.begin_column;
       long cB = wB.begin_column;
       for ( ; cA < wA.end_column; ++cA, ++cB)
         {
           A.ring().mult(tmp, c, B.entry(rB,cB));
           auto& a = A.entry(rA,cA);
           A.ring().add(a, a, tmp);
         }
     }
   A.ring().clear(tmp);
 }
示例#6
0
void DistanceMatrix::printCompareInfo(vector<double> _inputVec1, vector<double> _inputVec2, pair<int, double> _result, int choice){
    //retrieve values from the pair
    int index = _result.first;
    double minLikeness = _result.second;

   
    //retrieve the winning Matrix Window from listMW
    MatrixWindow *mw = listMW[index];

    //retrieve and print relevent info
    int i = mw->getLeftR();
    int j = mw->getLeftC();
   
    string iID = atomVec[i]->getSegID().c_str();
    string jID = atomVec[j]->getSegID().c_str();
    
    if(atomVec[i]->getSegID()==""){
	iID = atomVec[i]->getChainId().c_str();
	jID = atomVec[j]->getChainId().c_str();
    }
    
    int ires = atomVec[i]->getResidueNumber();
    int jres = atomVec[j]->getResidueNumber();

    string PDBname= getFileName(PDBid);
    string PDBnameShort = PDBname.substr(0,17);

	
    cout<<"Comparing with PDB "<<PDBnameShort<<endl;

    switch(choice){
	    case minRowWeighted: 
		fprintf(stdout, "MinRowWeighted compare: \tWindow %3d,%3d (Residues: %1s %3d, %1s %3d)\t%8.3f\n", i, j, iID.c_str(), ires, jID.c_str(), jres, minLikeness);
		break;
	    case minRowAndColWeighted:
		fprintf(stdout, "MinRowAndColWeighted compare: \tWindow %3d,%3d (Residues: %1s %3d, %1s %3d)\t%8.3f\n", i, j, iID.c_str(), ires, jID.c_str(), jres, minLikeness);
		break;
	    case correlation: 
		fprintf(stdout, "Correlation compare: \tWindow %3d,%3d (Residues: %1s %3d, %1s %3d)\t%8.3f\n", i, j, iID.c_str(), ires, jID.c_str(), jres, minLikeness);
		break;
	    case correlationRowCol:
		fprintf(stdout, "CorrelationRowCol compare: \tWindow %3d,%3d (Residues: %1s %3d, %1s %3d)\t%8.3f\n", i, j, iID.c_str(), ires, jID.c_str(), jres, minLikeness);
		break;
	    case correlationHeteroRowCol:
		fprintf(stdout, "CorrelationHeteroRowCol compare: \tWindow %3d,%3d (Residues: %1s %3d, %1s %3d)\t%8.3f\n", i, j, iID.c_str(), ires, jID.c_str(), jres, minLikeness);
		break;
	    default:
		cout<<"you suck! You f****d up printCompareInfo in DistanceMatrix--the one that takes the vector. S******d."<<endl;
		exit(3334);
    }//end switch	
	
    
    //print out the vectors we compared

    string label = "Weights:  ";
    if(weight.size() != 0){
        fprintf(stdout, "%-20s", label.c_str());
	for (uint i = 0; i < weight.size();i++){
	fprintf(stdout, "%8.3f, ", weight[i]);
    }
    fprintf(stdout, "\n");

    }
    label = "DistVectRow: ";
    fprintf(stdout, "%-20s", label.c_str());
    for (uint i = 0; i < _inputVec1.size();i++){
	fprintf(stdout, "%8.3f, ", _inputVec1[i]);
    }
    fprintf(stdout, "\n");

    //print row vector and correlation
    label = "RowsVect:";
    fprintf(stdout, "%-20s", label.c_str());
    vector<double> minRowValues = mw->getMinRowValues();

    for (int i=0; i<minRowValues.size(); i++){
	fprintf(stdout, "%8.3f, ", minRowValues[i]);
    }
    fprintf(stdout,"\n");
    if(choice != correlation){//if choice is correlation, we already printed out the correlation...
	double correlateR = MslTools::correlate(minRowValues, _inputVec1);
	fprintf(stdout, "RowCorrelation: \t %8.3f, ", correlateR);
    }
    cout<<endl;

    //print col vector and correlation if choice is MinRowAndColWeighted
    if(choice==minRowAndColWeighted || choice == correlationRowCol){
	label = "ColsVect: ";
	fprintf(stdout, "%-20s", label.c_str());

	vector<double> minColValues = mw->getMinColValues();
	for (int i=0; i<minColValues.size(); i++){
	    fprintf(stdout, "%8.3f, ", minColValues[i]);
	}
	fprintf(stdout,"\n");
	double correlateC = MslTools::correlate(minColValues, _inputVec1);
	fprintf(stdout, "ColCorrelation: \t %8.3f, ", correlateC);
	cout<<endl;
    }

    if (choice == correlationHeteroRowCol){

	    label = "DistVectCol: ";
	    fprintf(stdout, "%-20s", label.c_str());
	    for (uint i = 0; i < _inputVec2.size();i++){
		    fprintf(stdout, "%8.3f, ", _inputVec2[i]);
	    }
	    fprintf(stdout, "\n");

	    label = "ColsVect: ";
	    fprintf(stdout, "%-20s", label.c_str());
	    vector<double> minColValues = mw->getMinColValues();
	    for (int i=0; i<minColValues.size(); i++){
		    fprintf(stdout, "%8.3f, ", minColValues[i]);
	    }
	    fprintf(stdout,"\n");
	    double correlateC = MslTools::correlate(minColValues, _inputVec2);
	    fprintf(stdout, "ColCorrelation: \t %8.3f, ", correlateC);
	    cout<<endl;
    }

   

}
示例#7
0
pair<int, double> DistanceMatrix::compareAllWindows(vector<double> minDistVec1, vector<double> minDistVec2, vector<string> allowedAminoAcids1,vector<string> allowedAminoAcids2, int choice){
    int length = listMW.size();
    int bestIndex;
    MatrixWindow *bestWindow = NULL;
    double minLikeness = 1000000;//for choice == minRowWeighted or choice==minRowAndColWeighted
    double maxLikeness = -1.0;//for choice == correlation

    double deviationFromMaxLikeness = 0.5;

    vector<pair<double,int> > results;
    
    for (int i=0; i<length; i++){
	MatrixWindow *win = listMW[i];


        //cout << "Testing window: "<<endl<<win->toString()<<endl;
	double likeness;
	switch(choice){
		case minRowWeighted:
		    likeness = win->compareMinRowWeighted(minDistVec1);
		    if(likeness<(minLikeness+deviationFromMaxLikeness) && abs(likeness - minLikeness) > 0.001){
			minLikeness=likeness;
			bestWindow=win;
			bestIndex = i;

			results.push_back(pair<double,int>(minLikeness,bestIndex));
			}//end if
		    break;
		case minRowAndColWeighted:
		    likeness = win-> compareMinRCWeighted(minDistVec1);
		    if(likeness<(minLikeness+deviationFromMaxLikeness) && abs(likeness - minLikeness) > 0.001){
			minLikeness=likeness;
			bestWindow=win;
			bestIndex = i;
			results.push_back(pair<double,int>(minLikeness,bestIndex));
			}//end if
		    break;
		case correlation:
		    likeness = win->compareCorrelation(minDistVec1);
		    if(likeness>(maxLikeness-deviationFromMaxLikeness) && abs(likeness-maxLikeness) > 0.001){
			maxLikeness = likeness;
			bestWindow = win;
			bestIndex = i;
			results.push_back(pair<double,int>(maxLikeness,bestIndex));
		    }
		    break;
		case correlationRowCol:
			if (win->getUpLeftResidueNumbers()[0] == win->getUpLeftResidueNumbers()[1]){
				likeness = win -> compareCorrelationRowColAverage(minDistVec1);
				if(likeness>(maxLikeness-deviationFromMaxLikeness) && abs(likeness-maxLikeness) > 0.001){
					maxLikeness = likeness;
					bestWindow = win;
					bestIndex = i;

					results.push_back(pair<double,int>(maxLikeness,bestIndex));

				}
			}
		    break;
	        case correlationHeteroRowCol:
 		    likeness = win->compareCorrelationHeteroRowCol(minDistVec1, minDistVec2);
		    if(likeness>(maxLikeness-deviationFromMaxLikeness) && abs(likeness-maxLikeness) > 0.001){
			maxLikeness = likeness;
			bestWindow = win;
			bestIndex = i;

			results.push_back(pair<double,int>(maxLikeness,bestIndex));
		    }
		    break;
			
		default:
		    cout<< "Invalid int (choice) in function compareAllMinRowWeighted in DistanceMatrix."<<endl;
		    exit(336);
	}//end switch
	
	//fprintf(stdout, "\t%8.3f\n", likeness);
	win=NULL;
    }//end for on i

    pair<int, double> indexAndLikeness (0, MslTools::doubleMax);
    if (results.size() == 0){
	    return indexAndLikeness;
    }
    // Sort the results
    if(choice==minRowWeighted || choice==minRowAndColWeighted){
	    sort(results.begin(), results.end());
    } else{
	    sort(results.begin(), results.end(),greater<pair<double,int> >());
    }

		    
    // Apply Sequence Filtering to results.
    // Instead of results.size(), do results[0].first - 0.1 or something.
    int bestResultIndex = 0;
    if (allowedAminoAcids1.size() == listMW[0]->getWinSize() && allowedAminoAcids2.size() == listMW[0]->getWinSize()) {
	    for (uint i  = 0; i < results.size();i++){
		    if (listMW[results[i].second]->doesSequenceMatchRow(allowedAminoAcids1) && listMW[results[i].second]->doesSequenceMatchCol(allowedAminoAcids2)){
			    bestResultIndex = i;
			    break;
		    }
	    }
    } else  if (allowedAminoAcids1.size() == listMW[0]->getWinSize()){
	    
	    for (uint i  = 0; i < results.size();i++){
		    if (listMW[results[i].second]->doesSequenceMatchRow(allowedAminoAcids1)){
			    bestResultIndex = i;
			    break;
		    }
	    }
    } else  if (allowedAminoAcids2.size() == listMW[0]->getWinSize()){
	    for (uint i  = 0; i < results.size();i++){
		    if (listMW[results[i].second]->doesSequenceMatchCol(allowedAminoAcids2)){
			    bestResultIndex = i;
			    break;
		    }
	    }
    }



    indexAndLikeness.first  = results[bestResultIndex].second;
    indexAndLikeness.second = results[bestResultIndex].first;


    bestWindow=NULL;
    return indexAndLikeness;


}