]> git.donarmstrong.com Git - mothur.git/blob - eachgapdist.h
*** empty log message ***
[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
13 #include "dist.h"
14
15 /**************************************************************************************************/
16
17 class eachGapDist : public Dist {
18         
19 public:
20         void calcDist(Sequence A, Sequence B){          
21                 int diff = 0;
22                 int length = 0;
23                 int start = 0;
24                 
25                 string seqA = A.getAligned();
26                 string seqB = B.getAligned();
27
28                 int alignLength = seqA.length();
29                 
30                 for(int i=0; i<alignLength; i++){
31                         if(seqA[i] != '.' || seqB[i] != '.'){
32                                 start = i;
33                                 break;
34                         }
35                 }
36
37                 for(int i=start;i<alignLength;i++){
38                         if(seqA[i] == '.' && seqB[i] == '.'){
39                                 break;  
40                         }
41                         else if((seqA[i] == '-' && seqB[i] == '-') || (seqA[i] == '-' && seqB[i] == '.') || (seqA[i] == '.' && seqB[i] == '-')){;}
42                         else{
43                                 if(seqA[i] != seqB[i]){
44                                         diff++;
45                                 }
46                                 length++;
47                         }
48                 }
49                 
50                 if(length == 0) {       dist = 1.0000;                                                          }
51                 else                    {       dist = ((double)diff  / (double)length);        }
52         }
53 };
54
55 /**************************************************************************************************/
56
57 #endif