1 /** @source edamdef
2 **
3 ** Find EDAM ontology terms by identifier
4 **
5 ** @author Copyright (C) 2010 Jon Ison / EMBOSS
6 ** @version 1  First version</replaceable>
7 ** @modified July 2010  Jon Ison First version</replaceable>
8 ** @@
9 **
10 ** This program is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License
12 ** as published by the Free Software Foundation; either version 2
13 ** of the License, or (at your option) any later version.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ** GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 ********************************************************************/
24 
25 
26 /* ==================================================================== */
27 /* ========================== include files =========================== */
28 /* ==================================================================== */
29 
30 #include "emboss.h"
31 
32 /* Inclusion of system and local header files goes here */
33 
34 
35 
36 /* ==================================================================== */
37 /* ============================ constants ============================= */
38 /* ==================================================================== */
39 
40 /* #define and enum statements go here */
41 
42 
43 
44 /* ==================================================================== */
45 /* ======================== global variables ========================== */
46 /* ==================================================================== */
47 
48 /* Global variables definitions go here */
49 
50 
51 
52 /* ==================================================================== */
53 /* ============================== data ================================ */
54 /* ==================================================================== */
55 
56 /* Definition of datatypes go here */
57 
58 
59 
60 /* ==================================================================== */
61 /* ==================== function prototypes =========================== */
62 /* ==================================================================== */
63 
64 /* Function prototypes for public (external) functions go here */
65 
66 
67 
68 
69 /* @prog edamdef **************************************************************
70 **
71 ** Find EDAM ontology 'data' (identifier) terms by keyword
72 **
73 ******************************************************************************/
74 
main(int argc,char ** argv)75 int main(int argc, char **argv)
76 {
77     /* Variable declarations */
78     AjPStr   query;
79     AjPStr  *namespace = NULL;
80     AjPOutfile  outfile = NULL;
81     AjBool subclasses = ajTrue;
82     AjBool obsolete = ajFalse;
83 
84     AjPObo obo = NULL;
85     AjPObo obotest = NULL;
86     AjPOboin oboin = NULL;
87 
88     AjPList obolist = NULL;
89 
90     AjPStr oboqry = NULL;
91     AjPStr qrystr = NULL;
92     AjPTable foundtable = NULL;
93     AjPTable nstable = NULL;
94     const AjPStr name = NULL;
95 
96     AjPStrTok handle = NULL;
97     ajint i;
98     ajuint ifound = 0;
99     ajuint ikeep = 0;
100 
101     /* ACD processing */
102     embInit("edamdef", argc, argv);
103 
104     query     = ajAcdGetString("query");
105     namespace = ajAcdGetList("namespace");
106     outfile   = ajAcdGetOutobo("outfile");
107     subclasses = ajAcdGetBoolean("subclasses");
108     obsolete = ajAcdGetBoolean("obsolete");
109 
110     /* Application logic */
111     /* Check EDAM ontology (edam.obo) is installed indexed.
112        Loop through queryable fields
113         :Return list of EDAM ids with fields matching keyword(s)
114        Merge lists of matching entries
115        Write output file */
116 
117     oboin = ajOboinNew();
118     obo = ajOboNew();
119 
120     obolist = ajListNew();
121 
122     foundtable = ajTablestrNew(600);
123     nstable = ajTablestrNew(6);
124 
125     for(i=0; namespace[i]; i++)
126     {
127         ajTablePut(nstable, namespace[i], (void*) 1);
128     }
129 
130     handle = ajStrTokenNewC(query, ",");
131     while(ajStrTokenNextParse(handle, &qrystr))
132     {
133         ajFmtPrintS(&oboqry, "edam-des:%S", qrystr);
134         ajOboinQryS(oboin, oboqry);
135 
136         while(ajOboinRead(oboin, obo))
137         {
138             if(!obsolete && ajOboIsObsolete(obo))
139                 continue;
140 
141             ajListPushAppend(obolist, ajOboNewObo(obo));
142             if(subclasses)
143                 ajOboGetTree(obo, obolist);
144 
145             ajDebug("%S '%S' %Lu\n",
146                     qrystr, obo->Id, ajListGetLength(obolist));
147             while(ajListGetLength(obolist))
148             {
149                 ajListPop(obolist, (void**) &obotest);
150                 if(!obsolete && ajOboIsObsolete(obotest))
151                 {
152                     ajOboDel(&obotest);
153                     continue;
154                 }
155 
156                 ifound++;
157                 name = ajOboGetNamespace(obotest);
158 
159                 if(ajTableMatchS(nstable, name))
160                 {
161                     if(!ajTableMatchS(foundtable, obotest->Id))
162                     {
163                         ajObooutWrite(outfile, obotest);
164                         ajTablePut(foundtable, ajStrNewS(obotest->Id),
165                                    (void *) 1);
166                         ikeep++;
167                     }
168                 }
169                 ajOboDel(&obotest);
170             }
171         }
172     }
173 
174     if(!ifound)
175         ajErr("No matching terms");
176     else if(!ikeep)
177         ajErr("No terms in requested namespace");
178 
179     /* Memory clean-up and exit */
180 
181     ajOboDel(&obo);
182     ajOboinDel(&oboin);
183 
184     ajListFree(&obolist);
185 
186     ajStrTokenDel(&handle);
187 
188     ajStrDel(&query);
189     ajStrDel(&qrystr);
190     ajStrDel(&oboqry);
191 
192     ajTablestrFreeKey(&foundtable);
193     ajTableFree(&nstable);
194 
195     for(i=0; namespace[i]; i++)
196         ajStrDel(&namespace[i]);
197     AJFREE(namespace);
198 
199     ajOutfileClose(&outfile);
200 
201     embExit();
202 
203     return 0;
204 }
205 
206 
207 /* ==================================================================== */
208 /* ============================ functions ============================= */
209 /* ==================================================================== */
210 
211