]> git.donarmstrong.com Git - mothur.git/blob - eachgapdist.h
This contains Pat's bug fixes and updates. It represents mothur v.1.3.0
[mothur.git] / eachgapdist.h
1 #ifndef EACHGAPDIST_H
2 #define EACHGAPDIST_H
3 /*
4  *  eachgapdist.h
5  *  Mothur
6  *
7  *  Created by Sarah Westcott on 5/7/09.
8  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
9  *
10  */
11
12 #include "dist.h"
13
14 /**************************************************************************************************/
15
16 class eachGapDist : public Dist {
17         
18 public:
19         void calcDist(Sequence A, Sequence B){          
20                 int diff = 0;
21                 int length = 0;
22                 int start = 0;
23                 
24                 string seqA = A.getAligned();
25                 string seqB = B.getAligned();
26                 int alignLength = seqA.length();
27                 
28                 for(int i=0; i<alignLength; i++){
29                         if(seqA[i] != '.' || seqB[i] != '.'){
30                                 start = i;
31                                 break;
32                         }
33                 }
34
35                 for(int i=start;i<alignLength;i++){
36                         if(seqA[i] == '.' && seqB[i] == '.'){
37                                 break;  
38                         }
39                         else if((seqA[i] == '-' && seqB[i] == '-') || (seqA[i] == '-' && seqB[i] == '.') || (seqA[i] == '.' && seqB[i] == '-')){;}
40                         else{
41                                 if(seqA[i] != seqB[i]){
42                                         diff++;
43                                 }
44                                 length++;
45                         }
46                 }
47                 
48                 if(length == 0) {       dist = 1.0000;                                                          }
49                 else                    {       dist = ((double)diff  / (double)length);        }
50                 
51         }
52 };
53
54 /**************************************************************************************************/
55
56 #endif