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