Ejemplo n.º 1
0
int main(int argc, char **argv)
{
    AjPAlign align;
    AjPSeqall seqall;
    AjPSeq a;
    AjPSeq b;
    AjPStr alga;
    AjPStr algb;
    AjPStr ss;

    ajuint    lena;
    ajuint    lenb;

    const char   *p;
    const char   *q;

    ajint start1 = 0;
    ajint start2 = 0;

    float *path;
    ajint *compass;
    float* ix;
    float* iy;
    float* m;

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

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

    float score;

    AjBool dobrief = ajTrue;
    AjBool endweight = ajFalse; /* whether end gap penalties should be applied */

    float id   = 0.;
    float sim  = 0.;
    float idx  = 0.;
    float simx = 0.;

    AjPStr tmpstr = NULL;

    size_t stlen;

    embInit("needle", argc, argv);

    matrix    = ajAcdGetMatrixf("datafile");
    a         = ajAcdGetSeq("asequence");
    ajSeqTrim(a);
    seqall    = ajAcdGetSeqall("bsequence");
    gapopen   = ajAcdGetFloat("gapopen");
    gapextend = ajAcdGetFloat("gapextend");
    endgapopen   = ajAcdGetFloat("endopen");
    endgapextend = ajAcdGetFloat("endextend");
    dobrief   = ajAcdGetBoolean("brief");
    endweight   = ajAcdGetBoolean("endweight");

    align     = ajAcdGetAlign("outfile");

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

    AJCNEW(path, maxarr);
    AJCNEW(compass, maxarr);
    AJCNEW(m, maxarr);
    AJCNEW(ix, maxarr);
    AJCNEW(iy, maxarr);

    alga  = ajStrNew();
    algb  = ajStrNew();
    ss = ajStrNew();

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

    lena = ajSeqGetLen(a);

    while(ajSeqallNext(seqall,&b))
    {
	ajSeqTrim(b);
	lenb = ajSeqGetLen(b);

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

	len = lena*lenb;

	if(len>maxarr)
	{
	    stlen = (size_t) len;
	    AJCRESIZETRY(path,stlen);
	    if(!path)
		ajDie("Sequences too big. Try 'stretcher'");
	    AJCRESIZETRY(compass,stlen);
	    if(!compass)
		ajDie("Sequences too big. Try 'stretcher'");
        AJCRESIZETRY(m,stlen);
        if(!m)
        ajDie("Sequences too big. Try 'stretcher'");
        AJCRESIZETRY(ix,stlen);
        if(!ix)
        ajDie("Sequences too big. Try 'stretcher'");
        AJCRESIZETRY(iy,stlen);
        if(!iy)
        ajDie("Sequences too big. Try 'stretcher'");
	    maxarr=len;
	}


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

	ajStrAssignC(&alga,"");
	ajStrAssignC(&algb,"");

	score = embAlignPathCalcWithEndGapPenalties(p, q, lena, lenb,
	        gapopen, gapextend, endgapopen, endgapextend,
	        &start1, &start2, path, sub, cvt,
	        m, ix, iy, compass, ajTrue, endweight);



	embAlignWalkNWMatrixUsingCompass(p, q, &alga, &algb,
	        lena, lenb, &start1, &start2,
	        compass);
		
	embAlignReportGlobal(align, a, b, alga, algb,
			     start1, start2,
			     gapopen, gapextend,
			     score, matrix,
			     ajSeqGetOffset(a), ajSeqGetOffset(b));

	if(!dobrief)
	{
	  embAlignCalcSimilarity(alga,algb,sub,cvt,lena,lenb,&id,&sim,&idx,
				 &simx);
	  ajFmtPrintS(&tmpstr,"Longest_Identity = %5.2f%%\n",
			 id);
	  ajFmtPrintAppS(&tmpstr,"Longest_Similarity = %5.2f%%\n",
			 sim);
	  ajFmtPrintAppS(&tmpstr,"Shortest_Identity = %5.2f%%\n",
			 idx);
	  ajFmtPrintAppS(&tmpstr,"Shortest_Similarity = %5.2f%%",
			 simx);
	  ajAlignSetSubHeaderApp(align, tmpstr);
	}
	ajAlignWrite(align);
	ajAlignReset(align);

    }

    ajAlignClose(align);
    ajAlignDel(&align);

    ajSeqallDel(&seqall);
    ajSeqDel(&a);
    ajSeqDel(&b);

    AJFREE(compass);
    AJFREE(path);
    AJFREE(ix);
    AJFREE(iy);
    AJFREE(m);

    ajStrDel(&alga);
    ajStrDel(&algb);
    ajStrDel(&ss);
    ajStrDel(&tmpstr);

    embExit();

    return 0;
}
Ejemplo n.º 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;
}