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