示例#1
0
文件: merger.c 项目: WenchaoLin/JAMg
int main(int argc, char **argv)
{
    AjPAlign align;
    AjPSeq a;
    AjPSeq b;
    AjPSeqout seqout;

    AjPStr m;
    AjPStr n;

    AjPStr merged = NULL;

    ajuint lena;
    ajuint lenb;

    const char   *p;
    const char   *q;

    ajint start1 = 0;
    ajint start2 = 0;

    float *path;
    ajint *compass;

    AjPMatrixf matrix;
    AjPSeqCvt  cvt = 0;
    float **sub;

    float gapopen;
    float gapextend;
    ajulong maxarr = 1000;
    ajulong len;		  /* arbitrary. realloc'd if needed */
    size_t  stlen;

    float score;
    ajint begina;
    ajint beginb;

    embInit("merger", argc, argv);

    a         = ajAcdGetSeq("asequence");
    b         = ajAcdGetSeq("bsequence");
    seqout    = ajAcdGetSeqout("outseq");
    matrix    = ajAcdGetMatrixf("datafile");
    gapopen   = ajAcdGetFloat("gapopen");
    gapextend = ajAcdGetFloat("gapextend");
    align     = ajAcdGetAlign("outfile");

    gapopen = ajRoundFloat(gapopen, 8);
    gapextend = ajRoundFloat(gapextend, 8);

    AJCNEW(path, maxarr);
    AJCNEW(compass, maxarr);

    /*
    **  make the two sequences lowercase so we can show which one we are
    **  using in the merge by uppercasing it
    */

    ajSeqFmtLower(a);
    ajSeqFmtLower(b);

    m = ajStrNew();
    n = ajStrNew();

    sub = ajMatrixfGetMatrix(matrix);
    cvt = ajMatrixfGetCvt(matrix);

    begina = ajSeqGetBegin(a);
    beginb = ajSeqGetBegin(b);

    lena = ajSeqGetLen(a);
    lenb = ajSeqGetLen(b);

    if(lenb > (ULONG_MAX/(ajulong)(lena+1)))
	ajFatal("Sequences too big. Try 'supermatcher'");

    len  = lena*lenb;

    if(len>maxarr)
    {

	ajDebug("merger: resize path, len to %d (%d * $d)\n",
		len, lena, lenb);

	stlen = (size_t) len;
        AJCRESIZE(path,stlen);
        AJCRESIZE(compass,stlen);
        maxarr=len;
    }


    p = ajSeqGetSeqC(a);
    q = ajSeqGetSeqC(b);

    ajStrAssignC(&m,"");
    ajStrAssignC(&n,"");

    score = embAlignPathCalc(p,q,lena,lenb,gapopen,gapextend,path,sub,cvt,
		     compass, ajFalse);

    /*score = embAlignScoreNWMatrix(path,compass,gapopen,gapextend,
                                  a,b,lena,lenb,sub,cvt,
				  &start1,&start2);*/

    embAlignWalkNWMatrix(path,a,b,&m,&n,lena,lenb, &start1,&start2,gapopen,
			 gapextend,compass);

    /*
    ** now construct the merged sequence, uppercase the bits of the two
    ** input sequences which are used in the merger
    */
    merger_Merge(align, &merged,p,q,m,n,start1,start2,
		 ajSeqGetNameC(a),ajSeqGetNameC(b));

    embAlignReportGlobal(align, a, b, m, n,
			 start1, start2, gapopen, gapextend,
			 score, matrix, begina, beginb);

    ajAlignWrite(align);
    ajAlignReset(align);

    /* write the merged sequence */
    ajSeqAssignSeqS(a, merged);
    ajSeqoutWriteSeq(seqout, a);
    ajSeqoutClose(seqout);
    ajSeqoutDel(&seqout);

    ajSeqDel(&a);
    ajSeqDel(&b);

    ajAlignClose(align);
    ajAlignDel(&align);
    ajStrDel(&merged);

    AJFREE(compass);
    AJFREE(path);

    ajStrDel(&n);
    ajStrDel(&m);

    embExit();

    return 0;
}
示例#2
0
static AjBool  ssematch_NWScore(AjPScop temp_scop, 
				AjPSeq pseq, 
				ajint mode, 
				AjPMatrixf matrix,
				float gapopen, 
				float gapextend)


{
    ajint         start1  =0;	/* Start of seq 1, passed as arg but not used.*/
    ajint         start2  =0;	/* Start of seq 2, passed as arg but not used.*/
    ajint         maxarr  =300;	/* Initial size for matrix.                   */
    ajint         len;

    ajint        *compass;

    const char       *p;        /* Query sequence.                            */
    const char       *q;        /* Subject sequence from scop object.         */

    float     **sub;
    float       id       =0.;	/* Passed as arg but not used here.           */
    float       sim      =0.;	
    float       idx      =0.;	/* Passed as arg but not used here.           */
    float       simx     =0.;	/* Passed as arg but not used here.           */
    float      *path;

    AjPStr      pstr = NULL;	/*  m walk alignment for first sequence 
				    Passed as arg but not used here.          */
    AjPStr      qstr = NULL;	/*  n walk alignment for second sequence 
				    Passed as arg but not used here.          */

    AjPSeq      qseq = NULL;    /* Subject sequence.                          */

   
    ajint lenp;                 /* Length of query sequence.                  */
    ajint lenq;                 /* Length of subject sequence.                */
    

    AjPSeqCvt   cvt  = 0;
    AjBool      show = ajFalse; /*Passed as arg but not used here.            */






    AJCNEW(path, maxarr);
    AJCNEW(compass, maxarr);
    pstr = ajStrNew();    
    qstr = ajStrNew();    
    gapopen   = ajRoundFloat(gapopen,8);
    gapextend = ajRoundFloat(gapextend,8);
    sub = ajMatrixfGetMatrix(matrix);
    cvt = ajMatrixfGetCvt(matrix);


    
    
    /* Extract subject sequence from scop object, convert to 3 letter code. */
    if (mode == 0)
        qseq = ssematch_convertbases(temp_scop->Sse);
    else if (mode == 1)
        qseq = ssematch_convertbases(temp_scop->Sss);


    lenp = ajSeqGetLen(pseq); /* Length of query sequence.   */
    lenq = ajSeqGetLen(qseq); /* Length of subject sequence. */
   

   


    /* Start of main application loop */
    /* Intitialise variables for use by alignment functions*/	    
    len = (lenp * lenq);

    if(len>maxarr)
    {
	AJCRESIZE(path,len);
	AJCRESIZE(compass,len);
	maxarr=len;
    }

    p = ajSeqGetSeqC(pseq); 
    q = ajSeqGetSeqC(qseq); 

    ajStrAssignC(&pstr,"");
    ajStrAssignC(&qstr,"");


    /* Check that no sequence length is 0. */
    if((lenp == 0)||(lenq == 0))
    {
       	AJFREE(compass);
	AJFREE(path);
	ajStrDel(&pstr);
	ajStrDel(&qstr);
    }


    /* Call alignment functions. */
    embAlignPathCalc(p,q,lenp,lenq, gapopen,
		     gapextend,path,sub,cvt,compass,show);

    /*embAlignScoreNWMatrix(path,compass,gapopen,gapextend,
                          pseq, qseq,
			  lenp,lenq,sub,cvt,
			  &start1,&start2);*/

    embAlignWalkNWMatrix(path,pseq,qseq,&pstr,&qstr,
			 lenp,lenq,&start1,&start2,
                         gapopen,gapextend,compass);

    embAlignCalcSimilarity(pstr,qstr,sub,cvt,lenp,
			   lenq,&id,&sim,&idx, &simx);


    /* Assign score. */
    
    temp_scop->Score = sim;
    
  



    /* Tidy up */
    AJFREE(compass);
    AJFREE(path);
    ajStrDel(&pstr);
    ajStrDel(&qstr);
    ajSeqDel(&qseq); 

    
    /* Bye Bye */
    return ajTrue;
}