]> git.donarmstrong.com Git - mothur.git/blob - eachgapignore.h
added pipeline commands which involved change to command factory and command class...
[mothur.git] / eachgapignore.h
1 #ifndef EACHGAPIGNORE_H
2 #define EACHGAPIGNORE_H
3 /*
4  *  eachgapignore.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 eachGapIgnoreTermGapDist : public Dist {
18         
19 public:
20         
21         void calcDist(Sequence A, Sequence B){          
22                 int diff = 0;
23                 int length = 0;
24                 int start = 0;
25                 int end = 0;
26                 bool overlap = false;
27                 
28                 string seqA = A.getAligned();
29                 string seqB = B.getAligned();
30                 int alignLength = seqA.length();
31                 
32                 for(int i=0;i<alignLength;i++){
33                         if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){
34                                 start = i;
35 //                              cout << "start: " << start << endl;
36                                 overlap = true;
37                                 break;
38                         }
39                 }
40                 for(int i=alignLength-1;i>=0;i--){
41                         if(seqA[i] != '.' && seqB[i] != '.' && seqA[i] != '-' && seqB[i] != '-' ){
42                                 end = i;
43 //                              cout << "end: " << end << endl;
44                                 overlap = true;
45                                 break;
46                         }
47                 }
48                 
49                 for(int i=start;i<=end;i++){
50                         if(seqA[i] == '.' || seqB[i] == '.'){
51                                 break;  
52                         }
53                         else if(seqA[i] != '-' || seqB[i] != '-'){
54                                 if(seqA[i] != seqB[i]){
55                                         diff++;
56                                 }
57                                 length++;
58                         }
59                 }
60                 
61                 //non-overlapping sequences
62                 if (!overlap) { length = 0; }
63                 
64                 if(length == 0) {       dist = 1.0000;                                                          }
65                 else                    {       dist = ((double)diff  / (double)length);        }
66                 
67         }
68         
69 };
70
71 /**************************************************************************************************/
72
73 #endif
74
75