]> git.donarmstrong.com Git - mothur.git/blob - onegapignore.h
added pipeline commands which involved change to command factory and command class...
[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         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                 int end = 0;
28                 bool overlap = false;
29                 
30                 string seqA = A.getAligned();
31                 string seqB = B.getAligned();
32                 int alignLength = seqA.length();
33
34                 // this assumes that sequences start and end with '.'s instead of'-'s.
35                 for(int i=0;i<alignLength;i++){
36                         if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){
37                                 start = i;
38 //                              cout << "start: " << start << endl;
39                                 overlap = true;
40                                 break;
41                         }
42                 }
43                 for(int i=alignLength-1;i>=0;i--){
44                         if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){
45                                 end = i;
46 //                              cout << "end: " << end << endl;
47                                 overlap = true;
48                                 break;
49                         }
50                 }
51                 
52                 for(int i=start;i<=end;i++){
53                         if(seqA[i] == '-' && seqB[i] == '-'){   ;       }
54                         else if(seqB[i] != '-' && seqA[i] == '-'){
55                                 if(openGapA == 0){
56                                         difference++;
57                                         minLength++;
58                                         openGapA = 1;
59                                         openGapB = 0;
60                                 }
61                         }
62                         else if(seqA[i] != '-' && seqB[i] == '-'){
63                                 if(openGapB == 0){
64                                         difference++;
65                                         minLength++;
66                                         openGapA = 0;
67                                         openGapB = 1;
68                                 }
69                         }
70                         else if(seqA[i] != '-' && seqB[i] != '-'){
71                                 if(seqA[i] != seqB[i]){
72                                         difference++;
73                                 }
74                                 minLength++;
75                                 openGapA = 0;
76                                 openGapB = 0;
77                         }
78                 }
79                 
80                 //non-overlapping sequences
81                 if (!overlap) { minLength = 0; }
82                 
83                 if(minLength == 0)      {       dist = 1.0000;                                                  }
84                 else                            {       dist = (double)difference / minLength;  }
85         }
86
87 };
88
89 /**************************************************************************************************/
90
91 #endif
92