Commit a0420182 authored by Thomas Schiex's avatar Thomas Schiex
Browse files

Similarity matrices are stored as dissimilarity matrices

parent 7a8a792a
......@@ -116,6 +116,7 @@ void Cpd::readPSMatrix(const char* filename)
file >> s; // skip AA
for (int j = 0; j < 24; j++) {
file >> PSM[i][j];
PSM[i][j] = -PSM[i][j];
minscore = min(minscore,PSM[i][j]);
}
}
......@@ -129,7 +130,7 @@ void Cpd::readPSMatrix(const char* filename)
void Cpd::fillPSMbiases(size_t varIndex, vector<Cost> &biases)
{
for (char c : rotamers2aa[varIndex]) {
int bias = PSM[PSMIdx.find(c)->second][PSMIdx.find(nativeSequence[varIndex])->second];
int bias = PSMBias*PSM[PSMIdx.find(c)->second][PSMIdx.find(nativeSequence[varIndex])->second];
biases.push_back((Cost)bias);
}
}
......@@ -162,6 +163,7 @@ void Cpd::readPSSMatrix(const char* filename)
for (int j = 0; j < 20; j++) {
int score;
file >> score;
score = -score;
minscore = min(minscore,score);
scores.push_back(score);
}
......@@ -178,7 +180,7 @@ void Cpd::readPSSMatrix(const char* filename)
void Cpd::fillPSSMbiases(size_t varIndex, vector<Cost> &biases)
{
for (char c : rotamers2aa[varIndex]) {
int bias = PSSM[varIndex][PSSMIdx.find(c)->second];
int bias = PSSMBias*PSSM[varIndex][PSSMIdx.find(c)->second];
biases.push_back((Cost)bias);
}
}
......
......@@ -26,41 +26,48 @@ public:
size_t rot2aaSize(int varIndex) { return rotamers2aa[varIndex].size();}
char *nativeSequence = NULL;
bool isPSSMlen() {return PSSM.size();};
double PSMBias = 0.0;
double PSSMBias = 0.0;
int PSMBias = 0;
int PSSMBias = 0;
private:
const static map<char,int> PSMIdx; // converts AA char to indices in PSMatrix
const static map<char,int> PSSMIdx; // converts AA char to indices in PsiBlast PSSMatrix
vector< vector<char> > rotamers2aa;
vector< vector<Value> > LeftAA;
vector< vector<Value> > RightAA;
int PSM[24][24] = {{1, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0, 0, 0 ,0, 0, 0, 0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 0, 0, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0, 0, 0 ,1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0, 0, 0 ,0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0, 0, 0 ,0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0, 0, 0 ,0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0, 0, 0 ,0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 1}};
vector <vector<int>> PSSM;
TrieCpd *cpdtrie;
const static map<char,int> PSMIdx; // converts AA char to indices in PSMatrix
const static map<char,int> PSSMIdx; // converts AA char to indices in PsiBlast PSSMatrix
vector< vector<char> > rotamers2aa;
vector< vector<Value> > LeftAA;
vector< vector<Value> > RightAA;
int PSM[24][24] = {{0, 1, 1, 1, 1, 1, 1 ,1 ,1 ,1, 1, 1, 1, 1 ,1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 1, 1, 1,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, 1, 1 ,0, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1 ,1 ,1 ,1, 1, 1, 1, 1 ,1, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1 ,1 ,1 ,1, 1, 1, 1, 1 ,1, 1, 0, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1 ,1 ,1 ,1, 1, 1, 1, 1 ,1, 1, 1, 0, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1 ,1 ,1 ,1, 1, 1, 1, 1 ,1, 1, 1, 1, 0, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1 ,1 ,1 ,1, 1, 1, 1, 1 ,1, 1, 1, 1, 1, 0, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1 ,1 ,1 ,1, 1, 1, 1, 1 ,1, 1, 1, 1, 1, 1, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1 ,1 ,1 ,1, 1, 1, 1, 1 ,1, 1, 1, 1, 1, 1, 1, 0, 1, 1},
{1, 1, 1, 1, 1, 1, 1 ,1 ,1 ,1, 1, 1, 1, 1 ,1, 1, 1, 1, 1, 1, 1, 1, 0, 1},
{1, 1, 1, 1, 1, 1, 1 ,1 ,1 ,1, 1, 1, 1, 1 ,1, 1, 1, 1, 1, 1, 1, 1, 1, 0}};
vector <vector<int>> PSSM;
TrieCpd *cpdtrie;
};
#endif
/* Local Variables: */
/* c-basic-offset: 4 */
/* tab-width: 4 */
/* indent-tabs-mode: nil */
/* c-default-style: "k&r" */
/* End: */
......@@ -1404,12 +1404,12 @@ int _tmain(int argc, TCHAR *argv[])
// get psm bias
if (args.OptionId() == OPT_PSMBIAS) {
ToulBar2::cpd->PSSMBias =atof(args.OptionArg());
ToulBar2::cpd->PSMBias =atoi(args.OptionArg());
}
// get pssm bias
if (args.OptionId() == OPT_PSSMBIAS) {
ToulBar2::cpd->PSSMBias = atof(args.OptionArg());
ToulBar2::cpd->PSSMBias = atoi(args.OptionArg());
}
// discrete integration for computing the partition function Z
......@@ -1895,6 +1895,8 @@ int _tmain(int argc, TCHAR *argv[])
if (mutate) {
solver->mutate(mutationString);
}
if (ToulBar2::cpd)
solver->applyCompositionalBiases();
if (ToulBar2::dumpWCSP == 1) {
string problemname = ToulBar2::problemsaved_filename;
......
......@@ -113,7 +113,7 @@ void Solver::mutate(char *mutationString)
void Solver::applyCompositionalBiases()
{
if (ToulBar2::cpd->PSMBias != 0.0) {
if (ToulBar2::cpd->PSMBias != 0) {
if (ToulBar2::cpd->nativeSequence == NULL) {
cerr << "Cannot bias energy based on similarity matrix without native sequence." << endl;
exit(EXIT_FAILURE);
......@@ -127,7 +127,7 @@ void Solver::applyCompositionalBiases()
}
}
if (ToulBar2::cpd->PSSMBias != 0.0) {
if (ToulBar2::cpd->PSSMBias != 0) {
if (ToulBar2::cpd->isPSSMlen() != wcsp->numberOfVariables()) {
cerr << "The number of variable is not equal to the PSSM length." << endl;
exit(EXIT_FAILURE);
......
......@@ -495,6 +495,7 @@ public:
virtual void read_solution(const char *fileName, bool updateValueHeuristic = true) = 0; ///< \brief read a solution from a file
virtual void parse_solution(const char *certificate) = 0; ///< \brief read a solution from a string (see ToulBar2 option \e -x)
virtual void mutate(char *certificate) = 0; ///< \brief read a mutation string (see ToulBar2 option \e --mut)
virtual void applyCompositionalBiases() = 0;
virtual Cost getSolution(vector<Value> &solution) = 0; ///< \brief after solving the problem, add the optimal solution in the input/output vector and returns its optimum cost (warning! do not use it if doing solution counting or if there is no solution, see WeightedCSPSolver::solve output for that)
// -----------------------------------------------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment