]> git.donarmstrong.com Git - mothur.git/blob - eachgapignore.h
pat's minor edits to distance calculations
[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                 int end = 0;
26                 
27                 string seqA = A.getAligned();
28                 string seqB = B.getAligned();
29                 int alignLength = seqA.length();
30                 
31                 for(int i=0;i<alignLength;i++){
32                         if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){
33                                 start = i;
34                                 cout << "start: " << start << endl;
35                                 break;
36                         }
37                 }
38                 for(int i=alignLength-1;i>=0;i--){
39                         if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){
40                                 end = i;
41                                 cout << "end: " << end << endl;
42                                 break;
43                         }
44                 }
45                 
46                 for(int i=start;i<=end;i++){
47                         if(seqA[i] == '.' || seqB[i] == '.'){
48                                 break;  
49                         }
50                         else if(seqA[i] != '-' || seqB[i] != '-'){
51                                 if(seqA[i] != seqB[i]){
52                                         diff++;
53                                 }
54                                 length++;
55                         }
56                 }
57                 
58                 if(length == 0) {       dist = 1.0000;                                                          }
59                 else                    {       dist = ((double)diff  / (double)length);        }
60                 
61         }
62         
63 };
64
65 /**************************************************************************************************/
66
67 #endif
68
69