]> git.donarmstrong.com Git - mothur.git/blob - ignoregaps.h
added modify names parameter to set.dir
[mothur.git] / ignoregaps.h
1 #ifndef IGNOREGAPS_H
2 #define IGNOREGAPS_H
3 /*
4  *  ignoregaps.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 //      this class calculates distances by ignoring all gap characters.  so if seq a has an "A" and seq
17 //      b has a '-', there is no penalty
18
19 class ignoreGaps : public Dist {
20         
21 public:
22         
23         ignoreGaps() {}
24         
25         void calcDist(Sequence A, Sequence B){          
26                 int diff = 0;
27                 int length = 0;
28                 int start = 0;
29                 bool overlap = false;
30                 
31                 string seqA = A.getAligned();
32                 string seqB = B.getAligned();
33                 int alignLength = seqA.length();
34                 
35                 for(int i=0;i<alignLength;i++){
36                         if(seqA[i] != '.' && seqB[i] != '.'){
37                                 start = i;
38                                 overlap = true;
39                                 break;
40                         }
41                 }
42                 
43                 for(int i=start; i<alignLength; i++){
44                         if(seqA[i] == '.' || seqB[i] == '.'){
45                                 break;
46                         }
47                         else if((seqA[i] != '-' && seqB[i] != '-')){
48                                 if(seqA[i] != seqB[i]){
49                                         diff++;
50                                 }
51                                 length++;
52                         }
53                 }
54                 
55                 //non-overlapping sequences
56                 if (!overlap) { length = 0; }
57
58                 if(length == 0)         {       dist = 1.0000;                                                          }
59                 else                            {       dist = ((double)diff  / (double)length);        }
60                 
61         }
62         
63 };
64
65 /**************************************************************************************************/
66 #endif
67