1 /** @source drfindformat
2 **
3 ** Find public databases by type of content
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 drfindformat **********************************************************
70 **
71 ** Find public databases by type of query output format
72 **
73 ******************************************************************************/
74
main(int argc,char ** argv)75 int main(int argc, char **argv)
76 {
77 /* Variable declarations */
78 AjPStr query;
79 AjPOutfile outfile = NULL;
80
81 AjPResource resource = NULL;
82 AjPResourcein resourcein = NULL;
83 AjPOboin oboin = NULL;
84 AjPObo obo = NULL;
85 AjPStr oboqry = NULL;
86 AjPStr resourceqry = NULL;
87 AjPStr qrystr = NULL;
88 AjPTable obotable = NULL;
89 AjPTable foundtable = NULL;
90 AjBool subclasses = ajFalse;
91
92 AjPStrTok handle = NULL;
93 AjPList obolist = NULL;
94 AjPObo obotest = NULL;
95
96 ajuint i;
97 ajuint imax = 3;
98
99 const char* fields[] = {"id", "acc", "nam", "des"};
100
101 /* ACD processing */
102 embInit("drfindformat", argc, argv);
103
104 query = ajAcdGetString("query");
105 outfile = ajAcdGetOutresource("outfile");
106 /* sensitive = ajAcdGetBoolean("sensitive"); */
107 subclasses = ajAcdGetBoolean("subclasses");
108
109 resourcein = ajResourceinNew();
110 resource = ajResourceNew();
111 oboin = ajOboinNew();
112 obo = ajOboNew();
113
114 obolist = ajListNew();
115 obotable = ajTablestrNew(600);
116 foundtable = ajTablestrNew(600);
117
118
119 handle = ajStrTokenNewC(query, ",");
120 while(ajStrTokenNextParse(handle, &qrystr))
121 {
122 for(i=0;i<imax;i++)
123 {
124 ajFmtPrintS(&oboqry, "edam-%s:%S", fields[i], qrystr);
125
126 ajOboinQryS(oboin, oboqry);
127
128 while(ajOboinRead(oboin, obo))
129 {
130 ajListPushAppend(obolist, ajOboNewObo(obo));
131 if(subclasses)
132 ajOboGetTree(obo, obolist);
133
134 ajDebug("%S '%S' %Lu\n",
135 qrystr, obo->Id, ajListGetLength(obolist));
136 while(ajListGetLength(obolist))
137 {
138 ajListPop(obolist, (void**) &obotest);
139
140 if(!ajTableMatchS(obotable, obotest->Id))
141 {
142 ajDebug("edam %s '%S' namespace '%S' name '%S'\n",
143 fields[i], obotest->Id, obotest->Namespace,
144 obotest->Name);
145 ajTablePut(obotable, ajStrNewS(obotest->Id),
146 (void *) 1);
147 ajFmtPrintS(&resourceqry, "drcat-efmt:%S",
148 ajOboGetId(obotest));
149 ajResourceinQryS(resourcein, resourceqry);
150
151 while(ajResourceinRead(resourcein, resource))
152 {
153 if(!ajTableMatchS(foundtable, resource->Id))
154 {
155 ajDebug("drcat id '%S' categories %Lu\n",
156 resource->Id,
157 ajListGetLength(resource->Cat));
158 ajResourceoutWrite(outfile, resource);
159 ajTablePut(foundtable, ajStrNewS(resource->Id),
160 (void *) 1);
161 }
162 }
163 }
164 ajOboDel(&obotest);
165 }
166 }
167 }
168 }
169
170 /* Memory clean-up and exit */
171
172 ajOboDel(&obo);
173 ajOboinDel(&oboin);
174
175 ajResourceDel(&resource);
176 ajResourceinDel(&resourcein);
177
178 ajListFree(&obolist);
179
180 ajStrTokenDel(&handle);
181
182 ajStrDel(&qrystr);
183 ajStrDel(&query);
184 ajStrDel(&oboqry);
185 ajStrDel(&resourceqry);
186
187 ajTablestrFreeKey(&obotable);
188 ajTablestrFreeKey(&foundtable);
189
190 ajOutfileClose(&outfile);
191
192 embExit();
193
194 return 0;
195 }
196
197
198 /* ==================================================================== */
199 /* ============================ functions ============================= */
200 /* ==================================================================== */
201
202