1 /* @include ajfeat ************************************************************
2 **
3 ** A genome feature (in AJAX program context) is a description of a
4 ** genomic entity which was determined by some 'source' analysis
5 ** (which may be of 'wet lab' experimental or 'in silico'
6 ** computational nature), has a 'primary' descriptor ('Primary_Tag'),
7 ** may have some 'score' asserting the level of analysis confidence in
8 ** its identity (e.g. log likelihood relative to a null hypothesis or
9 ** other similar entity), has a 'Position' in the genome, and may have
10 ** any arbitrary number of descriptor tags associated with it.
11 **
12 ** @author Copyright (C) 1999 Richard Bruskiewich
13 ** @version $Revision: 1.80 $
14 ** @modified 2000 Ian Longden.
15 ** @modified 2001 Peter Rice.
16 ** @modified $Date: 2013/06/29 22:31:59 $ by $Author: rice $
17 ** @@
18 **
19 ** This library is free software; you can redistribute it and/or
20 ** modify it under the terms of the GNU Lesser General Public
21 ** License as published by the Free Software Foundation; either
22 ** version 2.1 of the License, or (at your option) any later version.
23 **
24 ** This library is distributed in the hope that it will be useful,
25 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27 ** Lesser General Public License for more details.
28 **
29 ** You should have received a copy of the GNU Lesser General Public
30 ** License along with this library; if not, write to the Free Software
31 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
32 ** MA  02110-1301,  USA.
33 ******************************************************************************/
34 
35 #ifndef AJFEAT_H
36 #define AJFEAT_H
37 
38 /* ========================================================================= */
39 /* ============================= include files ============================= */
40 /* ========================================================================= */
41 
42 #include "ajdefine.h"
43 #include "ajexcept.h"
44 #include "ajmem.h"
45 #include "ajreg.h"
46 #include "ajstr.h"
47 #include "ajtagval.h"
48 #include "ajfile.h"
49 #include "ajtime.h"
50 #include "ajfmt.h"
51 #include "ajfeatdata.h"
52 #include "ajseqdata.h"
53 #include <stdlib.h>
54 #include <stdio.h>
55 
56 AJ_BEGIN_DECLS
57 
58 
59 
60 
61 /* ========================================================================= */
62 /* =============================== constants =============================== */
63 /* ========================================================================= */
64 
65 
66 
67 
68 /* ========================================================================= */
69 /* ============================== public data ============================== */
70 /* ========================================================================= */
71 
72 
73 
74 
75 /* ========================================================================= */
76 /* =========================== public functions ============================ */
77 /* ========================================================================= */
78 
79 
80 
81 
82 /*
83 ** Prototype definitions
84 */
85 
86 ajint          ajFeatCompByEnd(const void *a, const void *b);
87 ajint          ajFeatCompByGroup(const void *a, const void *b);
88 ajint          ajFeatCompByStart(const void *a, const void *b);
89 ajint          ajFeatCompByType(const void *a, const void *b);
90 
91 const AjPTable ajFeatVocabGetTags(const char* name);
92 const AjPTable ajFeatVocabGetTagsNuc(const char* name);
93 const AjPTable ajFeatVocabGetTagsProt(const char* name);
94 const AjPTable ajFeatVocabGetTypes(const char* name);
95 const AjPTable ajFeatVocabGetTypesNuc(const char* name);
96 const AjPTable ajFeatVocabGetTypesProt(const char* name);
97 const AjPTable ajFeatVocabInit(const char* name);
98 const AjPTable ajFeatVocabInitNuc(const char* name);
99 const AjPTable ajFeatVocabInitProt(const char* name);
100 AjPFeature    ajFeatNewFeat(const AjPFeature orig);
101 void          ajFeatDel(AjPFeature *pthis);
102 void          ajFeatExit(void);
103 ajuint        ajFeatGetEnd(const AjPFeature thys);
104 char          ajFeatframeGetFrame(ajint frame);
105 char          ajFeatframeGetFrameNuc(ajint frame);
106 char          ajFeatstrandGetStrand(ajint strand);
107 AjBool        ajFeatGetForward(const AjPFeature thys);
108 ajint         ajFeatGetFrame(const AjPFeature thys);
109 ajuint        ajFeatGetLength(const AjPFeature thys);
110 AjBool        ajFeatGetNoteC(const AjPFeature thys, const char* name,
111                              AjPStr* val);
112 AjBool        ajFeatGetNoteCI(const AjPFeature thys, const char* name,
113                               ajint count, AjPStr* val);
114 AjBool        ajFeatGetNoteSI(const AjPFeature thys, const AjPStr name,
115                               ajint count, AjPStr* val);
116 AjBool        ajFeatGetNoteS(const AjPFeature thys, const AjPStr name,
117                              AjPStr* val);
118 AjBool        ajFeatGetRemoteseq(const AjPFeature thys, const AjPStr usa,
119                                  AjPSeq seq);
120 float         ajFeatGetScore(const AjPFeature thys);
121 AjBool        ajFeatGetScorerange(const AjPFeature thys,
122                                   float *minscore, float *maxscore);
123 const AjPStr  ajFeatGetSubtype(const AjPFeature thys);
124 const AjPStr  ajFeatGetSource(const AjPFeature thys);
125 AjBool        ajFeatGetFlags(const AjPFeature thys,  AjPStr* Pflagstr);
126 AjBool        ajFeatGetSeq(const AjPFeature feat,
127                            const AjPSeq seq, AjPStr* seqstr);
128 AjBool        ajFeatGetSeqJoin(const AjPFeature thys,
129                                const AjPSeq seq, AjPStr* Pseqstr);
130 ajuint        ajFeatGetStart(const AjPFeature thys);
131 char          ajFeatGetStrand(const AjPFeature thys);
132 AjBool        ajFeatGetTagC(const AjPFeature thys, const char* tname,
133                             ajint num, AjPStr* val);
134 AjBool        ajFeatGetTagS(const AjPFeature thys, const AjPStr name,
135                             ajint num, AjPStr* val);
136 AjBool        ajFeatGetTranslation(const AjPFeature feat, AjPStr* seqstr);
137 const AjPStr  ajFeatGetType(const AjPFeature thys);
138 AjBool        ajFeatGetXrefs(const AjPFeature thys, AjPList *Pxreflist);
139 AjBool        ajFeatIsCompMult(const AjPFeature gf);
140 AjBool        ajFeatIsLocal(const AjPFeature gf);
141 AjBool        ajFeatIsLocalRange(const AjPFeature gf,
142                                  ajuint start, ajuint end);
143 AjBool        ajFeatIsMultiple(const AjPFeature gf);
144 AjBool        ajFeatLocMark(const AjPFeature thys, const AjPFeattable table,
145                             AjPStr* Pseqstr);
146 AjPFeature    ajFeatNew(AjPFeattable thys,
147                         const AjPStr source, const AjPStr type,
148                         ajint Start, ajint End, float score,
149                         char strand, ajint frame);
150 AjPFeature    ajFeatNewII(AjPFeattable thys,
151                           ajint Start, ajint End);
152 AjPFeature    ajFeatNewIIRev(AjPFeattable thys,
153                              ajint Start, ajint End);
154 AjPFeature    ajFeatNewBetween(AjPFeattable thys,
155                                ajint Start);
156 AjPFeature   ajFeatNewNuc(AjPFeattable thys,
157                           const AjPStr source, const AjPStr type,
158                           ajint Start, ajint End,
159                           float score, char  strand,
160                           ajint frame, ajint exon,
161                           ajint Start2, ajint End2,
162                           const AjPStr entryid,  const AjPStr label);
163 AjPFeature   ajFeatNewNucFlags(AjPFeattable thys,
164                                const AjPStr source, const AjPStr type,
165                                ajint Start, ajint End,
166                                float score, char  strand,
167                                ajint frame, ajint exon,
168                                ajint Start2, ajint End2,
169                                const AjPStr entryid,  const AjPStr label,
170                                ajuint flags);
171 AjPFeature    ajFeatNewProt(AjPFeattable thys,
172                             const AjPStr source, const AjPStr type,
173                             ajint Start, ajint End,
174                             float score);
175 AjPFeature    ajFeatNewProtFlags(AjPFeattable thys,
176                                  const AjPStr source, const AjPStr type,
177                                  ajint Start, ajint End,
178                                  float score,
179                                  ajuint flags);
180 AjPFeature    ajFeatNewSub(AjPFeattable thys, AjPFeature parent,
181                            const AjPStr source, const AjPStr type,
182                            ajint Start, ajint End, float score,
183                            char strand, ajint frame);
184 AjPFeature    ajFeatNewIISub(AjPFeattable thys, AjPFeature parent,
185                              ajint Start, ajint End);
186 AjPFeature    ajFeatNewIIRevSub(AjPFeattable thys, AjPFeature parent,
187                                 ajint Start, ajint End);
188 AjPFeature   ajFeatNewNucSub(AjPFeattable thys, AjPFeature parent,
189                              const AjPStr source, const AjPStr type,
190                              ajint Start, ajint End,
191                              float score, char  strand,
192                              ajint frame, ajint exon,
193                              ajint Start2, ajint End2,
194                              const AjPStr entryid,  const AjPStr label);
195 AjPFeature   ajFeatNewNucFlagsSub(AjPFeattable thys, AjPFeature parent,
196                                   const AjPStr source, const AjPStr type,
197                                   ajint Start, ajint End,
198                                   float score, char  strand,
199                                   ajint frame, ajint exon,
200                                   ajint Start2, ajint End2,
201                                   const AjPStr entryid,  const AjPStr label,
202                                   ajuint flags);
203 AjPFeature    ajFeatNewProtSub(AjPFeattable thys, AjPFeature parent,
204                                const AjPStr source, const AjPStr type,
205                                ajint Start, ajint End,
206                                float score);
207 AjPFeature    ajFeatNewProtFlagsSub(AjPFeattable thys, AjPFeature parent,
208                                     const AjPStr source, const AjPStr type,
209                                     ajint Start, ajint End,
210                                     float score,
211                                     ajuint flags);
212 void          ajFeatReverse(AjPFeature thys, ajint ilen);
213 void          ajFeatSetDesc(AjPFeature thys, const AjPStr desc);
214 void          ajFeatSetDescApp(AjPFeature thys, const AjPStr desc);
215 void          ajFeatSetScore(AjPFeature thys, float score);
216 void          ajFeatSetSource(AjPFeature thys, const AjPStr source);
217 void          ajFeatSetStrand(AjPFeature thys, AjBool rev);
218 void          ajFeatSortByEnd(AjPFeattable Feattab);
219 void          ajFeatSortByStart(AjPFeattable Feattab);
220 void          ajFeatSortByType(AjPFeattable Feattab);
221 void          ajFeattableAdd(AjPFeattable thys, AjPFeature feature);
222 void          ajFeattableAddNew(AjPFeattable thys, AjPFeature feature);
223 void          ajFeattableClear(AjPFeattable thys);
224 void          ajFeattableDel(AjPFeattable *pthis);
225 ajint         ajFeattableGetBegin(const AjPFeattable thys);
226 ajint         ajFeattableGetEnd(const AjPFeattable thys);
227 const AjPStr  ajFeattableGetEntry(const AjPFeattable thys);
228 ajint         ajFeattableGetLen(const AjPFeattable thys);
229 const AjPStr  ajFeattableGetName(const AjPFeattable thys);
230 const char*   ajFeattableGetQryC(const AjPFeattable ftable);
231 const AjPStr  ajFeattableGetQryS(const AjPFeattable ftable);
232 AjBool        ajFeattableGetScorerange(const AjPFeattable thys,
233                                        float *minscore, float *maxscore);
234 ajuint        ajFeattableGetSize(const AjPFeattable thys);
235 const char*   ajFeattableGetTypeC(const AjPFeattable thys);
236 const AjPStr  ajFeattableGetTypeS(const AjPFeattable thys);
237 AjBool        ajFeattableGetXrefs(const AjPFeattable thys, AjPList *Pxreflist,
238                                   ajuint *Ptaxid);
239 AjBool        ajFeattableIsCircular(const AjPFeattable thys);
240 AjBool        ajFeattableIsNuc(const AjPFeattable thys);
241 AjBool        ajFeattableIsProt(const AjPFeattable thys);
242 ajuint        ajFeattableMerge(AjPFeattable thys, const AjPFeattable srctable);
243 AjPFeattable  ajFeattableNew(const AjPStr name);
244 AjPFeattable  ajFeattableNewDna(const AjPStr name);
245 AjPFeattable  ajFeattableNewFtable(const AjPFeattable orig);
246 AjPFeattable  ajFeattableNewFtableLimit(const AjPFeattable orig, ajint limit);
247 AjPFeattable  ajFeattableNewProt(const AjPStr name);
248 AjPFeattable  ajFeattableNewSeq(const AjPSeq seq);
249 ajuint        ajFeattablePos(const AjPFeattable thys, ajint ipos);
250 ajuint        ajFeattablePosI(const AjPFeattable thys,
251                               ajuint imin, ajint ipos);
252 ajuint        ajFeattablePosII(ajuint ilen, ajuint imin, ajint ipos);
253 void          ajFeattableReset(AjPFeattable thys, const AjPStr name);
254 void          ajFeattableReverse(AjPFeattable  thys);
255 void          ajFeattableSetCircular(AjPFeattable thys);
256 void          ajFeattableSetDefname(AjPFeattable thys, const AjPStr setname);
257 void          ajFeattableSetLength(AjPFeattable thys, ajuint len);
258 void          ajFeattableSetLinear(AjPFeattable thys);
259 void          ajFeattableSetNuc(AjPFeattable thys);
260 void          ajFeattableSetProt(AjPFeattable thys);
261 void          ajFeattableSetRange(AjPFeattable thys,
262                                   ajint fbegin, ajint fend);
263 void          ajFeattableSetReverse(AjPFeattable thys);
264 void          ajFeattableTrace(const AjPFeattable thys);
265 AjBool        ajFeattableTrim(AjPFeattable thys);
266 AjBool        ajFeattableTrimOff(AjPFeattable thys,
267                                  ajuint ioffset, ajuint ilen);
268 AjPFeatGfftags ajFeatGfftagsNew(void);
269 void           ajFeatGfftagsDel(AjPFeatGfftags*Pthys);
270 AjPFeatGfftags ajFeatGetGfftags(const AjPFeature thys);
271 void           ajFeatGfftagTrace(const AjPFeature thys);
272 const AjPStr   ajFeatGetId(const AjPFeature thys);
273 const AjPStr   ajFeatGetParent(const AjPFeature thys);
274 
275 ajuint        ajFeatGfftagAddSS(AjPFeature thys,
276                                 const AjPStr tag, const AjPStr value);
277 ajuint        ajFeatGfftagAddCS(AjPFeature thys,
278                                 const char* tag, const AjPStr value);
279 AjBool        ajFeatGfftagAddTag(AjPFeature thys, const AjPTagval tagval);
280 
281 AjBool        ajFeatTagAddSS(AjPFeature thys,
282                              const AjPStr tag, const AjPStr value);
283 AjBool        ajFeatTagAddCS(AjPFeature thys,
284                              const char* tag, const AjPStr value);
285 AjBool        ajFeatTagAddCC(AjPFeature thys,
286                              const char* tag, const char* value);
287 AjBool        ajFeatTagAddTag(AjPFeature thys, const AjPTagval tagval);
288 AjIList       ajFeatSubIter(const AjPFeature thys);
289 AjIList       ajFeatTagIter(const AjPFeature thys);
290 AjBool        ajFeatTagSet(AjPFeature thys,
291                            const AjPStr tag, const AjPStr value);
292 AjBool        ajFeatTagSetC(AjPFeature thys,
293                             const char* tag, const AjPStr value);
294 void          ajFeatTagTrace(const AjPFeature thys);
295 AjBool        ajFeatTagval(AjIList iter, AjPStr* tagnam,
296                            AjPStr* tagval);
297 void          ajFeatTest(void);
298 void          ajFeatTrace(const AjPFeature thys);
299 AjBool        ajFeatTrimOffRange(AjPFeature ft, ajuint ioffset,
300                                  ajuint begin, ajuint end,
301                                  AjBool dobegin, AjBool doend);
302 const AjPStr  ajFeatTypeGetCategory(const AjPStr type);
303 AjBool        ajFeatTypeIsCds(const AjPFeature gf);
304 AjBool        ajFeatTypeMatchC(const AjPFeature gf, const char* txt);
305 AjBool        ajFeatTypeMatchS(const AjPFeature gf, const AjPStr str);
306 AjBool        ajFeatTypeMatchWildS(const AjPFeature gf, const AjPStr str);
307 const AjPStr  ajFeatTypeNuc(const AjPStr type);
308 const AjPStr  ajFeatTypeProt(const AjPStr type);
309 AjBool        ajFeattagIsNote(const AjPStr tag);
310 
311 void          ajFeatUnused(void);
312 void          ajFeatWarn(const char* fmt, ...);
313 const AjPStr  ajFeattypeGetExternal(const AjPStr type, const AjPTable table);
314 const AjPStr  ajFeattypeGetInternal(const AjPStr type);
315 const AjPStr  ajFeattypeGetInternalEmbl(const AjPStr type);
316 const AjPStr  ajFeattypeGetInternalNuc(const AjPStr type);
317 const AjPStr  ajFeattypeGetInternalPir(const AjPStr type);
318 const AjPStr  ajFeattypeGetInternalProt(const AjPStr type);
319 const AjPStr  ajFeattypeGetInternalRefseqp(const AjPStr type);
320 AjBool        ajFeattagSpecial(const AjPStr tag, AjPStr* pval);
321 AjBool        ajFeattagSpecialGff2(const AjPStr tag, AjPStr* pval);
322 AjBool        ajFeattagSpecialGff3(const AjPStr tag, AjPStr* pval);
323 void          ajFeattagFormat(const AjPStr name, const AjPTable table,
324                               AjPStr* retstr);
325 const AjPStr  ajFeattagGetNameC(const char *tag, const AjPTable table,
326                                 AjBool* known);
327 const AjPStr  ajFeattagGetNameS(const AjPStr name, const AjPTable table,
328                                 AjBool* known);
329 void          ajFeattagGetLimit(const AjPStr name, const AjPTable table,
330                                 AjPStr* retstr);
331 
332 /*
333 ** End of prototype definitions
334 */
335 
336 /*
337 //#define       MAJFEATOBJVERIFY(p,c) ajFeatObjAssert((p), (c), \
338 //      __FILE__, __LINE__)
339 //#define       MAJFEATSETSCORE(p,s) (((AjPFeature)(p))->Score=(s))
340 //#define       MAJFEATSCORE(p)    ((p)->Score)
341 //#define       MAJFEATSOURCE(p)   ((p)->Source)
342 //#define       MAJFEATTYPE(p)     ((p)->Type)
343 //#define       MAJFEATTABSETVERSION(p,v) ((p)->Version=(v))
344 //#define       MAJFEATTABSETDATE(p,d)    ((p)->Date=(d))
345 //#define       MAJFEATTABDEFFORMAT(p,f)  ((p)->DefFormat=(f))
346 //#define       MAJFEATTABFORMAT(p)       ((p)->Format)
347 //#define       MAJFEATTABVERSION(p)      ((p)->Version)
348 //#define       MAJFEATTABDATE(p)         ((p)->Date)
349 //#define       MAJFEATTABDICTIONARY(p)   ((p)->Dictionary)
350 //#define       MAJFEATVOCABREADONLY(p,f) ((p)?(p)->ReadOnly=(f):AjTrue)
351 */
352 
353 
354 #ifdef AJ_COMPILE_DEPRECATED_BOOK
355 #endif /* AJ_COMPILE_DEPRECATED_BOOK */
356 
357 #ifdef AJ_COMPILE_DEPRECATED
358 
359 __deprecated AjBool        ajFeatGetNoteI(const AjPFeature thys,
360                                           const AjPStr name,
361                                           ajint count, AjPStr* val);
362 __deprecated AjPFeature    ajFeatCopy(const AjPFeature orig);
363 __deprecated AjPFeattable  ajFeattableCopy(const AjPFeattable orig);
364 __deprecated AjPFeattable  ajFeattableCopyLimit(const AjPFeattable orig,
365                                                 ajint limit);
366 __deprecated AjPFeattable  ajFeatUfoRead(AjPFeattabIn tabin, const AjPStr Ufo);
367 __deprecated AjPFeattable  ajFeatRead(AjPFeattabIn ftin);
368 __deprecated ajint         ajFeattableBegin(const AjPFeattable thys);
369 __deprecated ajint         ajFeattableEnd(const AjPFeattable thys);
370 __deprecated ajint         ajFeattableLen(const AjPFeattable thys);
371 __deprecated ajint         ajFeattableSize(const AjPFeattable thys);
372 __deprecated void          ajFeatDefName(AjPFeattable thys,
373                                          const AjPStr setname);
374 __deprecated AjBool        ajFeatGetNote(const AjPFeature thys,
375                                          const AjPStr name, AjPStr* val);
376 
377 __deprecated ajuint        ajFeatGfftagAdd(AjPFeature thys,
378                                            const AjPStr tag,
379                                            const AjPStr value);
380 __deprecated ajuint        ajFeatGfftagAddC(AjPFeature thys,
381                                             const char* tag,
382                                             const AjPStr value);
383 
384 __deprecated AjBool        ajFeatTagAdd(AjPFeature thys,
385                                         const AjPStr tag, const AjPStr value);
386 __deprecated AjBool        ajFeatTagAddC(AjPFeature thys,
387                                          const char* tag, const AjPStr value);
388 __deprecated AjBool        ajFeatIsChild(const AjPFeature gf);
389 
390 #endif /* AJ_COMPILE_DEPRECATED */
391 
392 
393 
394 
395 AJ_END_DECLS
396 
397 #endif /* AJFEAT_H */
398