]> git.donarmstrong.com Git - mothur.git/blob - ignoregaps.h
added pipeline commands which involved change to command factory and command class...
[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         void calcDist(Sequence A, Sequence B){          
24                 int diff = 0;
25                 int length = 0;
26                 int start = 0;
27                 bool overlap = false;
28                 
29                 string seqA = A.getAligned();
30                 string seqB = B.getAligned();
31                 int alignLength = seqA.length();
32                 
33                 for(int i=0;i<alignLength;i++){
34                         if(seqA[i] != '.' && seqB[i] != '.'){
35                                 start = i;
36                                 overlap = true;
37                                 break;
38                         }
39                 }
40                 
41                 for(int i=start; i<alignLength; i++){
42                         if(seqA[i] == '.' || seqB[i] == '.'){
43                                 break;
44                         }
45                         else if((seqA[i] != '-' && seqB[i] != '-')){
46                                 if(seqA[i] != seqB[i]){
47                                         diff++;
48                                 }
49                                 length++;
50                         }
51                 }
52                 
53                 //non-overlapping sequences
54                 if (!overlap) { length = 0; }
55
56                 if(length == 0)         {       dist = 1.0000;                                                          }
57                 else                            {       dist = ((double)diff  / (double)length);        }
58                 
59         }
60         
61 };
62
63 /**************************************************************************************************/
64 #endif
65