GBrowse

 view release on metacpan or  search on metacpan

libalign/CAlign.xs  view on Meta::CPAN

    fprintf(stderr,"row=%d, col=%d, score=%d, event=%s\n",row,col,dpm[row][col].score,
	    dpm[row][col].event==A_EXTEND ? "extend"
           :dpm[row][col].event==GAP_TGT  ? "gap_tgt"
           :dpm[row][col].event==GAP_SRC  ? "gap_src"
	   :"error");
#endif

    alignment[row-1] = col-1;
    if (dpm[row][col].event == A_EXTEND) {
      row--; col--;
    }

    else if (dpm[row][col].event == GAP_TGT) {
      col--;
    }

    else {
      alignment[row-1] = -1;  /* -1 means no match */
      row--;
    }
  }

#if DBG
  fprintf(stderr,"traceback done\n");
#endif

  *align_out = alignment;

#if DBG
  for (i=0;i<src_len;i++) {
    fprintf(stderr,"%3d %1c %3d %1c\n",
	    i,src[i],alignment[i],alignment[i]>=0 ? tgt[alignment[i]] : '-');
  }
#endif


  /* clean up */
  for (row=0; row<=src_len; row++) {
    free(dpm[row]);
  }
  free(dpm);
  return best_cell.score;
}

MODULE = Bio::Graphics::Browser::CAlign		PACKAGE = Bio::Graphics::Browser::CAlign

void
_do_alignment(packname="Bio::Graphics::Browser::CAlign",src,tgt,options=NULL)
     char*         packname
     char*         src
     char*         tgt
     SV*           options
     PROTOTYPE: $$;$
     PREINIT:
     MatchMatrix   matrix;
     HV*           optionh;
     SV            **value;
     int           score,i;
     AlignmentPtr  alignment;
     AV*           palign;
     PPCODE:
     {
       /* copy defaults from standardMatrix */
       initMatrix(&matrix);

       if (options != NULL) {
	 if (!SvROK(options) || (SvTYPE(SvRV(options)) != SVt_PVHV))
	   croak("_do_alignment(): third argument must be a hashref");
	 optionh = (HV*) SvRV(options);
	 if (value = hv_fetch(optionh,"match",strlen("match"),0))
	   matrix.match = SvIV(*value);
	 if (value = hv_fetch(optionh,"mismatch",strlen("mismatch"),0))
	   matrix.mismatch = SvIV(*value);
	 if (value = hv_fetch(optionh,"gap",strlen("gap"),0))
	   matrix.gap = SvIV(*value);
	 if (value = hv_fetch(optionh,"gap_extend",strlen("gap_extend"),0))
	   matrix.gap_extend = SvIV(*value);
	 if (value = hv_fetch(optionh,"wildcard_match",strlen("wildcard_match"),0))
	   matrix.wcmatch = SvIV(*value);
	 if (value = hv_fetch(optionh,"wildcard",strlen("wildcard"),0))
	   matrix.wildcard   = *SvPV_nolen(*value);
       }

       score = realign(src,tgt,&matrix,&alignment);

       palign = (AV*)sv_2mortal((SV*) newAV());
       av_extend(palign,strlen(src));
       for (i=0;i<strlen(src);i++)
	 if (alignment[i] >= 0)
	   av_push(palign,newSVnv(alignment[i]));
	 else
	   av_push(palign,&PL_sv_undef);

       XPUSHs(sv_2mortal(newSViv(score)));
       XPUSHs(sv_2mortal(newRV((SV*) palign)));
     }



( run in 0.988 second using v1.01-cache-2.11-cpan-5511b514fd6 )