]> git.donarmstrong.com Git - mothur.git/blob - onegapdist.h
altered venn command to make use of sharedchao for any number of groups, fixed window...
[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 openGapA = 0;
24                 int openGapB = 0;
25                 int minLength = 0;
26                 int start = 0;
27                 
28                 for(int i=0;i<A.getLength();i++){
29                         if(A.getAligned()[i] == '.' && B.getAligned()[i] == '.'){
30                         }
31                         else{
32                                 start = i;
33                                 break;
34                         }
35                 }
36                 for(int i=start;i<A.getLength();i++){
37                         if((A.getAligned()[i] == '-' || B.getAligned()[i] == '-') && (A.getAligned()[i] == '.' || B.getAligned()[i] == '.')){}
38                         else if(A.getAligned()[i] == '-' && B.getAligned()[i] != '-' && B.getAligned()[i] != '.'){
39                                 if(openGapA == 0){
40                                         difference++;
41                                         minLength++;
42                                         openGapA = 1;
43                                         openGapB = 0;
44                                 }
45                         }
46                         else if(A.getAligned()[i] != '-' && B.getAligned()[i] == '-' && A.getAligned()[i] != '.'){
47                                 if(openGapB == 0){
48                                         difference++;
49                                         minLength++;
50                                         openGapA = 0;
51                                         openGapB = 1;
52                                 }
53                         }
54                         else if(A.getAligned()[i] != '-' && B.getAligned()[i] != '-'){
55                                 if(A.getAligned()[i] != B.getAligned()[i]){
56                                         difference++;
57                                         minLength++;
58                                         openGapA = 0;
59                                         openGapB = 0;
60                                 }
61                                 else{
62                                         minLength++;
63                                         openGapA = 0;
64                                         openGapB = 0;
65                                 }
66                         }
67                         else if(A.getAligned()[i] == '.' && B.getAligned()[i] == '.'){
68                                 break;
69                         }
70                 }
71                 if(minLength == 0)      {       dist = 1.0000;                                                  }
72                 else                            {       dist = (double)difference / minLength;  }
73         }
74         
75 };
76
77 /**************************************************************************************************/
78
79 #endif