1 /* @source ensutility *********************************************************
2 **
3 ** Ensembl Utility functions
4 **
5 ** @author Copyright (C) 1999 Ensembl Developers
6 ** @author Copyright (C) 2006 Michael K. Schuster
7 ** @version $Revision: 1.26 $
8 ** @modified 2009 by Alan Bleasby for incorporation into EMBOSS core
9 ** @modified $Date: 2012/03/09 20:33:25 $ by $Author: mks $
10 ** @@
11 **
12 ** This library is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU Lesser General Public
14 ** License as published by the Free Software Foundation; either
15 ** version 2.1 of the License, or (at your option) any later version.
16 **
17 ** This library is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ** Lesser General Public License for more details.
21 **
22 ** You should have received a copy of the GNU Lesser General Public
23 ** License along with this library; if not, write to the Free Software
24 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 ** MA  02110-1301,  USA.
26 **
27 ******************************************************************************/
28 
29 /* ========================================================================= */
30 /* ============================= include files ============================= */
31 /* ========================================================================= */
32 
33 #include "ensregistry.h"
34 #include "enstranslation.h"
35 #include "ensutility.h"
36 
37 
38 
39 
40 /* ========================================================================= */
41 /* =============================== constants =============================== */
42 /* ========================================================================= */
43 
44 
45 
46 
47 /* ========================================================================= */
48 /* =========================== global variables ============================ */
49 /* ========================================================================= */
50 
51 
52 
53 
54 /* ========================================================================= */
55 /* ============================= private data ============================== */
56 /* ========================================================================= */
57 
58 
59 
60 
61 /* ========================================================================= */
62 /* =========================== private constants =========================== */
63 /* ========================================================================= */
64 
65 
66 
67 
68 /* ========================================================================= */
69 /* =========================== private variables =========================== */
70 /* ========================================================================= */
71 
72 /* #varstatic utilityGInit ****************************************************
73 **
74 ** Private boolean variable to ascertain that ensInit has been called once
75 ** and only once.
76 **
77 ******************************************************************************/
78 
79 static AjBool utilityGInit = AJFALSE;
80 
81 
82 
83 
84 /* ========================================================================= */
85 /* =========================== private functions =========================== */
86 /* ========================================================================= */
87 
88 
89 
90 
91 /* ========================================================================= */
92 /* ======================= All functions by section ======================== */
93 /* ========================================================================= */
94 
95 
96 
97 
98 /* @filesection ensutility ****************************************************
99 **
100 ** @nam1rule ens Function belongs to the Ensembl library
101 **
102 ******************************************************************************/
103 
104 
105 
106 
107 /* @datasection [none] Internals **********************************************
108 **
109 ** Functions to control Ensembl internals
110 **
111 ******************************************************************************/
112 
113 
114 
115 
116 /* @section Initialise ********************************************************
117 **
118 ** @fdata [none]
119 **
120 ** @nam2rule Init Initialise Ensembl internals
121 **
122 ** @valrule * [void]
123 **
124 ** @fcategory internals
125 ******************************************************************************/
126 
127 
128 
129 
130 /* @func ensInit **************************************************************
131 **
132 ** Initialises Ensembl internals.
133 **
134 ** @return [void]
135 **
136 ** @release 6.2.0
137 ** @@
138 ******************************************************************************/
139 
ensInit(void)140 void ensInit(void)
141 {
142     if (utilityGInit)
143         return;
144 
145     ensRegistryInit();
146 
147     ensTranslationInit();
148 
149     utilityGInit = ajTrue;
150 
151     return;
152 }
153 
154 
155 
156 
157 /* @section Exit **************************************************************
158 **
159 ** @fdata [none]
160 **
161 ** @nam2rule Exit Clear Ensembl internals
162 **
163 ** @valrule * [void]
164 **
165 ** @fcategory internals
166 ******************************************************************************/
167 
168 
169 
170 
171 /* @func ensExit **************************************************************
172 **
173 ** Clears Ensembl internals.
174 **
175 ** @return [void]
176 **
177 ** @release 6.2.0
178 ** @@
179 ******************************************************************************/
180 
ensExit(void)181 void ensExit(void)
182 {
183     if (!utilityGInit)
184         return;
185 
186     ensRegistryExit();
187 
188     ensTranslationExit();
189 
190     utilityGInit = ajFalse;
191 
192     return;
193 }
194 
195 
196 
197 
198 /* @section miscellaneous *****************************************************
199 **
200 ** Miscellaneous functions with no specific Ensembl datatype
201 **
202 ** @fdata [none]
203 **
204 ** @nam2rule Trace    Debug output
205 ** @nam3rule Query    AJAX Query
206 ** @nam3rule Seqin    AJAX Sequence Input
207 ** @nam3rule Seqdesc  Sequence Description
208 ** @nam3rule Seq      AJAX Sequence
209 ** @nam3rule Textin   AJAX Text Input
210 **
211 ** @argrule Query     qry      [const AjPQuery]    AJAX Query
212 ** @argrule Seq       seq      [const AjPSeq]      AJAX Sequence
213 ** @argrule Seqdesc   seqdesc  [const AjPSeqDesc]  AJAX Sequence Description
214 ** @argrule Seqin     seqin    [const AjPSeqin]    AJAX Sequence Input
215 ** @argrule Textin    textin   [const AjPTextin]   AJAX Text Input
216 ** @argrule Trace     level    [ajuint]            Indentation level
217 **
218 ** @valrule * [AjBool] True on success
219 **
220 ** @fcategory misc
221 ******************************************************************************/
222 
223 
224 
225 
226 /* @func ensTraceQuery ********************************************************
227 **
228 ** Trace an AJAX Query object.
229 **
230 ** @param [r] qry [const AjPQuery] AJAX Query
231 ** @param [r] level [ajuint] Indentation level
232 **
233 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
234 **
235 ** @release 6.4.0
236 ** @@
237 ******************************************************************************/
238 
ensTraceQuery(const AjPQuery qry,ajuint level)239 AjBool ensTraceQuery(const AjPQuery qry, ajuint level)
240 {
241     AjPStr indent = NULL;
242     AjIList iter = NULL;
243     AjPQueryField field = NULL;
244 
245     if (!qry)
246         return ajFalse;
247 
248     indent = ajStrNew();
249 
250     ajStrAppendCountK(&indent, ' ', level * 2);
251 
252     ajDebug("%SensTraceQuery %p\n"
253             "%S  SvrName      '%S'\n"
254             "%S  DbName       '%S'\n"
255             "%S  DbAlias      '%S'\n"
256             "%S  DbType       '%S'\n"
257             "%S  QueryFields   %p\n"
258             "%S  ResultsList   %p\n"
259             "%S  ResultsTable  %p\n"
260             "%S  Method       '%S'\n"
261             "%S  Qlinks       '%S'\n"
262             "%S  Formatstr    '%S'\n"
263             "%S  IndexDir     '%S'\n"
264             "%S  Directory    '%S'\n"
265             "%S  Filename     '%S'\n"
266             "%S  Exclude      '%S'\n"
267             "%S  DbFields     '%S'\n"
268             "%S  DbFilter     '%S'\n"
269             "%S  DbReturn     '%S'\n"
270             "%S  DbIdentifier '%S'\n"
271             "%S  DbAccession  '%S'\n"
272             "%S  DbUrl        '%S'\n"
273             "%S  DbProxy      '%S'\n"
274             "%S  DbHttpVer    '%S'\n"
275             "%S  ServerVer    '%S'\n"
276             "%S  SingleField  '%S'\n"
277             "%S  QryString    '%S'\n"
278             "%S  QryFields    '%S'\n"
279             "%S  Application  '%S'\n"
280             "%S  Fpos          %Ld\n"
281             "%S  TextAccess    %p\n"
282             "%S  Access        %p\n"
283             "%S  QryData       %p\n"
284             "%S  QueryType     %d\n"
285             "%S  DataType      %d\n"
286             "%S  QryDone      '%B'\n"
287             "%S  SetServer    '%B'\n"
288             "%S  SetDatabase  '%B'\n"
289             "%S  SetQuery     '%B'\n"
290             "%S  Wild         '%B'\n"
291             "%S  CaseId       '%B'\n"
292             "%S  HasAcc       '%B'\n"
293             "%S  CountEntries  %u\n"
294             "%S  TotalEntries  %u\n",
295             indent, qry,
296             indent, qry->SvrName,
297             indent, qry->DbName,
298             indent, qry->DbAlias,
299             indent, qry->DbType,
300             indent, qry->QueryFields,
301             indent, qry->ResultsList,
302             indent, qry->ResultsTable,
303             indent, qry->Method,
304             indent, qry->Qlinks,
305             indent, qry->Formatstr,
306             indent, qry->IndexDir,
307             indent, qry->Directory,
308             indent, qry->Filename,
309             indent, qry->Exclude,
310             indent, qry->DbFields,
311             indent, qry->DbFilter,
312             indent, qry->DbReturn,
313             indent, qry->DbIdentifier,
314             indent, qry->DbAccession,
315             indent, qry->DbUrl,
316             indent, qry->DbProxy,
317             indent, qry->DbHttpVer,
318             indent, qry->ServerVer,
319             indent, qry->SingleField,
320             indent, qry->QryString,
321             indent, qry->QryFields,
322             indent, qry->Application,
323             indent, qry->Fpos,
324             indent, qry->TextAccess,
325             indent, qry->Access,
326             indent, qry->QryData,
327             indent, qry->QueryType,
328             indent, qry->DataType,
329             indent, qry->QryDone,
330             indent, qry->SetServer,
331             indent, qry->SetDatabase,
332             indent, qry->SetQuery,
333             indent, qry->Wild,
334             indent, qry->CaseId,
335             indent, qry->HasAcc,
336             indent, qry->CountEntries,
337             indent, qry->TotalEntries);
338 
339     ajDebug("%S  AJAX List %p of AJAX Query Field objects:\n",
340             indent,
341             qry->QueryFields);
342 
343     iter = ajListIterNewread(qry->QueryFields);
344     while (!ajListIterDone(iter))
345     {
346         field = (AjPQueryField) ajListIterGet(iter);
347         ajDebug("%S    %10.10S   '%S'\n",
348                 indent, field->Field, field->Wildquery);
349     }
350     ajListIterDel(&iter);
351 
352     ajStrDel(&indent);
353 
354     return ajTrue;
355 }
356 
357 
358 
359 
360 /* @func ensTraceSeq **********************************************************
361 **
362 ** Trace an AJAX Sequence object.
363 **
364 ** @param [r] seq [const AjPSeq] AJAX Sequence
365 ** @param [r] level [ajuint] Indentation level
366 **
367 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
368 **
369 ** @release 6.4.0
370 ** @@
371 ******************************************************************************/
372 
ensTraceSeq(const AjPSeq seq,ajuint level)373 AjBool ensTraceSeq(const AjPSeq seq, ajuint level)
374 {
375     AjPStr indent = NULL;
376 
377     if (!seq)
378         return ajFalse;
379 
380     indent = ajStrNew();
381 
382     ajStrAppendCountK(&indent, ' ', level * 2);
383 
384     ajDebug("%SensTraceSeq %p\n"
385             "%S  Name      '%S'\n"
386             "%S  Acc       '%S'\n"
387             "%S  Sv        '%S'\n"
388             "%S  Gi        '%S'\n"
389             "%S  Tax       '%S'\n"
390             "%S  Taxid     '%S'\n"
391             "%S  Organelle '%S'\n"
392             "%S  Type      '%S'\n"
393             "%S  Molecule  '%S'\n"
394             "%S  Class     '%S'\n"
395             "%S  Division  '%S'\n"
396             "%S  Evidence  '%S'\n"
397             "%S  Db        '%S'\n"
398             "%S  Setdb     '%S'\n"
399             "%S  Full      '%S'\n"
400             "%S  Date       %p\n"
401             "%S  Desc      '%S'\n"
402             "%S  Fulldesc   %p\n"
403             "%S  Doc       '%S'\n"
404             "%S  Usa       '%S'\n"
405             "%S  Ufo       '%S'\n"
406             "%S  Formatstr '%S'\n"
407             "%S  Filename  '%S'\n"
408             "%S  Entryname '%S'\n"
409             "%S  TextPtr   '%S'\n"
410             "%S  Acclist    %p\n"
411             "%S  Keylist    %p\n"
412             "%S  Taxlist    %p\n"
413             "%S  Genelist   %p\n"
414             "%S  Reflist    %p\n"
415             "%S  Cmtlist    %p\n"
416             "%S  Xreflist   %p\n"
417             "%S  Seq        %p\n"
418             "%S  Fttable    %p\n"
419             "%S  Accuracy   %p\n"
420             "%S  Fpos       %Ld\n"
421             "%S  Rev       '%B'\n"
422             "%S  Reversed  '%B'\n"
423             "%S  Trimmed   '%B'\n"
424             "%S  Circular  '%B'\n"
425             "%S  Begin      %d\n"
426             "%S  End        %d\n"
427             "%S  Offset     %u\n"
428             "%S  Offend     %u\n"
429             "%S  Qualsize   %u\n"
430             "%S  Weight     %f\n"
431             "%S  Format     %d\n"
432             "%S  Etype      %d\n",
433             indent, seq,
434             indent, seq->Name,
435             indent, seq->Acc,
436             indent, seq->Sv,
437             indent, seq->Gi,
438             indent, seq->Tax,
439             indent, seq->Taxid,
440             indent, seq->Organelle,
441             indent, seq->Type,
442             indent, seq->Molecule,
443             indent, seq->Type,
444             indent, seq->Division,
445             indent, seq->Evidence,
446             indent, seq->Db,
447             indent, seq->Setdb,
448             indent, seq->Full,
449             indent, seq->Date,
450             indent, seq->Desc,
451             indent, seq->Fulldesc,
452             indent, seq->Doc,
453             indent, seq->Usa,
454             indent, seq->Ufo,
455             indent, seq->Formatstr,
456             indent, seq->Filename,
457             indent, seq->Entryname,
458             indent, seq->TextPtr,
459             indent, seq->Acclist,
460             indent, seq->Keylist,
461             indent, seq->Taxlist,
462             indent, seq->Genelist,
463             indent, seq->Reflist,
464             indent, seq->Cmtlist,
465             indent, seq->Xreflist,
466             indent, seq->Seq,
467             indent, seq->Fttable,
468             indent, seq->Accuracy,
469             indent, seq->Fpos,
470             indent, seq->Rev,
471             indent, seq->Reversed,
472             indent, seq->Trimmed,
473             indent, seq->Circular,
474             indent, seq->Begin,
475             indent, seq->End,
476             indent, seq->Offset,
477             indent, seq->Offend,
478             indent, seq->Qualsize,
479             indent, seq->Weight,
480             indent, seq->Format,
481             indent, seq->EType);
482 
483     ajStrDel(&indent);
484 
485     return ajTrue;
486 }
487 
488 
489 
490 
491 /* @func ensTraceSeqdesc ******************************************************
492 **
493 ** Trace an AJAX Sequence Description object.
494 **
495 ** @param [r] seqdesc [const AjPSeqDesc] AJAX Sequence Description
496 ** @param [r] level [ajuint] Indentation level
497 **
498 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
499 **
500 ** @release 6.4.0
501 ** @@
502 ******************************************************************************/
503 
ensTraceSeqdesc(const AjPSeqDesc seqdesc,ajuint level)504 AjBool ensTraceSeqdesc(const AjPSeqDesc seqdesc, ajuint level)
505 {
506     AjIList iter = NULL;
507 
508     AjPStr indent = NULL;
509     AjPStr value = NULL;
510 
511     if (!seqdesc)
512         return ajFalse;
513 
514     indent = ajStrNew();
515 
516     ajStrAppendCountK(&indent, ' ', level * 2);
517 
518     ajDebug("%SensTraceSeqdesc %p\n"
519             "%S  Name      '%S'\n"
520             "%S  Short      %p\n"
521             "%S  EC         %p\n"
522             "%S  AltNames   %p\n"
523             "%S  SubNames   %p\n"
524             "%S  Includes   %p\n"
525             "%S  Contains   %p\n"
526             "%S  Precursor '%B'\n"
527             "%S  Fragments  %u\n",
528             indent, seqdesc,
529             indent, seqdesc->Name,
530             indent, seqdesc->Short,
531             indent, seqdesc->EC,
532             indent, seqdesc->AltNames,
533             indent, seqdesc->SubNames,
534             indent, seqdesc->Includes,
535             indent, seqdesc->Contains,
536             indent, seqdesc->Precursor,
537             indent, seqdesc->Fragments);
538 
539     /* Trace the AJAX List of AJAX String short names. */
540 
541     if (seqdesc->Short)
542     {
543         ajDebug("%S    AJAX List of AJAX String short names:\n", indent);
544 
545         iter = ajListIterNew(seqdesc->Short);
546 
547         while (!ajListIterDone(iter))
548         {
549             value = (AjPStr) ajListIterGet(iter);
550 
551             ajDebug("%S      '%S'\n", indent, value);
552         }
553 
554         ajListIterDel(&iter);
555     }
556 
557     /* Trace the AJAX List of AJAX String EC numbers. */
558 
559     if (seqdesc->EC)
560     {
561         ajDebug("%S    AJAX List of AJAX String EC numbers:\n", indent);
562 
563         iter = ajListIterNew(seqdesc->EC);
564 
565         while (!ajListIterDone(iter))
566         {
567             value = (AjPStr) ajListIterGet(iter);
568 
569             ajDebug("%S      '%S'\n", indent, value);
570         }
571 
572         ajListIterDel(&iter);
573     }
574 
575     ajStrDel(&indent);
576 
577     return ajTrue;
578 }
579 
580 
581 
582 
583 /* @func ensTraceSeqin ********************************************************
584 **
585 ** Trace an AJAX Sequence Input object.
586 **
587 ** @param [r] seqin [const AjPSeqin] AJAX Sequence Input
588 ** @param [r] level [ajuint] Indentation level
589 **
590 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
591 **
592 ** @release 6.4.0
593 ** @@
594 ******************************************************************************/
595 
ensTraceSeqin(const AjPSeqin seqin,ajuint level)596 AjBool ensTraceSeqin(const AjPSeqin seqin, ajuint level)
597 {
598     AjPStr indent = NULL;
599 
600     indent = ajStrNew();
601 
602     ajStrAppendCountK(&indent, ' ', level * 2);
603 
604     ajDebug("%SensTraceSeqin %p\n"
605             "%S  Textin        %p\n"
606             "%S  Name         '%S'\n"
607             "%S  Acc          '%S'\n"
608             "%S  Inputtype    '%S'\n"
609             "%S  Type         '%S'\n"
610             "%S  Full         '%S'\n"
611             "%S  Date         '%S'\n"
612             "%S  Desc         '%S'\n"
613             "%S  Doc          '%S'\n"
614             "%S  Inseq        '%S'\n"
615             "%S  DbSequence   '%S'\n"
616             "%S  Usalist       %p\n"
617             "%S  Begin         %d\n"
618             "%S  End           %d\n"
619             "%S  Ufo          '%S'\n"
620             "%S  Fttable       %p\n"
621             "%S  Ftquery       %p\n"
622             "%S  Entryname    '%S'\n"
623             "%S  Features     '%B'\n"
624             "%S  IsNuc        '%B'\n"
625             "%S  IsProt       '%B'\n"
626             "%S  multiset     '%B'\n"
627             "%S  multidone    '%B'\n"
628             "%S  Lower        '%B'\n"
629             "%S  Upper        '%B'\n"
630             "%S  Rev          '%B'\n"
631             "%S  SeqData       %p\n",
632             indent, seqin,
633             indent, seqin->Input,
634             indent, seqin->Name,
635             indent, seqin->Acc,
636             indent, seqin->Inputtype,
637             indent, seqin->Type,
638             indent, seqin->Full,
639             indent, seqin->Date,
640             indent, seqin->Desc,
641             indent, seqin->Doc,
642             indent, seqin->Inseq,
643             indent, seqin->DbSequence,
644             indent, seqin->Usalist,
645             indent, seqin->Begin,
646             indent, seqin->End,
647             indent, seqin->Ufo,
648             indent, seqin->Fttable,
649             indent, seqin->Ftquery,
650             indent, seqin->Entryname,
651             indent, seqin->Features,
652             indent, seqin->IsNuc,
653             indent, seqin->IsProt,
654             indent, seqin->Multiset,
655             indent, seqin->Multidone,
656             indent, seqin->Lower,
657             indent, seqin->Upper,
658             indent, seqin->Rev,
659             indent, seqin->SeqData);
660 
661     ajStrDel(&indent);
662 
663     ensTraceTextin(seqin->Input, level + 1);
664 
665     return ajTrue;
666 }
667 
668 
669 
670 
671 /* @func ensTraceTextin *******************************************************
672 **
673 ** Trace an AJAX Text Input object.
674 **
675 ** @param [r] textin [const AjPTextin] AJAX Text Input
676 ** @param [r] level [ajuint] Indentation level
677 **
678 ** @return [AjBool] ajTrue upon success, ajFalse otherwise
679 **
680 ** @release 6.4.0
681 ** @@
682 ******************************************************************************/
683 
ensTraceTextin(const AjPTextin textin,ajuint level)684 AjBool ensTraceTextin(const AjPTextin textin, ajuint level)
685 {
686     AjPStr indent = NULL;
687 
688     if (!textin)
689         return ajFalse;
690 
691     indent = ajStrNew();
692 
693     ajStrAppendCountK(&indent, ' ', level * 2);
694 
695     ajDebug("%SensTraceTextin  %p\n"
696             "%S  Db           '%S'\n"
697             "%S  Qry          '%S'\n"
698             "%S  Formatstr    '%S'\n"
699             "%S  Filename     '%S'\n"
700             "%S  List          %p\n"
701             "%S  Filebuff      %p\n"
702             "%S  Fpos          %Ld\n"
703             "%S  Query         %p\n"
704             "%S  TextData      %p\n"
705             "%S  Search       '%B'\n"
706             "%S  Single       '%B'\n"
707             "%S  Multi        '%B'\n"
708             "%S  CaseId       '%B'\n"
709             "%S  Text         '%B'\n"
710             "%S  ChunkEntries '%B'\n"
711             "%S  Count         %u\n"
712             "%S  Filecount     %u\n"
713             "%S  Entrycount    %u\n"
714             "%S  Records       %u\n"
715             "%S  Format        %d\n",
716             indent, textin,
717             indent, textin->Db,
718             indent, textin->Qry,
719             indent, textin->Formatstr,
720             indent, textin->Filename,
721             indent, textin->List,
722             indent, textin->Filebuff,
723             indent, textin->Fpos,
724             indent, textin->Query,
725             indent, textin->TextData,
726             indent, textin->Search,
727             indent, textin->Single,
728             indent, textin->Multi,
729             indent, textin->CaseId,
730             indent, textin->Text,
731             indent, textin->ChunkEntries,
732             indent, textin->Count,
733             indent, textin->Filecount,
734             indent, textin->Entrycount,
735             indent, textin->Records,
736             indent, textin->Format);
737 
738     ajStrDel(&indent);
739 
740     ensTraceQuery(textin->Query, level + 1);
741 
742     return ajTrue;
743 }
744