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