1 /** @source edamhasoutput
2 **
3 ** Find EDAM ontology terms by has_output relationship
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 edamhasoutput ********************************************************
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 sensitive = ajFalse;
82     AjBool subclasses = ajFalse;
83     AjBool obsolete = ajTrue;
84 
85     AjPObo obo = NULL;
86     AjPObo oborelate = NULL;
87     AjPObo obotest = NULL;
88     AjPOboin oboin = NULL;
89     AjPOboin oboinrelate = NULL;
90 
91     AjPList obolist = ajListNew();
92 
93     AjPStr oboqry = NULL;
94     AjPStr oboqryrelate = NULL;
95     AjPStr qrystr = NULL;
96     AjPTable obotable = NULL;
97     AjPTable nstable = NULL;
98     AjPTable foundtable = NULL;
99     const AjPStr name = NULL;
100 
101     AjPStrTok handle = NULL;
102     ajuint i;
103     ajuint imax = 3;
104 
105     const char* fields[] = {"id", "acc", "nam", "des"};
106 
107     /* ACD processing */
108     embInit("edamhasoutput", argc, argv);
109 
110     query     = ajAcdGetString("identifier");
111     namespace = ajAcdGetList("namespace");
112     outfile   = ajAcdGetOutobo("outfile");
113     sensitive = ajAcdGetBoolean("sensitive");
114     subclasses = ajAcdGetBoolean("subclasses");
115     obsolete = ajAcdGetBoolean("obsolete");
116 
117     oboin = ajOboinNew();
118     obo = ajOboNew();
119     oboinrelate = ajOboinNew();
120     oborelate = ajOboNew();
121 
122     foundtable = ajTablestrNew(600);
123     obotable = ajTablestrNew(600);
124     nstable = ajTablestrNew(6);
125 
126     if(sensitive)
127         imax++;
128 
129     for(i=0; namespace[i]; i++)
130     {
131         ajTablePut(nstable, namespace[i], (void*) 1);
132     }
133 
134     handle = ajStrTokenNewC(query, ",");
135     while(ajStrTokenNextParse(handle, &qrystr))
136     {
137         for(i=0;i<imax;i++)
138         {
139             ajFmtPrintS(&oboqry, "edam-%s:%S", fields[i], qrystr);
140 
141             ajOboinQryS(oboin, oboqry);
142 
143             while(ajOboinRead(oboin, obo))
144             {
145                 if(!obsolete && ajOboIsObsolete(obo))
146                     continue;
147 
148                 ajListPushAppend(obolist, ajOboNewObo(obo));
149                 if(subclasses)
150                     ajOboGetTree(obo, obolist);
151 
152                 ajDebug("%S '%S' %Lu\n",
153                        qrystr, obo->Id, ajListGetLength(obolist));
154                 while(ajListGetLength(obolist))
155                 {
156                     ajListPop(obolist, (void**) &obotest);
157                     if(!obsolete && ajOboIsObsolete(obotest))
158                     {
159                         ajOboDel(&obotest);
160                         continue;
161                     }
162 
163                     if(!ajTableMatchS(obotable, obotest->Id))
164                     {
165                         ajFmtPrintS(&oboqryrelate, "edam-hasout:%S",
166                                     obotest->Id);
167                         ajOboinQryS(oboinrelate, oboqryrelate);
168                         while(ajOboinRead(oboinrelate, oborelate))
169                         {
170                             if(!obsolete && ajOboIsObsolete(oborelate))
171                                 continue;
172 
173                             name = ajOboGetNamespace(oborelate);
174                             if(ajTableMatchS(nstable, name))
175                             {
176                                 if(!ajTableMatchS(foundtable, oborelate->Id))
177                                 {
178                                     ajObooutWrite(outfile, oborelate);
179                                     ajTablePut(foundtable,
180                                                ajStrNewS(oborelate->Id),
181                                                (void *) 1);
182                                 }
183                             }
184                         }
185                     }
186                     ajOboDel(&obotest);
187                 }
188             }
189         }
190     }
191 
192     /* Memory clean-up and exit */
193 
194     ajListFree(&obolist);
195 
196     ajStrTokenDel(&handle);
197     ajStrDel(&qrystr);
198     ajTablestrFreeKey(&obotable);
199     ajTablestrFreeKey(&foundtable);
200     ajTableFree(&nstable);
201 
202     ajStrDel(&query);
203     for(i=0; namespace[i]; i++)
204         ajStrDel(&namespace[i]);
205     AJFREE(namespace);
206 
207     ajStrDel(&oboqry);
208     ajStrDel(&oboqryrelate);
209     ajOboDel(&obo);
210     ajOboDel(&oborelate);
211     ajOboinDel(&oboin);
212     ajOboinDel(&oboinrelate);
213 
214     ajOutfileClose(&outfile);
215 
216     embExit();
217 
218     return 0;
219 }
220 
221 
222 /* ==================================================================== */
223 /* ============================ functions ============================= */
224 /* ==================================================================== */
225 
226