1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
// $Id: pDistance.h 962 2006-11-07 15:13:34Z privmane $
#ifndef ___P_DISTANCE
#define ___P_DISTANCE
#include "definitions.h"
#include "distanceMethod.h"
/*********************************************************
p distance computes distance by counting number of differences and dividing by length of seq.
Weights are an input vector for giving additional weight to positions in the sequences.
*******************************************************/
class pDistance : public distanceMethod {
public:
explicit pDistance(){}
const MDOUBLE giveDistance( const sequence& s1,
const sequence& s2,
const vector<MDOUBLE> * weights,
MDOUBLE* score=NULL) const {//score is not used here
MDOUBLE p =0;
if (weights == NULL) {
for (int i = 0; i < s1.seqLen() ; ++i) if (s1[i] != s2[i]) p++;
p = p/s1.seqLen();
} else {
MDOUBLE len=0;
for (int i = 0; i < s1.seqLen() ; ++i) {
len +=((*weights)[i]);
if (s1[i] != s2[i]) p+=((*weights)[i]);
}
p = p/len;
}
return p;
}
virtual pDistance* clone() const {return new pDistance(*this);}
};
#endif
|