1 /* @source ajresourcewrite ****************************************************
2 **
3 ** AJAX data resource handling functions
4 **
5 ** @author Copyright (C) 2010 Peter Rice
6 ** @version $Revision: 1.19 $
7 ** @modified Oct 25 2010 pmr First AJAX version
8 ** @modified $Date: 2012/12/07 10:18:08 $ by $Author: rice $
9 ** @@
10 **
11 ** This library is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU Lesser General Public
13 ** License as published by the Free Software Foundation; either
14 ** version 2.1 of the License, or (at your option) any later version.
15 **
16 ** This library is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ** Lesser General Public License for more details.
20 **
21 ** You should have received a copy of the GNU Lesser General Public
22 ** License along with this library; if not, write to the Free Software
23 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 ** MA  02110-1301,  USA.
25 **
26 ******************************************************************************/
27 
28 #include "ajlib.h"
29 
30 #include "ajresourcewrite.h"
31 #include "ajfile.h"
32 
33 
34 static AjBool resourceoutWriteBasic(AjPFile outf,
35                                     const AjPResource resource);
36 static AjBool resourceoutWriteDrcat(AjPFile outf,
37                                     const AjPResource resource);
38 static AjBool resourceoutWriteList(AjPFile outf,
39                                     const AjPResource resource);
40 static AjBool resourceoutWriteWebpage(AjPFile outf,
41                                       const AjPResource resource);
42 static AjBool resourceoutWriteWsbasic(AjPFile outf,
43                                       const AjPResource resource);
44 
45 
46 
47 
48 
49 /* @datastatic ResourcePOutFormat *********************************************
50 **
51 ** Data output formats data structure
52 **
53 ** @alias ResourceSoutFormat
54 ** @alias ResourceOOutFormat
55 **
56 ** @attr Name [const char*] Format name
57 ** @attr Desc [const char*] Format description
58 ** @attr Write [AjBool function] Output function, returns ajTrue on success
59 ** @@
60 ******************************************************************************/
61 
62 typedef struct ResourceSOutFormat
63 {
64     const char *Name;
65     const char *Desc;
66     AjBool (*Write) (AjPFile outf, const AjPResource resource);
67 } ResourceOOutFormat;
68 
69 #define ResourcePOutFormat ResourceOOutFormat*
70 
71 
72 static ResourceOOutFormat resourceoutFormatDef[] =
73 {
74 /* "Name",        "Description" */
75 /*     WriteFunction */
76 
77   {"drcat",         "Data resource catalogue entry format",
78        &resourceoutWriteDrcat},
79 
80   {"basic",         "Basic data resource catalogue entry format",
81        &resourceoutWriteBasic},
82 
83   {"wsbasic",       "Webservice annotated data resource catalogue entry format",
84        &resourceoutWriteWsbasic},
85 
86   {"list",          "List of resource ids",
87        &resourceoutWriteList},
88 
89   {"webpage",       "DRCAT web page",
90        &resourceoutWriteWebpage},
91 
92   {NULL, NULL, NULL}
93 };
94 
95 
96 
97 
98 /* @filesection ajresource ****************************************************
99 **
100 ** @nam1rule aj Function belongs to the AJAX library.
101 **
102 ******************************************************************************/
103 
104 
105 
106 
107 
108 /* @datasection [AjPOutfile] Data resource data output ************************
109 **
110 ** Function is for manipulating data resource data objects
111 **
112 ** @nam2rule Resourceout Data resource data output
113 **
114 ******************************************************************************/
115 
116 
117 
118 
119 /* @section data resource data outputs ****************************************
120 **
121 ** These functions write the data resource data provided by the first argument
122 **
123 ** @fdata [AjPOutfile]
124 **
125 ** @nam3rule Write Write data resource data
126 **
127 ** @argrule * outf [AjPOutfile] Output file
128 ** @argrule * resource [const AjPResource] Data resource data
129 **
130 ** @valrule * [AjBool] true on success
131 **
132 ** @fcategory output
133 **
134 ******************************************************************************/
135 
136 
137 
138 
139 /* @func ajResourceoutWrite ***************************************************
140 **
141 ** Write a data resource in a named format
142 **
143 ** @param [u] outf [AjPOutfile] Output file
144 ** @param [r] resource [const AjPResource] Data resource object
145 **
146 ** @return [AjBool] True on success
147 **
148 **
149 ** @release 6.4.0
150 ******************************************************************************/
151 
ajResourceoutWrite(AjPOutfile outf,const AjPResource resource)152 AjBool ajResourceoutWrite(AjPOutfile outf, const AjPResource resource)
153 {
154     ajuint i = ajOutfileGetFormatindex(outf);
155     AjPFile outfile = ajOutfileGetFile(outf);
156 
157     return (*resourceoutFormatDef[i].Write)(outfile, resource);
158 }
159 
160 
161 
162 
163 /* @funcstatic resourceoutWriteDrcat ******************************************
164 **
165 ** Write resource object to file in EMBOSS drcat.dat format.
166 **
167 ** All elements / fields are written.
168 **
169 ** @param [u] outf [AjPFile] Output resource file
170 ** @param [r] resource [const AjPResource] Resource object
171 ** @return [AjBool] True on success
172 **
173 ** @release 6.4.0
174 ** @@
175 ******************************************************************************/
176 
resourceoutWriteDrcat(AjPFile outf,const AjPResource resource)177 static AjBool resourceoutWriteDrcat(AjPFile outf, const AjPResource resource)
178 {
179     AjPReslink tmplink = NULL;
180     AjPResquery tmpqry = NULL;
181     AjPResterm resterm = NULL;
182     AjPStr  tmpstr  = NULL;
183     AjIList iter    = NULL;
184 
185     if(!outf)
186         return ajFalse;
187 
188     ajFmtPrintF(outf, "%-8s%S\n", "ID", resource->Id);
189 
190     iter = ajListIterNew(resource->Idalt);
191     while((tmpstr = ajListstrIterGet(iter)))
192         ajFmtPrintF(outf, "%-8s%S\n", "IDalt", tmpstr);
193     ajListIterDel(&iter);
194 
195     if(ajStrGetLen(resource->Acc))
196         ajFmtPrintF(outf, "%-8s%S\n", "Acc", resource->Acc);
197     ajFmtPrintF(outf, "%-8s%S\n", "Name", resource->Name);
198     ajFmtPrintF(outf, "%-8s%S\n", "Desc", resource->Desc);
199 
200     if(ajStrGetLen(resource->Url))
201         ajFmtPrintF(outf, "%-8s%S\n", "URL", resource->Url);
202     if(ajStrGetLen(resource->Urllink))
203         ajFmtPrintF(outf, "%-8s%S\n", "URLlink", resource->Urllink);
204     if(ajStrGetLen(resource->Urlrest))
205         ajFmtPrintF(outf, "%-8s%S\n", "URLrest", resource->Urlrest);
206     if(ajStrGetLen(resource->Urlsoap))
207         ajFmtPrintF(outf, "%-8s%S\n", "URLsoap", resource->Urlsoap);
208 
209     iter = ajListIterNew(resource->Cat);
210     while((tmpstr = ajListstrIterGet(iter)))
211         ajFmtPrintF(outf, "%-8s%S\n", "Cat", tmpstr);
212     ajListIterDel(&iter);
213 
214     iter = ajListIterNew(resource->Taxon);
215     while((resterm = ajListIterGet(iter)))
216         ajFmtPrintF(outf, "%-8s%S | %S\n", "Taxon",
217                     resterm->Id, resterm->Name);
218     ajListIterDel(&iter);
219 
220     iter = ajListIterNew(resource->Edamtpc);
221     while((resterm = ajListIterGet(iter)))
222         ajFmtPrintF(outf, "%-8s%S | %S\n", "EDAMtpc",
223                     resterm->Id, resterm->Name);
224     ajListIterDel(&iter);
225 
226     iter = ajListIterNew(resource->Edamdat);
227     while((resterm = ajListIterGet(iter)))
228         ajFmtPrintF(outf, "%-8s%S | %S\n", "EDAMdat",
229                     resterm->Id, resterm->Name);
230     ajListIterDel(&iter);
231 
232     iter = ajListIterNew(resource->Edamid);
233     while((resterm = ajListIterGet(iter)))
234         ajFmtPrintF(outf, "%-8s%S | %S\n", "EDAMid",
235                     resterm->Id, resterm->Name);
236     ajListIterDel(&iter);
237 
238     iter = ajListIterNew(resource->Edamfmt);
239     while((resterm = ajListIterGet(iter)))
240         ajFmtPrintF(outf, "%-8s%S | %S\n", "EDAMfmt",
241                     resterm->Id, resterm->Name);
242     ajListIterDel(&iter);
243 
244     iter = ajListIterNew(resource->Xref);
245     while((tmplink = ajListIterGet(iter)))
246         ajFmtPrintF(outf, "%-8s%S | %S\n",
247                     "Xref", tmplink->Source,
248                     tmplink->Term);
249     ajListIterDel(&iter);
250 
251     iter = ajListIterNew(resource->Query);
252     while((tmpqry = ajListIterGet(iter)))
253         ajFmtPrintF(outf, "%-8s %S | %S | %S | %S\n",
254                     "Query", tmpqry->Datatype, tmpqry->Format,
255                     tmpqry->Term, tmpqry->Url);
256     ajListIterDel(&iter);
257 
258     iter = ajListIterNew(resource->Example);
259     while((tmpstr = ajListstrIterGet(iter)))
260         ajFmtPrintF(outf, "%-8s%S\n", "Example", tmpstr);
261     ajListIterDel(&iter);
262 
263     ajFmtPrintF(outf, "\n");
264 
265     return ajTrue;
266 }
267 
268 
269 
270 
271 /* @funcstatic resourceoutWriteBasic ******************************************
272 **
273 ** Write resource object to file in EMBOSS drcat.dat format.
274 **
275 ** Only the most important elements / fields are written:
276 ** Recommended or official unique identifier ('ID')
277 ** The full (verbose english) name ('Name')
278 ** URL of the database server ('URL')
279 **
280 ** @param [u] outf [AjPFile] Output resource file
281 ** @param [r] resource [const AjPResource] Resource object
282 ** @return [AjBool] True on success
283 **
284 ** @release 6.4.0
285 ** @@
286 ******************************************************************************/
287 
resourceoutWriteBasic(AjPFile outf,const AjPResource resource)288 static AjBool resourceoutWriteBasic(AjPFile outf, const AjPResource resource)
289 {
290     if(!outf)
291         return ajFalse;
292 
293     ajFmtPrintF(outf, "%-8s%S\n", "ID", resource->Id);
294     ajFmtPrintF(outf, "%-8s%S\n", "Name", resource->Name);
295     if(ajStrGetLen(resource->Url))
296         ajFmtPrintF(outf, "%-8s%S\n", "URL", resource->Url);
297 
298     ajFmtPrintF(outf, "\n");
299 
300     return ajTrue;
301 }
302 
303 
304 
305 
306 /* @funcstatic resourceoutWriteList *******************************************
307 **
308 ** Write resource object id to file
309 **
310 ** @param [u] outf [AjPFile] Output resource file
311 ** @param [r] resource [const AjPResource] Resource object
312 ** @return [AjBool] True on success
313 **
314 ** @release 6.4.0
315 ** @@
316 ******************************************************************************/
317 
resourceoutWriteList(AjPFile outf,const AjPResource resource)318 static AjBool resourceoutWriteList(AjPFile outf, const AjPResource resource)
319 {
320     if(!outf)
321         return ajFalse;
322     if(!resource)
323         return ajFalse;
324 
325     if(ajStrGetLen(resource->Db))
326         ajFmtPrintF(outf, "%S:%S\n", resource->Db, resource->Id);
327     else
328         ajFmtPrintF(outf, "%S\n", resource->Id);
329 
330     return ajTrue;
331 }
332 
333 
334 
335 
336 /* @funcstatic resourceoutWriteWebpage ****************************************
337 **
338 ** Write resource object to file in DRCAT web pageformat.
339 **
340 ** All elements / fields are written.
341 **
342 ** @param [u] outf [AjPFile] Output resource file
343 ** @param [r] resource [const AjPResource] Resource object
344 ** @return [AjBool] True on success
345 **
346 ** @release 6.4.0
347 ** @@
348 ******************************************************************************/
349 
resourceoutWriteWebpage(AjPFile outf,const AjPResource resource)350 static AjBool resourceoutWriteWebpage(AjPFile outf, const AjPResource resource)
351 {
352     AjPResquery tmpqry = NULL;
353     AjPResterm resterm = NULL;
354     AjPStr  snstr   = NULL;
355     AjPStr  tmpstr   = NULL;
356     AjPStr  tmpurl   = NULL;
357     AjPStr  tmpid    = NULL;
358     AjPStr  tmpname  = NULL;
359     AjPStr  tmpqid   = NULL;
360     AjPStr  tmpqname = NULL;
361     AjPStr  tmpqterm = NULL;
362     AjIList iter     = NULL;
363     AjIList iterq    = NULL;
364     ajuint i = 0;
365     AjPStrTok handle = NULL;
366     AjPStrTok namehandle = NULL;
367     AjPStrTok termhandle = NULL;
368     const char* biourl = "http://bioportal.bioontology.org/ontologies/45846";
369 
370     if(!outf)
371         return ajFalse;
372 
373     ajFmtPrintF(outf,
374                 "<!DOCTYPE HTML PUBLIC "
375                 "\"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
376     ajFmtPrintF(outf,
377                 "<html>\n");
378 
379     ajFmtPrintF(outf,
380                 "<head>\n");
381     ajFmtPrintF(outf,
382                 "<meta http-equiv=\"Content-Type\" "
383                 "content=\"text/html;charset=UTF-8\" />\n");
384     ajFmtPrintF(outf,
385                 "<title>Bioinformatics Data Resource Catalogue</title>\n");
386     ajFmtPrintF(outf,
387                 "</head>\n\n\n");
388 
389     ajFmtPrintF(outf,
390                 "<body bgcolor=\"#ffffff\">\n");
391 
392     ajFmtPrintF(outf,
393                 "<!-- ID -->\n");
394 
395     if(ajStrGetLen(resource->Url))
396        ajFmtPrintF(outf,
397                    "<center><h1><a href=\"%S\">%S</a></h1></center>\n",
398                    resource->Url, resource->Id);
399     else
400        ajFmtPrintF(outf,
401                    "<center><h1>%S</h1></center>\n",
402                    resource->Id);
403 
404     ajFmtPrintF(outf,
405                 "<!-- Name -->\n");
406 
407     ajFmtPrintF(outf,
408                 "<center><h2>%S</h2> </center>\n",
409                 resource->Name);
410 
411     ajFmtPrintF(outf,
412                 "<!-- Desc -->\n");
413     ajFmtPrintF(outf,
414                 "<p><i>%S</i></p>\n",
415                 resource->Desc);
416 
417     ajFmtPrintF(outf,
418                 "<table>\n");
419 
420     ajFmtPrintF(outf,
421                 "<!-- ID -->\n");
422 
423     ajFmtPrintF(outf,
424                 "  <tr align=\"left\"><th>ID</th><td>%S</td></tr>\n",
425                 resource->Id);
426 
427     ajFmtPrintF(outf,
428                 "<!-- IDalt or omit -->\n");
429 
430     if(ajListGetLength(resource->Idalt))
431     {
432         ajFmtPrintF(outf,
433                     "  <tr align=\"left\"><th>IDalt</th><td>");
434 
435         i = 0;
436         iter = ajListIterNew(resource->Idalt);
437         while((tmpstr = ajListstrIterGet(iter)))
438         {
439             if(i++)
440                 ajFmtPrintF(outf, ", ");
441             ajFmtPrintF(outf, "%S", tmpstr);
442         }
443 
444         ajListIterDel(&iter);
445 
446         ajFmtPrintF(outf,
447                     "</td></tr>\n");
448     }
449 
450     if(ajStrGetLen(resource->Acc))
451     {
452         ajFmtPrintF(outf,
453                     "<!-- ACC or omit -->\n");
454 
455         ajFmtPrintF(outf,
456                     "  <tr align=\"left\"><th>Acc</th><td>%S</td></tr>\n",
457                     resource->Acc);
458     }
459 
460 
461     if(ajStrGetLen(resource->Url))
462         ajFmtPrintF(outf,
463                     "  <tr align=\"left\"><th>Home</th><td>"
464                     "<a href=\"%S\">%S</a></td></tr>\n",
465                     resource->Url, resource->Url);
466 
467     if(ajListGetLength(resource->Edamtpc))
468     {
469         ajFmtPrintF(outf,
470                 "<!-- EDAMtpc -->\n");
471 
472         iter = ajListIterNew(resource->Edamtpc);
473 
474         while((resterm = ajListIterGet(iter)))
475         {
476             ajStrAssignS(&tmpid, resterm->Id);
477             ajStrCutBraces(&tmpid);
478             ajStrFmtPercentEncodeC(&tmpid, " /()");
479             ajFmtPrintF(outf,
480                         "  <tr align=\"left\"><th>EDAM topic</th><td>"
481                         "<a href=\"%s?p=terms&conceptid=EDAM%%3A%S\">%S</a>"
482                         "</td></tr>\n",
483                         biourl, tmpid, resterm->Name);
484         }
485         ajListIterDel(&iter);
486     }
487 
488     ajFmtPrintF(outf,
489                 "<!-- Cat or omit -->\n");
490 
491     if(ajListGetLength(resource->Cat))
492     {
493         iter = ajListIterNew(resource->Cat);
494         while((tmpstr = ajListstrIterGet(iter)))
495             ajFmtPrintF(outf,
496                         "  <tr align=\"left\"><th>Category</th>"
497                         "<td>%S</td></tr>\n",
498                         tmpstr);
499         ajListIterDel(&iter);
500     }
501 
502     ajFmtPrintF(outf,
503                 "<!-- Taxon (comma-separated list) -->\n");
504 
505     ajFmtPrintF(outf,
506                 "  <tr align=\"left\"><th>Taxon</th><td>");
507     i = 0;
508     iter = ajListIterNew(resource->Taxon);
509     while((resterm = ajListIterGet(iter)))
510     {
511         if(i++)
512             ajFmtPrintF(outf, ", ");
513         ajFmtPrintF(outf,
514                     "<a href=\"http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/"
515                     "wwwtax.cgi?id=%S\">%S</a>",
516                     resterm->Id, resterm->Name);
517     }
518 
519     ajListIterDel(&iter);
520     ajFmtPrintF(outf,
521                 "</td></tr>\n");
522 
523 
524     ajFmtPrintF(outf,
525                 "<!-- URLlink or omit -->\n");
526 
527     if(ajStrGetLen(resource->Urllink))
528          ajFmtPrintF(outf,
529                      "<tr align=\"left\"><th>Linking</th><td>"
530                      "<a href=\"%S\">%S</a></td></tr>\n",
531                      resource->Urllink, resource->Urllink);
532 
533     ajFmtPrintF(outf,
534                 "<!-- URLrest or omit -->\n");
535 
536     if(ajStrGetLen(resource->Urlrest))
537          ajFmtPrintF(outf,
538                      "<tr align=\"left\"><th>REST</th><td>"
539                      "<a href=\"%S\">%S</a></td></tr>\n",
540                      resource->Urlrest, resource->Urlrest);
541 
542     ajFmtPrintF(outf,
543                 "<!-- URLsoap or omit -->\n");
544 
545     if(ajStrGetLen(resource->Urlsoap))
546          ajFmtPrintF(outf,
547                      "<tr align=\"left\"><th>SOAP</th><td>"
548                      "<a href=\"%S\">%S</a></td></tr>\n",
549                      resource->Urlsoap, resource->Urlsoap);
550 
551     ajFmtPrintF(outf,
552                 "<!-- Xref - omit ! -->\n");
553 
554     ajFmtPrintF(outf,
555                 "</table>\n");
556 
557 
558     ajFmtPrintF(outf,
559                 "<!-- Query or omit, free-text comments given in {} --> \n");
560     if(ajListGetLength(resource->Query))
561     {
562         ajFmtPrintF(outf,
563                     "<h3>Available data</h3>\n");
564         ajFmtPrintF(outf,
565                     "<table>\n");
566         ajFmtPrintF(outf,
567                     "   <thead>\n");
568         ajFmtPrintF(outf,
569                     "      <tr align=\"left\">\n");
570         ajFmtPrintF(outf,
571                     "         <th>Data</th>\n");
572         ajFmtPrintF(outf,
573                     "         <th>Format</th>\n");
574         ajFmtPrintF(outf,
575                     "         <th>Query</th>\n");
576         ajFmtPrintF(outf,
577                     "         <th>Link</th>\n");
578         ajFmtPrintF(outf,
579                     "      </tr>\n");
580         ajFmtPrintF(outf,
581                     "   </thead>\n");
582         ajFmtPrintF(outf,
583                     "   <tbody>\n");
584 
585         iter = ajListIterNew(resource->Query);
586         while((tmpqry = ajListIterGet(iter)))
587         {
588             ajStrAssignS(&tmpname, tmpqry->Datatype);
589             ajStrCutBraces(&tmpname);
590             ajStrFmtPercentEncodeC(&tmpname, " /()");
591             ajFmtPrintF(outf,
592                         "     <tr>\n");
593             ajFmtPrintF(outf,
594                         "       <td>"
595                         "<a href=\"%s?"
596                         "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n",
597                         biourl, tmpname, tmpqry->Datatype);
598 
599             ajStrAssignS(&tmpname, tmpqry->Format);
600             ajStrCutBraces(&tmpname);
601             ajStrFmtPercentEncodeC(&tmpname, " /()");
602             ajFmtPrintF(outf,
603                         "       <td>"
604                         "<a href=\"%s?"
605                         "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n",
606                         biourl, tmpname, tmpqry->Format);
607 
608             ajStrAssignS(&tmpname, tmpqry->Term);
609             ajStrCutBraces(&tmpname);
610             ajStrFmtPercentEncodeC(&tmpname, " /()");
611             ajFmtPrintF(outf,
612                         "       <td>"
613                         "<a href=\"%s?"
614                         "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n",
615                         biourl, tmpname, tmpqry->Term);
616             ajFmtPrintF(outf,
617                         "       <td>%S</td>\n",
618                         tmpqry->Url);
619             ajFmtPrintF(outf,
620                         "     </tr>\n\n");
621         }
622         ajListIterDel(&iter);
623 
624         ajFmtPrintF(outf,
625                     "   </tbody>\n");
626         ajFmtPrintF(outf,
627                     "</table>\n");
628     }
629 
630     ajFmtPrintF(outf,
631                 "<!-- Example or omit -->\n");
632 
633     if(ajListGetLength(resource->Example))
634     {
635         ajFmtPrintF(outf,
636                     "<h3>Example queries</h3>\n");
637 
638         ajFmtPrintF(outf,
639                     "<table>\n");
640         ajFmtPrintF(outf,
641                     "   <thead>\n");
642         ajFmtPrintF(outf,
643                     "      <tr align=\"left\">\n");
644         ajFmtPrintF(outf,
645                     "         <th>Data</th>\n");
646         ajFmtPrintF(outf,
647                     "         <th>Format</th>\n");
648         ajFmtPrintF(outf,
649                     "         <th>Query</th>\n");
650         ajFmtPrintF(outf,
651                     "         <th>Example</th>\n");
652         ajFmtPrintF(outf,
653                     "      </tr>\n");
654         ajFmtPrintF(outf,
655                     "   </thead>\n");
656         ajFmtPrintF(outf,
657                     "   <tbody>\n");
658 
659         iter = ajListIterNew(resource->Example);
660         while((tmpstr = ajListstrIterGet(iter)))
661         {
662             ajStrTokenAssignC(&handle, tmpstr, "|");
663             ajStrTokenNextParse(handle, &tmpid);
664             ajStrRemoveWhiteExcess(&tmpid);
665             ajStrTokenNextParse(handle, &tmpname);
666             ajStrRemoveWhiteExcess(&tmpname);
667 
668             iterq = ajListIterNew(resource->Query);
669             while((tmpqry = ajListIterGet(iterq)))
670             {
671                 if(!ajStrMatchS(tmpid, tmpqry->Term))
672                    continue;
673 
674                 ajStrAssignS(&tmpqid, tmpqry->Datatype);
675                 ajStrCutBraces(&tmpqid);
676                 ajStrFmtPercentEncodeC(&tmpqid, " /()");
677 
678                 ajFmtPrintF(outf,
679                             "     <tr>\n");
680                 ajFmtPrintF(outf,
681                             "       <td>"
682                             "<a href=\"%s?"
683                             "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n",
684                             biourl, tmpqid, tmpqry->Datatype); /* datatype */
685 
686                 ajStrAssignS(&tmpqid, tmpqry->Format);
687                 ajStrCutBraces(&tmpqid);
688                 ajStrFmtPercentEncodeC(&tmpqid, " /()");
689 
690                 ajFmtPrintF(outf,
691                             "       <td>"
692                             "<a href=\"%s?"
693                             "p=terms&conceptid=EDAM%%3A%S\">%S</a></td>\n",
694                             biourl, tmpqid, tmpqry->Format); /* format */
695 
696                 ajStrAssignS(&tmpurl, tmpqry->Url);
697                 ajStrAssignS(&tmpqid, tmpqry->Term);
698                 ajStrCutBraces(&tmpqid);
699                 ajStrFmtPercentEncodeC(&tmpqid, " /()");
700 
701                 i = 0;
702                 ajStrTokenAssignC(&handle, tmpid, ";");
703                 ajStrTokenAssignC(&namehandle, tmpname, ";");
704                 ajStrTokenAssignC(&termhandle, tmpqry->Term, ";");
705                 ajFmtPrintF(outf,
706                             "       <td>");
707 
708                 while(ajStrTokenNextParse(handle, &tmpqid))
709                 {
710                     ajStrTokenNextParse(namehandle, &tmpqname);
711                     ajStrTokenNextParse(termhandle, &tmpqterm);
712 
713                     if(i)
714                         ajFmtPrintF(outf,
715                                     "; ");
716 
717                     ajStrRemoveWhiteExcess(&tmpqid);
718                     ajStrCutBraces(&tmpqid);
719 
720                     ajFmtPrintF(outf,
721                                 "<a href=\"%s?"
722                                 "p=terms&conceptid=EDAM%%3A%S\">%S</a>",
723                                 biourl, tmpqid, tmpqterm); /* id term */
724 
725                     ajFmtPrintS(&snstr, "%%s%u", (i+1));
726                     ajStrExchangeSS(&tmpurl, snstr, tmpqname);
727 
728                     i++;
729 
730                 }
731                 ajFmtPrintF(outf,
732                                 "</td>\n");
733 
734                 ajFmtPrintS(&snstr, "%%s");
735                 ajStrExchangeSS(&tmpurl, snstr, tmpname);
736 
737                 ajFmtPrintF(outf,
738                             "       <td><a href=\"%S\">%S</a></td>\n",
739                             tmpurl, tmpname); /* url, exampleid */
740 
741                 ajFmtPrintF(outf,
742                                 "     </tr>\n");
743             }
744             ajListIterDel(&iterq);
745         }
746 
747         ajListIterDel(&iter);
748 
749         ajFmtPrintF(outf,
750                     "   </tbody>\n");
751         ajFmtPrintF(outf,
752                     "</table>\n");
753     }
754 
755     ajFmtPrintF(outf, "\n\n</body></html>\n");
756 
757     ajStrDel(&tmpid);
758     ajStrDel(&tmpname);
759     ajStrDel(&tmpurl);
760     ajStrDel(&tmpqid);
761     ajStrDel(&tmpqname);
762     ajStrDel(&tmpqterm);
763     ajStrDel(&snstr);
764 
765     ajStrTokenDel(&handle);
766     ajStrTokenDel(&namehandle);
767     ajStrTokenDel(&termhandle);
768 
769     return ajTrue;
770 }
771 
772 
773 
774 
775 /* @funcstatic resourceoutWriteWsbasic ****************************************
776 **
777 ** Write resource object to file in EMBOSS db.dat format.
778 **
779 ** An extension of ajResourceoutWriteBasic, the following fields / elements
780 ** are written:
781 **
782 ** Recommended or official unique identifier ('ID')
783 ** The full (verbose english) name ('Name')
784 ** URL of the database server ('URL')
785 **
786 ** and also:
787 ** URL of documentation on SOAP-based interfaces ('URLsoap')
788 ** URL of documentation on REST-based interfaces ('URLrest')
789 **
790 ** @param [u] outf [AjPFile] Output resource file
791 ** @param [r] resource [const AjPResource] Resource object
792 ** @return [AjBool] True on success
793 **
794 ** @release 6.4.0
795 ** @@
796 ******************************************************************************/
797 
resourceoutWriteWsbasic(AjPFile outf,const AjPResource resource)798 static AjBool resourceoutWriteWsbasic(AjPFile outf,
799                                       const AjPResource resource)
800 {
801     if(!outf)
802         return ajFalse;
803 
804     (void) resource;
805     (void) outf;
806 
807     return ajTrue;
808 }
809 
810 
811 
812 
813 /* @datasection [none] Miscellaneous functions ********************************
814 **
815 ** Functions to initialise and clean up internals
816 **
817 ** @nam2rule Resourceout Data output internals
818 **
819 ******************************************************************************/
820 
821 
822 
823 
824 /* @section Printing **********************************************************
825 **
826 ** Printing details of the internals to a file
827 **
828 ** @fdata [none]
829 **
830 ** @nam2rule Resourceoutprint
831 **
832 ** @fcategory output
833 **
834 ******************************************************************************/
835 
836 
837 
838 
839 /* @section Print *************************************************************
840 **
841 ** Printing to a file
842 **
843 ** @fdata [none]
844 **
845 ** @nam3rule Book Print as docbook table
846 ** @nam3rule Html Print as html table
847 ** @nam3rule Wiki Print as wiki table
848 ** @nam3rule Text Print as text
849 **
850 ** @argrule * outf [AjPFile] output file
851 ** @argrule Text full [AjBool] Print all details
852 **
853 ** @valrule * [void]
854 **
855 ** @fcategory cast
856 **
857 ******************************************************************************/
858 
859 
860 
861 
862 /* @func ajResourceoutprintBook ***********************************************
863 **
864 ** Reports the resource format internals as Docbook text
865 **
866 ** @param [u] outf [AjPFile] Output file
867 ** @return [void]
868 **
869 ** @release 6.4.0
870 ** @@
871 ******************************************************************************/
872 
ajResourceoutprintBook(AjPFile outf)873 void ajResourceoutprintBook(AjPFile outf)
874 {
875     ajint i = 0;
876 
877     ajFmtPrintF(outf, "<para>The supported data resource output "
878                 "formats are summarised "
879                 "in the table below. The columns are as follows: "
880                 "<emphasis>Output format</emphasis> (format name), "
881                  "<emphasis>Description</emphasis> (short description of "
882                 "the format).</para> \n\n");
883 
884     ajFmtPrintF(outf, "<table frame=\"box\" rules=\"cols\">\n");
885     ajFmtPrintF(outf, "  <caption>Data resource output formats</caption>\n");
886     ajFmtPrintF(outf, "  <thead>\n");
887     ajFmtPrintF(outf, "    <tr align=\"center\">\n");
888     ajFmtPrintF(outf, "      <th>Output Format</th>\n");
889     ajFmtPrintF(outf, "      <th>Description</th>\n");
890     ajFmtPrintF(outf, "    </tr>\n");
891     ajFmtPrintF(outf, "  </thead>\n");
892     ajFmtPrintF(outf, "  <tbody>\n");
893 
894     for(i=0; resourceoutFormatDef[i].Name; i++)
895     {
896         ajFmtPrintF(outf, "    <tr>\n");
897         ajFmtPrintF(outf, "      <td>%s</td>\n",
898                     resourceoutFormatDef[i].Name);
899         ajFmtPrintF(outf, "      <td>%s</td>\n",
900                     resourceoutFormatDef[i].Desc);
901     }
902 
903     ajFmtPrintF(outf, "  </tbody>\n");
904     ajFmtPrintF(outf, "</table>\n");
905 
906     return;
907 }
908 
909 
910 
911 
912 /* @func ajResourceoutprintHtml ***********************************************
913 **
914 ** Reports the internal data structures
915 **
916 ** @param [u] outf [AjPFile] Output file
917 ** @return [void]
918 **
919 ** @release 6.4.0
920 ** @@
921 ******************************************************************************/
922 
ajResourceoutprintHtml(AjPFile outf)923 void ajResourceoutprintHtml(AjPFile outf)
924 {
925     ajint i = 0;
926 
927     ajFmtPrintF(outf, "<table border=3>");
928     ajFmtPrintF(outf, "<tr><th>Data resource Format</th>\n");
929     ajFmtPrintF(outf, "<th>Description</th></tr>\n");
930     ajFmtPrintF(outf, "\n");
931     ajFmtPrintF(outf, "# Data resource output formats\n");
932     ajFmtPrintF(outf, "# Name    Format name (or alias)\n");
933     ajFmtPrintF(outf, "# Desc    Format description\n");
934     ajFmtPrintF(outf, "# Name         Description\n");
935     ajFmtPrintF(outf, "\n");
936     ajFmtPrintF(outf, "ResourceFormat {\n");
937 
938     for(i=0; resourceoutFormatDef[i].Name; i++)
939     {
940         ajFmtPrintF(outf, "<tr><td>\n%-12s\n"
941                         "<td>\"%s\"</td></tr>\n",
942 			resourceoutFormatDef[i].Name,
943 			resourceoutFormatDef[i].Desc);
944     }
945 
946     ajFmtPrintF(outf, "}\n\n");
947 
948     return;
949 }
950 
951 
952 
953 
954 /* @func ajResourceoutprintText ***********************************************
955 **
956 ** Reports the internal data structures
957 **
958 ** @param [u] outf [AjPFile] Output file
959 ** @param [r] full [AjBool] Full report (usually ajFalse)
960 ** @return [void]
961 **
962 ** @release 6.4.0
963 ** @@
964 ******************************************************************************/
965 
ajResourceoutprintText(AjPFile outf,AjBool full)966 void ajResourceoutprintText(AjPFile outf, AjBool full)
967 {
968     ajint i = 0;
969 
970     ajFmtPrintF(outf, "\n");
971     ajFmtPrintF(outf, "# Data resource output formats\n");
972     ajFmtPrintF(outf, "# Name    Format name (or alias)\n");
973     ajFmtPrintF(outf, "# Desc    Format description\n");
974     ajFmtPrintF(outf, "# Name         Description\n");
975     ajFmtPrintF(outf, "\n");
976     ajFmtPrintF(outf, "ResourceFormat {\n");
977 
978     for(i=0; resourceoutFormatDef[i].Name; i++)
979     {
980 	if(full)
981 	    ajFmtPrintF(outf, "  %-12s \"%s\"\n",
982 			resourceoutFormatDef[i].Name,
983 			resourceoutFormatDef[i].Desc);
984     }
985 
986     ajFmtPrintF(outf, "}\n\n");
987 
988     return;
989 }
990 
991 
992 
993 
994 /* @func ajResourceoutprintWiki ***********************************************
995 **
996 ** Reports the data resource output format internals as wikitext
997 **
998 ** @param [u] outf [AjPFile] Output file
999 ** @return [void]
1000 **
1001 ** @release 6.4.0
1002 ** @@
1003 ******************************************************************************/
1004 
ajResourceoutprintWiki(AjPFile outf)1005 void ajResourceoutprintWiki(AjPFile outf)
1006 {
1007     ajint i = 0;
1008     ajint j = 0;
1009     AjPStr namestr = NULL;
1010 
1011     ajFmtPrintF(outf, "{| class=\"wikitable sortable\" border=\"2\"\n");
1012     ajFmtPrintF(outf, "|-\n");
1013     ajFmtPrintF(outf, "!Format!!"
1014                 "class=\"unsortable\"|Description\n");
1015 
1016     for(i=0; resourceoutFormatDef[i].Name; i++)
1017     {
1018         ajFmtPrintF(outf, "|-\n");
1019         ajStrAssignC(&namestr, resourceoutFormatDef[i].Name);
1020 
1021         for(j=i+1; resourceoutFormatDef[j].Name; j++)
1022         {
1023             if(resourceoutFormatDef[j].Write == resourceoutFormatDef[i].Write)
1024             {
1025                 ajFmtPrintAppS(&namestr, "<br>%s",
1026                                resourceoutFormatDef[j].Name);
1027                 ajWarn("Data resource output format '%s' same as '%s' "
1028                        "but not alias",
1029                        resourceoutFormatDef[j].Name,
1030                        resourceoutFormatDef[i].Name);
1031             }
1032         }
1033         ajFmtPrintF(outf, "|%S||%s\n",
1034 		    namestr,
1035 		    resourceoutFormatDef[i].Desc);
1036     }
1037 
1038     ajFmtPrintF(outf, "|}\n");
1039 
1040     ajStrDel(&namestr);
1041 
1042     return;
1043 }
1044 
1045 
1046 
1047 
1048 /* @section Miscellaneous *****************************************************
1049 **
1050 ** Functions to initialise and clean up internals
1051 **
1052 ** @fdata [none]
1053 **
1054 ** @nam3rule Exit Clean up and exit
1055 **
1056 ** @valrule * [void]
1057 **
1058 ** @fcategory misc
1059 **
1060 ******************************************************************************/
1061 
1062 
1063 
1064 
1065 /* @func ajResourceoutExit ****************************************************
1066 **
1067 ** Cleans up data output internal memory
1068 **
1069 ** @return [void]
1070 **
1071 ** @release 6.4.0
1072 ** @@
1073 ******************************************************************************/
1074 
ajResourceoutExit(void)1075 void ajResourceoutExit(void)
1076 {
1077     return;
1078 }
1079 
1080 
1081 
1082 
1083 /* @datasection [none] Output formats *****************************************
1084 **
1085 ** Output formats internals
1086 **
1087 ** @nam2rule Resourceoutformat Data resource output format specific
1088 **
1089 ******************************************************************************/
1090 
1091 
1092 
1093 
1094 /* @section cast **************************************************************
1095 **
1096 ** Values for output formats
1097 **
1098 ** @fdata [none]
1099 **
1100 ** @nam3rule Find Return index to named format
1101 ** @nam3rule Test Test format value
1102 **
1103 ** @argrule * format [const AjPStr] Format name
1104 ** @argrule Find iformat [ajint*] Index matching format name
1105 **
1106 ** @valrule * [AjBool] True if found
1107 **
1108 ** @fcategory cast
1109 **
1110 ******************************************************************************/
1111 
1112 
1113 
1114 
1115 /* @func ajResourceoutformatFind **********************************************
1116 **
1117 ** Looks for the specified format(s) in the internal definitions and
1118 ** returns the index.
1119 **
1120 ** Sets iformat as the recognised format, and returns ajTrue.
1121 **
1122 ** @param [r] format [const AjPStr] Format required.
1123 ** @param [w] iformat [ajint*] Index
1124 ** @return [AjBool] ajTrue on success.
1125 **
1126 ** @release 6.4.0
1127 ** @@
1128 ******************************************************************************/
1129 
ajResourceoutformatFind(const AjPStr format,ajint * iformat)1130 AjBool ajResourceoutformatFind(const AjPStr format, ajint* iformat)
1131 {
1132     AjPStr tmpformat = NULL;
1133     ajuint i = 0;
1134 
1135     /* ajDebug("ajResourceoutformatFind '%S'\n", format); */
1136     if(!ajStrGetLen(format))
1137 	return ajFalse;
1138 
1139     ajStrAssignS(&tmpformat, format);
1140     ajStrFmtLower(&tmpformat);
1141 
1142     for(i=0; resourceoutFormatDef[i].Name; i++)
1143     {
1144 	/* ajDebug("test %d '%s' \n", i, resourceoutFormatDef[i].Name); */
1145 	if(ajStrMatchCaseC(tmpformat, resourceoutFormatDef[i].Name))
1146 	{
1147 	    *iformat = i;
1148 	    ajStrDel(&tmpformat);
1149 	    /* ajDebug("found '%s' at %d\n", resourceoutFormatDef[i].Name, i); */
1150 	    return ajTrue;
1151 	}
1152     }
1153 
1154     ajErr("Unknown output format '%S'", format);
1155 
1156     ajStrDel(&tmpformat);
1157 
1158     *iformat = 0;
1159 
1160     return ajFalse;
1161 }
1162 
1163 
1164 
1165 
1166 /* @func ajResourceoutformatTest **********************************************
1167 **
1168 ** Tests whether a named data resource output format is known
1169 **
1170 ** @param [r] format [const AjPStr] Format
1171 ** @return [AjBool] ajTrue if formats was accepted
1172 **
1173 ** @release 6.4.0
1174 ** @@
1175 ******************************************************************************/
1176 
ajResourceoutformatTest(const AjPStr format)1177 AjBool ajResourceoutformatTest(const AjPStr format)
1178 {
1179     ajint i;
1180 
1181     for (i=0; resourceoutFormatDef[i].Name; i++)
1182 	if(ajStrMatchCaseC(format, resourceoutFormatDef[i].Name))
1183 	    return ajTrue;
1184 
1185     return ajFalse;
1186 }
1187