Ejemplo n.º 1
0
pair<vector<int>, double>  DistanceMatrix::compareAllWindows(DistanceMatrix &_distMat, int choice){
   vector<MatrixWindow*> listOther = _distMat.getMatrixWindows();
    int length = listMW.size();
    int lengthOther = listOther.size();
    vector<int> minCoord(2, 0.0);
    MatrixWindow *minWindow1 = NULL;
    MatrixWindow *minWindow2 = NULL;
    double minLikeness= MslTools::doubleMax;

    for (int i =0; i<length; i++){//loops through listMW to get comparee

	MatrixWindow *win1 = listMW[i];
	for (int j=0; j<lengthOther; j++){//loops through listOther to get comparor

	    MatrixWindow *win2 = listOther[j];
	    
	    double likeness;
	    //decides which compare method from MatrixWindow to call
	    switch(choice){
		    case standard:
			likeness = (*win1).compare((*win2));
			break;
		    case diag:
			likeness = (*win1).compareDiagonal((*win2));
			break;
		    case doubleDiag:
			likeness = (*win1).compareDoubleDiagonal((*win2));
			break;
		    case minDist:
			likeness = (*win1).compareMinDist((*win2));
			break;
		    case minDistRow:
			likeness=(*win1).compareMinRow((*win2));
			break;
		    case minDistCol:
			likeness=(*win1).compareMinCol((*win2));
			break;
		    default:
			cout<<"Invalid argument in function DistanceMatrix::compareAll()."<<endl;
			exit(333);
	    }//end switch
	    
	    if (likeness<minLikeness && abs(likeness - minLikeness) > 0.001){
		    cout << "New likeness: "<<likeness<<endl;
		minLikeness=likeness;
		minWindow1 = win1;
		minWindow2 = win2;
		minCoord[0]= i;
		minCoord[1]=j;

	    }//endif
	    win2=NULL;
	}//end for on j
	win1= NULL;
    }//end for on i

    
    pair<vector<int>, double> coordsAndLikeness(minCoord, minLikeness);

    minWindow1=NULL;
    minWindow2=NULL;

    return coordsAndLikeness;

}
Ejemplo n.º 2
0
vector<DistanceMatrixResult> DistanceMatrix::multiCompareAllWindows(DistanceMatrix &_distMat, int choice, int _numCompare){
/*
    //which chains to skip:
    map<string, bool> forbiddenIDMat1;
    map<string, bool> forbiddenIDMat2;

    // Maintain the proper spacing between residues of different matrix window pairs. 
    map<string,int> properRegisterRow;
    map<string,int> properRegisterCol;
    map<string,int>::iterator findRegistry;
*/
    //get list of MWs to compare
    vector<MatrixWindow*> listOther = _distMat.getMatrixWindows();
    int length = listMW.size();
    int lengthOther = listOther.size();

    //vector of objects to return
    vector<DistanceMatrixResult> returnVec;

    //loop over number of times to compare all
    for(int k=0; k<_numCompare; k++){

	//minimum windows and indices
	MatrixWindow *minWindow1 = NULL;
	MatrixWindow *minWindow2 = NULL;
	double minLikeness = 1000000;
	int minIndex1=0;
	int minIndex2=0;

	//IDs to skip in the future
	string i1IDWin;
	string j1IDWin;
	string i2IDWin;
	string j2IDWin;


    //which chains to skip:
    map<string, bool> forbiddenIDMat1;
    map<string, bool> forbiddenIDMat2;

    // Maintain the proper spacing between residues of different matrix window pairs. 
    map<string,int> properRegisterRow;
    map<string,int> properRegisterCol;
    map<string,int>::iterator findRegistry;


	for (int i =0; i<length; i++){//loops through listMW to get compare

	    MatrixWindow *win1 = listMW[i];
	    for (int j=0; j<lengthOther; j++){//loops through listOther to get comparor
		
		MatrixWindow *win2 = listOther[j];

		//get the ID (seg or chain) so we can filter ones we want to skip
		int i1 = win1->getLeftR();
		int j1 = win1->getLeftC();
		int i2 = win2->getLeftR();
		int j2 = win2->getLeftC();
     
		string i1ID = atomVec[i1]->getSegID();
		string j1ID = atomVec[j1]->getSegID();
		string i2ID = _distMat.getAtomVector()[i2]->getSegID();
		string j2ID = _distMat.getAtomVector()[j2]->getSegID();
    
		if(i1ID=="" || j1ID=="" || i2ID=="" ||j2ID==""){
   
		    i1ID = atomVec[i1]->getChainId();
		    j1ID = atomVec[j1]->getChainId();
		    i2ID = _distMat.getAtomVector()[i2]->getChainId();
		    j2ID = _distMat.getAtomVector()[j2]->getChainId();
		}//end if
		
		
		// Skip if both chains are forbidden within a matrix
		if (forbiddenIDMat1.find(i1ID+":"+j1ID)!=forbiddenIDMat1.end() || forbiddenIDMat2.find(i2ID+":"+j2ID)!=forbiddenIDMat2.end()) continue;
		

		// Skip if both inter-matrix segids found and if difference in residue number is not the same.
		findRegistry = properRegisterRow.find(i1ID+":"+i2ID);
		double diffInResidueNumber = atomVec[i1]->getResidueNumber() - _distMat.getAtomVector()[i2]->getResidueNumber();
		if (findRegistry != properRegisterRow.end() && findRegistry->second != diffInResidueNumber) continue;

		findRegistry        = properRegisterCol.find(j1ID+":"+j2ID);
		diffInResidueNumber = atomVec[j1]->getResidueNumber() - _distMat.getAtomVector()[j2]->getResidueNumber();
		if (findRegistry != properRegisterCol.end() && findRegistry->second != diffInResidueNumber) continue;

		
		double likeness;
		//decides which compare method from MatrixWindow to call
		switch(choice){
		    case standard:
			likeness = (*win1).compare((*win2));
			break;
		    case diag:
			likeness = (*win1).compareDiagonal((*win2));
			break;
		    case doubleDiag:
			likeness = (*win1).compareDoubleDiagonal((*win2));
			break;
		    case minDist:
			likeness = (*win1).compareMinDist((*win2));
			break;
		    case minDistRow:
			likeness=(*win1).compareMinRow((*win2));
			break;
		    case minDistCol:
			likeness=(*win1).compareMinCol((*win2));
			break;
		    default:
			cout<<"Invalid argument in function DistanceMatrix::compareAll()."<<endl;
			exit(333);
		}//end switch

		if (likeness<minLikeness && abs(likeness - minLikeness) > 0.001){
		    minLikeness = likeness;
		    minWindow1 = win1;
		    minWindow2 = win2;
		    minIndex1 = i;
		    minIndex2 = j;
		    
		    
		    //set the ID to avoid in the future
		    i1IDWin = i1ID;
		    j1IDWin = j1ID;
		    i2IDWin = i2ID;
		    j2IDWin = j2ID;
		    
		 
		}//endif
		win2=NULL;
	    }//end for on j
	    win1= NULL;
	}//end for on i
	

	// Allowed   inter matrix identifier[SEGID] difference in residue numbers
	vector<int> residueNumbers1 = minWindow1->getUpLeftResidueNumbers();
	vector<int> residueNumbers2 = minWindow2->getUpLeftResidueNumbers();

	properRegisterRow[i1IDWin+":"+i2IDWin] =   (residueNumbers1[0] - residueNumbers2[0]);
	properRegisterRow[i2IDWin+":"+i1IDWin] = - (residueNumbers1[0] - residueNumbers2[0]);
	properRegisterCol[j1IDWin+":"+j2IDWin] =   (residueNumbers1[1] - residueNumbers2[1]);
	properRegisterCol[j2IDWin+":"+j1IDWin] = - (residueNumbers1[1] - residueNumbers2[1]);

	// Forbidden intra matrix identifier[SEGID] pairs
	forbiddenIDMat1[i1IDWin+":"+j1IDWin] = false;
	forbiddenIDMat1[j1IDWin+":"+i1IDWin] = false;	
	forbiddenIDMat2[i2IDWin+":"+j2IDWin] = false;	
	forbiddenIDMat2[j2IDWin+":"+i2IDWin] = false;	


	DistanceMatrixResult currentResult(*this, *minWindow1, _distMat, *minWindow2, minLikeness);

	returnVec.push_back(currentResult);

	minWindow1=NULL;
	minWindow2=NULL;

    }//end for on k

    return returnVec;

}
Ejemplo n.º 3
0
//must add segID
void DistanceMatrix::printCompareInfo(DistanceMatrix &_distMat, pair<vector<int>, double> _result, int choice){
    
    //retrieve values from the pair
    vector<int> mwIndex(2, 0.0);
    mwIndex= _result.first;
    double minLikeness = _result.second;

    //retrieve the winning Matrix Windows
    vector<MatrixWindow*> listMW2 = _distMat.getMatrixWindows();
    MatrixWindow *minWindow1 = listMW[mwIndex[0]];
    MatrixWindow *minWindow2 = listMW2[mwIndex[1]];

    //print information
    int i1 = (*minWindow1).getLeftR();
    int j1 = (*minWindow1).getLeftC();
    int i2 = (*minWindow2).getLeftR();
    int j2 = (*minWindow2).getLeftC();
     
    string i1ID = atomVec[i1]->getSegID().c_str();
    string j1ID = atomVec[j1]->getSegID().c_str();
    string i2ID = _distMat.getAtomVector()[i2]->getSegID().c_str();
    string j2ID = _distMat.getAtomVector()[j2]->getSegID().c_str();
    
    if(i1ID=="" || j1ID=="" || i2ID=="" ||j2ID==""){
   
	i1ID = atomVec[i1]->getChainId().c_str();
	j1ID = atomVec[j1]->getChainId().c_str();
	i2ID = _distMat.getAtomVector()[i2]->getChainId().c_str();
	j2ID = _distMat.getAtomVector()[j2]->getChainId().c_str();
    }

    int i1res = atomVec[i1]->getResidueNumber();
    int j1res = atomVec[j1]->getResidueNumber();
    int i2res = _distMat.getAtomVector()[i2]->getResidueNumber();
    int j2res = _distMat.getAtomVector()[j2]->getResidueNumber();

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

    string PDBname2 = getFileName(_distMat.getPDBid());
    string PDBnameShort2 = PDBname2.substr(0,17);

    cout<<"Comparing PDBs "<<PDBnameShort<<", "<<PDBnameShort2<<endl;


    switch(choice){
	    case standard:
		fprintf(stdout, "Standard compare:\t\tWindow1 %3d,%3d (Residues: %1s%3d, %1s%3d)\tWindow2 %3d,%3d (Residues: %1s%3d, %1s%3d)\t%8.3f\n", i1, j1, i1ID.c_str(), i1res, j1ID.c_str(), j1res, i2, j2, i2ID.c_str(), i2res, j2ID.c_str(), j2res, minLikeness);
		break;
	    case diag:
		fprintf(stdout, "Diagonal compare: \t\tWindow1 %3d,%3d (Residues: %1s%3d, %1s%3d)\tWindow2 %3d,%3d (Residues: %1s%3d, %1s%3d)\t%8.3f\n", i1, j1, i1ID.c_str(), i1res, j1ID.c_str(), j1res, i2, j2, i2ID.c_str(), i2res, j2ID.c_str(), j2res, minLikeness);
	     	break;
	    case doubleDiag:
		fprintf(stdout, "Double Diagonal compare: \tWindow1 %3d,%3d (Residues: %1s%3d, %1s%3d)\tWindow2 %3d,%3d (Residues: %1s%3d, %1s%3d)\t%8.3f\n", i1, j1, i1ID.c_str(), i1res, j1ID.c_str(), j1res, i2, j2, i2ID.c_str(), i2res, j2ID.c_str(), j2res, minLikeness);
		break;
	    case minDist:
		fprintf(stdout, "Minimum Distance compare: \tWindow1 %3d,%3d (Residues: %1s%3d, %1s%3d)\tWindow2 %3d,%3d (Residues: %1s%3d, %1s%3d)\t%8.3f\n", i1, j1, i1ID.c_str(), i1res, j1ID.c_str(), j1res, i2, j2, i2ID.c_str(), i2res, j2ID.c_str(), j2res, minLikeness);
		break;
	    case minDistRow:
		fprintf(stdout, "Minimum Distance Row compare: \tWindow1 %3d,%3d (Residues: %1s%3d, %1s%3d)\tWindow2 %3d,%3d (Residues: %1s%3d, %1s%3d)\t%8.3f\n", i1, j1, i1ID.c_str(), i1res, j1ID.c_str(), j1res, i2, j2, i2ID.c_str(), i2res, j2ID.c_str(), j2res, minLikeness);
		break;
	    case minDistCol:
		fprintf(stdout, "Minimum Distance Column compare: \tWindow1 %3d,%3d (Residues: %1s%3d, %1s%3d)\tWindow2 %3d,%3d (Residues: %1s%3d, %1s%3d)\t%8.3f\n", i1, j1, i1ID.c_str(), i1res, j1ID.c_str(), j1res, i2, j2, i2ID.c_str(), i2res, j2ID.c_str(), j2res, minLikeness);
		break;
	    default:
		cout<<"Error. Incorrect int value (choice) in DistanceMatrix::printCompareInfo(...)"<<endl;
		exit(334);
    }//end switch
}
Ejemplo n.º 4
0
int main(int argc, char *argv[]){
    
    // Option Parser
    Options opt = setupOptions(argc,argv);

    ifstream fs2;

    //create system and dm for first PDB
    PDBReader reader;
    reader.open(opt.inputPDB);
    reader.read();
    reader.close();

    System *constSys = new System(reader.getAtoms());
    DistanceMatrix constDM;
    
    //add CA atoms to the atom vectors
    for (int j=0; j<constSys->residueSize(); j++){
	Residue &tempRes=constSys->getResidue(j);
	if (tempRes.exists("CA")){
	    constDM.addAtom(tempRes("CA"));
	}
    }//end for on j

    
    //fill the DistanceMatrix and set window size
    constDM.setGeneralWinSize(opt.windowSize);
    constDM.createDistanceMatrix();
    constDM.setIntraChain(opt.intraChainCompare);
    constDM.setPDBid(opt.inputPDB);
    constDM.setDebug(opt.debug);

    //create matrix windows
    constDM.createMatrixWindows();

    delete(constSys);


    if (constDM.getMatrixWindows().size()==0){
	    cout<<"Uh-oh.All the windows got filtered in the PDB you wanted to compare against."<<endl;
	    exit(111);
    }

// COMMMENT OUT BEGINS

/*

    //read in list of PDBs to compare to first PDB
    vector<string> list;
    ifstream fs;

    fs.open(opt.pdbList.c_str());
    if (fs.fail()){
	cerr<<"Cannot open file "<<opt.pdbList<<endl;
	exit(1);
    }

    while(true){
	string line;
	getline(fs, line);

	if(fs.fail()){
	    //no more lines to read, quite the while.
	    break;
	}

	if(line==""){
	    continue;
	}
	list.push_back(line);
    }

    fs.close();


    // List of distance matrices, one for each PDB
    vector<DistanceMatrix> DMVec(list.size());

    // A system object for each PDB
    vector<System*> sysVec(list.size(), NULL);

    // Create DistanceMatrix and System Objects for list of PDBs
    for(int i=0; i<list.size(); i++){

	cout<<i<<"create sys and dm."<<endl;

	PDBReader rAv;
	rAv.open(list[i]);
	rAv.read();
	rAv.close();

	sysVec[i] =new System(rAv.getAtoms());
    
	//add CA atoms to the atom vectors
	for (int j=0; j<sysVec[i]->residueSize(); j++){
	    Residue &tempRes=sysVec[i]->getResidue(j);
	    if (tempRes.exists("CA")){
		//only add CA if it is on a helix
		string segID = tempRes("CA").getSegID();
		//if(segID == "" || segID.at(0) == 'H'){
		    DMVec[i].addAtom(tempRes("CA"));
		    //	}
	    }
	}//end for on j
	//fill the DistanceMatrix and set window size
	DMVec[i].setGeneralWinSize(opt.windowSize);
	DMVec[i].createDistanceMatrix();
	DMVec[i].setIntraChain(opt.intraChainCompare);
	DMVec[i].setPDBid(list[i]);

	//create matrix windows
	DMVec[i].createMatrixWindows();
	
	delete(sysVec[i]);

    }//end for on i
*/

// COMMMENT OUT ENDS

// NEW BEGINS

// load distance matrix database from an external binary file
    DistanceMatrixDatabase dmd;
    dmd.load_checkpoint("try.bin");

// List of distance matrices, one for each PDB
//************* from now on, all DMVec become pointers ****************//
    vector<DistanceMatrix *> &DMVec = dmd.getDistanceMatrixList();
/*
    for (uint i = 0;i < dms.size();i++){
            cout << "DM["<<i<<"]: "<<dms[i]->getPDBid()<<endl;
    }
    cout << "Done"<<endl;
*/

    
    //ManageResults to take care of printing/sorting at end
    ManageDistanceMatrixResults resultManager;

	    
    for(int i=0; i<DMVec.size(); i++){

	    cout<< "Trying "<<DMVec[i]->getPDBid()<<" ("<<i<<") # Residues: "<<DMVec.size()<<" Number of MatrixWindows to compare: "<<DMVec[i]->getMatrixWindows().size();

	    //don't compare if all of the windows got filtered out
	    if (DMVec[i]->getMatrixWindows().size() == 0){
		    cout << " Sorry Zero Matrix Windows !"<<endl;
		    continue;
	    }
	    
	    cout <<endl;

	    vector<DistanceMatrixResult> resultsToAdd;

	    if(opt.searchCriteria=="standard"){
		resultsToAdd = constDM.multiCompareAllWindows(*DMVec[i], DistanceMatrix::standard, opt.numberOfIterations);
	    }//end if
	    if(opt.searchCriteria=="diagonal"){
		resultsToAdd = constDM.multiCompareAllWindows(*DMVec[i], DistanceMatrix::diag, opt.numberOfIterations);
       	    }
	    if(opt.searchCriteria=="doubleDiagonal"){
		resultsToAdd = constDM.multiCompareAllWindows(*DMVec[i], DistanceMatrix::doubleDiag, opt.numberOfIterations);
	    }
	    if(opt.searchCriteria=="minDistance"){
		resultsToAdd = constDM.multiCompareAllWindows(*DMVec[i], DistanceMatrix::minDist, opt.numberOfIterations);
	    }
	    if(opt.searchCriteria=="minDistanceRow"){
		resultsToAdd = constDM.multiCompareAllWindows(*DMVec[i], DistanceMatrix::minDistRow, opt.numberOfIterations);
	    }

	    bool addFlag = false;
 	    for (uint j = 0; j< resultsToAdd.size();j++){
 		    if (opt.likenessTolerance == MslTools::doubleMax || resultsToAdd[j].getLikeness() <= opt.likenessTolerance){
			    addFlag = true;
			    break;
 		    }
	    }

	    if (addFlag &&  resultsToAdd.size() > 0){

		    resultManager.addResults(resultsToAdd);	    		    
	    }


    }//end for on i

// NEW ENDS
    
    cout << "Printing"<<endl;
    resultManager.setAlignPdbs(opt.alignPdbs);
//    cout << "hello"<<endl;
    resultManager.setRmsdTol(opt.rmsdTol);
//    cout << "hello again"<<endl;
    resultManager.printResults();

    cout << "Done."<<endl;
    return 0;
}