Exemplo n.º 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;
}
Exemplo n.º 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;
}
Exemplo n.º 3
0
static AjBool remap_Ambiguous(const AjPStr str)
{
    ajuint ipos;
    char chr;
    
    for (ipos=0; ipos<ajStrGetLen(str); ipos++) 
    {
    	chr = ajStrGetCharPos(str, ipos);
    	if (tolower((int)chr) != 'a' &&
    	    tolower((int)chr) != 'c' &&
    	    tolower((int)chr) != 'g' &&
    	    tolower((int)chr) != 't'
    	    )
            return ajTrue;
    }

    return ajFalse;
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
    /* Variable Declarations */
    AjPStr code = NULL;
    AjPFile mfptr = NULL;
    AjPFile wfptr = NULL;
    AjPFile outf = NULL;

    EmbPPropMolwt *mwdata;
    EmbPPropAmino *aadata;

    float *dhstat = NULL;

    char    code1;
    AjPStr  code3 = NULL;
    ajint idx    = 0;
    ajuint i;
    ajuint iend;
    AjPStr  propstr = NULL;
    float charge;
    char csign;

    /* ACD File Processing */
    embInit("inforesidue", argc, argv);
    code = ajAcdGetString("code");
    mfptr   = ajAcdGetDatafile("aadata");
    wfptr   = ajAcdGetDatafile("mwdata");
    outf = ajAcdGetOutfile("outfile");

    aadata = embPropEaminoRead(mfptr);
    mwdata = embPropEmolwtRead(wfptr);
    if(!embReadAminoDataFloatC(DAYHOFF_FILE,&dhstat,(float)0.001))
        ajFatal("Set the EMBOSS_DATA environment variable");


    /* Application logic */

    ajStrFmtUpper(&code);
    iend = ajStrGetLen(code);
    ajFmtPrintF(outf, "%-4s %-5s %-20s %6s %9s %-30s %s\n",
                "Code", "Short", "Mnemonic",
                "Charge", "MolWt",
                "Properties", "Ambiguity");
    for(i=0; i<iend; i++)
    {
        code1=ajStrGetCharPos(code,i);
        if(ajResidueExistsChar(code1))
        {
            idx = ajBasecodeToInt(code1);
            ajResidueToTriplet(code1, &code3);
            ajStrFmtTitle(&code3);

            if(!embPropGetProperties(aadata[idx], &propstr))
                ajStrAssignC(&propstr, "(none)");

            charge = embPropGetCharge(aadata[idx]);
            if(charge > 0.0)
                csign = '+';
            else if(charge < 0.0)
                csign = '-';
            else
                csign = ' ';

            ajFmtPrintF(outf, "%-4c %-5S %-20S %3c%3.1f %9.4f %-30S %S\n",
                        code1, code3, ajResidueGetMnemonic(code1),
                        csign, fabs(charge),
                        embPropMolwtGetMolwt(mwdata[idx]),
                        propstr, ajResidueGetCodes(code1));
        }
        else
        {
            ajFmtPrintF(outf, "%-4c %-5s %-20s %6s %9s %-30s %s\n",
                        code1, ".", "invalid", ".", ".", ".", ".");

        }

    }



    /* Memory management and exit */
    ajStrDel(&code);
    ajStrDel(&code3);
    ajStrDel(&propstr);
    ajFileClose(&outf);
    ajFileClose(&mfptr);
    ajFileClose(&wfptr);
    ajFileClose(&outf);
    embPropAminoDel(&aadata);
    embPropMolwtDel(&mwdata);
    AJFREE(dhstat);

    embExit();

    return 0;
}
Exemplo n.º 5
0
static AjBool assemoutWriteSamAlignment(AjPFile outf, const AjPAssemRead r,
					AjPAssemContig const * contigs,
					ajint ncontigs)
{
    AjPAssemTag    t = NULL;
    AjIList l = NULL;
    AjPStr qualstr = NULL;
    AjPStr tmp  = NULL;
    ajint  POS  = 0;
    AjPStr CIGAR = NULL;
    const char* RNEXT = NULL;
    AjPStr SEQ  = NULL;
    AjPStr QUAL = NULL;
    AjPStr SEQunpadded  = NULL;
    AjPStr QUALunpadded = NULL;
    AjPStr consensus = NULL;
    AjBool rc= ajFalse;
    AjBool ret = ajTrue;
    const char* refseq = NULL;
    const AjPAssemContig contig = NULL;

    ajuint k = 0;

    if(r->Reference>=ncontigs)
	ajDie("assemoutWriteSamAlignment: reference sequence number"
		" '%d' is larger than or equal to known number of reference"
		" sequences '%d'. Problem while processing read '%S'.",
		r->Reference,
		ncontigs,
		r->Name);

    contig = (r->Reference==-1 ? NULL : contigs[r->Reference]);

    ajStrAssignRef(&SEQ, r->Seq);
    consensus = contig==NULL? NULL : contig->Consensus;

    if (r->Rnext==-1)
	RNEXT= "*";
    else if(r->Rnext==r->Reference)
	RNEXT = "=";
    else
	RNEXT = ajStrGetPtr(contigs[r->Rnext]->Name);

    if (r->Flag & BAM_FREVERSE)
    {
	rc = ajTrue;
	qualstr = ajStrNewS(r->SeqQ);

	if(!r->Reversed)
	{
	    ajStrReverse(&qualstr);
	    ajSeqstrReverse(&SEQ);
	}

	QUAL = qualstr;
	POS = r->y1;
	ajStrAssignSubS(&tmp, SEQ,
		ajStrGetLen(r->Seq) - r->y2,
		ajStrGetLen(r->Seq) - r->x2
	);

    }
    else
    {
	rc= ajFalse;
	POS = r->x1;
	QUAL = r->SeqQ;
	ajStrAssignSubS(&tmp, SEQ,
		r->x2-1,
		r->y2-1
	);
    }

    if(r->Cigar==NULL && consensus)
    {
	refseq = ajStrGetPtr(consensus) + (rc ? r->y1-1 : r->x1-1);

	CIGAR = assemoutMakeCigar(refseq, ajStrGetPtr(tmp));

	SEQunpadded = ajStrNewRes(ajStrGetLen(SEQ));
	QUALunpadded = ajStrNewRes(ajStrGetLen(SEQ));

	for(k=0; k< ajStrGetLen(SEQ); k++)
	{
	    if (ajStrGetCharPos(SEQ, k) == '*')
		continue;

	    ajStrAppendK(&SEQunpadded, ajStrGetCharPos(SEQ, k));
	    ajStrAppendK(&QUALunpadded, ajStrGetCharPos(QUAL, k));
	}

	ajDebug("cigar: %S\n", CIGAR);

	ajStrAssignS(&tmp, CIGAR);

	if(rc)
	{
	    if(r->y2 < (ajint)ajStrGetLen(SEQ))
		ajFmtPrintS(&CIGAR, "%dS%S",
		            ajStrGetLen(SEQ) - r->y2, tmp);
	    if(r->x2 > 1)
		ajFmtPrintAppS(&CIGAR, "%dS", r->x2 - 1);
	}
	else
	{
	    if(r->x2 > 1)
		ajFmtPrintS(&CIGAR, "%dS%S", r->x2 - 1, tmp);
	    if(r->y2 < (ajint)ajStrGetLen(SEQ))
		ajFmtPrintAppS(&CIGAR, "%dS",
		               ajStrGetLen(SEQ) - r->y2);
	}
	ajStrDel(&tmp);
    }
    else if(r->Cigar==NULL)
    {
	ajErr("both CIGAR string and consensus sequence not available");
	ret = ajFalse;
	ajStrAssignK(&CIGAR, '*');
    }
    else if(!ajStrGetLen(r->Cigar))
	ajStrAssignK(&CIGAR, '*');
    else if(ajStrGetLen(r->Cigar))
    {
	if(!ajStrGetLen(SEQ))
	    ajStrAssignK(&SEQ, '*');

	if(!ajStrGetLen(QUAL))
	    ajStrAssignK(&QUAL, '*');
    }

    ajStrDel(&tmp);

    ajFmtPrintF(outf, "%S\t%d\t%s\t%d\t%d\t%S\t%s\t%Ld\t%d\t%S\t%S",
	    r->Name,
	    r->Flag,
	    (contig==NULL ? "*" : ajStrGetPtr(contig->Name)),
	    POS,
	    r->MapQ,
	    (CIGAR ? CIGAR : r->Cigar),
	    RNEXT,
	    r->Pnext,
	    r->Tlen,
	    (r->Cigar ? SEQ  : SEQunpadded),
	    (r->Cigar ? QUAL : QUALunpadded));

    l = ajListIterNewread(r->Tags);
    while (!ajListIterDone(l))
    {
	t = ajListIterGet(l);

	/* TODO: array type, 'B' */

	/* In SAM, all single integer types are mapped to int32_t [SAM spec] */
	ajFmtPrintF(outf, "\t%S:%c:",
		t->Name,
		(t->type == 'c' || t->type == 'C' ||
		 t->type == 's' || t->type == 'S'
				|| t->type == 'I') ? 'i' : t->type
	);

	if(t->x1 || t->y1)
	    ajFmtPrintF(outf, " %u %u", t->x1, t->y1);

	if(t->Comment && ajStrGetLen(t->Comment)>0)
	    ajFmtPrintF(outf, "%S", t->Comment);

    }
    ajListIterDel(&l);

    ajFmtPrintF(outf, "\n");

    if(qualstr)
	ajStrDel(&qualstr);

    ajStrDel(&SEQ);
    ajStrDel(&CIGAR);
    ajStrDel(&SEQunpadded);
    ajStrDel(&QUALunpadded);

    return ret;
}
Exemplo n.º 6
0
static void domainalign_ProcessStampFile(AjPStr in, 
					 AjPStr out,
					 AjPDomain domain, 
					 ajint noden, 
					 AjPFile logf)
{
    AjPFile  outf = NULL;  /* Output file pointer.          */
    AjPFile   inf = NULL;  /* Input file pointer.           */
    AjPStr  temp1 = NULL;  /* Temporary string.             */
    AjPStr  temp2 = NULL;  /* Temporary string.             */
    AjPStr  temp3 = NULL;  /* Temporary string.             */
    AjPStr   line = NULL;  /* Line of text from input file. */
    ajint     blk = 1;     /* Count of the current block in the input file.
			      Block 1 is the numbering and protein sequences, 
			      Block 2 is the secondary structure, 
			      Block 3 is the Very/Less/Post similar records*/
    AjBool     ok = ajFalse;
    
    
    /* Initialise strings. */
    line    = ajStrNew();
    temp1    = ajStrNew();
    temp2    = ajStrNew();
    temp3    = ajStrNew();


    /* Open input and output files. */
    if(!(inf=ajFileNewInNameS(in)))
	ajFatal("Could not open input file in domainalign_ProcessStampFile");
    



    /* Start of code for reading input file. 
       Ignore everything up to first line beginning with 'Number'. */
    while((ajReadlineTrim(inf,&line)))
    {
	/* ajFileReadLine will trim the tailing \n. */
	if((ajStrGetCharPos(line, 1)=='\0'))
	{
	    ok = ajTrue;
	    break;
	}
    }
    
    
    
    /* Read rest of input file. */
    if(ok)
    {
	/* Write DOMAIN classification records to file. */
	if(!(outf=ajFileNewOutNameS(out)))
	 ajFatal("Could not open output file in domainalign_ProcessStampFile");

	
	if((domain->Type == ajSCOP))
	{
	    ajFmtPrintF(outf,"# TY   SCOP\n# XX\n");
	    ajFmtPrintF(outf,"# CL   %S",domain->Scop->Class);
	    ajFmtPrintSplit(outf,domain->Scop->Fold,"\n# XX\n# FO   ",
			    75," \t\n\r");
	    ajFmtPrintSplit(outf,domain->Scop->Superfamily,"# XX\n# SF   ",
			    75," \t\n\r");
	    ajFmtPrintSplit(outf,domain->Scop->Family,"# XX\n# FA   ",
			    75," \t\n\r");
	    ajFmtPrintF(outf,"# XX\n");
	}
	else
	{
	    ajFmtPrintF(outf,"# TY   CATH\n# XX\n");
	    ajFmtPrintF(outf,"# CL   %S",domain->Cath->Class);
	    ajFmtPrintSplit(outf,domain->Cath->Architecture,"\n# XX\n# AR   ",
			    75," \t\n\r");
	    ajFmtPrintSplit(outf,domain->Cath->Topology,"# XX\n# TP   ",75,
			    " \t\n\r");
	    ajFmtPrintSplit(outf,domain->Cath->Superfamily,"# XX\n# SF   ",75,
			    " \t\n\r");
	    ajFmtPrintF(outf,"# XX\n");
	}
	if((domain->Type == ajSCOP))
	{
	    if(noden==1) 
		ajFmtPrintF(outf,"# SI   %d\n# XX",domain->Scop->Sunid_Class);
	    else if(noden==2)
		ajFmtPrintF(outf,"# SI   %d\n# XX",domain->Scop->Sunid_Fold);
	    else if(noden==3)
		ajFmtPrintF(outf,"# SI   %d\n# XX",
			    domain->Scop->Sunid_Superfamily);
	    else if(noden==4) 	
		ajFmtPrintF(outf,"# SI   %d\n# XX",
			    domain->Scop->Sunid_Family);
	    else
		ajFatal("Node number error in domainalign_ProcessStampFile");
	}
	else
	{
	    if(noden==5) 
		ajFmtPrintF(outf,"# SI   %d\n# XX", domain->Cath->Class_Id);
	    else if(noden==6)
		ajFmtPrintF(outf,"# SI   %d\n# XX", domain->Cath->Arch_Id);
	    else if(noden==7)
		ajFmtPrintF(outf,"# SI   %d\n# XX",domain->Cath->Topology_Id);
	    else if(noden==8)
		ajFmtPrintF(outf,"# SI   %d\n# XX",
			    domain->Cath->Superfamily_Id);
	    else if(noden==9)  
		ajFmtPrintF(outf,"# SI   %d\n# XX",domain->Cath->Family_Id);
	    else
		ajFatal("Node number error in domainalign_ProcessStampFile");
	}   



	while((ajReadlineTrim(inf,&line)))
	{
	    /* Increment counter for block of file. */
	    if((ajStrGetCharPos(line, 1)=='\0'))
	    {
		blk++;
		if(blk==4)
		    blk=1;
	    
		continue;
	    }



	    /* Block of numbering line and protein sequences. */
	    if(blk==1)
	    {
		/* Print the number line out as it is. */
		if(ajStrPrefixC(line,"Number"))
		    ajFmtPrintF(outf,"\n# %7s %S\n"," ", line);
		else
		{
		    /* Read only the 7 characters
		       of the domain identifier
		       code in. */
		    ajFmtScanS(line, "%S", &temp1);
		    ajStrAssignSubS(&temp2, temp1, 0, 6);


		    /* Read the sequence. */
		    ajStrAssignSubS(&temp3, line, 13, 69);
		    ajStrExchangeSetCC(&temp3, " ", "X");
		    ajFmtPrintF(logf, "Replaced ' ' in STAMP alignment "
				"with 'X'\n");
		    ajStrFmtUpper(&temp3);
		

		    /* Write domain id code and sequence out. */
		    ajFmtPrintF(outf,"%-15S%7d %S%7d\n",
				temp2, 0, temp3, 0);
		}
	    }
	    /* Secondary structure filled with '????' (unwanted). */
	    else if(blk==2)
	    {
		continue;
	    }
	    /* Similarity lines. */
	    else
	    {
		if(ajStrPrefixC(line,"Post"))
		{
		    /* Read the sequence. */
		    ajStrAssignSubS(&temp3, line, 13, 69);

		    /* Write post similar line out. */
		    ajFmtPrintF(outf,"%-15s%7s %S\n","# Post_similar", " ",
				temp3);
		}
		/* Ignore Very and Less similar lines. */
		else continue;
	    }
	}
    }
    else /* ok == ajFalse. */
    {
	ajWarn("\n***********************************************\n"
	       "* STAMP was called but output file was EMPTY! *\n"
	       "*   NO OUTPUT FILE GENERATED FOR THIS NODE.   *\n"
	       "***********************************************\n");
	ajFmtPrintF(logf, "STAMP called but output file empty.  "
		    "No output file for this node!");
    }
    


    /* Clean up and close input and output files. */
    ajFileClose(&outf);
    ajFileClose(&inf);
    ajStrDel(&line);
    ajStrDel(&temp1);
    ajStrDel(&temp2);
    ajStrDel(&temp3);
    

    /* All done. */
    return;
}
Exemplo n.º 7
0
/* @funcstatic domainalign_ProcessTcoffeeFile *********************************
**
** Parses tcoffee output.
**
** @param [r] in [AjPStr] Name of TCOFFEE input file
** @param [r] align [AjPStr] Name of sequence alignment file for output
** @param [r] domain [AjPDomain] Domain being aligned
** @param [r] noden [ajint] Node-level of alignment** 
** @param [r] logf [AjPFile] Log file
**
** @return [void] True on success
** @@
****************************************************************************/
static void domainalign_ProcessTcoffeeFile(AjPStr in, 
					   AjPStr align, 
					   AjPDomain domain,
					   ajint noden, 
					   AjPFile logf)
{
    AjPFile  outf = NULL;  /* Output file pointer. */
    AjPFile   inf = NULL;  /* Input file pointer. */
    AjPStr  temp1 = NULL;  /* Temporary string. */
    AjPStr  temp2 = NULL;  /* Temporary string. */
    AjPStr  temp3 = NULL;  /* Temporary string. */
    AjPStr   line = NULL;  /* Line of text from input file. */
    
    
    /* Initialise strings. */
    line    = ajStrNew();
    temp1   = ajStrNew();
    temp2   = ajStrNew();
    temp3   = ajStrNew();



    /* Open input and output files. */
    if(!(inf=ajFileNewInNameS(in)))
        ajFatal("Could not open input file in domainalign_ProcessTcoffeeFile");
    if(!(outf=ajFileNewOutNameS(align)))
        ajFatal("Could not open output file in domainalign_ProcessTcoffeeFile");
    

    /*Write DOMAIN classification records to file*/
    if((domain->Type == ajSCOP))
    {
	ajFmtPrintF(outf,"# TY   SCOP\n# XX\n");
	ajFmtPrintF(outf,"# CL   %S",domain->Scop->Class);
	ajFmtPrintSplit(outf,domain->Scop->Fold,"\n# XX\n# FO   ",75," \t\n\r");
	ajFmtPrintSplit(outf,domain->Scop->Superfamily,"# XX\n# SF   ",75," \t\n\r");
	ajFmtPrintSplit(outf,domain->Scop->Family,"# XX\n# FA   ",75," \t\n\r");
	ajFmtPrintF(outf,"# XX\n");
    }
    else
    {
	ajFmtPrintF(outf,"# TY   CATH\n# XX\n");
	ajFmtPrintF(outf,"# CL   %S",domain->Cath->Class);
	ajFmtPrintSplit(outf,domain->Cath->Architecture,"\n# XX\n# AR   ",75," \t\n\r");
	ajFmtPrintSplit(outf,domain->Cath->Topology,"# XX\n# TP   ",75," \t\n\r");
	ajFmtPrintSplit(outf,domain->Cath->Superfamily,"# XX\n# SF   ",75," \t\n\r");
	ajFmtPrintF(outf,"# XX\n");
    }
    
    if((domain->Type == ajSCOP))
    {
	if(noden==1) 
	    ajFmtPrintF(outf,"# SI   %d\n# XX\n",domain->Scop->Sunid_Class);
	else if(noden==2)
	    ajFmtPrintF(outf,"# SI   %d\n# XX\n",domain->Scop->Sunid_Fold);
	else if(noden==3)
	    ajFmtPrintF(outf,"# SI   %d\n# XX\n",domain->Scop->Sunid_Superfamily);
	else if(noden==4) 	
	    ajFmtPrintF(outf,"# SI   %d\n# XX\n", domain->Scop->Sunid_Family);
	else
	    ajFatal("Node number error in domainalign_ProcessStampFile");
    }	
    else
    {
	    if(noden==5) 
		ajFmtPrintF(outf,"# SI   %d\n# XX\n", domain->Cath->Class_Id);
	    else if(noden==6)
		ajFmtPrintF(outf,"# SI   %d\n# XX\n", domain->Cath->Arch_Id);
	    else if(noden==7)
		ajFmtPrintF(outf,"# SI   %d\n# XX\n",domain->Cath->Topology_Id);
	    else if(noden==8)
		ajFmtPrintF(outf,"# SI   %d\n# XX\n",domain->Cath->Superfamily_Id);
	    else if(noden==9)  
		ajFmtPrintF(outf,"# SI   %d\n# XX\n",domain->Cath->Family_Id);
	    else
		ajFatal("Node number error in domainalign_ProcessStampFile");
    }   


    
    /* Start of code for reading input file. */
    /*Ignore everything up to first line beginning with 'Number'*/
    while((ajReadlineTrim(inf,&line)))
        /* ajFileReadLine will trim the tailing \n. */
        if((ajStrGetCharPos(line, 1)=='\0'))
            break;

    
    /* Read rest of input file. */
    while((ajReadlineTrim(inf,&line)))
    {
      if((ajStrGetCharPos(line, 1)=='\0'))
        continue; 
        
       /* Print the number line out as it is. */
            else if(ajStrPrefixC(line,"CLUSTAL"))
              continue;
	    else if(ajStrPrefixC(line," "))
                ajFmtPrintF(outf,"\n");
        /* write out a block of protein sequences. */
        else
        {
               /* Read only the 7 characters of the domain identifier code in. */
               ajFmtScanS(line, "%S %S", &temp1,&temp3);
                 ajStrAssignSubS(&temp2, temp1, 0, 6);
  
  
         /* Read the sequence
                   ajStrAssignSubS(&temp3, line, 13, 69);
                   ajStrExchangeSetCC(&temp3, " ", "X");
                   ajStrFmtUpper(&temp3);*/
                
  
                   /* Write domain id code and sequence out. */
                   ajFmtPrintF(outf,"%-13S%S\n",temp2, temp3);              
        }
    }
    

    /* Clean up and close input and output files. */
    ajFileClose(&outf);
    ajFileClose(&inf);
    ajStrDel(&line);
    ajStrDel(&temp1);
    ajStrDel(&temp2);
    ajStrDel(&temp3);
    

    /* All done. */
    return;
}
Exemplo n.º 8
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;
}