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