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;
}
Beispiel #2
0
int main(int argc, char **argv)
{
    /* Variable declarations */
    AjPStr   dbname = NULL;
    AjPStr   svrname = NULL;
    AjPFile  outfile = NULL;    
    AjPResource resource = NULL;
    AjPResourcein resourcein = NULL;
    AjPStr resourceqry = NULL;
    AjPStr type     = NULL;
    AjBool id;
    AjBool qry;
    AjBool all;
    AjBool verbose;
    AjPStr methods = NULL;
    AjPStr release = NULL;
    AjPStr comment = NULL;
    AjPStr defined = NULL;
    AjPList list = NULL;
    AjPTagval tagval = NULL;
    AjIList iter = NULL;
    ajuint space = 0;
    AjPList aliaslist = NULL;
    AjIList aliter = NULL;
    const AjPStr alias = NULL;
    ajuint maxlen;
    AjPStr truedbname = NULL;
    AjBool isalias = ajFalse;

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

    dbname   = ajAcdGetString("database");
    svrname   = ajAcdGetString("server");
    verbose  = ajAcdGetBoolean("full");
    outfile  = ajAcdGetOutfile("outfile");
    
    ajStrAssignS(&truedbname, dbname);
    ajNamAliasDatabase(&truedbname);
    ajStrFmtLower(&truedbname);

    if(!ajStrMatchS(dbname, truedbname))
        isalias = ajTrue;

    /* Application logic */
    /* Check EMBOSS database information.
       Write output file */

    if(ajNamDbDetailsSvr(truedbname, svrname, &type, &id, &qry, &all,
                         &comment, &release, &methods, &defined))
    {
        if(isalias)
            ajFmtPrintF(outfile, "# %S is an alias for %S defined in %S\n",
                        dbname, truedbname, defined);
        else
            ajFmtPrintF(outfile, "# %S is defined in %S\n",
                        truedbname, defined);

        ajFmtPrintF(outfile, "# access levels id: %B query: %B all: %B\n\n",
                    id, qry, all);
        ajFmtPrintF(outfile, "DBNAME %S [\n", truedbname);

        if(ajStrGetLen(svrname))
            list = ajNamDbGetAttrlistSvr(truedbname, svrname);
        else
            list = ajNamDbGetAttrlist(truedbname);

        iter = ajListIterNewread(list);
        while(!ajListIterDone(iter))
        {
            tagval = ajListIterGet(iter);
            space = 15 - ajStrGetLen(ajTagvalGetTag(tagval));
            ajFmtPrintF(outfile, "   %S:%.*s\"%S\"\n",
                        ajTagvalGetTag(tagval),
                        space, "                    ",
                        ajTagvalGetValue(tagval));
            ajTagvalDel(&tagval);
        }
        ajListIterDel(&iter);
        ajListFree(&list);

        ajFmtPrintF(outfile, "]\n");

        if(verbose)
        {
            aliaslist = ajListNew();
            ajNamListFindAliases(truedbname, aliaslist);

            if(ajListGetLength(aliaslist))
            {
                ajFmtPrintF(outfile, "\n");
                    
                aliter = ajListIterNewread(aliaslist);

                maxlen = 1;
                while(!ajListIterDone(aliter))
                {
                    alias = ajListIterGet(aliter);
                    if(MAJSTRGETLEN(alias) > maxlen)
                        maxlen = MAJSTRGETLEN(alias);
                }
                
                ajListIterDel(&aliter);
                aliter = ajListIterNewread(aliaslist);

                while(!ajListIterDone(aliter))
                {
                    alias = ajListIterGet(aliter);

                    if(ajStrFindK(alias, ':') < 0)
                        ajFmtPrintF(outfile, "ALIAS %-*S %S\n",
                                    maxlen, alias, truedbname);
                }

                ajListIterDel(&aliter);
            }

            ajListstrFree(&aliaslist);
        }

        ajStrDel(&type);
        ajStrDel(&methods);
        ajStrDel(&release);
        ajStrDel(&comment);
        ajStrDel(&defined);
    }
    else
    {
/* try looking in DRCAT */
        resourcein = ajResourceinNew();
        resource = ajResourceNew();

        ajFmtPrintS(&resourceqry, "drcat:%S", dbname);
        ajResourceinQryS(resourcein, resourceqry);
        if(ajResourceinRead(resourcein, resource))
        {
            ajFmtPrintF(outfile, "DBNAME %S [\n", dbname);
            ajFmtPrintF(outfile, "   comment: \"defined in DRCAT\"\n");
            ajFmtPrintF(outfile, "]\n");
         }
        ajResourceinDel(&resourcein);
        ajResourceDel(&resource);
        ajStrDel(&resourceqry);
    }

    /* Memory clean-up and exit */

    ajFileClose(&outfile);
    ajStrDel(&truedbname);
    ajStrDel(&dbname);
    ajStrDel(&svrname);

    embExit();

    return 0;
}