-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCigarAlignment.C
85 lines (64 loc) · 1.74 KB
/
CigarAlignment.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/****************************************************************
CigarAlignment.C
Copyright (C)2014 William H. Majoros ([email protected]).
This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
License (GPL) version 3, as described at www.opensource.org.
****************************************************************/
#include <iostream>
#include "CigarAlignment.H"
using namespace std;
using namespace BOOM;
CigarAlignment::CigarAlignment(int length)
: A(length)
{
// ctor
}
int &CigarAlignment::operator[](int i)
{
return A[i];
}
int CigarAlignment::operator[](int i) const
{
return A[i];
}
int CigarAlignment::mapApproximate(int i,Direction prefer) const
{
const int L=A.size();
switch(prefer) {
case DIR_LEFT: // prefer left
for(int j=i ; j>=0 ; --j)
if(A[j]!=CIGAR_UNDEFINED) return A[j];
for(int j=i+1 ; j<L ; ++j)
if(A[j]!=CIGAR_UNDEFINED) return A[j];
break;
case DIR_RIGHT:// prefer right
for(int j=i ; j<L ; ++j)
if(A[j]!=CIGAR_UNDEFINED) return A[j];
for(int j=i-1 ; j>=0 ; --j)
if(A[j]!=CIGAR_UNDEFINED) return A[j];
break;
case DIR_NONE:// prefer shortest distance
for(int j=i, k=i ; j>=0 || k<L ; --j, ++k) {
if(j>=0 && A[j]!=CIGAR_UNDEFINED) return A[j];
if(k<L && A[k]!=CIGAR_UNDEFINED) return A[k];
}
break;
default: throw "Bad direction in CigarAlignment::mapApproximate()";
}
return CIGAR_UNDEFINED;
}
CigarAlignment *CigarAlignment::invert(int length) const
{
CigarAlignment &I=*new CigarAlignment(length);
I.A.setAllTo(CIGAR_UNDEFINED);
int L=A.size();
for(int i=0 ; i<L ; ++i) {
const int to=A[i];
if(to!=CIGAR_UNDEFINED) I[to]=i;
}
return &I;
}
int CigarAlignment::length() const
{
return A.size();
}