File: pDistance.h

package info (click to toggle)
fastml 3.11-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,772 kB
  • sloc: cpp: 48,522; perl: 3,588; ansic: 819; makefile: 386; python: 83; sh: 55
file content (37 lines) | stat: -rw-r--r-- 1,099 bytes parent folder | download | duplicates (6)
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