]> git.donarmstrong.com Git - mothur.git/blob - onegapdist.h
added count.groups command and paralellized align.seqs for windows
[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         
21         oneGapDist() {}
22         oneGapDist(const oneGapDist& ddb) {}
23         
24         void calcDist(Sequence A, Sequence B){
25                 
26                 int difference = 0;
27                 int minLength = 0;
28                 int openGapA = 0;
29                 int openGapB = 0;
30                 int start = 0;
31                 
32                 string seqA = A.getAligned();
33                 string seqB = B.getAligned();
34                 int alignLength = seqA.length();
35                 
36                 for(int i=0;i<alignLength;i++){
37                         if((seqA[i] != '.' || seqB[i] != '.')){
38                                 start = i;
39                                 break;
40                         }
41                 }
42
43                 for(int i=start;i<alignLength;i++){
44                         if((seqA[i] == '-' && seqB[i] == '-') || (seqA[i] == '.' && seqB[i] == '-') || (seqA[i] == '-' && seqB[i] == '.')){     ;       }
45                         else if(seqA[i] == '.' && seqB[i] == '.'){
46                                 break;
47                         }
48                         else if(seqB[i] != '-' && (seqA[i] == '-' || seqA[i] == '.')){
49                                 if(openGapA == 0){
50                                         difference++;
51                                         minLength++;
52                                         openGapA = 1;
53                                         openGapB = 0;
54                                 }
55                         }
56                         else if(seqA[i] != '-' && (seqB[i] == '-' || seqB[i] == '.')){
57                                 if(openGapB == 0){
58                                         difference++;
59                                         minLength++;
60                                         openGapA = 0;
61                                         openGapB = 1;
62                                 }
63                         }
64                         else if(seqA[i] != '-' && seqB[i] != '-'){
65                                 if(seqA[i] != seqB[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         
79                 if(minLength == 0)      {       dist = 1.0000;                                                  }
80                 else                            {       dist = (double)difference / minLength;  }
81         }
82         
83 };
84
85 /**************************************************************************************************/
86
87 #endif