コード例 #1
0
void ajCallRegisterOld(const char *name, CallFunc func)
{
    void *rec;
    char* keyname = NULL;
    ajuint *i;
 
    if(!oldcallTable)
    {
	oldcallTable = ajTableNewFunctionLen(50, callCmpStr,callStrHash);
	oldcallCount = ajTableNewFunctionLen(50, callCmpStr,callStrHash);
    }
    
    rec = ajTableFetch(oldcallTable, name);	/* does it exist already */

    if(!rec)
    {
	keyname = ajCharNewC(name);
	ajTablePut(oldcallTable, keyname, (void *) func);
	keyname = ajCharNewC(name);
        AJNEW0(i);
	ajTablePut(oldcallCount, keyname, i);
    }

    return;
}
コード例 #2
0
static AjPTable btwisted_getdinucdata(AjPFile inf)
{
    AjPStr valstr   = NULL;
    AjPStr key      = NULL;
    AjPStr line     = NULL;
    AjPStrTok token = NULL;
    AjPTable table  = NULL;

    valstr = ajStrNew();
    line = ajStrNew();

    table = ajTablestrNewCase(20);

    while(ajReadlineTrim(inf,&line))
    {
	if(*ajStrGetPtr(line)=='#')
	    continue;
	token = ajStrTokenNewC(line," \n\t\r");
	key   = ajStrNew();
	ajStrTokenNextParseC(&token," \n\t\r",&key);
	valstr = ajStrNew();
	ajStrTokenNextParseC(&token," \n\t\r",&valstr);
	ajTablePut(table,(void *)key,(void *) valstr);
	ajStrTokenDel(&token);
    }


    ajStrDel(&line);

    return table;
}
コード例 #3
0
static void remap_read_equiv(AjPFile *equfile, AjPTable *table,
			     AjBool commercial)
{
    AjPStr line;
    AjPStr key;
    AjPStr value;

    const char *p;

    line = ajStrNew();

    while(ajReadlineTrim(*equfile,&line))
    {
        p = ajStrGetPtr(line);

        if(!*p || *p=='#' || *p=='!')
            continue;
        p = ajSysFuncStrtok(p," \t\n");
        key = ajStrNewC(p);
        p = ajSysFuncStrtok(NULL," \t\n");
        value = ajStrNewC(p);
	if(!commercial)
	    ajStrTrimEndC(&value,"*");
        ajTablePut(*table,(void *)key, (void *)value);
    }

    ajFileClose(equfile);
    ajStrDel(&line);

    return;
}
コード例 #4
0
static void restover_read_equiv(AjPFile equfile, AjPTable table)
{
    AjPStr line;
    AjPStr key;
    AjPStr value;

    const char *p;

    line = ajStrNew();

    while(ajReadlineTrim(equfile,&line))
    {
	p=ajStrGetPtr(line);
	if(!*p || *p=='#' || *p=='!')
	    continue;
	p=ajSysFuncStrtok(p," \t\n");
	key=ajStrNewC(p);
	p=ajSysFuncStrtok(NULL," \t\n");
	value=ajStrNewC(p);
	ajTablePut(table,(void *)key, (void *)value);
    }

    ajStrDel(&line);

    return;
}
コード例 #5
0
static void remap_RemoveMinMax(AjPList restrictlist,
	AjPTable hittable, ajint mincuts, ajint maxcuts)
{

    AjIList miter;		/* iterator for matches list */
    EmbPMatMatch m = NULL;	/* restriction enzyme match structure */
    PValue value;
    AjPStr key  = NULL;
    AjPStr keyv = NULL;


    key = ajStrNew();

    /* if no hits then ignore much of this routine */
    if(ajListGetLength(restrictlist))
    {
        /* count the enzymes */
	miter = ajListIterNewread(restrictlist);
	while((m = ajListIterGet(miter)) != NULL)
	{
	    ajStrAssignS(&key, m->cod);

	    /* increment the count of key */
	    value = (PValue) ajTableFetchmodS(hittable, key);
	    if(value == NULL)
	    {
		AJNEW0(value);
		value->count = 1;
		value->iso = ajStrNew();
		ajStrAssignS(&(value->iso), m->iso);
		keyv = ajStrNew();
		ajStrAssignS(&keyv,key);
		ajTablePut(hittable, (void *)keyv, (void *)value);
	    }
	    else
		value->count++;
	}
	ajListIterDel(&miter);


	/* now remove enzymes from restrictlist if <mincuts | >maxcuts */
	miter = ajListIterNew(restrictlist);
	while((m = ajListIterGet(miter)) != NULL)
	{
	    value = (PValue) ajTableFetchmodS(hittable, (m->cod));
            if(value->count < mincuts || value->count > maxcuts)
	    {
            	ajListIterRemove(miter);
                embMatMatchDel(&m);
            }
	}
	ajListIterDel(&miter);
    }

    ajStrDel(&key);

    return;
}
コード例 #6
0
static AjBool ajMessReadErrorFile(void)
{
    char line[512];
    char name[12];
    char message[200];
    FILE *fp=0;
    char *mess;
    char *cp;
    char *namestore;
    char *messstore;

    if(messErrorFile)
	fp = fopen(messErrorFile,"r");

    if(!fp)
    {
	messErrorFile = ajFmtString("%s/messages/messages.english",
				    getenv("EMBOSS_ROOT"));
	fp = fopen(messErrorFile,"r");
    }


    if(!fp)
	return ajFalse;

    messErrorTable = ajTablecharNew();

    while(fgets(line, 512, fp))
    {
	if(sscanf(line,"%s %s",name,message)!=2)
	    ajFatal("Library sscanf1");

	cp = strchr(line,'"');
	cp++;
	mess = &message[0];

	while(*cp != '"')
	{
	    *mess = *cp;
	    cp++;
	    mess++;
	}

	*mess = '\0';
	namestore = ajFmtString("%s",name);
	messstore = ajFmtString("%s",message);
	mess = (char *) ajTableFetch(messErrorTable, namestore);

	if(mess)
	    ajErr("%s is listed more than once in file %s",
			name,messErrorFile);
	else
	    ajTablePut(messErrorTable, namestore, messstore);
    }

    return ajTrue;
}
コード例 #7
0
static void jaspextract_readmatrixlist(AjPTable mtable, const AjPStr directory)
{
    const AjPStr datadir = NULL;

    AjPStr matrixfile = NULL;
    AjPFile inf = NULL;

    AjPStr line  = NULL;
    AjPStr key   = NULL;
    AjPStr value = NULL;
    
    matrixfile = ajStrNew();
    

    datadir = ajDatafileValuePath();
    if(!datadir)
        ajFatal("jaspextract: Cannot determine the EMBOSS data directory");
    
    ajFmtPrintS(&matrixfile,"%S%s",directory,MATRIXFILE);

    if(!ajFilenameExistsRead(matrixfile))
        ajFatal("jaspextract: Directory (%S) doesn't appear to be a JASPAR "
                "one\nNo matrix_list.txt file found",directory);


    inf  = ajFileNewInNameS(matrixfile);
    if(!inf)
        ajFatal("Cannot open input file: %S",matrixfile);

    while(ajReadline(inf,&line))
    {
        key = ajStrNew();
        
        if(ajFmtScanS(line,"%S",&key) != 1)
        {
            ajStrDel(&key);
            continue;
        }

        value = ajStrNew();
        ajStrAssignS(&value,line);

        ajTablePut(mtable,(void *)key, (void *)value);
    }
    

    ajFileClose(&inf);
    
    ajStrDel(&matrixfile);
    ajStrDel(&line);
        
    return;
}
コード例 #8
0
void ajCallRegister(const char *name, CallFunc func)
{
    void *rec;
    char* keyname = NULL;

 
    if(!callTable)
	callTable = ajTableNewFunctionLen(50, callCmpStr,callStrHash);

    rec = ajTableFetch(callTable, name);	/* does it exist already */

    if(!rec)
    {
	keyname = ajCharNewC(name);
	ajTablePut(callTable, keyname, (void *) func);
    }

    return;
}
コード例 #9
0
static AjPTable dastestGetTitleCount(const AjPDasServer server)
{
    AjIList iter  = NULL;

    AjPTable titlecount = NULL;
    AjPDasSource source = NULL;

    AjPStr title = NULL;

    ajuint* count = NULL;

    titlecount = ajTablestrNewCaseConst(ajListGetLength(server->sources)+20);


    iter = ajListIterNew(server->sources);

    while(!ajListIterDone(iter))
    {
	source = ajListIterGet(iter);

	title = source->title;

	count = ajTableFetchmodS(titlecount,title);

	if (count != NULL)
        {
	    (*count)++;
        }
	else
	{
	    AJNEW(count);
	    *count = 1;
            ajTablePut(titlecount, title, (void*)count);
	}

    }

    ajListIterDel(&iter);

    return titlecount;
}
コード例 #10
0
static AjPTable emira_makepreftab(void)
{
    AjPTable ret = NULL;
    ajuint i;
    AjPStr key = NULL;
    AjPStr value = NULL;
    
    ret = ajTablestrNewLen(MIRATAB_GUESS);

    i = 0;
    while(miraprefix[i].qname)
    {
	key   = ajStrNewC(miraprefix[i].qname);
	value = ajStrNewC(miraprefix[i].prefix);

	ajTablePut(ret, (void *)key, (void *)value);
	++i;
    }

    return ret;
}
コード例 #11
0
void ajCallTableRegister(AjPTable table, const char *name, void *func)
{
    void *rec;
    char* keyname = NULL;
 
    if(!table)
      ajFatal("ajCallTableRegister called for undefined table with name '%s'",
	      name);

    rec = ajTableFetch(table, name);	/* does it exist already */

    if(!rec)
    {
	keyname = ajCharNewC(name);
	ajTablePut(table, keyname, (void *) func);
    }
    else
    {
        ajWarn("ajCallTableRegister duplicate name '%s'", name);
    }

    return;
}
コード例 #12
0
int main(int argc, char **argv)
{
    /* Variable declarations */
    AjPStr   query;
    AjPOutfile  outfile = NULL;

    AjPResource resource = NULL;
    AjPResourcein resourcein = NULL;
    AjPOboin oboin = NULL;
    AjPObo obo = NULL;
    AjPStr oboqry = NULL;
    AjPStr resourceqry = NULL;
    AjPStr qrystr = NULL;
    AjPTable obotable = NULL;
    AjPTable foundtable = NULL;
    AjBool subclasses = ajFalse;

    AjPStrTok handle = NULL;
    AjPList obolist = NULL;
    AjPObo obotest = NULL;

    ajuint i;
    ajuint imax = 3;

    const char* fields[] = {"id", "acc", "nam", "des"};

    /* ACD processing */
    embInit("drfindid", argc, argv);

    query     = ajAcdGetString("query");
    outfile   = ajAcdGetOutresource("outfile");
    /*    sensitive = ajAcdGetBoolean("sensitive"); */
    subclasses = ajAcdGetBoolean("subclasses");

    resourcein = ajResourceinNew();
    resource = ajResourceNew();
    oboin = ajOboinNew();
    obo = ajOboNew();

    obolist = ajListNew();
    obotable = ajTablestrNew(600);
    foundtable = ajTablestrNew(600);


    handle = ajStrTokenNewC(query, ",");
    while(ajStrTokenNextParse(&handle, &qrystr))
    {
        for(i=0; i<imax; i++)
        {
            ajFmtPrintS(&oboqry, "edam-%s:%S", fields[i], qrystr);

            ajOboinQryS(oboin, oboqry);

            while(ajOboinRead(oboin, obo))
            {
                ajListPushAppend(obolist, ajOboNewObo(obo));
                if(subclasses)
                    ajOboGetTree(obo, obolist);

                ajDebug("%S '%S' %u\n",
                        qrystr, obo->Id, ajListGetLength(obolist));
                while(ajListGetLength(obolist))
                {
                    ajListPop(obolist, (void**) &obotest);

                    if(!ajTableMatchS(obotable, obotest->Id))
                    {
                        ajDebug("edam %s '%S' namespace '%S' name '%S'\n",
                                fields[i], obotest->Id, obotest->Namespace,
                                obotest->Name);
                        ajTablePut(obotable, ajStrNewS(obotest->Id),
                                   (void *) 1);
                        ajFmtPrintS(&resourceqry, "drcat-eid:%S",
                                    ajOboGetId(obotest));
                        ajResourceinQryS(resourcein, resourceqry);

                        while(ajResourceinRead(resourcein, resource))
                        {
                            if(!ajTableMatchS(foundtable, resource->Id))
                            {
                                ajDebug("drcat id '%S' category '%S'\n",
                                        resource->Id, resource->Cat);
                                ajResourceoutWrite(outfile, resource);
                                ajTablePut(foundtable, ajStrNewS(resource->Id),
                                           (void *) 1);
                            }
                        }
                    }
                    ajOboDel(&obotest);
                }
            }
        }
    }

    /* Memory clean-up and exit */

    ajOboDel(&obo);
    ajOboinDel(&oboin);
    ajResourceDel(&resource);
    ajResourceinDel(&resourcein);

    ajListFree(&obolist);

    ajStrTokenDel(&handle);

    ajStrDel(&qrystr);
    ajStrDel(&query);
    ajStrDel(&oboqry);
    ajStrDel(&resourceqry);

    ajTablestrFreeKey(&obotable);
    ajTablestrFreeKey(&foundtable);


    ajOutfileClose(&outfile);

    embExit();

    return 0;
}
コード例 #13
0
ファイル: tfscan.c プロジェクト: WenchaoLin/JAMg
int main(int argc, char **argv)
{
    AjPSeqall seqall;
    AjPSeq seq   = NULL;
    AjPReport outf = NULL;
    AjPFile inf  = NULL;

    ajint begin;
    ajint end;

    AjPList l = NULL;

    AjPStr strand = NULL;
    AjPStr substr = NULL;
    AjPStr line   = NULL;
    AjPStr name   = NULL;
    AjPStr acc    = NULL;
    AjPStr bf     = NULL;
    AjPStr menu;
    AjPStr pattern  = NULL;
    AjPStr opattern = NULL;
    AjPStr pname    = NULL;
    AjPStr key      = NULL;
    AjPStr value    = NULL;
    AjPTable atable = NULL;
    AjPTable btable = NULL;
    
    ajint mismatch;
    ajint minlength;
    
    ajint sum;
    ajint v;

    char cp;
    const char *p;


    embInit("tfscan", argc, argv);

    seqall     = ajAcdGetSeqall("sequence");
    outf       = ajAcdGetReport("outfile");
    mismatch   = ajAcdGetInt("mismatch");
    minlength  = ajAcdGetInt("minlength");
    menu       = ajAcdGetListSingle("menu");

    pname = ajStrNew();
    cp=ajStrGetCharFirst(menu);

    if(cp=='F')
	ajStrAssignC(&pname,"tffungi");
    else if(cp=='I')
	ajStrAssignC(&pname,"tfinsect");
    else if(cp=='O')
	ajStrAssignC(&pname,"tfother");
    else if(cp=='P')
	ajStrAssignC(&pname,"tfplant");
    else if(cp=='V')
	ajStrAssignC(&pname,"tfvertebrate");
    else if(cp=='C')
	inf = ajAcdGetDatafile("custom");

    if(cp!='C')
    {
	inf = ajDatafileNewInNameS(pname);
	if(!inf)
	    ajFatal("Either EMBOSS_DATA undefined or TFEXTRACT needs running");
    }

    name     = ajStrNew();
    acc      = ajStrNew();
    bf       = ajStrNewC("");
    substr   = ajStrNew();
    line     = ajStrNew();
    pattern  = ajStrNewC("AA");
    opattern = ajStrNew();

    while(ajSeqallNext(seqall, &seq))
    {
	begin=ajSeqallGetseqBegin(seqall);
	end=ajSeqallGetseqEnd(seqall);
	ajStrAssignC(&name,ajSeqGetNameC(seq));
	strand=ajSeqGetSeqCopyS(seq);

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

	l=ajListNew();
	atable = ajTablestrNew(1000);
	btable = ajTablestrNew(1000);
	
	sum=0;
	while(ajReadlineTrim(inf,&line))
	{
	    p = ajStrGetPtr(line);

	    if(!*p || *p=='#' || *p=='\n' || *p=='!')
		continue;

	    ajFmtScanS(line,"%S%S%S",&pname,&pattern,&acc);
	    p += ajStrGetLen(pname);
	    while(*p && *p==' ')
		++p;
	    p += ajStrGetLen(pattern);
	    while(*p && *p==' ')
		++p;
	    p += ajStrGetLen(acc);
	    while(*p && *p==' ')
		++p;

	    ajStrAssignS(&opattern,pattern);
	    ajStrAssignC(&bf,p); /* rest of line */
	    
	    v = embPatVariablePattern(pattern,substr,pname,l,0,
				      mismatch,begin);
	    if(v)
	    {
		key = ajStrNewS(pname);
		value = ajStrNewS(acc);
		ajTablePut(atable,(void *)key,(void *)value);
		key = ajStrNewS(pname);
		value = ajStrNewS(bf);
		ajTablePut(btable,(void *)key,(void *)value);
	    }
	    sum += v;
	}

	if(sum)
	    tfscan_print_hits(&l,sum,outf,atable,seq,minlength,
			      btable);

	ajFileSeek(inf,0L,0);
	ajListFree(&l);
	ajTablestrFree(&atable);
	ajTablestrFree(&btable);
	ajStrDel(&strand);
    }

    ajStrDel(&line);
    ajStrDel(&name);
    ajStrDel(&acc);
    ajStrDel(&pname);
    ajStrDel(&opattern);
    ajStrDel(&bf);
    ajStrDel(&pattern);
    ajStrDel(&substr);
    ajSeqDel(&seq);
    ajFileClose(&inf);
    ajReportClose(outf);
    ajReportDel(&outf);

    ajSeqallDel(&seqall);
    ajSeqDel(&seq);
    ajStrDel(&menu);

    embExit();

    return 0;
}
コード例 #14
0
int main(int argc, char **argv)
{
    /* Variable declarations */
    AjPOutfile  outfile = NULL;    
    AjBool obsolete = ajTrue;

    AjPObo obo = NULL;
    AjPObo oboanc = NULL;
    AjPObo oboparent = NULL;
    AjPOboall oboall = NULL;
    AjPOboin oboin = NULL;

    AjPStr oboqryup = NULL;
    AjPStr oboqryanc = NULL;
    AjPTable alltable = NULL;
    AjPTable newtable = NULL;

    AjPStr up = NULL;
    AjPList uplist = NULL;

    ajuint iterms = 0;
    AjPStr topid = NULL;
    AjPStr obodb = NULL;
    AjBool saved = ajFalse;

   /* ACD processing */
    embInit("ontogetcommon", argc, argv);

    oboall   = ajAcdGetOboall("oboterms");
    outfile  = ajAcdGetOutobo("outfile");
    obsolete = ajAcdGetBoolean("obsolete");

    oboin = ajOboinNew();
    oboparent = ajOboNew();
    oboanc = ajOboNew();
    uplist = ajListNew();

    alltable = ajTablestrNew(600);
    newtable = ajTablestrNew(600);

    while(ajOboallNext(oboall, &obo))
    {
        saved = ajFalse;
        if(!obsolete && ajOboIsObsolete(obo))
            continue;

        if(!iterms)
        {
            ajDebug("store id '%S'\n", ajOboGetId(obo));
            ajStrAssignS(&obodb, ajOboGetDb(obo));
            ajTablePut(alltable, ajStrNewS(ajOboGetId(obo)), NULL);
            saved = ajTrue;
        }
        else 
        {
            ajDebug("test id '%S'\n", ajOboGetId(obo));
            if(ajTableMatchS(alltable, ajOboGetId(obo)))
            {
                ajDebug("keep id '%S'\n", ajOboGetId(obo));
                ajTablePut(newtable, ajStrNewS(ajOboGetId(obo)), NULL);
                saved = ajTrue;
            }
        }

        if(saved)
            ajStrAssignS(&topid, ajOboGetId(obo));
        
        if(ajOboGetParents(obo, uplist)) /* that was the root */
        {
            while(ajListstrPop(uplist, &up))
            {
                ajDebug("up: '%S'\n", up);
                ajFmtPrintS(&oboqryup, "%S-id:%S", ajOboGetDb(obo), up);
                ajOboinQryS(oboin, oboqryup);
                while(ajOboinRead(oboin, oboparent))
                {
                    if(!obsolete && ajOboIsObsolete(oboparent))
                        continue;

                    if(!iterms)
                    {
                        ajDebug("store parent '%S'\n", ajOboGetId(oboparent));
                        ajTablePut(alltable, ajStrNewS(ajOboGetId(oboparent)),
                                   NULL);
                    }
                    else 
                    {
                        ajDebug("test parent '%S'\n", ajOboGetId(oboparent));
                        if(ajTableMatchS(alltable, ajOboGetId(oboparent)))
                        {
                            ajDebug("keep parent '%S'\n",
                                    ajOboGetId(oboparent));
                            ajTablePut(newtable,
                                       ajStrNewS(ajOboGetId(oboparent)),
                                       NULL);
                            if(!saved)
                            {
                                ajStrAssignS(&topid, ajOboGetId(oboparent));
                                saved = ajTrue;
                            }
                        }
                    }
                    if(!ajOboGetParents(oboparent, uplist))
                        continue;
                }
                ajStrDel(&up);
            }
        }
        
        if(iterms)
            ajTableMergeAnd(alltable, newtable);

        ajDebug("id: '%S' saved %u\n",
               ajOboGetId(obo),
               ajTableGetLength(alltable));

        if(!ajTableGetLength(alltable))
            ajDie("Query '%S' no matching ancestor found for obo term '%S:%S'",
                  ajOboallGetQryS(oboall), ajOboGetDb(obo), ajOboGetId(obo));
        iterms++;
    }

    ajFmtPrintS(&oboqryanc, "%S-id:%S", obodb, topid);
    ajOboinQryS(oboin, oboqryanc);
    while(ajOboinRead(oboin, oboanc))
    {
        ajObooutWrite(outfile, oboanc);
    }


    /* Memory clean-up and exit */

    ajOboallDel(&oboall);
    ajOboinDel(&oboin);
    ajOboDel(&oboanc);
    ajOboDel(&oboparent);

    ajListFree(&uplist);

    ajTablestrFreeKey(&alltable);
    ajTablestrFreeKey(&newtable);

    ajStrDel(&oboqryup);
    ajStrDel(&oboqryanc);
    ajStrDel(&obodb);
    ajStrDel(&topid);

    ajOutfileClose(&outfile);
    
    embExit();

    return 0;
}
コード例 #15
0
ファイル: taxgetspecies.c プロジェクト: WenchaoLin/JAMg
int main(int argc, char **argv)
{
    /* Variable declarations */
    AjPOutfile outfile = NULL;    
    AjPTaxall taxall = NULL;

    AjPTax tax     = NULL;
    AjPTax taxtest     = NULL;

    AjPList taxlist = ajListNew();

    AjPTable foundtable = NULL;
    ajuint ifound = 0;
    ajuint ikeep = 0;

    /* ACD processing */
    embInit("taxgetspecies", argc, argv);

    taxall    = ajAcdGetTaxonall("taxons");
    outfile   = ajAcdGetOuttaxon("outfile");

    foundtable = ajTablestrNew(600);

    while(ajTaxallNext(taxall, &tax))
    {
        ajListPushAppend(taxlist, ajTaxNewTax(tax));
        ajTaxGetTree(tax, taxlist);

        while(ajListGetLength(taxlist))
        {
            ajListPop(taxlist, (void**) &taxtest);

            if(!ajStrMatchC(ajTaxGetRank(taxtest), "species"))
            {
                ajTaxDel(&taxtest);
                continue;
            }

            ifound++;
            if(!ajTableMatchS(foundtable, taxtest->Id))
            {
                ajTaxoutWrite(outfile, taxtest);
                ajTablePut(foundtable, ajStrNewS(taxtest->Id),
                           (void *) 1);
                ikeep++;
            }
            ajTaxDel(&taxtest);
        }
    }
 
    if(!ifound)
        ajErr("No matching terms");

    /* Memory clean-up and exit */

    ajListFree(&taxlist);

    ajTaxallDel(&taxall);
    ajTaxDel(&tax);

    ajOutfileClose(&outfile);
    ajTablestrFreeKey(&foundtable);
   
    embExit();

    return 0;
}
コード例 #16
0
ファイル: ontoget.c プロジェクト: WenchaoLin/JAMg
int main(int argc, char **argv)
{
    /* Variable declarations */
    AjPOutfile outfile = NULL;    
    AjPOboall oboall = NULL;
    AjBool subclasses = ajFalse;
    AjBool obsolete = ajFalse;

    AjPObo obo     = NULL;
    AjPObo obotest = NULL;

    AjPList obolist = ajListNew();

    AjPTable foundtable = NULL;
    ajuint ifound = 0;
    ajuint ikeep = 0;

    /* ACD processing */
    embInit("ontoget", argc, argv);

    oboall    = ajAcdGetOboall("oboterms");
    outfile   = ajAcdGetOutobo("outfile");
    subclasses = ajAcdGetBoolean("subclasses");
    obsolete = ajAcdGetBoolean("obsolete");
    
    foundtable = ajTablestrNew(600);

    while(ajOboallNext(oboall, &obo))
    {
        ajListPushAppend(obolist, ajOboNewObo(obo));
        if(subclasses)
            ajOboGetTree(obo, obolist);

        while(ajListGetLength(obolist))
        {
            ajListPop(obolist, (void**) &obotest);
            if(!obsolete && ajOboIsObsolete(obotest))
            {
                ajOboDel(&obotest);
                continue;
            }

            ifound++;
            if(!ajTableMatchS(foundtable, obotest->Id))
            {
                ajObooutWrite(outfile, obotest);
                ajTablePut(foundtable, ajStrNewS(obotest->Id),
                           (void *) 1);
                ikeep++;
            }
            ajOboDel(&obotest);
        }
    }

    if(!ifound)
        ajErr("No matching terms");

    /* Memory clean-up and exit */

    ajListFree(&obolist);

    ajOboallDel(&oboall);
    ajOboDel(&obo);

    ajOutfileClose(&outfile);
    ajTablestrFreeKey(&foundtable);
   
    embExit();

    return 0;
}
コード例 #17
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;
}
コード例 #18
0
AjBool ajDebugTest(const char* token)
{
    AjPStr filename = NULL;
    const char* debugtestname = ".debugtest";
    char* ctoken = NULL;
    AjPStr line = NULL;
    AjPStr strtoken = NULL;
    AjPStr rest = NULL;
    static ajint depth    = 0;

    struct 
    {
        ajuint count;
        ajuint max;
    } *stats;
    
    if(depth)
        return ajFalse;

    depth++;

    if(!messDebugTestInit)
    {
        filename = ajStrNewC(debugtestname);

        if(ajFilenameExists(filename))
        {
            messDebugTestFile = ajFileNewInNameS(filename);
        }
        else
        {
            ajFmtPrintS(&filename, "%s%s%s",
                        getenv("HOME"), SLASH_STRING, debugtestname); 
            if(ajFilenameExists(filename))
                messDebugTestFile = ajFileNewInNameS(filename);
        }
        ajStrDel(&filename);

        if(messDebugTestFile) 
        {
            messDebugTestTable = ajTablecharNewLen(256);

            while(ajReadlineTrim(messDebugTestFile, &line))
            {
                if(ajStrExtractFirst(line, &rest, &strtoken))
                {
                    AJNEW0(stats);
                    ctoken = ajCharNewS(strtoken);
                    if(ajStrIsInt(rest))
                        ajStrToUint(rest, &stats->max);
                    else
                        stats->max = UINT_MAX;
                    ajTablePut(messDebugTestTable, ctoken, stats);
                    ctoken = NULL;
                    stats = NULL;
                }
            }

            ajStrDel(&line);
            ajStrDel(&strtoken);
            ajStrDel(&rest);
            ajFileClose(&messDebugTestFile);
        }
        messDebugTestInit = ajTrue;
     }

    depth--;
    
    if(!messDebugTestTable)
        return ajFalse;

    depth++;
    stats = ajTableFetch(messDebugTestTable, token);
    depth--;
    

    if(!stats)
        return ajFalse;

    if(!stats->max)
        return ajTrue;

    if(stats->count++ >= stats->max)
        return ajFalse;

    return ajTrue;
}
コード例 #19
0
static void eprimer3_report(AjPFile outfile, const AjPStr output,
                            ajint numreturn, ajint begin)
{
    AjPStr line = NULL;
    AjPStrTok linetokenhandle;
    char eol[] = "\n\r";
    AjPStrTok keytokenhandle;
    char equals[] = "=";
    AjPStr key   = NULL;
    AjPStr value = NULL;
    AjBool gotsequenceid = AJFALSE;
    AjPTable table;

    linetokenhandle = ajStrTokenNewC(output, eol);

    /* get next line of relevant results */
    while(ajStrTokenNextParseC(&linetokenhandle, eol, &line))
    {
        if(!gotsequenceid)
        {
            /*
            ** Att the start of another sequence's results?
            ** Start storing the results in the table.
            */

            if(ajStrCmpLenC(line, "PRIMER_SEQUENCE_ID=", 19) == 0)
            {
                gotsequenceid = AJTRUE;
                table = ajTablestrNew(TABLEGUESS);

            }
            else
                continue;
        }
        else
        {
            /*
            ** At the end of this sequence? - marked by a '=' in the primer3
            ** output - then output the results.
            */
            if(ajStrCmpC(line, "=") == 0)
            {
                gotsequenceid = AJFALSE;
                eprimer3_output_report(outfile, table, numreturn, begin);
                ajTablestrFree(&table);
                continue;
            }
        }

        /*
        ** store key and value in table and parse values
        ** when have all of the sequence
        ** results in the table because the LEFT, RIGHT
        ** and INTERNAL results for each
        ** resulting primer are interleaved
        */

        keytokenhandle = ajStrTokenNewC(line, equals);

        key = ajStrNew();
        ajStrTokenNextParse(&keytokenhandle, &key);

        value = ajStrNew();
        ajStrTokenNextParse(&keytokenhandle, &value);

        ajDebug("key=%S\tvalue=%S\n", key, value);

        ajTablePut(table,(void *)key, (void *)value);

        ajStrTokenDel(&keytokenhandle);
    }

    ajStrDel(&line);
    ajStrTokenDel(&linetokenhandle);
    ajTablestrFree(&table);

    return;
}
コード例 #20
0
ファイル: taxgetrank.c プロジェクト: WenchaoLin/JAMg
int main(int argc, char **argv)
{
    /* Variable declarations */
    AjPOutfile  outfile = NULL;    
    AjPStr* ranks = NULL;
    AjBool hidden = ajFalse;

    AjPTax tax = NULL;
    AjPTax taxparent = NULL;
    AjPTaxall taxall = NULL;
    AjPTaxin taxinparent = NULL;

    AjPStr taxqryup = NULL;
    AjPTable foundtable = NULL;
    const AjPStr taxrank = NULL;

    ajuint up;
    AjPList uplist = NULL;
    ajuint i;

    /* ACD processing */
    embInit("taxgetrank", argc, argv);

    taxall   = ajAcdGetTaxonall("taxons");
    ranks   = ajAcdGetList("rank");
    outfile  = ajAcdGetOuttaxon("outfile");
    hidden = ajAcdGetBoolean("hidden");
    
    for(i=0; ranks[i]; i++)
    {
        ajStrExchangeKK(&ranks[i], '_', ' ');
    }

    taxinparent = ajTaxinNew();
    taxparent = ajTaxNew();
    uplist = ajListNew();

    foundtable = ajTablestrNew(600);

    while(ajTaxallNext(taxall, &tax))
    {
        up = ajTaxGetParent(tax);
        while (up > 1)
        {
            ajFmtPrintS(&taxqryup, "%S-id:%u", ajTaxGetDb(tax), up);
            ajTaxinQryS(taxinparent, taxqryup);

            if(!ajTaxinRead(taxinparent, taxparent))
                break;

            if(hidden || !ajTaxIsHidden(taxparent))
            {
                taxrank = ajTaxGetRank(taxparent);
                for(i=0; ranks[i]; i++)
                {
                    if(ajStrMatchS(taxrank, ranks[i]))
                    {
                        if(!ajTableMatchS(foundtable, taxparent->Id))
                        {
                            ajTaxoutWrite(outfile, taxparent);
                            ajTablePut(foundtable,
                                       ajStrNewS(taxparent->Id),
                                       (void *) 1);
                        }
                    }

                }
            }

            up = ajTaxGetParent(taxparent);
        }
    }

    /* Memory clean-up and exit */

    ajTaxallDel(&taxall);
    ajTaxinDel(&taxinparent);
    ajTaxDel(&tax);
    ajTaxDel(&taxparent);

    ajListFree(&uplist);

    ajTablestrFreeKey(&foundtable);

    ajStrDel(&taxqryup);
    ajStrDelarray(&ranks);
    ajOutfileClose(&outfile);
    
    embExit();

    return 0;
}
コード例 #21
0
static AjBool cacheNodeInsert(EnsPCache cache, CachePNode node)
{
    CachePNode old = NULL;

    if(!cache)
        return ajFalse;

    if(!node)
        return ajFalse;

    if(cache->MaxSize && (node->Bytes > cache->MaxSize))
        return ajFalse;

    /* Insert the node into the AJAX List. */

    ajListPushAppend(cache->List, (void *) node);

    /* Insert the node into the AJAX Table. */

    ajTablePut(cache->Table, node->Key, (void *) node);

    /* Update the cache statistics. */

    cache->Bytes += node->Bytes;

    cache->Count++;

    cache->Stored++;

    /* If the cache is too big, remove the top node(s). */

    while((cache->MaxBytes && (cache->Bytes > cache->MaxBytes)) ||
          (cache->MaxCount && (cache->Count > cache->MaxCount)))
    {
        /* Remove the top node from the AJAX List. */

        ajListPop(cache->List, (void **) &old);

        /* Remove the node also from the AJAX Table. */

        ajTableRemove(cache->Table, old->Key);

        /* Update the cache statistics. */

        cache->Bytes -= old->Bytes;

        cache->Count--;

        cache->Dropped++;

        /* Write changes of value data to disk if any. */

        if(cache->Write && old->Value && old->Dirty)
            (*cache->Write)(old->Value);

        /* Both, key and value data are deleted via cacheNodeDel. */

        cacheNodeDel(cache, &old);
    }

    return ajTrue;
}
コード例 #22
0
static AjBool assemblyexceptionadaptorCacheInit(
    EnsPAssemblyexceptionadaptor aea)
{
    ajuint *Pidentifier = NULL;

    AjPList list = NULL;
    AjPList aes  = NULL;

    AjPStr statement = NULL;

    EnsPAssemblyexception ae = NULL;

    if(!aea)
        return ajFalse;

    if(aea->CacheBySeqregionIdentifier)
        return ajTrue;
    else
        aea->CacheBySeqregionIdentifier =
            ajTableNewFunctionLen(0, ensTableCmpUint, ensTableHashUint);

    statement = ajFmtStr(
        "SELECT "
        "assembly_exception.assembly_exception_id, "
        "assembly_exception.seq_region_id, "
        "assembly_exception.seq_region_start, "
        "assembly_exception.seq_region_end, "
        "assembly_exception.exc_type, "
        "assembly_exception.exc_seq_region_id, "
        "assembly_exception.exc_seq_region_start, "
        "assembly_exception.exc_seq_region_end, "
        "assembly_exception.ori "
        "FROM "
        "assembly_exception, "
        "seq_region, "
        "coord_system "
        "WHERE "
        "seq_region.seq_region_id = "
        "assembly_exception.seq_region_id "
        "AND "
        "seq_region.coord_system_id = "
        "coord_system.coord_system_id "
        "AND "
        "coord_system.species_id = %u",
        ensDatabaseadaptorGetIdentifier(aea->Adaptor));

    aes = ajListNew();

    assemblyexceptionadaptorFetchAllBySQL(aea, statement, aes);

    ajStrDel(&statement);

    while(ajListPop(aes, (void **) &ae))
    {
        list = (AjPList) ajTableFetch(aea->CacheBySeqregionIdentifier,
                                      (const void *)
                                      &ae->SeqregionIdentifier);

        if(!list)
        {
            AJNEW0(Pidentifier);

            *Pidentifier = ae->SeqregionIdentifier;

            list = ajListNew();

            ajTablePut(aea->CacheBySeqregionIdentifier,
                       (void *) Pidentifier,
                       (void *) list);
        }

        ajListPushAppend(list, (void *) ae);
    }

    ajListFree(&aes);

    return ajTrue;
}
コード例 #23
0
static AjPTable jaspscan_ReadFamList(const AjPStr jaspdir)
{
    AjPTable ret = NULL;
    AjPStr lfile = NULL;
    AjPStr line  = NULL;
    AjPStr key   = NULL;
    AjPStr str   = NULL;
 
    PJspmat info = NULL;
    
    AjPFile inf  = NULL;
    const char *p = NULL;
    const char *q = NULL;
    
    lfile = ajStrNew();
    line  = ajStrNew();
    str   = ajStrNew();
    
    ajFmtPrintS(&lfile,"%S%s%s",jaspdir,SLASH_STRING,J_LIST);


    inf = ajDatafileNewInNameS(lfile);
    if(!inf)
	ajFatal("Matrix list file %S not found",lfile);


    ret = ajTablestrNewLen(JASPTAB_GUESS);
    
    
    while(ajReadlineTrim(inf,&line))
    {
	info = jaspscan_infonew();
	ajFmtScanS(line,"%S%S",&info->id,&info->num);

	p = ajStrGetPtr(line);
	while(*p !='\t')
	    ++p;
	++p;
	while(*p != '\t')
	    ++p;
	++p;

	q = p;
	while(*q != '\t')
	    ++q;

	ajStrAssignSubC(&info->name,p,0,q-p-1);

	++q;
	p = q;
	while(*q != ';')
	    ++q;

	ajStrAssignSubC(&info->klass,p,0,q-p-1);
	ajStrRemoveWhiteExcess(&info->klass);

	p = q+1;
	while(*p)
	{
	    q = p;
	    while(* q && *q != ';')
		++q;
	    ajStrAssignSubC(&str,p,0,q-p-1);
	    ajStrRemoveWhiteExcess(&str);

	    jaspscan_coretoken(info, str);
	    
	    if(!*q)
		p = q;
	    else
		p = q +1;
	}

	key = ajStrNew();
	ajStrAssignS(&key,info->id);
	ajTablePut(ret,(void *)key,(void *) info);
    }
    

    ajFileClose(&inf);

    ajStrDel(&lfile);
    ajStrDel(&line);
    ajStrDel(&str);
	

    return ret;
}
コード例 #24
0
ファイル: taxgetdown.c プロジェクト: WenchaoLin/JAMg
int main(int argc, char **argv)
{
    /* Variable declarations */
    AjPOutfile outfile = NULL;    
    AjPTaxall taxall = NULL;

    AjPTax tax     = NULL;

    AjPList taxlist = ajListNew();

    AjPTax taxchild = NULL;
    AjPTaxin taxchildin = NULL;
    AjPStr taxchildqry = NULL;
    AjPTable foundtable = NULL;
    ajuint ifound = 0;
    ajuint ichild = 0;
    ajuint ikeep = 0;

    /* ACD processing */
    embInit("taxgetdown", argc, argv);

    taxall    = ajAcdGetTaxonall("taxons");
    outfile   = ajAcdGetOuttaxon("outfile");

    taxchildin = ajTaxinNew();

    taxchild = ajTaxNew();

    foundtable = ajTablestrNew(600);

    while(ajTaxallNext(taxall, &tax))
    {
        ifound++;
        ajFmtPrintS(&taxchildqry, "%S-up:%S",
                    ajTaxGetDb(tax), ajTaxGetId(tax));
        ajTaxinQryS(taxchildin, taxchildqry);
        while(ajTaxinRead(taxchildin, taxchild))
        {
            ichild++;
            if(!ajTableMatchS(foundtable, taxchild->Id))
            {
                ajTaxoutWrite(outfile, taxchild);
                ajTablePut(foundtable, ajStrNewS(taxchild->Id),
                           (void *) 1);
                ikeep++;
            }
        }
    }

    if(!ifound)
        ajErr("No matching terms");

    /* Memory clean-up and exit */

    ajStrDel(&taxchildqry);

    ajListFree(&taxlist);

    ajTaxallDel(&taxall);
    ajTaxDel(&tax);
    ajTaxinDel(&taxchildin);
    ajTaxDel(&taxchild);

    ajOutfileClose(&outfile);

    ajTablestrFreeKey(&foundtable);
   
    embExit();

    return 0;
}