48 istringstream istr(cigar_string);
52 while(istr >>
len >> c) {
54 if(m_elements.empty()) {
59 if(m_elements.empty()) {
63 cigar_string = cigar_string.substr(clip_pos);
69 clip_pos = (
int)istr.tellg();
78 }
else if(el.
m_type ==
'D')
83 if(m_elements.empty() || m_elements.front().m_type != el.
m_type)
84 m_elements.push_front(el);
86 m_elements.front().m_len += el.
m_len;
93 }
else if(el.
m_type ==
'D')
98 if(m_elements.empty() || m_elements.back().m_type != el.
m_type)
99 m_elements.push_back(el);
101 m_elements.back().m_len += el.
m_len;
106 ITERATE(list<SElement>,
i, m_elements)
109 int missingstart = qstart+m_qfrom;
112 int missingend = qlen-1-m_qto-qstart;
124 ITERATE(list<SElement>,
i, m_elements) {
125 if(
i->m_type ==
'M') {
128 for(
int l = 0;
l <
i->m_len; ++
l) {
134 indels.push_back(indl);
136 is_match = !is_match;
144 indels.push_back(indl);
146 }
else if(
i->m_type ==
'D') {
148 indels.push_back(indl);
152 indels.push_back(indl);
164 ITERATE(list<SElement>,
i, m_elements) {
165 if(
i->m_type ==
'M') {
168 for(
int l = 0;
l <
i->m_len; ++
l) {
173 is_match = !is_match;
180 }
else if(
i->m_type ==
'D') {
189 int missingstart = qstart+m_qfrom;
192 int missingend = qlen-1-m_qto-qstart;
203 ITERATE(list<SElement>,
i, m_elements) {
204 if(
i->m_type ==
'M') {
205 align.first.insert(align.first.end(),
query,
query+
i->m_len);
209 }
else if(
i->m_type ==
'D') {
210 align.first.insert(align.first.end(),
i->m_len,
'-');
214 align.first.insert(align.first.end(),
query,
query+
i->m_len);
216 align.second.insert(align.second.end(),
i->m_len,
'-');
227 ITERATE(list<SElement>,
i, m_elements) {
228 if(
i->m_type ==
'M') {
229 for(
int l = 0;
l <
i->m_len; ++
l) {
235 }
else if(
i->m_type ==
'D') {
249 ITERATE(list<SElement>,
i, m_elements) {
250 if(
i->m_type ==
'M') {
251 for(
int l = 0;
l <
i->m_len; ++
l) {
257 }
else if(
i->m_type ==
'D') {
274 ITERATE(list<SElement>,
i, m_elements) {
275 if(
i->m_type ==
'M') {
276 for(
int l = 0;
l <
i->m_len; ++
l) {
281 }
else if(
i->m_type ==
'D') {
283 score -= gopen+gapextend*
i->m_len;
286 score -= gopen+gapextend*
i->m_len;
297 int* s =
new int[nb+1];
298 int* sm =
new int[nb+1];
299 int* gapb =
new int[nb+1];
300 char* mtrx =
new char[(na+1)*(nb+1)];
307 for(
int i = 2;
i <= nb; ++
i)
308 sm[
i] = sm[
i-1]-sigma;
311 for(
int i = 0;
i <= nb; ++
i)
312 gapb[
i] = bignegative;
314 enum{Agap = 1, Bgap = 2, Astart = 4, Bstart = 8};
317 for(
int i = 1;
i <= nb; ++
i) {
323 for(
int i = 0;
i < na; ++
i) {
324 *(++m) = Bstart|Bgap;
326 int gapa = bignegative;
328 const char* matrix =
delta[ai];
330 for(
int j = 0; j < nb; ) {
332 int ss = sm[j]+matrix[(
int)
b[j]];
340 int& gapbj = gapb[++j];
342 if(sm[j]-rs > gapbj) {
369 m = mtrx+(na+1)*(nb+1)-1;
371 while(ia >= 0 || ib >= 0) {
374 while(!(*m&Astart)) {
383 while(!(*m&Bstart)) {
411 int* s =
new int[nb+1];
412 int* sm =
new int[nb+1];
413 int* gapb =
new int[nb+1];
414 char* mtrx =
new char[(na+1)*(nb+1)];
418 enum{Agap = 1, Bgap = 2, Astart = 4, Bstart = 8, Zero = 16};
420 for(
int i = 0;
i <= nb; ++
i) {
428 char* max_ptr = mtrx;
431 for(
int i = 0;
i < na; ++
i) {
435 const char* matrix =
delta[ai];
437 for(
int j = 0; j < nb; ) {
439 int ss = sm[j]+matrix[(
int)
b[j]];
447 int& gapbj = gapb[++j];
449 if(sm[j]-rs > gapbj) {
485 int ia = (
int)(max_ptr-mtrx)/(nb+1)-1;
486 int ib = (max_ptr-mtrx)%(nb+1)-1;
489 while((ia >= 0 || ib >= 0) && !(*m&Zero)) {
492 while(!(*m&Astart)) {
501 while(!(*m&Bstart)) {
525 CCigar LclAlign(
const char*
a,
int na,
const char*
b,
int nb,
int rho,
int sigma,
bool pinleft,
bool pinright,
const char delta[256][256]) {
529 int* s =
new int[nb+1];
530 int* sm =
new int[nb+1];
531 int* gapb =
new int[nb+1];
532 char* mtrx =
new char[(na+1)*(nb+1)];
537 enum{Agap = 1, Bgap = 2, Astart = 4, Bstart = 8, Zero = 16};
541 gapb[0] = bignegative;
545 mtrx[1] = Astart|Agap;
546 gapb[1] = bignegative;
547 for(
int i = 2;
i <= nb; ++
i) {
548 sm[
i] = sm[
i-1]-sigma;
550 gapb[
i] = bignegative;
555 for(
int i = 1;
i <= nb; ++
i) {
558 gapb[
i] = bignegative;
564 char* max_ptr = mtrx;
567 for(
int i = 0;
i < na; ++
i) {
568 *(++m) = pinleft ? Bstart|Bgap : Zero;
569 int gapa = bignegative;
572 const char* matrix =
delta[ai];
574 for(
int j = 0; j < nb; ) {
576 int ss = sm[j]+matrix[(
int)
b[j]];
584 int& gapbj = gapb[++j];
586 if(sm[j]-rs > gapbj) {
614 if(*sp <= 0 && !pinleft) {
630 maxa = (
int)(max_ptr-mtrx)/(nb+1)-1;
631 maxb = (max_ptr-mtrx)%(nb+1)-1;
637 while((ia >= 0 || ib >= 0) && !(*m&Zero)) {
640 while(!(*m&Astart)) {
649 while(!(*m&Bstart)) {
676 int* s =
new int[nb+1];
677 int* sm =
new int[nb+1];
678 int* gapb =
new int[nb+1];
679 char* mtrx =
new char[(na+1)*(nb+1)];
683 enum{Agap = 1, Bgap = 2, Astart = 4, Bstart = 8, Zero = 16};
685 for(
int i = 0;
i <= nb; ++
i) {
693 char* max_ptr = mtrx;
699 const char* matrix =
delta[ai];
701 int bleft = blimits->
GetFrom();
702 int bright = blimits->
GetTo();
708 for(
int j = bleft; j <= bright; ) {
710 int ss = sm[j]+matrix[(
int)
b[j]];
718 int& gapbj = gapb[++j];
720 if(sm[j]-rs > gapbj) {
753 if(++blimits ==
last)
759 for( ; bright <
next-1; ++bright)
765 int ia = (
int)(max_ptr-mtrx)/(nb+1)-1;
766 int ib = (max_ptr-mtrx)%(nb+1)-1;
769 while((ia >= 0 || ib >= 0) && !(*m&Zero)) {
772 while(!(*m&Astart)) {
781 while(!(*m&Bstart)) {
807 for(
int i = 0;
i < 256; ++
i) {
809 for(
int j = 0; j < 256; ++j) {
811 else matrix[
i][j] = -mismatch;
818 string aa(
"ARNDCQEGHILKMFPSTWYVBZX*");
820 4,-1,-2,-2, 0,-1,-1, 0,-2,-1,-1,-1,-1,-2,-1, 1, 0,-3,-2, 0,-2,-1, 0,-4,
821 -1, 5, 0,-2,-3, 1, 0,-2, 0,-3,-2, 2,-1,-3,-2,-1,-1,-3,-2,-3,-1, 0,-1,-4,
822 -2, 0, 6, 1,-3, 0, 0, 0, 1,-3,-3, 0,-2,-3,-2, 1, 0,-4,-2,-3, 3, 0,-1,-4,
823 -2,-2, 1, 6,-3, 0, 2,-1,-1,-3,-4,-1,-3,-3,-1, 0,-1,-4,-3,-3, 4, 1,-1,-4,
824 0,-3,-3,-3, 9,-3,-4,-3,-3,-1,-1,-3,-1,-2,-3,-1,-1,-2,-2,-1,-3,-3,-2,-4,
825 -1, 1, 0, 0,-3, 5, 2,-2, 0,-3,-2, 1, 0,-3,-1, 0,-1,-2,-1,-2, 0, 3,-1,-4,
826 -1, 0, 0, 2,-4, 2, 5,-2, 0,-3,-3, 1,-2,-3,-1, 0,-1,-3,-2,-2, 1, 4,-1,-4,
827 0,-2, 0,-1,-3,-2,-2, 6,-2,-4,-4,-2,-3,-3,-2, 0,-2,-2,-3,-3,-1,-2,-1,-4,
828 -2, 0, 1,-1,-3, 0, 0,-2, 8,-3,-3,-1,-2,-1,-2,-1,-2,-2, 2,-3, 0, 0,-1,-4,
829 -1,-3,-3,-3,-1,-3,-3,-4,-3, 4, 2,-3, 1, 0,-3,-2,-1,-3,-1, 3,-3,-3,-1,-4,
830 -1,-2,-3,-4,-1,-2,-3,-4,-3, 2, 4,-2, 2, 0,-3,-2,-1,-2,-1, 1,-4,-3,-1,-4,
831 -1, 2, 0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
int i = 0;
i < num; ++
i) {
855 for(
int j = 0; j < num; ++j) {
856 int score = scores[num*j+
i];
858 matrix[(
int)c][(
int)d] = score;
867 int length = (
int)seq.size();
876 case 'A': tA += 1;
break;
877 case 'C': tC += 1;
break;
878 case 'G': tG += 1;
break;
879 case 'T': tT += 1;
break;
883 double entropy = -(tA*
log(tA/length)+tC*
log(tC/length)+tG*
log(tG/length)+tT*
log(tT/length))/(length*
log(4.));
void PushFront(const SElement &el)
TCharAlign ToAlign(const char *query, const char *subject) const
void PushBack(const SElement &el)
int Distance(const char *query, const char *subject) const
CCigar(int qto=-1, int sto=-1)
TInDels GetInDels(int sstart, const char *const query, const char *subject) const
string CigarString(int qstart, int qlen) const
int Score(const char *query, const char *subject, int gopen, int gapextend, const char delta[256][256]) const
string DetailedCigarString(int qstart, int qlen, const char *query, const char *subject) const
int Matches(const char *query, const char *subject) const
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
double Entropy(const string &seq)
CCigar LclAlign(const char *a, int na, const char *b, int nb, int rho, int sigma, const char delta[256][256])
CCigar VariBandAlign(const char *a, int na, const char *b, int nb, int rho, int sigma, const char delta[256][256], const TSignedSeqRange *blimits)
CCigar GlbAlign(const char *a, int na, const char *b, int nb, int rho, int sigma, const char delta[256][256])
pair< string, string > TCharAlign
vector< CInDelInfo > TInDels
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define BEGIN_SCOPE(ns)
Define a new scope.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
TTo GetTo(void) const
Get the To member data.
TFrom GetFrom(void) const
Get the From member data.
unsigned int
A callback function used to compare two keys in a database.
Magic spell ;-) needed for some weird compilers... very empiric.
Int4 delta(size_t dimension_, const Int4 *score_)
static int match(PCRE2_SPTR start_eptr, PCRE2_SPTR start_ecode, uint16_t top_bracket, PCRE2_SIZE frame_size, pcre2_match_data *match_data, match_block *mb)
static SLJIT_INLINE sljit_ins l(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)