]> git.donarmstrong.com Git - mothur.git/blob - onegapignore.h
pat's minor edits to distance calculations
[mothur.git] / onegapignore.h
1 #ifndef ONEIGNOREGAPS_H
2 #define ONEIGNOREGAPS_H
3 /*
4  *  onegapignore.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 oneGapIgnoreTermGapDist : public Dist {
18         
19 public:
20         void calcDist(Sequence A, Sequence B){
21                 
22                 int difference = 0;
23                 int openGapA = 0;
24                 int openGapB = 0;
25                 int minLength = 0;
26                 int start = 0;
27                 int end = 0;
28                 
29                 string seqA = A.getAligned();
30                 string seqB = B.getAligned();
31                 int alignLength = seqA.length();
32
33                 // this assumes that sequences start and end with '.'s instead of'-'s.
34                 for(int i=0;i<alignLength;i++){
35                         if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){
36                                 start = i;
37                                 cout << "start: " << start << endl;
38                                 break;
39                         }
40                 }
41                 for(int i=alignLength-1;i>=0;i--){
42                         if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){
43                                 end = i;
44                                 cout << "end: " << end << endl;
45                                 break;
46                         }
47                 }
48                 
49                 for(int i=start;i<=end;i++){
50                         if(seqA[i] == '-' && seqB[i] == '-'){   ;       }
51                         else if(seqB[i] != '-' && seqA[i] == '-'){
52                                 if(openGapA == 0){
53                                         difference++;
54                                         minLength++;
55                                         openGapA = 1;
56                                         openGapB = 0;
57                                 }
58                         }
59                         else if(seqA[i] != '-' && seqB[i] == '-'){
60                                 if(openGapB == 0){
61                                         difference++;
62                                         minLength++;
63                                         openGapA = 0;
64                                         openGapB = 1;
65                                 }
66                         }
67                         else if(seqA[i] != '-' && seqB[i] != '-'){
68                                 if(seqA[i] != seqB[i]){
69                                         difference++;
70                                 }
71                                 minLength++;
72                                 openGapA = 0;
73                                 openGapB = 0;
74                         }
75                 }
76
77                 if(minLength == 0)      {       dist = 1.0000;                                                  }
78                 else                            {       dist = (double)difference / minLength;  }
79         }
80
81 };
82
83 /**************************************************************************************************/
84
85 #endif
86