]> git.donarmstrong.com Git - mothur.git/blob - eachgapignore.h
This contains Pat's bug fixes and updates. It represents mothur v.1.3.0
[mothur.git] / eachgapignore.h
1 #ifndef EACHGAPIGNORE_H
2 #define EACHGAPIGNORE_H
3 /*
4  *  eachgapignore.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 eachGapIgnoreTermGapDist : public Dist {
18         
19 public:
20         
21         void calcDist(Sequence A, Sequence B){          
22                 int diff = 0;
23                 int length = 0;
24                 int start = 0;
25                 
26                 string seqA = A.getAligned();
27                 string seqB = B.getAligned();
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] != '-'){
42                                 if(seqA[i] != seqB[i]){
43                                         diff++;
44                                 }
45                                 length++;
46                         }
47                 }
48                 
49                 if(length == 0) {       dist = 1.0000;                                                          }
50                 else                    {       dist = ((double)diff  / (double)length);        }
51                 
52         }
53         
54 };
55
56 /**************************************************************************************************/
57
58 #endif
59
60