]> git.donarmstrong.com Git - mothur.git/blob - eachgapdist.h
changed random forest output filename
[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         
21         eachGapDist() {}
22         
23         void calcDist(Sequence A, Sequence B){          
24                 int diff = 0;
25                 int length = 0;
26                 int start = 0;
27                 
28                 string seqA = A.getAligned();
29                 string seqB = B.getAligned();
30
31                 int alignLength = seqA.length();
32                 
33                 for(int i=0; i<alignLength; i++){
34                         if(seqA[i] != '.' || seqB[i] != '.'){
35                                 start = i;
36                                 break;
37                         }
38                 }
39
40                 for(int i=start;i<alignLength;i++){
41                         if(seqA[i] == '.' && seqB[i] == '.'){
42                                 break;  
43                         }
44                         else if((seqA[i] == '-' && seqB[i] == '-') || (seqA[i] == '-' && seqB[i] == '.') || (seqA[i] == '.' && seqB[i] == '-')){;}
45                         else{
46                                 if(seqA[i] != seqB[i]){
47                                         diff++;
48                                 }
49                                 length++;
50                         }
51                 }
52                 
53                 if(length == 0) {       dist = 1.0000;                                                          }
54                 else                    {       dist = ((double)diff  / (double)length);        }
55         }
56 };
57
58 /**************************************************************************************************/
59
60 #endif