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