示例#1
0
static void palindrome_Print(AjPFile outfile,
			     const AjPStr seq, const Palindrome pal,
			     ajint maxLen)
{

    ajint i;
    ajint j;

    if(pal->forwardEnd - pal->forwardStart > maxLen)
	return;

    ajFmtPrintF(outfile, "%-8d ", (pal->forwardStart+1));
    for(i = pal->forwardStart; i < pal->forwardEnd; i++)
	ajFmtPrintF(outfile, "%c", ajStrGetCharPos(seq, i));

    ajFmtPrintF(outfile, " %8d\n         ", pal->forwardEnd);

    for(i = pal->forwardStart,
	j=pal->revStart; i < pal->forwardEnd; i++)
	if(ajStrGetCharPos(seq, i) == ajBaseAlphacharComp(ajStrGetCharPos(seq, j--)))
	    ajFmtPrintF(outfile, "|");
	else
	    ajFmtPrintF(outfile, " ");

    ajFmtPrintF(outfile, "\n%-8d ", (pal->revStart+1));

    for(i = pal->revStart; i > pal->revEnd; i--)
	ajFmtPrintF(outfile, "%c", ajStrGetCharPos(seq, i));

    ajFmtPrintF(outfile, " %8d\n\n", (pal->revEnd+2));

    return;
}
示例#2
0
int main(int argc, char **argv)
{
    /* Variable Declarations */
    AjPFile outf;
    AjPStr code = NULL;
    char    code1;
    ajuint i;
    ajuint iend;

    /* ACD File Processing */
    embInit("infobase", argc, argv);
    code = ajAcdGetString("code");
    outf = ajAcdGetOutfile("outfile");


    /* Application logic */

    ajStrFmtUpper(&code);
    iend = ajStrGetLen(code);
    ajFmtPrintF(outf, "%4s %-10s %-10s %s\n",
                "Code", "Ambiguity", "Complement", "Mnemonic");
    for(i=0;i<iend;i++)
    {
        code1=ajStrGetCharPos(code,i);
        if(ajBaseExistsChar(code1))
        {
            ajFmtPrintF(outf, "%-4c %-10S %-10c %S\n",
                        code1, ajBaseGetCodes(code1),
                        ajBaseAlphacharComp(code1),
                        ajBaseGetMnemonic(code1));
        }
        else
        {
            ajFmtPrintF(outf, "%-4c %-10s %-10c %s\n",
                        code1, ".",
                        '.',
                        "invalid");

        }
        
    }
    
    

    /* Memory management and exit */
    ajStrDel(&code);
    ajFileClose(&outf);

    embExit();

    return 0;
}
示例#3
0
int main(int argc, char **argv)
{

    AjPSeqall seqall;
    AjPSeq sequence;
    AjPFile outfile;
    ajint minLen;
    ajint maxLen;
    ajint maxGap;
    ajint beginPos;
    ajint endPos;
    ajint maxmismatches;

    AjPStr seqstr;
    ajint current;
    ajint rev;
    ajint count;
    ajint gap;

    ajint begin;
    ajint end;
    ajint mismatches;
    ajint mismatchAtEnd;
    ajint istart;
    ajint iend;
    ajint ic;
    ajint ir;

    AjBool alln;		/* TRUE if all of palindrome is N's */

    Palindrome pfirstpal;
    Palindrome plastpal = NULL;
    Palindrome ppal = NULL;
    Palindrome pnext = NULL;

    AjBool found = AJFALSE;

    embInit("palindrome", argc, argv);

    seqall  = ajAcdGetSeqall("sequence");
    minLen  = ajAcdGetInt("minpallen");
    maxLen  = ajAcdGetInt("maxpallen");
    maxGap  = ajAcdGetInt("gaplimit");
    outfile = ajAcdGetOutfile("outfile");

    maxmismatches = ajAcdGetInt("nummismatches");
    overlap       = ajAcdGetBoolean("overlap");

    while(ajSeqallNext(seqall, &sequence))
    {
	beginPos = ajSeqallGetseqBegin(seqall);
	endPos = ajSeqallGetseqEnd(seqall);

	/* set to NULL to indicate that we have no first palindrome find yet */
	pfirstpal = NULL;

	/* write header to file */

	ajFmtPrintF(outfile, "Palindromes of:  %s \n", ajSeqGetNameC(sequence));
	ajFmtPrintF(outfile, "Sequence length is: %d \n", ajSeqGetLen(sequence));
	ajFmtPrintF(outfile, "Start at position: %d\nEnd at position: %d\n",
		    beginPos, endPos);
	ajFmtPrintF(outfile,"Minimum length of Palindromes is: %d \n", minLen);
	ajFmtPrintF(outfile,"Maximum length of Palindromes is: %d \n", maxLen);
	ajFmtPrintF(outfile,"Maximum gap between elements is: %d \n", maxGap);
	ajFmtPrintF(outfile,"Number of mismatches allowed in Palindrome: %d\n",
		    maxmismatches);
	ajFmtPrintF(outfile, "\n\n\n");
	ajFmtPrintF(outfile, "Palindromes:\n");


	/* set vars in readiness to enter loop */
	seqstr = ajStrNewC(ajSeqGetSeqC(sequence));
	begin  = beginPos - 1;
	end    = endPos - 1;

	ajStrFmtLower(&seqstr); /* make comparisons case independent */

	/* loop to look for inverted repeats */
	for(current = begin; current < end; current++)
	{
	    iend = current + 2*(maxLen) + maxGap;
	    if(iend > end)
		iend = end;
	    istart = current + minLen;

	    for(rev = iend; rev > istart; rev--)
	    {
		count = 0;
		mismatches = 0;
		mismatchAtEnd = 0;
		alln = ajTrue;
		ic = current;
		ir = rev;
		if(ajStrGetCharPos(seqstr, ic) ==
		   ajBaseAlphacharComp(ajStrGetCharPos(seqstr, ir)))
		    while(mismatches <= maxmismatches && ic < ir)
		    {
			if(ajStrGetCharPos(seqstr, ic++) ==
			   ajBaseAlphacharComp(ajStrGetCharPos(seqstr, ir--)))
			{
			    mismatchAtEnd = 0;
			    if(ajStrGetCharPos(seqstr, ic-1) != 'n')
				alln = ajFalse;
			}
			else
			{
			    mismatches++;
			    mismatchAtEnd++;
			}
			count++;
		    }

		count -= mismatchAtEnd;
		gap = rev - current - count - count + 1;

		/* Find out if there's a reverse repeat long enough */
		if(count >= minLen && gap <= maxGap && !alln)
		{
		    /* create new struct to hold palindrome data */
		    ppal = palindrome_New(current,(current+count),rev,
					  (rev-count));

		    /*
		    ** if it is the first palindrome find then save it as start
		    **  of palindrome list
		    */
		    if(pfirstpal == NULL)
		    {
			pfirstpal = ppal;
			plastpal = ppal;
		    }
		    else
		    {
			/* Is it  a subset of a palindrome already met */
			pnext = pfirstpal;
			found = AJFALSE;
			while(pnext != NULL)
			{
			    if(overlap && palindrome_AInB(ppal, pnext))
			    {
				found = AJTRUE;
				break;
			    }

			    if(!overlap && palindrome_AOverB(ppal, pnext))
			    {
				if(palindrome_Longer(ppal, pnext))
				{
				    palindrome_Swap(ppal, pnext);
				}

				found = AJTRUE;
				break;
			    }
			    pnext = pnext->next;
			}

			/* if new palindrome add to end of list */
			if(!found)
			{
			    plastpal->next = ppal;
			    plastpal = ppal;
			}
			else
			    AJFREE(ppal);
		    }
		}
	    }
	}
    
    
    
    
	/* Print out palindromes */
	ppal = pfirstpal;
	while(ppal != NULL)
	{
	    palindrome_Print(outfile, seqstr, ppal, maxLen);
	    ppal = ppal->next;
	}
    
    
	/* make a gap beween outputs of different sequences */
	ajFmtPrintF(outfile, "\n\n\n");
    
    
	/* free memory used for palindrome list */
	ppal = pfirstpal;
	while(ppal != NULL)
	{
	    pnext = ppal->next;
	    AJFREE(ppal);
	    ppal = pnext;
	}
    
	ajStrDel(&seqstr);
    
    }

    ajFileClose(&outfile);

    ajSeqallDel(&seqall);
    ajSeqDel(&sequence);
    ajStrDel(&seqstr);

    embExit();

    return 0;
}