ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/GAlnExtend.h
(Generate patch)
# Line 5 | Line 5
5  
6   #include "GBase.h"
7   #include "GList.hh"
8 < #include <string.h>
8 > #include "gdna.h"
9  
10 < #define GDEBUG 1
10 > //#define GDEBUG 1
11  
12   enum {
13      gxEDIT_OP_MASK = 0x3,
# Line 98 | Line 98
98  
99          if (GX_EDITOP_GET(oplast) == op) {
100              uint32 l=ops[opnum-1];
101 <            ops[opnum-1]=GX_EDITOP_CONS((GX_EDITOP_GET(l)),
101 >            ops[opnum-1]=GX_EDITOP_CONS((GX_EDITOP_GET(l)),
102                 (GX_EDITOP_VAL(l) + k));
103              }
104          else {
# Line 215 | Line 215
215  
216   };
217  
218 < #define GREEDY_MAX_COST_FRACTION 5
218 > #define GREEDY_MAX_COST_FRACTION 8
219   /* (was 2) sequence_length / (this number) is a measure of how hard the
220    alignment code will work to find the optimal alignment; in fact
221    this gives a worst case bound on the number of loop iterations */
# Line 346 | Line 346
346         a_len=0;
347             b_len=0;
348             if (ed_script==NULL) return;
349 <           for (uint32 i=0; i<ed_script->opnum; i++) {
349 >           for (uint32 i=0; i<ed_script->opnum; i++) {
350                    int num=((ed_script->ops[i]) >> 2);
351                    char op_type = 3 - ( ed_script->ops[i] & gxEDIT_OP_MASK );
352                    if (op_type == 3 || op_type < 0 )
# Line 371 | Line 371
371             }
372  
373   #ifdef GDEBUG
374 <        void printAlignment(FILE* f, const char* sa, int sa_len,
374 >        void printAlignment(FILE* f, const char* sa, int sa_len,
375                       const char* sb, int sb_len) {
376                  //print seq A
377             char al[1024]; //display buffer for seq A
# Line 436 | Line 436
436         }
437   #endif
438    };
439 <  
439 >
440   struct GXAlnInfo {
441   const char *qseq;
442   int ql,qr;
# Line 466 | Line 466
466    bool operator<(GXAlnInfo& d) {
467      return ((score==d.score)? pid>d.pid : score>d.score);
468      }
469  bool operator>(GXAlnInfo& d) {
470    return ((score==d.score)? pid<d.pid : score<d.score);
471    }
469    bool operator==(GXAlnInfo& d) {
470      return (score==d.score && pid==d.pid);
471      }
# Line 484 | Line 481
481     bool operator<(GXSeed& d){
482        return ((b_ofs==d.b_ofs) ? a_ofs<d.a_ofs : b_ofs<d.b_ofs);
483        }
487   bool operator>(GXSeed& d){
488      return ((b_ofs==d.b_ofs) ? a_ofs>d.a_ofs : b_ofs>d.b_ofs);
489      }
484     bool operator==(GXSeed& d){
485        return (b_ofs==d.b_ofs && a_ofs==d.a_ofs); //should never be the case, seeds are uniquely constructed
486        }
# Line 554 | Line 548
548          int a_gap=scur.a_ofs-sprev.a_ofs-sprev.len;
549          int max_gap=b_gap;
550          int min_gap=a_gap;
551 <        if (min_gap>max_gap) swap(max_gap, min_gap);
551 >        if (min_gap>max_gap) Gswap(max_gap, min_gap);
552          int _penalty=0;
553          if (min_gap<0) { //overlap
554                 if (max_gap>0) { _penalty=GMAX((-min_gap), max_gap); }
# Line 574 | Line 568
568       //return ((score==d.score) ? seeds.Count()>d.seeds.Count() : score>d.score);
569       return ((score==d.score) ? w_min_b<d.w_min_b : score>d.score);
570       }
577  bool operator>(GXBand& d){
578     //return ((score==d.score) ? seeds.Count()<d.seeds.Count() : score<d.score);
579    return ((score==d.score) ? w_min_b>d.w_min_b : score<d.score);
580     }
571    bool operator==(GXBand& d){
572      //return (score==d.score && seeds.Count()==d.seeds.Count());
573       return (score==d.score && w_min_b==d.w_min_b);
# Line 588 | Line 578
578   class GXBandSet:public GList<GXBand> {
579    public:
580     GXSeed* qmatch; //long match (mismatches allowed) if a very good match was extended well
581 +   GXSeed* tmatch; //terminal match to be used if there is no better alignment
582     int idxoffset; //global anti-diagonal->index offset (a_len-1)
583     //used to convert a diagonal to an index
584     //diagonal is always b_ofs-a_ofs, so the minimum value is -a_len+1
# Line 601 | Line 592
592     GXBandSet(int a_len, int b_len):GList<GXBand>(a_len+b_len-1, false, true, false) {
593        idxoffset=a_len-1;
594        qmatch=NULL;
595 +      tmatch=NULL; //terminal match to be used if everything else fails
596            //diag will range from -a_len+1 to b_len-1, so after adjustment
597            //by idxoffset we get a max of a_len+b_len-2
598        int bcount=a_len+b_len-1;
599        for (int i=0;i<bcount;i++)
600 <                   this->Add(new GXBand(i-idxoffset));
600 >              this->Add(new GXBand(i-idxoffset));
601             //unsorted, this should set fList[i]
602        }
603     ~GXBandSet() {
# Line 620 | Line 612
612       }
613   };
614  
615 + struct GXSeqData {
616 +  const char* aseq;
617 +  int alen;
618 +  const char* bseq;
619 +  int blen;
620 +  GVec<uint16>** amers;
621 +  int amlen; //minimum alignment length that's sufficient to
622 +             //trigger the quick extension heuristics
623 +  GXSeqData(const char* sa=NULL, int la=0, const char* sb=NULL, int lb=0,
624 +  GVec<uint16>* mers[]=NULL):aseq(sa), alen(la),
625 +     bseq(sb),  blen(lb), amers(mers), amlen(0) {
626 +   calc_amlen();
627 +   calc_bmlen();
628 +   }
629 +  void calc_amlen() {
630 +    if (alen) {
631 +       int ah=iround(double(alen)*0.8);
632 +       if (ah<12) ah=12;
633 +       if (amlen>ah) amlen=ah;
634 +       }
635 +    }
636 +  void calc_bmlen() {
637 +    if (blen) {
638 +      int bh = iround(double(alen)*0.6);
639 +      if (bh<12) bh=12;
640 +      if (amlen>bh) amlen=bh;
641 +      }
642 +    }
643 +  void update(const char* sa, int la, GVec<uint16>** mers,
644 +          const char* sb, int lb, int mlen=0) {
645 +     aseq=sa;
646 +     alen=la;
647 +     amers=mers;
648 +     if (mlen) {
649 +       amlen=mlen;
650 +       }
651 +       else calc_amlen();
652 +     if (sb==bseq && blen==lb) return;
653 +     bseq=sb;
654 +     blen=lb;
655 +     calc_bmlen();
656 +     }
657 +  /*
658 +  void update_b(const char* sb, int lb) {
659 +     if (sb==bseq && blen==lb) return;
660 +     bseq=sb;
661 +     blen=lb;
662 +     calc_bmlen();
663 +     }*/
664 + };
665 +
666 + uint16 get6mer(char* p);
667 + void table6mers(const char* s, int slen, GVec<uint16>* amers[]);
668  
669 < GXBandSet* collectSeeds_R(GList<GXSeed>& seeds, const char* seqa, int a_len, const char* seqb, int b_len); //for overlap at 3' end of seqb
669 > GXBandSet* collectSeeds_R(GList<GXSeed>& seeds, GXSeqData& sd); //for overlap at 3' end of seqb
670  
671 < GXBandSet* collectSeeds_L(GList<GXSeed>& seeds, const char* seqa, int a_len, const char* seqb, int b_len); //for overlap at 5' end of seqb
671 > GXBandSet* collectSeeds_L(GList<GXSeed>& seeds, GXSeqData& sd); //for overlap at 5' end of seqb
672  
673   void printEditScript(GXEditScript* ed_script);
674  
# Line 646 | Line 691
691   struct CAlnTrim {
692    GAlnTrimType type;
693    int boundary; //base index (either left or right) excluding terminal poly-A stretches
694 <  void prepare(GAlnTrimType trim_type, const char* s, int s_len) {
695 <    type=trim_type;
694 >  int safelen; //alignment length > amlen should be automatically validated
695 >  int seedlen;
696 >  void prepare(const char* s, int s_len) {
697 >    //type=trim_type;
698 >    //amlen=smlen;
699      boundary=0;
700      if (type==galn_TrimLeft) {
701          int s_lbound=0;
# Line 676 | Line 724
724         }
725      }
726  
727 <  CAlnTrim(GAlnTrimType trim_type, const char* s, int s_len) {
728 <    prepare(trim_type, s, s_len);
727 >  CAlnTrim(GAlnTrimType trim_type, const char* s, int s_len, int smlen):
728 >                   type(trim_type), boundary(0), safelen(smlen) {
729 >    prepare(s, s_len);
730      }
731  
732    bool validate(int sl, int sr, int alnpid, int adist) {
733     int alnlen=sr-sl+1;
734 +   if (alnpid>93 && alnlen>safelen) return true;
735     sl--;sr--; //boundary is 0-based
736 <   int badj=0;
737 <   int admax=3;
738 <   if (alnlen<11) {
736 >   int badj=0; //default boundary is 3 bases distance to end
737 >   int admax=1;
738 >   if (alnlen<13) {
739        //stricter boundary check
740 +      if (alnpid<90) return false;
741        badj=2;
742 <      admax=1;
742 >      if (alnlen<=7) { badj++; admax=0; }
743        }
744     if (adist>admax) return false;
745     if (type==galn_TrimRight) {
746        return (sr>=boundary+badj);
747        }
748     else {
749 <      //left side should be more stringent
750 <      if (alnpid<91) {
751 <        if (alnlen<11) return false;
749 >      //left match should be more stringent (5')
750 >      if (alnpid<93) {
751 >        if (alnlen<13) return false;
752 >        admax=0;
753          badj++;
754          }
755        return (sl<=boundary-badj);
# Line 719 | Line 771
771   GXAlnInfo* GreedyAlign(const char* q_seq,  int q_alnstart, const char* s_seq, int s_alnstart,
772          bool editscript=false, int reward=2, int penalty=3, int xdrop=8);
773  
774 < GXAlnInfo* match_LeftEnd(const char* seqa, int seqa_len, const char* seqb, int seqb_len,
775 <          CGreedyAlignData* gxmem=NULL, int min_pid=83);
724 < GXAlnInfo* match_RightEnd(const char* seqa, int seqa_len, const char* seqb, int seqb_len,
725 <          CGreedyAlignData* gxmem=NULL, int min_pid=73);
774 > GXAlnInfo* match_LeftEnd(GXSeqData& sd, CGreedyAlignData* gxmem=NULL, int min_pid=83);
775 > GXAlnInfo* match_RightEnd(GXSeqData& sd, CGreedyAlignData* gxmem=NULL, int min_pid=73);
776   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines