]> git.donarmstrong.com Git - mothur.git/blob - ignoregaps.h
added count.groups command and paralellized align.seqs for windows
[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         ignoreGaps(const ignoreGaps& ddb) {}
25         
26         void calcDist(Sequence A, Sequence B){          
27                 int diff = 0;
28                 int length = 0;
29                 int start = 0;
30                 bool overlap = false;
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                                 overlap = true;
40                                 break;
41                         }
42                 }
43                 
44                 for(int i=start; i<alignLength; i++){
45                         if(seqA[i] == '.' || seqB[i] == '.'){
46                                 break;
47                         }
48                         else if((seqA[i] != '-' && seqB[i] != '-')){
49                                 if(seqA[i] != seqB[i]){
50                                         diff++;
51                                 }
52                                 length++;
53                         }
54                 }
55                 
56                 //non-overlapping sequences
57                 if (!overlap) { length = 0; }
58
59                 if(length == 0)         {       dist = 1.0000;                                                          }
60                 else                            {       dist = ((double)diff  / (double)length);        }
61                 
62         }
63         
64 };
65
66 /**************************************************************************************************/
67 #endif
68