Exemplo n.º 1
0
static void acdrelations_readtypefile
            (AjPFile inf, 
	     PKtype *T)
{
    AjPStr     line    = NULL;
    PKtypedat  dattmp  = NULL;
    AjPList    datlist = NULL;
    
    if(!T)
        ajFatal("Null arg error 1 in acdrelations_readtypefile");
    if(!inf)
        ajFatal("Null arg error 3 in acdrelations_readtypefile");


    /* Allocate memory */
    line           = ajStrNew();
    datlist        = ajListNew();

    
    /* Read data from file */
    while(ajReadline(inf,&line))
    {
        /* Discard comment lines */
        if(ajStrPrefixC(line,"#")) 
            continue;

        /* Create object for holding line */
        dattmp = ajKtypedatNew();
        
        /* Tokenise line delimited by '|'
           Parse first token (value of knowntype: attribute) */
        ajStrAssignS(&dattmp->ktype, ajStrParseC(line, "|"));
        ajStrRemoveSetC(&dattmp->ktype, "_");
        ajStrRemoveWhite(&dattmp->ktype);
        
        /* Parse second token (ACD datatype) */
        ajStrAssignS(&dattmp->acdtype, ajStrParseC(NULL, "|"));

        /* Parse third token (EDAM relations: value ) */
        ajStrAssignS(&dattmp->edam, ajStrParseC(NULL, "|"));

        /* Push line onto list */
        ajListPushAppend(datlist, dattmp);
    }
    

    /* Write PKtype structure */
    ((*T)->n) = ajListToarray(datlist, (void***) &((*T)->dat));
  
    
    /* Free memory */
    ajStrDel(&line);
    ajListFree(&datlist);

    return;
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
    /* Variable Declarations */
    AjPFile   inf     = NULL;
    AjPFile   outf    = NULL; 

    AjPStr    line    = NULL;  /* Line from inf     */
    AjPStr    option  = NULL;
    AjBool    doall   = AJFALSE;
    AjBool    doend   = AJFALSE;
    AjBool    doexcess = AJFALSE;

    /* ACD File Processing */
    embInit("nospace", argc, argv);
    inf  = ajAcdGetInfile("infile");
    outf = ajAcdGetOutfile("outfile");
    option = ajAcdGetListSingle("menu");

    if(ajStrMatchC(option, "all"))
        doall = ajTrue;
    else if(ajStrMatchC(option, "end"))
        doend = ajTrue;
    else if(ajStrMatchC(option, "excess"))
        doexcess = ajTrue;

    /* Application logic */
    line    = ajStrNew();

    while(ajReadline(inf,&line))
      {
          if(doall)
              ajStrRemoveWhite(&line);
          else if(doend)
              ajStrTrimWhiteEnd(&line);
          else if(doexcess)
              ajStrRemoveWhiteExcess(&line);
	ajFmtPrintF(outf, "%S\n", line);
      }

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

    ajStrDel(&line);
    ajStrDel(&option);

    embExit();

    return 0;
}
Exemplo n.º 3
0
static void jaspscan_ParseInput(const AjPStr dir, const AjPStr jaspdir,
				const AjPStr mats, const AjPStr excl,
				ajuint *recurs, AjPList ret)
{
    ajuint nm = 0;
    ajuint ne = 0;
    AjPStr *carr = NULL;
    AjPStr *earr = NULL;
    AjPFile inf = NULL;
    AjPStr line = NULL;
    AjPStr comm = NULL;
    AjPStr val  = NULL;
    
    ajuint i;
    ajuint j;
    
    char c;

    ajuint rlen = 0;
    

    if(*recurs > JASPSCAN_RECURS)
	ajFatal("Too many recursion levels in matrix list files");
    
    line = ajStrNew();
    comm = ajStrNew();
    

    if(mats)
    {
	nm = ajArrCommaList(mats,&carr);	
	for(i=0; i < nm; ++i)
	{
	    if(ajStrGetCharFirst(carr[i]) != '@')
		ajStrFmtUpper(&carr[i]);
	
	    if(ajStrMatchC(carr[i],"ALL"))
	    {
		jaspscan_GetFileList(dir, jaspdir, "*", ret);
		ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel);
	    }
	    else if(ajStrGetCharFirst(carr[i]) == '@')
	    {
		ajStrTrimStartC(&carr[i],"@");
		inf = ajFileNewInNameS(carr[i]);
		if(!inf)
		    ajFatal("Cannot open list file %S",carr[i]);

		while(ajReadlineTrim(inf,&line))
		{
		    ajStrRemoveWhite(&line);
		    c = ajStrGetCharFirst(line);
		    if(c == '#' || c== '!')
			continue;
		    if(ajStrGetLen(comm))
			ajStrAppendC(&comm,",");
		    ajStrFmtUpper(&line);
		    ajStrAppendS(&comm,line);
		}

		*recurs += 1;
		jaspscan_ParseInput(dir,jaspdir,comm,NULL,recurs,ret);
		*recurs -= 1;
		ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel);	    

		ajFileClose(&inf);
	    }
	    else
	    {
		jaspscan_GetFileList(dir,jaspdir,ajStrGetPtr(carr[i]),ret);
		ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel);
	    }
	}

	for(i=0; i < nm; ++i)
	    ajStrDel(&carr[i]);

	AJFREE(carr);
    }
    
    


    if(excl)
    {
	ne = ajArrCommaList(excl,&earr);
	
	for(i=0; i < ne; ++i)
	{
	    if(ajStrGetCharFirst(earr[i]) != '@')
		ajStrFmtUpper(&earr[i]);
	
	    if(ajStrGetCharFirst(earr[i]) == '@')
	    {
		ajStrTrimStartC(&earr[i],"@");
		inf = ajFileNewInNameS(earr[i]);
		if(!inf)
		    ajFatal("Cannot open list file %S",earr[i]);

		while(ajReadlineTrim(inf,&line))
		{
		    ajStrRemoveWhite(&line);
		    c = ajStrGetCharFirst(line);
		    if(c == '#' || c== '!')
			continue;
		    if(ajStrGetLen(comm))
			ajStrAppendC(&comm,",");
		    ajStrFmtUpper(&line);
		    ajStrAppendS(&comm,line);
		}

		*recurs += 1;
		jaspscan_ParseInput(dir,jaspdir,NULL,comm,recurs,ret);
		*recurs -= 1;
		ajListSortUnique(ret, ajStrVcmp, jaspscan_strdel);	    

		ajFileClose(&inf);
	    }
	    else
	    {
		ajStrAssignS(&line,earr[i]);
		ajStrAppendC(&line,J_EXT);
		rlen = ajListGetLength(ret);
		for(j=0; j < rlen; ++j)
		{
		    ajListPop(ret,(void **)&val);
		    if(ajStrSuffixS(val,line))
			ajStrDel(&val);
		    else
			ajListPushAppend(ret,(void *)val);
		}
		
	    }
	} 


	for(i=0; i < ne; ++i)
	    ajStrDel(&earr[i]);
	AJFREE(earr);
    }
    

    ajStrDel(&line);
    ajStrDel(&comm);

    return;
}
Exemplo n.º 4
0
static void remap_NoCutList(AjPFile outfile, const AjPTable hittable,
			    AjBool html, const AjPStr enzymes, AjBool blunt,
			    AjBool sticky, ajuint sitelen, AjBool commercial,
			    AjBool ambiguity, AjBool limit,
			    const AjPTable retable)
{

    /* for iterating over hittable */
    PValue value;
    void **keyarray = NULL;			/* array for table */
    void **valarray = NULL;			/* array for table */
    ajint i;

    /* list of enzymes that cut */
    AjPList cutlist;
    AjIList citer;			/* iterator for cutlist */
    AjPStr cutname = NULL;
    AjBool found;

    /* for parsing value->iso string */
    AjPStrTok tok;
    char tokens[] = " ,";
    AjPStr code = NULL;
    const char *p;

    /* for reading in enzymes names */
    AjPFile enzfile = NULL;
    AjPStr *ea;
    ajint ne;				/* number of enzymes */
    AjBool isall = ajTrue;

    /* list of enzymes that don't cut */
    AjPList nocutlist;
    AjIList niter;			/* iterator for nocutlist */
    AjPStr nocutname = NULL;

    /* count of rejected enzymes not matching criteria */
    ajint rejected_count = 0;

    EmbPPatRestrict enz;

    /* for renaming preferred isoschizomers */
    AjPList newlist;

     /*
     **
     ** Make a list of enzymes('cutlist') that hit
     ** including the isoschizomer names
     **
     */
    ajDebug("Make a list of all enzymes that cut\n");


    cutlist   = ajListstrNew();
    nocutlist = ajListstrNew();


    ajTableToarrayKeysValues(hittable, &keyarray, &valarray);
    for(i = 0; keyarray[i]; i++)
    {
        value = (PValue) valarray[i];
        cutname = ajStrNew();
        ajStrAssignRef(&cutname, keyarray[i]);
        ajListstrPushAppend(cutlist, cutname);

        /* Add to cutlist all isoschizomers of enzymes that cut */
        ajDebug("Add to cutlist all isoschizomers of enzymes that cut\n");

        /* start token to parse isoschizomers names */
        tok = ajStrTokenNewC(value->iso,  tokens);
        while(ajStrTokenNextParseC(&tok, tokens, &code))
        {
            cutname = ajStrNew();
            ajStrAssignS(&cutname, code);
            ajListstrPushAppend(cutlist, cutname);
        }
        ajStrTokenDel(&tok);
    }
    ajStrDel(&code);
    AJFREE(keyarray);
    AJFREE(valarray);



     /*
     ** Read in list of enzymes ('nocutlist') - either all or
     ** the input enzyme list.
     ** Exclude those that don't match the selection criteria - count these.
     */

    ajDebug("Read in a list of all input enzyme names\n");

    ne = 0;
    if(!enzymes)
	isall = ajTrue;
    else
    {
	/* get input list of enzymes into ea[] */
	ne = ajArrCommaList(enzymes, &ea);
	if(ajStrMatchCaseC(ea[0], "all"))
	    isall = ajTrue;
	else
	{
	    isall = ajFalse;
	    for(i=0; i<ne; ++i)
		ajStrRemoveWhite(&ea[i]);
	}
    }

    enzfile = ajDatafileNewInNameC(ENZDATA);

    /* push all enzyme names without the required criteria onto nocutlist */

    enz = embPatRestrictNew();
    while(!ajFileIsEof(enzfile))
    {
        if(!embPatRestrictReadEntry(enz, enzfile))
	    continue;

         /* 
	 ** If user entered explicit enzyme list, then check to see if
	 ** this is one of that explicit list 
	 */
        if(!isall)
	{
            found = AJFALSE;
            for(i=0; i<ne; ++i)
                if(ajStrMatchCaseS(ea[i], enz->cod))
		{
		    found = AJTRUE;
                    break;
                }

	    if(!found)			/* not in the explicit list */
		continue;

	    ajDebug("RE %S is in the input explicit list of REs\n", enz->cod);
	}

	/* ignore ncuts==0 as they are unknown */
	if(!enz->ncuts)
	{
	    /* number of cut positions */
            ajDebug("RE %S has an unknown number of cut positions\n",
		    enz->cod);
	    continue;
	}
        ajDebug("RE %S has a known number of cut sites\n", enz->cod);

	if(enz->len < sitelen)
	{
	    /* recognition site length */
            ajDebug("RE %S does not have a long enough recognition site\n", 
		    enz->cod);
	    rejected_count++;
	    continue;
	}

	if(!blunt && enz->blunt)
	{
	    /* blunt/sticky */
            ajDebug("RE %S is blunt\n", enz->cod);
	    rejected_count++;
	    continue;
	}

	if(!sticky && !enz->blunt)
	{
	    /* blunt/sticky */
            ajDebug("RE %S is sticky\n", enz->cod);
	    rejected_count++;
	    continue;
	}

	/* commercially available enzymes have uppercase patterns */
	p = ajStrGetPtr(enz->pat);

         /* 
	 ** The -commercial qualifier is only used if we are searching
	 ** through 'all' of the REBASE database - if we have specified an
	 ** explicit list of enzymes then they are searched for whether or
	 ** not they are commercially available
	 */
	if((*p >= 'a' && *p <= 'z') && commercial && isall)
	{
            ajDebug("RE %S is not commercial\n", enz->cod);
	    rejected_count++;
	    continue;
        }

	if(!ambiguity && remap_Ambiguous(enz->pat)) {
	    ajDebug("RE %S is ambiguous\n", enz->cod);
	    rejected_count++;
	    continue;	
	}

        ajDebug("RE %S matches all required criteria\n", enz->cod);

        code = ajStrNew();
	ajStrAssignS(&code, enz->cod);
	ajListstrPushAppend(nocutlist, code);
    }
    embPatRestrictDel(&enz);
    ajFileClose(&enzfile);


    for(i=0; i<ne; ++i)
	if(ea[i])
	    ajStrDel(&ea[i]);

    if(ne)
	AJFREE(ea);

    /*
     ** Change names of enzymes in the non-cutter list
     ** to that of preferred (prototype) 
     ** enzyme name so that the isoschizomers of cutters
     ** will be removed from the 
     ** non-cutter list in the next bit.
     ** Remove duplicate prototype names.
     */
    if(limit)
    {
        newlist = ajListstrNew();
        remap_RenamePreferred(nocutlist, retable, newlist);
        ajListstrFreeData(&nocutlist);
        nocutlist = newlist;
        ajListSortUnique(nocutlist, remap_cmpcase, remap_strdel);
    }


     /*
     ** Iterate through the list of input enzymes removing those that are in
     ** the cutlist.
     */

    ajDebug("Remove from the nocutlist all enzymes and isoschizomers "
	    "that cut\n");

     /*
     **  This steps down both lists at the same time, comparing names and
     **  iterating to the next name in whichever list whose name compares
     **  alphabetically before the other.  Where a match is found, the
     **  nocutlist item is deleted.
     */

    ajListSort(nocutlist, remap_cmpcase);
    ajListSort(cutlist, remap_cmpcase);

    citer = ajListIterNewread(cutlist);
    niter = ajListIterNew(nocutlist);

    /*
       while((cutname = (AjPStr)ajListIterGet(citer)) != NULL)
       ajDebug("dbg cutname = %S\n", cutname);
       */

    nocutname = (AjPStr)ajListIterGet(niter);
    cutname   = (AjPStr)ajListIterGet(citer);

    ajDebug("initial cutname, nocutname: '%S' '%S'\n", cutname, nocutname);

    while(nocutname != NULL && cutname != NULL)
    {
	i = ajStrCmpCaseS(cutname, nocutname);
	ajDebug("compare cutname, nocutname: %S %S ", cutname, nocutname);
	ajDebug("ajStrCmpCase=%d\n", i);
	if(i == 0)
	{
	    /* match - so remove from nocutlist */
	    ajDebug("ajListstrRemove %S\n", nocutname);
	    ajListstrIterRemove(niter);
	    nocutname = (AjPStr)ajListIterGet(niter);
	     /* 
	     ** Don't increment the cutname list pointer here
	     ** - there may be more than one entry in the nocutname
	     ** list with the same name because we have converted 
	     ** isoschizomers to their preferred name
	     */
	    /* cutname = (AjPStr)ajListIterGet(citer); */
	}
	else if(i == -1)
	    /* cutlist name sorts before nocutlist name */
	    cutname = (AjPStr)ajListIterGet(citer);
	else if(i == 1)
	    /* nocutlist name sorts before cutlist name */
	    nocutname = (AjPStr)ajListIterGet(niter);
    }

    ajListIterDel(&citer);
    ajListIterDel(&niter);
    ajListstrFreeData(&cutlist);


     /* Print the resulting list of those that do not cut*/

    ajDebug("Print out the list\n");

    /* print the title */
    if(html)
	ajFmtPrintF(outfile, "<H2>");
    ajFmtPrintF(outfile, "\n\n# Enzymes that do not cut\n\n");

    if(html)
	ajFmtPrintF(outfile, "</H2>\n");

    if(html)
	ajFmtPrintF(outfile, "<PRE>");

    /*  ajListSort(nocutlist, ajStrVcmp);*/
    niter = ajListIterNewread(nocutlist);
    i = 0;
    while((nocutname = (AjPStr)ajListIterGet(niter)) != NULL)
    {
	ajFmtPrintF(outfile, "%-10S", nocutname);
	/* new line after every 7 names printed */
	if(i++ == 7)
	{
	    ajFmtPrintF(outfile, "\n");
	    i = 0;
	}
    }
    ajListIterDel(&niter);


    /* end the output */
    ajFmtPrintF(outfile, "\n");
    if(html) {ajFmtPrintF(outfile, "</PRE>\n");}



     /*
     ** Print the count of rejected enzymes
     ** N.B. This is the count of ALL rejected enzymes including all
     ** isoschizomers
     */

    if(html)
        ajFmtPrintF(outfile, "<H2>");
    ajFmtPrintF(outfile,
		"\n\n# No. of cutting enzymes which do not match the\n"
		"# SITELEN, BLUNT, STICKY, COMMERCIAL, AMBIGUOUS criteria\n\n");
    if(html)
	ajFmtPrintF(outfile, "</H2>\n");
    ajFmtPrintF(outfile, "%d\n", rejected_count);

    ajDebug("Tidy up\n");
    ajListstrFreeData(&nocutlist);
    ajListstrFreeData(&cutlist);

    return;
}
Exemplo n.º 5
0
/* @funcstatic seqwords_keysearch  ********************************************
**
** Search swissprot with terms structure and writes a hitlist structure
**
** @param [r] inf   [AjPFile]     File pointer to swissprot database
** @param [r] terms [AjPTerms]    Terms object pointer
** @param [w] hits  [EmbPHitlist*] Hitlist object pointer
**
** @return [AjBool] True on success
** @@
******************************************************************************/
static AjBool seqwords_keysearch(AjPFile inf, 
				 AjPTerms terms,
				 EmbPHitlist *hits)
{
    AjPStr   line           =NULL;	/* Line of text. */
    AjPStr   id             =NULL;	/* Line of text. */
    AjPStr   temp           =NULL;
    ajint    s              =0;         /* Temp. start of hit value. */
    ajint    e              =0;         /* Temp. end of hit value. */
    AjPInt   start          =NULL;      /* Array of start of hit(s). */
    AjPInt   end            =NULL;      /* Array of end of hit(s). */
    ajint    nhits          =0;         /* Number of hits. */
    ajint    x              =0;         
    AjBool   foundkw        =ajFalse;
    AjBool   foundft        =ajFalse;


    /* Check for valid args. */
    if(!inf)
	return ajFalse;
    

    

    /* Allocate strings and arrays. */
    line       = ajStrNew();
    id         = ajStrNew();
    start      = ajIntNew();
    end        = ajIntNew();



    /* Start of main loop. */
    while((ajReadlineTrim(inf,&line)))
    {
	/* Parse the AC line. */
	if(ajStrPrefixC(line,"AC"))
	{
	    /* Copy accesion number and remove the ';' from the end. */
	    ajFmtScanS(line, "%*s %S", &id);
	    ajStrExchangeCC(&id, ";", "\0");
	    
	    
	    /* Reset flags & no. hits. */
	    foundkw=ajFalse;
	    foundft=ajFalse;
	    nhits=0;
	}
	
	
	/* Search the description and keyword lines with search terms. */
	else if((ajStrPrefixC(line,"DE") || (ajStrPrefixC(line,"KW"))))
	{
	    /* 
	     ** Search terms have a leading and trailing space to prevent 
	     ** them being found as substrings within other words.  To 
	     ** catch cases where a DE or KW line begins with a search 
	     ** term, we must add a leading and trailing space to line.
	     ** We must first remove punctation from the line to be parsed.
	     */
	    ajStrExchangeSetCC(&line, ".,;:", "    ");
	    ajStrAppendK(&line, ' ');
	    ajStrInsertC(&line, 0, " ");


	    for (x = 0; x < terms->N; x++)
		/* Search term is found. */
		if((ajStrFindCaseS(line, terms->Keywords[x])!=-1))
		{	
		    foundkw=ajTrue;
		    break;
		}
	}

	
	/* Search the feature table line with search terms. */
	else if((ajStrPrefixC(line,"FT   DOMAIN")))
	{
	    /*	
	     ** Search terms have a leading and trailing space to prevent 
	     ** them being found as substrings within other words.  To 
	     ** catch cases where a FT line ends with a search 
	     ** term, we must add a  trailing space to line 
	     ** We must first remove punctation from the line to be parsed.
	     */
	    ajStrExchangeSetCC(&line, ".,;:", "    ");
	    ajStrAppendK(&line, ' ');
	    

	    for (x = 0; x < terms->N; x++)
		if((ajStrFindCaseS(line, terms->Keywords[x])!=-1))
		{
		    /* Search term is found. */
		    foundft = ajTrue;
		    nhits++;
		    
		    /* Assign start and end of hit. */
		    ajFmtScanS(line, "%*s %*s %d %d", &s, &e);


		    ajIntPut(&start, nhits-1, s);
		    ajIntPut(&end, nhits-1, e);
		    break;
		}
	}
	

	/* Parse the sequence. */
	else if((ajStrPrefixC(line,"SQ") && ((foundkw == ajTrue) ||
					     (foundft == ajTrue))))
	{
	    /* Allocate memory for temp. sequence. */
	    temp       = ajStrNew();


	    /* Read the sequence into hitlist structure. */
	    while((ajReadlineTrim(inf,&line)) && !ajStrPrefixC(line,"//"))
		/* Read sequence line into temp. */
		ajStrAppendC(&temp,ajStrGetPtr(line)+3);
 

	    /* Clean up temp. sequence. */
	    ajStrRemoveWhite(&temp);


	    /*Priority is given to domain (rather than full length) sequence.*/
	    if(foundft)
	    {
		for(x=0;x<nhits;x++)
		{
		    /* Increment counter of hits for subsequent hits*/
		    (*hits)->N++;

		    
		    /* Reallocate memory for array of hits in hitlist
                       structure. */
		    AJCRESIZE((*hits)->hits, (*hits)->N);
		    (*hits)->hits[(*hits)->N-1]=embHitNew();
		    ajStrAssignC(&(*hits)->hits[(*hits)->N-1]->Model,
				 "KEYWORD");
		    

		    /* Assign start and end of hit. */
		    (*hits)->hits[(*hits)->N-1]->Start = ajIntGet(start, x);
		    (*hits)->hits[(*hits)->N-1]->End = ajIntGet(end, x);
				

		    /* Extract sequence within specified range */
		    ajStrAssignSubS(&(*hits)->hits[(*hits)->N - 1]->Seq, temp, 
				(*hits)->hits[(*hits)->N - 1]->Start - 1, 
				(*hits)->hits[(*hits)->N - 1]->End - 1);
		    

		    /* Put id into structure */
		    ajStrAssignRef(&(*hits)->hits[(*hits)->N - 1]->Acc, id);
		}
	    }
	    else
	    {
		/* Increment counter of hits */
		(*hits)->N++;

		    
		/* Reallocate memory for array of hits in hitlist structure */
		AJCRESIZE((*hits)->hits, (*hits)->N);
		(*hits)->hits[(*hits)->N-1]=embHitNew();
		ajStrAssignC(&(*hits)->hits[(*hits)->N-1]->Model, "KEYWORD");

		/* Extract whole sequence */
		ajStrAssignRef(&(*hits)->hits[(*hits)->N - 1]->Seq, temp); 
		(*hits)->hits[(*hits)->N - 1]->Start = 1; 
		(*hits)->hits[(*hits)->N - 1]->End =
		    ajStrGetLen((*hits)->hits[(*hits)->N - 1]->Seq); 


		/* Put id into structure */
		ajStrAssignRef(&(*hits)->hits[(*hits)->N - 1]->Acc, id);
	    }

	    /* Free temp. sequence */
	    ajStrDel(&temp);
	}
    }


    /* Clean up */
    ajStrDel(&line);
    ajStrDel(&id);
    ajIntDel(&start);
    ajIntDel(&end);

    return ajTrue;
}
Exemplo n.º 6
0
int main(int argc, char **argv)
{

    AjPList idlist;
    AjPList* fieldList = NULL;

    AjBool systemsort;
    AjBool cleanup;

    ajint blastv = 0;
    char dbtype  = '\0';

    ajuint maxindex;
    ajuint maxidlen = 0;
    ajuint maxlen;

    AjPStr version = NULL;
    AjPStr seqtype = NULL;

    AjPFile elistfile  = NULL;
    AjPFile* alistfile = NULL;

    AjPStr dbname   = NULL;
    AjPStr release  = NULL;
    AjPStr datestr  = NULL;
    AjPStr sortopt  = NULL;
    void **entryIds = NULL;

    AjBool usesrc = AJTRUE;

    AjPStr directory;
    AjPStr indexdir;
    AjPStr filename;
    AjPStr exclude;
    AjPStr curfilename = NULL;

    AjPStr idformat = NULL;

    EmbPEntry entry;

    PBlastDb db = NULL;

    ajuint idCount = 0;
    ajuint idDone;
    AjPList listTestFiles = NULL;
    void ** testFiles = NULL;
    ajuint nfiles;
    ajuint ifile;
    ajuint jfile;

    ajuint filesize;
    short recsize;
    ajuint maxfilelen = 20;
    char date[4] =
    {
	0,0,0,0
    };

    AjPStr tmpfname = NULL;
    AjPStr* fields  = NULL;

    AjPFile entFile = NULL;

    AjPStr* divfiles   = NULL;
    ajint* maxFieldLen = NULL;

    ajuint ifield  = 0;
    ajuint nfields = 0;

    AjPFile logfile = NULL;
    ajuint* countField = NULL;
    ajuint* fieldTot = NULL;
    ajuint idCountFile = 0;
    ajuint i = 0;

    embInit("dbiblast", argc, argv);

    idformat = ajStrNewC("NCBI");

    fields     = ajAcdGetList("fields");
    directory  = ajAcdGetDirectoryName("directory");
    indexdir   = ajAcdGetOutdirName("indexoutdir");
    filename   = ajAcdGetString("filenames");
    exclude    = ajAcdGetString("exclude");
    dbname     = ajAcdGetString("dbname");
    release    = ajAcdGetString("release");
    datestr    = ajAcdGetString("date");
    systemsort = ajAcdGetBoolean("systemsort");
    cleanup    = ajAcdGetBoolean("cleanup");
    sortopt    = ajAcdGetString("sortoptions");
    maxindex   = ajAcdGetInt("maxindex");
    version    = ajAcdGetListSingle("blastversion");
    seqtype    = ajAcdGetListSingle("seqtype");
    usesrc     = ajAcdGetBoolean("sourcefile");
    logfile    = ajAcdGetOutfile("outfile");

    while(fields[nfields])		/* array ends with a NULL */
	nfields++;

    if(nfields)
    {
	AJCNEW(maxFieldLen, nfields);
	AJCNEW0(countField, nfields);
	AJCNEW0(fieldTot, nfields);
	for(ifield=0; ifield < nfields; ifield++)
	    maxFieldLen[ifield] = (ajint) maxindex * -1;

	if(systemsort)
	    AJCNEW(alistfile, nfields);
	else
	{
	    AJCNEW(fieldList, nfields);
	    for(ifield=0; ifield < nfields; ifield++)
		fieldList[ifield] = ajListNew();
	}
    }
    
    if(ajStrMatchC(datestr, "00/00/00"))
	ajFmtPrintS(&datestr, "%D", ajTimeRefTodayFmt("dbindex"));

    ajStrRemoveWhite(&dbname);		/* used for temp filenames */
    embDbiDateSet(datestr, date);
    idlist = ajListNew();
    
    if(ajUtilGetBigendian())
	readReverse = ajFalse;
    else
	readReverse = ajTrue;
    
    ajStrToInt(version, &blastv);
    dbtype = ajStrGetCharFirst(seqtype);
    
    ajDebug("reading '%S/%S'\n", directory, filename);
    ajDebug("writing '%S/'\n", indexdir);
    
    listTestFiles = embDbiFileListExc(directory, filename, exclude);
    ajListSort(listTestFiles, ajStrVcmp);
    nfiles = ajListToarray(listTestFiles, &testFiles);
    if(!nfiles)
        ajDie("No input files in '%S' matched filename '%S'",
              directory, filename);
    
    embDbiLogHeader(logfile, dbname, release, datestr,
		     indexdir, maxindex);

    embDbiLogFields(logfile, fields, nfields);
    embDbiLogSource(logfile, directory, filename, exclude,
		    (AjPStr*) testFiles, nfiles);
    embDbiLogCmdline(logfile);

    AJCNEW0(divfiles, nfiles);
    
    /*
    ** process each input file, one at a time
    */
    
    jfile = 0;
    for(ifile=0; ifile < nfiles; ifile++)
    {
	curfilename = (AjPStr) testFiles[ifile];
	if(!dbiblast_blastopenlib(curfilename,
				  usesrc, blastv, dbtype, &db))
	    continue;	 /* could be the wrong file type with "*.*" */

	ajDebug("processing filename '%S' ...\n", curfilename);
	ajDebug("processing file '%S' ...\n", db->TFile->Name);


	ajStrAssignS(&divfiles[jfile], db->TFile->Name);
	ajFilenameTrimPath(&divfiles[jfile]);
	if(ajStrGetLen(divfiles[jfile]) >= maxfilelen)
	    maxfilelen = ajStrGetLen(divfiles[jfile]) + 1;

	if(systemsort)	 /* elistfile for entries, alist for fields */
	    elistfile = embDbiSortOpen(alistfile, jfile,
				       dbname, fields, nfields);

	idCountFile = 0;
	for(i=0;i<nfields;i++)
	    countField[i] = 0;
	while((entry=dbiblast_nextblastentry(db, jfile,
					     idformat, systemsort,
					     fields,
					     maxFieldLen,
					     &maxidlen, countField,
					     elistfile, alistfile)))
	{
	    idCountFile++;
	    if(!systemsort)	    /* save the entry data in lists */
	    {
		embDbiMemEntry(idlist, fieldList, nfields, entry, jfile);
	    }
	}
	idCount += idCountFile;
	if(systemsort)
	{
	    embDbiSortClose(&elistfile, alistfile, nfields);
	    /* lost the entry, so can't free it :-) */
	}

	embDbiLogFile(logfile, curfilename, idCountFile, fields,
		      countField, nfields);
	dbiblast_dbfree(&db);
	jfile++;
    }
    nfiles = jfile;
    
    /*
    ** write the division.lkp file
    */
    
    embDbiWriteDivision(indexdir, dbname, release, date,
			maxfilelen, nfiles, divfiles, NULL);
    
    /*
    ** Write the entryname.idx index
    */
    
    ajStrAssignC(&tmpfname, "entrynam.idx");
    entFile = ajFileNewOutNamePathS(tmpfname, indexdir);
    
    recsize = maxidlen+10;
    filesize = 300 + (idCount*(ajint)recsize);
    embDbiHeader(entFile, filesize, idCount, recsize, dbname, release, date);
    
    if(systemsort)
        idDone = embDbiSortWriteEntry(entFile, maxidlen,
				      dbname, nfiles, cleanup, sortopt);
    else			  /* save entries in entryIds array */
    {
        idDone = embDbiMemWriteEntry(entFile, maxidlen,
				     idlist, &entryIds);
	if(idDone != idCount)
	    ajFatal("Duplicates not allowed for in-memory processing");
    }
    
    embDbiHeaderSize(entFile, 300+(idDone*(ajint)recsize), idDone);
    ajFileClose(&entFile);
    
    /*
    ** Write the fields index files
    */
    
    for(ifield=0; ifield < nfields; ifield++)
    {

        if(maxindex)
	    maxlen = maxindex;
	else
	{
	    if(maxFieldLen[ifield] >= 0)
		maxlen = maxFieldLen[ifield];
	    else
		maxlen = - maxFieldLen[ifield];
	}

        if(systemsort)
	    fieldTot[ifield] = embDbiSortWriteFields(dbname, release,
						     date, indexdir,
						     fields[ifield], maxlen,
						     nfiles, idCount,
						     cleanup, sortopt);
	else
	    fieldTot[ifield] = embDbiMemWriteFields(dbname, release,
						    date, indexdir,
						    fields[ifield], maxlen,
						    fieldList[ifield],
						    entryIds);
    }
    
    embDbiLogFinal(logfile,maxindex, maxFieldLen, fields, fieldTot,
		   nfields, nfiles, idDone, idCount);

    if(systemsort)
	embDbiRmEntryFile(dbname, cleanup);
    
    ajListMap(idlist, embDbiEntryDelMap, NULL);
    ajListFree(&idlist);
    AJFREE(entryIds);

    ajStrDelarray(&fields);

    for(i=0;i<nfields;i++)
    {
	if(systemsort)
	{
	    ajFileClose(&alistfile[i]);
	}
	else
	{
	    ajListMap(fieldList[i], embDbiFieldDelMap, NULL);
	    ajListFree(&fieldList[i]);
	}
    }
    AJFREE(alistfile);
    AJFREE(fieldList);
    ajStrDel(&version);
    ajStrDel(&seqtype);
    ajFileClose(&elistfile);
    for(i=0;i<nfiles;i++)
    {
	ajStrDel(&divfiles[i]);
    }
    AJFREE(countField);
    AJFREE(fieldTot);

    ajStrDel(&dbname);
    ajStrDel(&release);
    ajStrDel(&datestr);
    ajStrDel(&sortopt);
    ajStrDel(&directory);
    ajStrDel(&indexdir);
    ajStrDel(&filename);
    ajStrDel(&exclude);
    ajStrDel(&idformat);
    ajStrDel(&tmpfname);

    AJFREE(maxFieldLen);

    ajFileClose(&logfile);

    ajListstrFreeData(&listTestFiles);

    ajStrDel(&t);
    ajStrDel(&id);
    ajStrDel(&acc);
    ajStrDel(&hline);
    ajStrDel(&tmpdes);
    ajStrDel(&tmpfd);
    ajStrDel(&tmpgi);
    ajStrDel(&tmpdb);
    ajStrDel(&tmpac);
    ajStrDel(&tmpsv);
    ajRegFree(&wrdexp);

    embDbiEntryDel(&dbiblastEntry);

    if(fdl)
    {
        for(i=0; i < nfields; i++)
            ajListFree(&fdl[i]);
        AJFREE(fdl);
    }

    for(i=0;i<nfiles;i++)
    {
        ajStrDel(&divfiles[i]);
    }
    AJFREE(divfiles);
    AJFREE(testFiles);

    embExit();

    return 0;
}
Exemplo n.º 7
0
int main(int argc, char **argv)
{
    AjPList idlist;
    AjPList* fieldList = NULL;

    AjBool systemsort;
    AjBool cleanup;

    ajuint maxindex;
    ajuint maxidlen = 0;
    ajuint maxlen;

    AjPFile elistfile  = NULL;
    AjPFile* alistfile = NULL;

    AjPStr dbname   = NULL;
    AjPStr release  = NULL;
    AjPStr datestr  = NULL;
    AjPStr sortopt  = NULL;
    void **entryIds = NULL;

    AjPStr directory;
    AjPStr indexdir;
    AjPStr filename;
    AjPStr exclude;
    AjPStr curfilename = NULL;

    AjPFile libr=NULL;
    AjPStr idformat = NULL;

    EmbPEntry entry;

    ajuint idtype  = 0;

    ajuint idCount = 0;
    ajuint idDone;
    AjPList listInputFiles = NULL;
    void ** inputFiles = NULL;
    ajuint nfiles;
    ajuint ifile;

    ajuint filesize;
    short recsize;
    ajuint maxfilelen = 20;
    char date[4] =
    {
	0,0,0,0
    };

    AjPStr tmpfname = NULL;
    AjPStr* fields  = NULL;

    AjPFile entFile  = NULL;

    AjPStr* divfiles   = NULL;
    AjPRegexp regIdExp      = NULL;
    ajint* maxFieldLen = NULL;

    ajuint ifield  = 0;
    ajuint nfields = 0;

    AjPFile logfile = NULL;
    ajuint* countField = NULL;
    ajuint* fieldTot = NULL;
    ajuint idCountFile = 0;
    ajuint i;

    embInit("dbifasta", argc, argv);

    idformat   = ajAcdGetListSingle("idformat");
    fields     = ajAcdGetList("fields");
    directory  = ajAcdGetDirectoryName("directory");
    indexdir   = ajAcdGetOutdirName("indexoutdir");
    filename   = ajAcdGetString("filenames");
    exclude    = ajAcdGetString("exclude");
    dbname     = ajAcdGetString("dbname");
    release    = ajAcdGetString("release");
    datestr    = ajAcdGetString("date");
    systemsort = ajAcdGetBoolean("systemsort");
    cleanup    = ajAcdGetBoolean("cleanup");
    sortopt    = ajAcdGetString("sortoptions");
    maxindex   = ajAcdGetInt("maxindex");
    logfile    = ajAcdGetOutfile("outfile");

    while(fields[nfields])		/* array ends with a NULL */
	nfields++;

    if(nfields)
    {
	AJCNEW(maxFieldLen, nfields);
	AJCNEW0(countField, nfields);
	AJCNEW0(fieldTot, nfields);
	for(ifield=0; ifield < nfields; ifield++)
	    maxFieldLen[ifield] = (ajint)maxindex * -1;

	if(systemsort)
	    AJCNEW(alistfile, nfields);
	else
	{
	    AJCNEW(fieldList, nfields);
	    for(ifield=0; ifield < nfields; ifield++)
		fieldList[ifield] = ajListNew();
	}
    }

    if(ajStrMatchC(datestr, "00/00/00"))
	ajFmtPrintS(&datestr, "%D", ajTimeRefTodayFmt("dbindex"));

    ajStrRemoveWhite(&dbname);		/* used for temp filenames */
    embDbiDateSet(datestr, date);
    idlist = ajListNew();

    regIdExp = dbifasta_getExpr(idformat, &idtype);

    ajDebug("reading '%S/%S'\n", directory, filename);
    ajDebug("writing '%S/'\n", indexdir);

    listInputFiles = embDbiFileListExc(directory, filename, exclude);
    ajListSort(listInputFiles, &ajStrVcmp);
    nfiles = (ajuint) ajListToarray(listInputFiles, &inputFiles);
    if(!nfiles)
        ajDie("No input files in '%S' matched filename '%S'",
              directory, filename);

    embDbiLogHeader(logfile, dbname, release, datestr,
		     indexdir, maxindex);

    embDbiLogFields(logfile, fields, nfields);
    embDbiLogSource(logfile, directory, filename, exclude,
		    (AjPStr*) inputFiles, nfiles);
    embDbiLogCmdline(logfile);

    AJCNEW0(divfiles, nfiles);

    /*
    ** process each input file, one at a time
    */

    for(ifile=0; ifile < nfiles; ifile++)
    {
	ajStrAssignS(&curfilename,(AjPStr) inputFiles[ifile]);
	embDbiFlatOpenlib(curfilename, &libr);
	ajFilenameTrimPath(&curfilename);
	if(ajStrGetLen(curfilename) >= maxfilelen)
	    maxfilelen = ajStrGetLen(curfilename) + 1;

	ajDebug("processing filename '%S' ...\n", curfilename);
	ajDebug("processing file '%F' ...\n", libr);
	ajStrAssignS(&divfiles[ifile], curfilename);

	if(systemsort)	 /* elistfile for entries, alist for fields */
	    elistfile = embDbiSortOpen(alistfile, ifile,
				       dbname, fields, nfields);

	idCountFile = 0;
	for(i=0;i<nfields;i++)
	    countField[i] = 0;
	while((entry=dbifasta_NextFlatEntry(libr, ifile,
					    regIdExp, idtype,
					    systemsort, fields, 
					    maxFieldLen, &maxidlen,
					    countField, elistfile,
					    alistfile)))
	{
	    idCountFile++;
	    if(!systemsort)	    /* save the entry data in lists */
		embDbiMemEntry(idlist, fieldList, nfields,
			       entry, ifile);
		entry = NULL;
	}
	idCount += idCountFile;
	if(systemsort)
	{
	    embDbiSortClose(&elistfile, alistfile, nfields);
	    AJFREE(entry);
	}
	else
	{
	    embDbiEntryDel(&dbifastaGEntry);
	}
	embDbiLogFile(logfile, curfilename, idCountFile, fields,
		      countField, nfields);
    }

    /*  write the division.lkp file */
    embDbiWriteDivision(indexdir, dbname, release, date,
			maxfilelen, nfiles, divfiles, NULL);

    /* Write the entryname.idx index */
    ajStrAssignC(&tmpfname, "entrynam.idx");
    entFile = ajFileNewOutNamePathS(tmpfname, indexdir);

    recsize = maxidlen+10;
    filesize = 300 + (idCount*(ajint)recsize);
    embDbiHeader(entFile, filesize, idCount, recsize, dbname, release, date);

    if(systemsort)
        idDone = embDbiSortWriteEntry(entFile, maxidlen,
				      dbname, nfiles, cleanup, sortopt);
    else			  /* save entries in entryIds array */
    {
        idDone = embDbiMemWriteEntry(entFile, maxidlen,
				     idlist, &entryIds);
	if(idDone != idCount)
	    ajFatal("Duplicates not allowed for in-memory processing");
    }

    embDbiHeaderSize(entFile, 300+(idDone*(ajint)recsize), idDone);
    ajFileClose(&entFile);

    /* Write the fields index files */
    for(ifield=0; ifield < nfields; ifield++)
    {
        if(maxindex)
	    maxlen = maxindex;
	else
	{
	    if(maxFieldLen[ifield] >= 0)
		maxlen = maxFieldLen[ifield];
	    else
		maxlen = - maxFieldLen[ifield];
	}

        if(systemsort)
	    fieldTot[ifield] = embDbiSortWriteFields(dbname, release,
						     date, indexdir,
						     fields[ifield], maxlen,
						     nfiles, idCount,
						     cleanup, sortopt);
	else
	    fieldTot[ifield] = embDbiMemWriteFields(dbname, release,
						    date, indexdir,
						    fields[ifield], maxlen,
						    fieldList[ifield],
						    entryIds);
    }

    embDbiLogFinal(logfile,maxindex, maxFieldLen, fields, fieldTot,
		   nfields, nfiles, idDone, idCount);

    if(systemsort)
	embDbiRmEntryFile(dbname, cleanup);

    ajStrDel(&idformat);
    ajStrDelarray(&fields);
    ajStrDel(&filename);
    ajStrDel(&exclude);
    ajStrDel(&dbname);
    ajStrDel(&release);
    ajStrDel(&datestr);
    ajStrDel(&sortopt);
    ajStrDel(&directory);
    ajStrDel(&indexdir);
    ajStrDel(&tmpfname);
    ajFileClose(&libr);
    ajFileClose(&logfile);

    for(i=0;i<nfields;i++)
    {
	if(systemsort)
	{
	    ajFileClose(&alistfile[i]);
	}
	else
	{
	    ajListMap(fieldList[i], &embDbiFieldDelMap, NULL);
	    ajListFree(&fieldList[i]);
	}
    }

    AJFREE(alistfile);
    AJFREE(fieldList);
    AJFREE(maxFieldLen);
    AJFREE(countField);
    AJFREE(fieldTot);

    for(i=0;i<nfiles;i++)
    {
	ajStrDel(&divfiles[i]);
    }

    AJFREE(divfiles);
    AJFREE(inputFiles);

    embDbiEntryDel(&dbifastaGEntry);

    ajStrDel(&dbifastaGRline);
    ajStrDel(&dbifastaGTmpId);

    if(dbifastaGFdl)
    {
	for(i=0; i < nfields; i++)
	    ajListFree(&dbifastaGFdl[i]);
	AJFREE(dbifastaGFdl);
    }

    ajListMap(idlist, &embDbiEntryDelMap, NULL);
    ajListFree(&idlist);
    ajListstrFreeData(&listInputFiles);
    AJFREE(entryIds);
    ajRegFree(&dbifastaGIdexp);
    ajRegFree(&dbifastaGWrdexp);
    ajRegFree(&regIdExp);

    ajStrDel(&dbifastaGTmpAc);
    ajStrDel(&dbifastaGTmpSv);
    ajStrDel(&dbifastaGTmpGi);
    ajStrDel(&dbifastaGTmpDb);
    ajStrDel(&dbifastaGTmpDes);
    ajStrDel(&dbifastaGTmpFd);
    ajStrDel(&curfilename);

    embExit();

    return 0;
}
Exemplo n.º 8
0
int main(int argc, char **argv)
{
    /* Global details */
    AjBool explain_flag;
    AjBool file_flag;
    AjPStr* task;
    AjBool do_primer;
    AjBool do_hybrid;
    ajint num_return;
    ajint first_base_index;

    /* "Sequence" Input Tags */
    AjPSeqall sequence;
    AjPRange included_region;
    AjPRange target;
    AjPRange excluded_region;
    AjPStr left_input;
    AjPStr right_input;

    /* Primer details */
    AjBool pick_anyway;
    AjPFile mispriming_library;
    float max_mispriming;
    float pair_max_mispriming;
    ajint gc_clamp;
    ajint opt_size;
    ajint min_size;
    ajint max_size;
    float opt_tm;
    float min_tm;
    float max_tm;
    float max_diff_tm;
    float opt_gc_percent;
    float min_gc;
    float max_gc;
    float salt_conc;
    float dna_conc;
    ajint num_ns_accepted;
    float self_any;
    float self_end;
    ajint max_poly_x;

    /* Sequence Quality. These are not (yet) implemented */
    /*
       AjPFile sequence_quality;
       ajint	min_quality;
       ajint	min_end_quality;
       ajint	quality_range_min;
       ajint	quality_range_max;
       */

    /* Product details */
    ajint product_opt_size;
    AjPRange product_size_range;
    float product_opt_tm;
    float product_min_tm;
    float product_max_tm;

    /* Objective Function Penalty Weights for Primers */
    float max_end_stability;

    /* these are not (yet) implemented */
    /*
       float		inside_penalty;
       float		outside_penalty;
    */

    /* Primer penalties */
    /* these are not (yet) implemented */

    /* Internal Oligo "Sequence" Input Tags */
    AjPRange internal_oligo_excluded_region;

    /* Internal Oligo "Global" Input Tags */
    AjPStr internal_oligo_input;
    ajint internal_oligo_opt_size;
    ajint internal_oligo_min_size;
    ajint internal_oligo_max_size;
    float internal_oligo_opt_tm;
    float internal_oligo_min_tm;
    float internal_oligo_max_tm;
    float internal_oligo_opt_gc_percent;
    float internal_oligo_min_gc;
    float internal_oligo_max_gc;
    float internal_oligo_salt_conc;
    float internal_oligo_dna_conc;
    float internal_oligo_self_any;
    float internal_oligo_self_end;
    ajint internal_oligo_max_poly_x;
    AjPFile internal_oligo_mishyb_library;
    float internal_oligo_max_mishyb;

    /*
       ajint		internal_oligo_min_quality;
    */

    /* Internal Oligo penalties */
    /* these are not (yet) implemented */

    /* EMBOSS-wrapper-specific stuff */
    AjPFile	outfile;

    /* other variables */
    AjPStr result = NULL;
    AjPStr strand = NULL;
    AjPStr substr = NULL;
    AjPSeq seq    = NULL;
    ajint begin   = 0;
    ajint end;
    FILE* stream;
    AjPStr taskstr  = NULL;
    const AjPStr program = NULL;

    /* pipe variables */

    int *pipeto;	  /* pipe to feed the exec'ed program input */
    int *pipefrom;	  /* pipe to get the exec'ed program output */

    embInit("eprimer3", argc, argv);

    /* Global details */
    explain_flag     = ajAcdGetBoolean("explainflag");
    file_flag        = ajAcdGetBoolean("fileflag");
    task             = ajAcdGetList("task");
    do_primer        = ajAcdGetToggle("primer");
    do_hybrid        = ajAcdGetToggle("hybridprobe");
    num_return       = ajAcdGetInt("numreturn");
    first_base_index = ajAcdGetInt("firstbaseindex");

    /* "Sequence" Input Tags */
    sequence        = ajAcdGetSeqall("sequence");
    included_region = ajAcdGetRange("includedregion");
    target          = ajAcdGetRange("targetregion");
    excluded_region = ajAcdGetRange("excludedregion");
    left_input      = ajAcdGetString("forwardinput");
    right_input     = ajAcdGetString("reverseinput");

    /* Primer details */
    pick_anyway         = ajAcdGetBoolean("pickanyway");
    mispriming_library  = ajAcdGetInfile("mispriminglibraryfile");
    max_mispriming      = ajAcdGetFloat("maxmispriming");
    pair_max_mispriming = ajAcdGetFloat("pairmaxmispriming");
    gc_clamp            = ajAcdGetInt("gcclamp");
    opt_size            = ajAcdGetInt("osize");
    min_size            = ajAcdGetInt("minsize");
    max_size            = ajAcdGetInt("maxsize");
    opt_tm              = ajAcdGetFloat("otm");
    min_tm              = ajAcdGetFloat("mintm");
    max_tm              = ajAcdGetFloat("maxtm");
    max_diff_tm         = ajAcdGetFloat("maxdifftm");
    opt_gc_percent      = ajAcdGetFloat("ogcpercent");
    min_gc              = ajAcdGetFloat("mingc");
    max_gc              = ajAcdGetFloat("maxgc");
    salt_conc           = ajAcdGetFloat("saltconc");
    dna_conc            = ajAcdGetFloat("dnaconc");
    num_ns_accepted     = ajAcdGetInt("numnsaccepted");
    self_any            = ajAcdGetFloat("selfany");
    self_end            = ajAcdGetFloat("selfend");
    max_poly_x          = ajAcdGetInt("maxpolyx");

    AJCNEW0(pipeto,2);
    AJCNEW0(pipefrom,2);

    /* Sequence Quality */
    /* these are not (yet) implemented */
    /*
       sequence_quality  = ajAcdGetInfile("sequencequality");
       min_quality       = ajAcdGetInt("minquality");
       min_end_quality   = ajAcdGetInt("minendquality");
       quality_range_min = ajAcdGetInt("qualityrangemin");
       quality_range_max = ajAcdGetInt("qualityrangemax");
       */

    /* Product details */
    product_opt_size    = ajAcdGetInt("psizeopt");
    product_size_range  = ajAcdGetRange("prange");
    product_opt_tm      = ajAcdGetFloat("ptmopt");
    product_min_tm      = ajAcdGetFloat("ptmmin");
    product_max_tm      = ajAcdGetFloat("ptmmax");

    /* Objective Function Penalty Weights for Primers */
    max_end_stability   = ajAcdGetFloat("maxendstability");
    /* these are not (yet) implemented */
    /*
       inside_penalty      = ajAcdGetFloat("insidepenalty");
       outside_penalty     = ajAcdGetFloat("outsidepenalty");
    */

    /* Primer penalties */
    /* these are not (yet) implemented */

    /* Internal Oligo "Sequence" Input Tags */
    internal_oligo_excluded_region = ajAcdGetRange("oexcludedregion");
    internal_oligo_input           = ajAcdGetString("oligoinput");

    /* Internal Oligo "Global" Input Tags */
    internal_oligo_opt_size       = ajAcdGetInt("osizeopt");
    internal_oligo_min_size       = ajAcdGetInt("ominsize");
    internal_oligo_max_size       = ajAcdGetInt("omaxsize");
    internal_oligo_opt_tm         = ajAcdGetFloat("otmopt");
    internal_oligo_min_tm         = ajAcdGetFloat("otmmin");
    internal_oligo_max_tm         = ajAcdGetFloat("otmmax");
    internal_oligo_opt_gc_percent = ajAcdGetFloat("ogcopt");
    internal_oligo_min_gc         = ajAcdGetFloat("ogcmin");
    internal_oligo_max_gc         = ajAcdGetFloat("ogcmax");
    internal_oligo_salt_conc      = ajAcdGetFloat("osaltconc");
    internal_oligo_dna_conc       = ajAcdGetFloat("odnaconc");
    internal_oligo_self_any       = ajAcdGetFloat("oanyself");
    internal_oligo_self_end       = ajAcdGetFloat("oendself");
    internal_oligo_max_poly_x     = ajAcdGetInt("opolyxmax");
    internal_oligo_mishyb_library = ajAcdGetInfile("mishyblibraryfile");
    internal_oligo_max_mishyb     = ajAcdGetFloat("omishybmax");
    /*
       internal_oligo_min_quality    = ajAcdGetInt("oligominquality");
    */

    /* Internal Oligo penalties */
    /* these are not (yet) implemented */


    /* EMBOSS-wrapper-specific stuff */
    outfile = ajAcdGetOutfile("outfile");


    ajStrRemoveWhite(&left_input);
    ajStrRemoveWhite(&right_input);

    /*
    ** OK - we will now try to do a separate fork-exec for each sequence.
    */

    result = ajStrNew();

    while(ajSeqallNext(sequence, &seq))
    {
        program = ajAcdGetpathC("primer3_core");

        if(!ajSysExecRedirectC(ajStrGetPtr(program),&pipeto,&pipefrom))
            ajFatal("eprimer3: Could not exec primer3_core");

        stream = eprimer3_start_write(pipeto[1]);

        /* send primer3 Primer "Global" parameters */
        eprimer3_send_bool(stream, "PRIMER_EXPLAIN_FLAG", explain_flag);
        eprimer3_send_bool(stream, "PRIMER_FILE_FLAG", file_flag);

        if(do_hybrid)
        {
            if(!ajStrCmpC(task[0], "1"))
                ajStrAssignC(&taskstr, "pick_pcr_primers_and_hyb_probe");
            else if(!ajStrCmpC(task[0], "2"))
                ajStrAssignC(&taskstr, "pick_left_only");
            else if(!ajStrCmpC(task[0], "3"))
                ajStrAssignC(&taskstr, "pick_right_only");
            else if(!ajStrCmpC(task[0], "4"))
                ajStrAssignC(&taskstr, "pick_hyb_probe_only");

            if (!do_primer)
                ajStrAssignC(&taskstr, "pick_hyb_probe_only");
        }
        else
        {
            if(!ajStrCmpC(task[0], "1"))
                ajStrAssignC(&taskstr, "pick_pcr_primers");
            else if(!ajStrCmpC(task[0], "2"))
                ajStrAssignC(&taskstr, "pick_left_only");
            else if(!ajStrCmpC(task[0], "3"))
                ajStrAssignC(&taskstr, "pick_right_only");
            else if(!ajStrCmpC(task[0], "4"))
                ajStrAssignC(&taskstr, "pick_hyb_probe_only");
        }

        eprimer3_send_string(stream, "PRIMER_TASK", taskstr);
        eprimer3_send_int(stream, "PRIMER_NUM_RETURN", num_return);
        eprimer3_send_int(stream, "PRIMER_FIRST_BASE_INDEX",
                          first_base_index);
        eprimer3_send_bool(stream, "PRIMER_PICK_ANYWAY", pick_anyway);

        /* mispriming library may not have been specified */
        if(mispriming_library)
            eprimer3_send_stringC(stream, "PRIMER_MISPRIMING_LIBRARY",
                                  ajFileGetPrintnameC(mispriming_library));

        eprimer3_send_float(stream, "PRIMER_MAX_MISPRIMING",
                            max_mispriming);
        eprimer3_send_float(stream, "PRIMER_PAIR_MAX_MISPRIMING",
                            pair_max_mispriming);
        eprimer3_send_int(stream, "PRIMER_GC_CLAMP", gc_clamp);
        eprimer3_send_int(stream, "PRIMER_OPT_SIZE", opt_size);
        eprimer3_send_int(stream, "PRIMER_MIN_SIZE", min_size);
        eprimer3_send_int(stream, "PRIMER_MAX_SIZE", max_size);
        eprimer3_send_float(stream, "PRIMER_OPT_TM", opt_tm);
        eprimer3_send_float(stream, "PRIMER_MIN_TM", min_tm);
        eprimer3_send_float(stream, "PRIMER_MAX_TM", max_tm);
        eprimer3_send_float(stream, "PRIMER_MAX_DIFF_TM", max_diff_tm);
        eprimer3_send_float(stream, "PRIMER_OPT_GC_PERCENT",
                            opt_gc_percent);
        eprimer3_send_float(stream, "PRIMER_MIN_GC", min_gc);
        eprimer3_send_float(stream, "PRIMER_MAX_GC", max_gc);
        eprimer3_send_float(stream, "PRIMER_SALT_CONC", salt_conc);
        eprimer3_send_float(stream, "PRIMER_DNA_CONC", dna_conc);
        eprimer3_send_int(stream, "PRIMER_NUM_NS_ACCEPTED",
                          num_ns_accepted);
        eprimer3_send_float(stream, "PRIMER_SELF_ANY", self_any);
        eprimer3_send_float(stream, "PRIMER_SELF_END", self_end);
        eprimer3_send_int(stream, "PRIMER_MAX_POLY_X", max_poly_x);
        eprimer3_send_int(stream, "PRIMER_PRODUCT_OPT_SIZE",
                          product_opt_size);
        eprimer3_send_range2(stream, "PRIMER_PRODUCT_SIZE_RANGE",
                             product_size_range);
        eprimer3_send_float(stream, "PRIMER_PRODUCT_OPT_TM",
                            product_opt_tm);
        eprimer3_send_float(stream, "PRIMER_PRODUCT_MIN_TM",
                            product_min_tm);
        eprimer3_send_float(stream, "PRIMER_PRODUCT_MAX_TM",
                            product_max_tm);
        eprimer3_send_float(stream, "PRIMER_MAX_END_STABILITY",
                            max_end_stability);

        /* send primer3 Internal Oligo "Global" parameters */
        eprimer3_send_int(stream, "PRIMER_INTERNAL_OLIGO_OPT_SIZE",
                          internal_oligo_opt_size);
        eprimer3_send_int(stream, "PRIMER_INTERNAL_OLIGO_MIN_SIZE",
                          internal_oligo_min_size);
        eprimer3_send_int(stream, "PRIMER_INTERNAL_OLIGO_MAX_SIZE",
                          internal_oligo_max_size);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_OPT_TM",
                            internal_oligo_opt_tm);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_MIN_TM",
                            internal_oligo_min_tm);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_MAX_TM",
                            internal_oligo_max_tm);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_OPT_GC_PERCENT",
                            internal_oligo_opt_gc_percent);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_MIN_GC",
                            internal_oligo_min_gc);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_MAX_GC",
                            internal_oligo_max_gc);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_SALT_CONC",
                            internal_oligo_salt_conc);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_DNA_CONC",
                            internal_oligo_dna_conc);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_SELF_ANY",
                            internal_oligo_self_any);
        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_SELF_END",
                            internal_oligo_self_end);
        eprimer3_send_int(stream, "PRIMER_INTERNAL_OLIGO_MAX_POLY_X",
                          internal_oligo_max_poly_x);

        /*
        ** internal oligo mishybridising library may not have been
        ** specified
        */
        if(internal_oligo_mishyb_library)
            eprimer3_send_stringC(stream,
                                  "PRIMER_INTERNAL_OLIGO_MISHYB_LIBRARY",
                                  ajFileGetPrintnameC(internal_oligo_mishyb_library));

        eprimer3_send_float(stream, "PRIMER_INTERNAL_OLIGO_MAX_MISHYB",
                            internal_oligo_max_mishyb);


        /*
        ** Start sequence-specific stuff
        */

        begin = ajSeqallGetseqBegin(sequence) - 1;
        end   = ajSeqallGetseqEnd(sequence) - 1;

        strand = ajSeqGetSeqCopyS(seq);

        ajStrFmtUpper(&strand);
        ajStrAssignSubC(&substr,ajStrGetPtr(strand), begin, end);

        /* send flags to turn on using optimal product size */
        eprimer3_send_float(stream, "PRIMER_PAIR_WT_PRODUCT_SIZE_GT",
                            (float)0.05);
        eprimer3_send_float(stream, "PRIMER_PAIR_WT_PRODUCT_SIZE_LT",
                            (float)0.05);

        /* send primer3 Primer "Sequence" parameters */
        eprimer3_send_string(stream, "SEQUENCE", substr);

        /* if no ID name, use the USA */
        if(ajStrMatchC(ajSeqGetNameS(seq),""))
            eprimer3_send_string(stream, "PRIMER_SEQUENCE_ID",
                                 ajSeqGetUsaS(seq));
        else
            eprimer3_send_string(stream, "PRIMER_SEQUENCE_ID",
                                 ajSeqGetNameS(seq));

        eprimer3_send_range(stream, "INCLUDED_REGION", included_region,
                            begin);
        eprimer3_send_range(stream, "TARGET", target, begin);
        eprimer3_send_range(stream, "EXCLUDED_REGION", excluded_region,
                            begin);
        eprimer3_send_string(stream, "PRIMER_LEFT_INPUT", left_input);
        eprimer3_send_string(stream, "PRIMER_RIGHT_INPUT", right_input);

        /* send primer3 Internal Oligo "Sequence" parameters */
        eprimer3_send_range(stream,
                            "PRIMER_INTERNAL_OLIGO_EXCLUDED_REGION",
                            internal_oligo_excluded_region, begin);
        eprimer3_send_string(stream, "PRIMER_INTERNAL_OLIGO_INPUT",
                             internal_oligo_input);


        /* end the primer3 input sequence record with a '=' */
        eprimer3_send_end(stream);
        /* and close the ouput pipe stream */
        eprimer3_end_write(stream);

        /* read the primer3 output */
        eprimer3_read(pipefrom[0], &result);

        eprimer3_report(outfile, result, num_return, begin);

        ajStrSetClear(&result);

#ifndef WIN32
        close(pipeto[1]);
        close(pipefrom[0]);
#endif
    }	/* end of sequence loop */


    ajStrDel(&result);
    ajSeqDel(&seq);
    ajStrDel(&strand);
    ajStrDel(&substr);
    ajFileClose(&outfile);
    ajStrDel(&taskstr);
    ajStrDelarray(&task);

    ajSeqallDel(&sequence);
    ajSeqDel(&seq);

    ajRangeDel(&included_region);
    ajRangeDel(&target);
    ajRangeDel(&excluded_region);
    ajRangeDel(&product_size_range);
    ajRangeDel(&internal_oligo_excluded_region);

    ajStrDel(&left_input);
    ajStrDel(&right_input);
    ajStrDel(&internal_oligo_input);

    AJFREE(pipeto);
    AJFREE(pipefrom);

    ajFileClose(&mispriming_library);

    embExit();

    return 0;
}
Exemplo n.º 9
0
/* @prog ssematch ***********************************************************
**
** Searches a DCF file (domain classification file) for secondary structure 
** matches.
**
****************************************************************************/
int main(int argc, char **argv)
{
    /* Variables declarations */
    AjPFile dcfin        = NULL; /* Domain classification file */
    AjPFile ssin         = NULL; /* Secondary structure input file*/
    AjPMatrixf matrix    = NULL; /* Substitution matrix */
    AjPFile out_ss       = NULL; /* For ss top matches*/
    AjPFile out_se       = NULL; /* For se top matches*/
    AjPFile outfile      = NULL; /* Output file*/
    AjPFile logf         = NULL; /* Log file */
    float gapopen_sss    = 0.0;  /* Gap insertion penalty */
    float gapopen_sse    = 0.0;
    float gapopen        = 0.0;
    float gapextend_sss  = 0.0;  /* Gap extension penalty */
    float gapextend_sse  = 0.0;
    float gapextend      = 0.0;
    ajint max_hits       = 0;    /* number of top alignments to display*/
    ajint mode           = 0;
    ajint x              = 0;

    AjPScop temp_scop    = NULL; /* scop object pointer*/

    AjPList  scop_list   = NULL; /* list of scop objects for entire domain
				    classification file */
     
    AjIList       iter   = NULL;
    AjPStr        msg    = NULL; /* Pointer to String used for messages */
    AjPStr        line   = NULL;
   
    AjPStr    qse        = NULL; /* query secondary structure elements*/
    AjPStr    qss        = NULL; /* query secondary structure (by residue)*/
    AjPSeq    q3se       = NULL; /* query secondary structure elements, 3-letter 
				    code*/
    AjPSeq    q3ss       = NULL; /* query secondary structure 
				    (by residue), 3-letter code*/
    AjPSeq    query      = NULL;
    




    /* Read data from acd */
    embInitPV("ssematch",argc,argv,"DOMAINATRIX",VERSION);
    dcfin       = ajAcdGetInfile("dcfinfile");
    ssin       = ajAcdGetInfile("ssinfile");
    max_hits      = ajAcdGetInt("maxhits");
    matrix        = ajAcdGetMatrixf("datafile");
    gapopen_sss   = ajAcdGetFloat("rgapopen");
    gapextend_sss = ajAcdGetFloat("rgapextend");
    gapopen_sse   = ajAcdGetFloat("egapopen");
    gapextend_sse = ajAcdGetFloat("egapextend");
    out_ss        = ajAcdGetOutfile("outssfile");
    out_se        = ajAcdGetOutfile("outsefile");
    logf       = ajAcdGetOutfile("logfile");






    /* Create list of scop objects for entire input domain classification file. */
    scop_list  = ajListNew();
    while((temp_scop = (ajScopReadCNew(dcfin, "*"))))
        ajListPushAppend(scop_list,temp_scop);


    /* Error handing if domain classification file was empty. */
    if(!(ajListGetLength(scop_list)))
    {
      
        ajWarn("Empty list from scop input file\n");
	ajFileClose(&dcfin);
	ajFileClose(&ssin);
	ajMatrixfDel(&matrix);
       	ajFileClose(&out_ss);
	ajFileClose(&out_se);
       	ajFileClose(&logf);
	while(ajListPop(scop_list, (void *) &temp_scop))
	    ajScopDel(&temp_scop);
	ajListFree(&scop_list);
        ajListIterDel(&iter);    
	
	ajExit();
	return 1;
    }

    /* Error handling in case of empty query file. */
    if(ssin == NULL)   
    {
        ajWarn("Empty secondary structure query file\n");
	ajFileClose(&dcfin);
	ajFileClose(&ssin);
	ajMatrixfDel(&matrix);
       	ajFileClose(&out_ss);
	ajFileClose(&out_se);
       	ajFileClose(&logf);
	while(ajListPop(scop_list, (void *) &temp_scop))
	    ajScopDel(&temp_scop);
	ajListFree(&scop_list);
        ajListIterDel(&iter);    
	
	ajExit();
	return 1; 
    }      
    
    /* Assign sequences in query file to sequence objects. */
    qse = ajStrNew();
    qss = ajStrNew();
    
    while(ajReadlineTrim(ssin,&line))
    {
        /* SE string */
        if(ajStrPrefixC(line,"SE"))
	{
	    ajFmtScanS(line, "%*s %S", &qse);
            /* Convert this string to 3-letter code & then convert to AjPSeq 
	       object. */
            q3se = ssematch_convertbases(qse);
        }
        /* SS string */
	else if(ajStrPrefixC(line,"SS"))
	{
            while((ajReadlineTrim(ssin,&line)) && !ajStrPrefixC(line,"XX"))
                ajStrAppendS(&qss,line);
            ajStrRemoveWhite(&qss);

            /* Convert this string to 3-letter code & then to AjPSeq object. */
            q3ss = ssematch_convertbases(qss);
      	}
    }



    /* For se & then for ss, modes 0 & 1. */
    for(mode = 0; mode <= 1; mode++)
    {
        /* Assign arguments for alignment function. */
        if (mode == 0) 
        {
            query = q3se;
            gapopen = gapopen_sse; 
            gapextend = gapextend_sse;
            outfile =  out_se;
        } 
        else if(mode == 1)
        {
            query = q3ss;  
            gapopen = gapopen_sss; 
            gapextend = gapextend_sss;
            outfile =  out_ss;   
        }


        /* Iterate through list of scop objects & calculate alignment scores. */
        iter=ajListIterNew(scop_list);
        while((temp_scop=(AjPScop)ajListIterGet(iter)))
        {
            /* The function extracts the se (mode 0) or ss (mode 1) subject 
	       sequences from the scop object, performs a Needleman-Wunsch 
	       global alignment with the query sequence & allocates the score 
	       to the Score element of the scop object*/ 

	    if(!(ssematch_NWScore(temp_scop , query, mode, matrix, gapopen, gapextend)))

	    {
                ajFmtPrintF(logf, "%-15s\n", "ALIGNMENT");
                ajFmtPrintF(logf, "Could not align sequence in scop domain %S\n ", 
			    temp_scop->Entry); 
	        ajFmtPrintS(&msg, "Could not align sequence in scop domain %S\n ", 
			    temp_scop->Entry);
	        ajWarn(ajStrGetPtr(msg));
                continue;
	    }
	}


        ajListIterDel(&iter);
      	temp_scop    = NULL;


        /* Sort list of Scop objects by Score */
        ajListSort(scop_list, ssematch_CompScoreInv);
	
	
        iter=ajListIterNew(scop_list);
        /* Write top-scoring hits to outfile. */
        for(x=0; x < max_hits; x++ )
	{
            temp_scop=(AjPScop)ajListIterGet(iter);
 
	    /* Print score to output file. */
	    ajFmtPrintF(outfile, "XX   ALIGNMENT SCORE %.3f\nXX\n", temp_scop->Score);
	    
	    /* Could also write alignment - later modification. */
	    if(!ajScopWrite(outfile, temp_scop))
		ajFatal("Could not write output file %S\n", outfile);

        
        }

	ajListIterDel(&iter); 
     	temp_scop    = NULL;
    }


      
    /* Memoryt management. */
    ajFileClose(&dcfin);
    ajFileClose(&ssin);
    ajMatrixfDel(&matrix);
    ajFileClose(&out_ss);
    ajFileClose(&out_se);
    ajFileClose(&logf);
    while(ajListPop(scop_list, (void *) &temp_scop))
	ajScopDel(&temp_scop);
    ajListFree(&scop_list);
    ajStrDel(&msg);
    ajStrDel(&line);
    ajStrDel(&qse); 
    ajStrDel(&qss);
    ajSeqDel(&q3se);
    ajSeqDel(&q3ss);
    

    ajExit();
    return 0;
}
Exemplo n.º 10
0
static ajint silent_restr_read(AjPList *relist,const AjPStr enzymes)
{
    EmbPPatRestrict rptr = NULL;
    AjPFile fin = NULL;

    AjPStr refilename = NULL;
    register ajint RStotal = 0;
    PRinfo rinfo = NULL;
    AjBool isall = ajFalse;
    ajint ne = 0;
    ajint i;
    AjPStr *ea = NULL;

    refilename = ajStrNewC("REBASE/embossre.enz");
    rptr       = embPatRestrictNew();
    *relist    = ajListNew();

    fin = ajDatafileNewInNameS(refilename);
    if(!fin)
	ajFatal("Aborting...restriction file '%S' not found", refilename);

    /* Parse the user-selected enzyme list */
    if(!enzymes)
	isall = ajTrue;
    else
    {
	ne = ajArrCommaList(enzymes,&ea);
        for(i=0;i<ne;++i)
	    ajStrRemoveWhite(&ea[i]);

        if(ajStrMatchCaseC(ea[0],"all"))
            isall = ajTrue;
        else
            isall = ajFalse;
    }

    while(!ajFileIsEof(fin))
    {
        if(!embPatRestrictReadEntry(rptr,fin))
	    continue;

     	if(!isall)
	{
		for(i=0;i<ne;++i)
		if(ajStrMatchCaseS(ea[i],rptr->cod))
			break;
	    	if(i==ne)
			continue;
        }

        AJNEW(rinfo);
        /* reading in RE info into rinfo from EmbPPatRestrict structure */
        rinfo->code  = ajStrNewC(ajStrGetPtr(rptr->cod));
	rinfo->site  = ajStrNewC(ajStrGetPtr(rptr->pat));
        rinfo->ncuts = rptr->ncuts;
        rinfo->cut1  = rptr->cut1;
        rinfo->cut2  = rptr->cut2;
        rinfo->cut3  = rptr->cut3;
        rinfo->cut4  = rptr->cut4;
	ajListPush(*relist,(void *)rinfo);
	RStotal++;
    }

    for(i=0;i<ne;++i)
	ajStrDel(&ea[i]);
    AJFREE(ea);

    embPatRestrictDel(&rptr);
    ajFileClose(&fin);
    ajStrDel(&refilename);

    return RStotal;
}
Exemplo n.º 11
0
static AjBool dbxflat_ParseFastq(EmbPBtreeEntry entry, AjPFile inf)
{
    AjPStr line = NULL;
    ajlong pos  = 0L;
    ajuint seqlen = 0;
    ajuint qlen = 0;
    AjPStr tmpfd  = NULL;
    AjPStr str = NULL;
    AjPStr de = NULL;
    AjBool ok;

    if(!dbxflat_wrdexp)
	dbxflat_wrdexp = ajRegCompC("([A-Za-z0-9.:=]+)");

    line = ajStrNewC("");
    
    pos = ajFileResetPos(inf);

    if(!ajReadlineTrim(inf,&line))
    {
        ajStrDel(&line);
        return ajFalse;
    }

    /* first line of entry */

    if(!ajStrPrefixC(line,"@"))
        return ajFalse;

    entry->fpos = pos;
    ajStrCutStart(&line, 1);
    ajStrExtractFirst(line, &de, &entry->id);

    if(desfield && ajStrGetLen(de))
    {
	while(ajRegExec(dbxflat_wrdexp,de))
	{
	    ajRegSubI(dbxflat_wrdexp, 1, &tmpfd);
	    str = ajStrNew();
	    ajStrAssignS(&str,tmpfd);
	    ajListPush(desfield->data,(void *)str);
	    ajRegPost(dbxflat_wrdexp, &de);
	}
    }

/* now read sequence */
    ok = ajReadlineTrim(inf,&line);
    while(ok && !ajStrPrefixC(line, "+"))
    {
        ajStrRemoveWhite(&line);
        seqlen += MAJSTRGETLEN(line);
        ok = ajReadlineTrim(inf,&line);
    }

    if(!ok)
        return ajFalse;

    ok = ajReadlineTrim(inf,&line);
    while(ok)
    {
        qlen += MAJSTRGETLEN(line);
        if(qlen < seqlen)
            ok = ajReadlineTrim(inf,&line);
        else
            ok = ajFalse;
    }

    ajStrDel(&de);
    ajStrDel(&tmpfd);
    ajStrDel(&line);
    
    return ajTrue;
}
Exemplo n.º 12
0
/* @funcstatic acdrelations_procacdfile ***************************************
**
** Process ACD file and write new ACD file with new relations: attributes
** added (replaced if necessary).
**
** @param [r] inf  [AjPFile] ACD input file
** @param [r] outf [AjPFile] ACD output file
** @param [r] P    [PEdam]   edam object
** @param [r] T    [PKtype]  ktype object
** @return [void] 
** @@
******************************************************************************/
static void acdrelations_procacdfile
            (AjPFile inf, 
	     AjPFile outf, 
	     PEdam P,
    	     PKtype T)
{
  AjPStr   line     = NULL;
  AjPStr   tok      = NULL;
  AjPStr   acdtype  = NULL;  
  AjPStr   strtmp   = NULL;
  AjPList  strlist  = NULL;
  AjPStr  *strarr   = NULL;
  ajint    nstr     = 0;
  

  /* Allocate memory */
  line        = ajStrNew();
  tok         = ajStrNew();
  acdtype     = ajStrNew();  
  strlist     = ajListstrNew();

  
  /*  Read next line */
  while(ajReadline(inf,&line))
    {
      ajFmtScanS(line, "%S", &tok);
      
      /* Write application definition or section definition out as-is */
      if(ajStrMatchC(tok, "application:")  ||
	 ajStrMatchC(tok, "section:"))
      {
	  ajFmtPrintF(outf, "%S", line);
	  while(ajReadline(inf,&line))
          {
	      ajFmtPrintF(outf, "%S", line);
	      ajFmtScanS(line, "%S", &tok);
	      if(ajStrMatchC(tok, "]"))
                  break;
          }
      }
      /* Write variables, endsection definitions and comments out as-is */
      else if(ajStrMatchC(tok, "variable:")   ||
	      ajStrMatchC(tok, "endsection:") ||
              ajStrMatchC(tok, "#"))
          ajFmtPrintF(outf, "%S", line);

      /* Write out blank lines as-is */
      else if (!ajFmtScanS(line, "%S", &tok))
          ajFmtPrintF(outf, "%S", line);
      /* Process data definition */
      else
          /* First line of data definition */
      {
          /* Process and write datatype line */
          ajFmtPrintF(outf, "%S", line);
          ajFmtScanS(line, "%S", &acdtype);
	  ajStrRemoveSetC(&acdtype, ":");

          /* Process subsequent (attribute) lines */
	  while(ajReadline(inf,&line))
	    {
	      strtmp = ajStrNew();
	      ajStrAssignS(&strtmp, line);
	      ajStrRemoveWhite(&strtmp);
	      ajListstrPushAppend(strlist, strtmp);

	      ajFmtScanS(line, "%S", &tok);

              /* Reached end of data definition */
              if(ajStrMatchC(tok, "]"))
              {
                  nstr = ajListstrToarray(strlist, &strarr);
                  
                  /* Write relations: line */
                  acdrelations_writerelations(outf, acdtype, strarr, nstr, P, T);

                  AJFREE(strarr);
                  ajListstrFreeData(&strlist);
		  strlist = ajListstrNew();
		  
		  ajFmtPrintF(outf, "%S", line);
		  break;
		}
              /* Ignore existing relations: lines */
              else if(ajStrMatchC(tok, "relations:"))
                  continue;
              
	      ajFmtPrintF(outf, "%S", line);
	    }
	}
    }


  /* Free memory */
  ajStrDel(&line);
  ajStrDel(&tok);
  ajStrDel(&acdtype);
  ajListstrFreeData(&strlist);

  return;
}
Exemplo n.º 13
0
static void acdrelations_readdatfile
            (AjPFile inf, 
	     PEdam *P)
{
  AjPStr  line           = NULL;
  const AjPStr  tok      = NULL;
  const AjPStr  subtok   = NULL;
  AjPStr  strtmp         = NULL;
  AjPList strlist        = NULL;

  AjPStr  acdtype        = NULL;
  AjPStr  relations      = NULL;

  PEdamdat dattmp        = NULL;
  AjPList  datlist       = NULL;
  
  if(!P)
    ajFatal("Null arg error 1 in acdrelations_readdatfile");
  if(!inf)
    ajFatal("Null arg error 3 in acdrelations_readdatfile");  


  /* Allocate memory */
  line      = ajStrNew();
  acdtype   = ajStrNew();
  relations = ajStrNew();
  datlist   = ajListNew();

  /* Read data from file */
  while(ajReadline(inf,&line))
    {
      /* Discard comment lines */
      if(ajStrPrefixC(line,"#")) 
	continue;

      
      
      /* Tokenise line, delimited by '|'.
         Parse first token (ACD datatype ) */
      ajStrAssignS(&acdtype, ajStrParseC(line, "|")); 
      
      /* Parse second token (EDAM relations: value ) */
      ajStrAssignS(&relations, ajStrParseC(NULL, "|")); 

      /* Parse third token (attribute:value strings block) */
      tok = ajStrParseC(NULL, "|");
        

      /* Create new string list */
      strlist = ajListstrNew();

      /* Tokenise third token itself into tokens delimited by ' ' (space)
         Parse tokens (individual attribute:value strings)*/
      if((subtok=ajStrParseC(tok, ";")))
      {
          strtmp = ajStrNew();
          ajStrAssignS(&strtmp, subtok);
          ajStrRemoveWhite(&strtmp);
          ajListstrPushAppend(strlist, strtmp);
              
          while((subtok=ajStrParseC(NULL, ";")))
          {
              strtmp = ajStrNew();
              ajStrAssignS(&strtmp, subtok);
              ajStrRemoveWhite(&strtmp);
              ajListstrPushAppend(strlist, strtmp);
          }
      }
      
      /* Write PEdamdat structure & push onto list */
      dattmp = ajEdamdatNew();
      ajStrRemoveWhite(&acdtype);
      ajStrAssignS(&dattmp->acdtype, acdtype);
      ajStrAssignS(&dattmp->edam, relations);
      dattmp->n = ajListstrToarray(strlist, &dattmp->acdattr);
      ajListPushAppend(datlist, dattmp);
      
      /* Clear nodes (but not strings) from string list */
      ajListstrFree(&strlist);
    }
  

  /* Write PEdam structure */
  ((*P)->n) = ajListToarray(datlist, (void***) &((*P)->dat));

  /* Free memory */
  ajStrDel(&line);
  ajStrDel(&acdtype);
  ajStrDel(&relations);
  ajListFree(&datlist);

  return;
}
Exemplo n.º 14
0
int main(int argc, char **argv)
{
    const char *codons[]=
    {
	"TAG","TAA","TGA","GCG","GCA","GCT","GCC","TGT", /* 00-07 */
	"TGC","GAT","GAC","GAA","GAG","TTT","TTC","GGT", /* 08-15 */
	"GGG","GGA","GGC","CAT","CAC","ATA","ATT","ATC", /* 16-23 */
	"AAA","AAG","CTA","TTA","TTG","CTT","CTC","CTG", /* 24-31 */
	"ATG","AAT","AAC","CCG","CCA","CCT","CCC","CAA", /* 32-39 */
	"CAG","CGT","CGA","CGC","AGG","AGA","CGG","TCG", /* 40-47 */
	"TCA","AGT","TCT","TCC","AGC","ACG","ACT","ACA", /* 48-55 */
	"ACC","GTA","GTT","GTC","GTG","TGG","TAT","TAC"	 /* 56-63 */
    };

    const char *aa=
	"***AAAACCDDEEFFGGGGHHIIIKKLLLLLLMNNPPPPQQRRRRRRSSSSSSTTTTVVVVWYY";

    AjPFile inf     = NULL;
    AjPFile outf    = NULL;
    char *entryname = NULL;
    AjPStr fname    = NULL;
    AjPStr key      = NULL;
    AjPStr tmpkey   = NULL;
    AjBool allrecords = AJFALSE;

    AjPTable table  = NULL;
    ajint i = 0;
    ajint j = 0;
    ajint k = 0;
    ajint x = 0;
    ajint savecount[3];

    AjPStr *keyarray = NULL;
    CutgPValues *valarray = NULL;
    AjPCod codon  = NULL;
    ajint sum = 0;
    char c;

    AjPList flist = NULL;
    AjPFile logf = NULL;
    AjPStr  entry = NULL;
    AjPStr  baseentry = NULL;
    AjPStr  wild  = NULL;
    AjPStr division = NULL;
    AjPStr release = NULL;
    AjPStr wildspecies = NULL;
    CutgPValues value = NULL;
    AjPStr docstr = NULL;
    AjPStr species = NULL;
    AjPStr filename = NULL;
    ajint nstops;

    embInit("cutgextract",argc,argv);

    tmpkey = ajStrNew();
    fname  = ajStrNew();


    table = ajTablestrNewLen(TABLE_ESTIMATE);


    flist = ajAcdGetDirlist("directory");
    wild  = ajAcdGetString("wildspec");
    release  = ajAcdGetString("release");
    logf = ajAcdGetOutfile("outfile");
    wildspecies = ajAcdGetString("species");
    filename = ajAcdGetString("filename");
    allrecords = ajAcdGetBoolean("allrecords");

    ajStrInsertC(&release, 0, "CUTG");
    ajStrRemoveWhite(&release);

    while(ajListPop(flist,(void **)&entry))
    {
	ajStrAssignS(&baseentry, entry);
	ajFilenameTrimPath(&baseentry);
	ajDebug("Testing file '%S'\n", entry);
	if(!ajStrMatchWildS(baseentry,wild))
	{
	    ajStrDel(&entry);
	    continue;
	}

	ajDebug("... matched wildcard '%S'\n", wild);
	inf = ajFileNewInNameS(entry);
	if(!inf)
	    ajFatal("cannot open file %S",entry);

	ajFmtPrintS(&division, "%F", inf);
	ajFilenameTrimAll(&division);

	while((entryname = cutgextract_next(inf, wildspecies,
					    &species, &docstr)))
	{
	    if(ajStrGetLen(filename))
		ajStrAssignS(&tmpkey,filename);
	    else
		ajStrAssignC(&tmpkey,entryname);

	    /* See if organism is already in the table */
	    value = ajTableFetch(table,tmpkey);
	    if(!value)			/* Initialise */
	    {
		key = ajStrNewS(tmpkey);
		AJNEW0(value);
		ajStrAssignS(&value->Species,species);
		ajStrAssignS(&value->Division, division);
		ajTablePut(table,(void *)key,(void *)value);
	    }
	    for(k=0;k<3;k++)
		savecount[k] = value->Count[k];
	    nstops = cutgextract_readcodons(inf,allrecords, value->Count);
	    if(nstops < 1)
	    {
		value->Skip++;
		continue;
	    }
	    value->CdsCount++;
	    if(nstops>1)
	    {
		value->CdsCount += (nstops - 1);
		value->Warn++;
		ajWarn("Found %d stop codons (%d %d %d) for CDS '%S'",
		       nstops,
		       value->Count[0] - savecount[0],
		       value->Count[1] - savecount[1],
		       value->Count[2] - savecount[2],
		       cutgextractSavepid);
	    }
	}
	ajStrDel(&entry);
	ajFileClose(&inf);
    }

    ajTableToarrayKeysValues(table,(void***) &keyarray, (void***) &valarray);

    i = 0;
    while(keyarray[i])
    {
	key   = keyarray[i];
	value = (CutgPValues) valarray[i++];
	codon = ajCodNew();
	sum   = 0;
	for(j=0;j<CODONS;++j)
	{
	    sum += value->Count[j];
	    x = ajCodIndexC(codons[j]);
	    codon->num[x] = value->Count[j];

	    c = aa[j];
	    if(c=='*')
		codon->aa[x] = 27;
	    else
		codon->aa[x] = c-'A';
	}
	ajCodCalcUsage(codon,sum);

	ajStrAppendC(&key, ".cut");
	if(allrecords)
	{
	    if(value->Warn)
		ajFmtPrintF(logf, "Writing %S CDS: %d Warnings: %d\n",
			    key, value->CdsCount, value->Warn);
	    else
		ajFmtPrintF(logf, "Writing %S CDS: %d\n",
			    key, value->CdsCount);
	}
	else
	{
	    if(value->Skip)
		ajFmtPrintF(logf, "Writing %S CDS: %d Skipped: %d\n",
			    key, value->CdsCount, value->Skip);
	    else
		ajFmtPrintF(logf, "Writing %S CDS: %d\n",
			    key, value->CdsCount);
	}

	ajFmtPrintS(&fname,"CODONS/%S",key);
	outf = ajDatafileNewOutNameS(fname);
	if(!outf)
	    ajFatal("Cannot open output file %S",fname);

	ajCodSetNameS(codon, key);
	ajCodSetSpeciesS(codon, value->Species);
	ajCodSetDivisionS(codon, value->Division);
	ajCodSetReleaseS(codon, release);
	ajCodSetNumcds(codon, value->CdsCount);
	ajCodSetNumcodons(codon, sum);

	ajCodWrite(codon, outf);
	ajFileClose(&outf);


	ajStrDel(&key);
	ajStrDel(&value->Division);
	ajStrDel(&value->Doc);
	ajStrDel(&value->Species);
	AJFREE(value);
	ajCodDel(&codon);
    }

    AJFREE(keyarray);
    AJFREE(valarray);

    ajTableFree(&table);
    ajListFree(&flist);
    ajStrDel(&wild);
    ajStrDel(&release);
    ajStrDel(&wildspecies);
    ajStrDel(&filename);
    ajFileClose(&logf);

    ajStrDel(&cutgextractSavepid);
    ajStrDel(&cutgextractLine);
    ajStrDel(&cutgextractOrg);

    ajStrDel(&fname);
    ajStrDel(&tmpkey);
    ajStrDel(&species);
    ajStrDel(&docstr);
    ajStrDel(&division);
    ajStrDel(&baseentry);

    embExit();

    return 0;
}