1 /** @source goname
2 **
3 ** Find gene 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 goname ***************************************************************
70 **
71 ** Find GO 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 char wordchars[] =
102 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
103 "0123456789*?";
104
105 /* ACD processing */
106 embInit("goname", argc, argv);
107
108 query = ajAcdGetString("query");
109 namespace = ajAcdGetList("namespace");
110 outfile = ajAcdGetOutobo("outfile");
111 subclasses = ajAcdGetBoolean("subclasses");
112 obsolete = ajAcdGetBoolean("obsolete");
113
114 /* Application logic */
115 /* Check GO ontology (gene_ontology.*.obo) is installed indexed.
116 Loop through queryable fields
117 :Return list of GO ids with fields matching keyword(s)
118 Merge lists of matching entries
119 Write output file */
120
121 oboin = ajOboinNew();
122 obo = ajOboNew();
123
124 obolist = ajListNew();
125
126 foundtable = ajTablestrNew(600);
127 nstable = ajTablestrNew(6);
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 if(ajStrIsCharsetC(qrystr, wordchars))
138 ajFmtPrintS(&oboqry, "go-nam:%S", qrystr);
139 else
140 ajFmtPrintS(&oboqry, "go-acc:%S", qrystr);
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 while(ajListGetLength(obolist))
153 {
154 ajListPop(obolist, (void**) &obotest);
155 if(!obsolete && ajOboIsObsolete(obotest))
156 {
157 ajOboDel(&obotest);
158 continue;
159 }
160
161 ifound++;
162 name = ajOboGetNamespace(obotest);
163
164 if(ajTableMatchS(nstable, name))
165 {
166 if(!ajTableMatchS(foundtable, obotest->Id))
167 {
168 ajObooutWrite(outfile, obotest);
169 ajTablePut(foundtable, ajStrNewS(obotest->Id),
170 (void *) 1);
171 ikeep++;
172 }
173 }
174 ajOboDel(&obotest);
175 }
176 }
177 }
178
179 if(!ifound)
180 ajErr("No matching terms");
181 else if(!ikeep)
182 ajErr("No terms in requested namespace");
183
184 /* Memory clean-up and exit */
185
186 ajOboDel(&obo);
187 ajOboinDel(&oboin);
188
189 ajListFree(&obolist);
190
191 ajStrTokenDel(&handle);
192
193 ajStrDel(&query);
194 ajStrDel(&oboqry);
195 ajStrDel(&qrystr);
196
197 ajTablestrFreeKey(&foundtable);
198 ajTableFree(&nstable);
199
200 for(i=0; namespace[i]; i++)
201 ajStrDel(&namespace[i]);
202 AJFREE(namespace);
203
204 ajOutfileClose(&outfile);
205
206 embExit();
207
208 return 0;
209 }
210
211
212 /* ==================================================================== */
213 /* ============================ functions ============================= */
214 /* ==================================================================== */
215
216