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