File: ensassembly.c

package info (click to toggle)
emboss 6.6.0%2Bdfsg-15
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 571,580 kB
  • sloc: ansic: 460,579; java: 29,383; perl: 13,573; sh: 12,753; makefile: 3,295; csh: 706; asm: 351; xml: 239; pascal: 237; modula3: 8
file content (611 lines) | stat: -rw-r--r-- 17,705 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
/* @source ensassembly ********************************************************
**
** Ensembl Assembly functions
**
** @author Copyright (C) 1999 Ensembl Developers
** @author Copyright (C) 2006 Michael K. Schuster
** @version $Revision: 1.28 $
** @modified 2009 by Alan Bleasby for incorporation into EMBOSS core
** @modified $Date: 2013/02/17 13:02:40 $ by $Author: mks $
** @@
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA  02110-1301,  USA.
**
******************************************************************************/

/* ========================================================================= */
/* ============================= include files ============================= */
/* ========================================================================= */

#include "ensassembly.h"




/* ========================================================================= */
/* =============================== constants =============================== */
/* ========================================================================= */




/* ========================================================================= */
/* =========================== global variables ============================ */
/* ========================================================================= */




/* ========================================================================= */
/* ============================= private data ============================== */
/* ========================================================================= */




/* ========================================================================= */
/* =========================== private constants =========================== */
/* ========================================================================= */




/* ========================================================================= */
/* =========================== private variables =========================== */
/* ========================================================================= */




/* ========================================================================= */
/* =========================== private functions =========================== */
/* ========================================================================= */




/* ========================================================================= */
/* ======================= All functions by section ======================== */
/* ========================================================================= */




/* @filesection ensassembly ***************************************************
**
** @nam1rule ens Function belongs to the Ensembl library
**
******************************************************************************/




/* @datasection [EnsPAssembly] Ensembl Assembly *******************************
**
** @nam2rule Assembly Functions for manipulating Ensembl Assembly objects
**
******************************************************************************/




/* @section constructors ******************************************************
**
** All constructors return a new Ensembl Assembly by pointer.
** It is the responsibility of the user to first destroy any previous
** Assembly. The target pointer does not need to be initialised to
** NULL, but it is good programming practice to do so anyway.
**
** @fdata [EnsPAssembly]
**
** @nam3rule New Constructor
** @nam4rule Cpy Constructor with existing object
** @nam4rule Ini Constructor with initial values
** @nam4rule Ref Constructor by incrementing the reference counter
**
** @argrule Cpy assembly [const EnsPAssembly] Ensembl Assembly
** @argrule Ini asmsrid [ajuint] Assembled Ensembl Sequence Region identifier
** @argrule Ini asmstart [ajuint] Assembled Sequence Region start coordinate
** @argrule Ini asmend [ajuint] Assembled Sequence Region end coordinate
** @argrule Ini cmpsrid [ajuint] Component Ensembl Sequence Region identifier
** @argrule Ini cmpstart [ajuint] Component Sequence Region start coordinate
** @argrule Ini cmpend [ajuint] Component Sequence Region end coordinate
** @argrule Ini orientation [ajint] Relative orientation
** @argrule Ref assembly [EnsPAssembly] Ensembl Assembly
**
** @valrule * [EnsPAssembly] Ensembl Assembly or NULL
**
** @fcategory new
******************************************************************************/




/* @func ensAssemblyNewCpy ****************************************************
**
** Object-based constructor function, which returns an independent object.
**
** @param [r] assembly [const EnsPAssembly] Ensembl Assembly
**
** @return [EnsPAssembly] Ensembl Assembly or NULL
**
** @release 6.4.0
** @@
******************************************************************************/

EnsPAssembly ensAssemblyNewCpy(const EnsPAssembly assembly)
{
    EnsPAssembly pthis = NULL;

    if (!assembly)
        return NULL;

    AJNEW0(pthis);

    pthis->Use = 1U;

    pthis->AssembledIdentifier = assembly->AssembledIdentifier;
    pthis->AssembledStart      = assembly->AssembledStart;
    pthis->AssembledEnd        = assembly->AssembledEnd;
    pthis->ComponentIdentifier = assembly->ComponentIdentifier;
    pthis->ComponentStart      = assembly->ComponentStart;
    pthis->ComponentEnd        = assembly->ComponentEnd;
    pthis->Orientation         = assembly->Orientation;

    return pthis;
}




/* @func ensAssemblyNewIni ****************************************************
**
** Constructor for an Ensembl Assembly with initial values.
**
** @param [r] asmsrid [ajuint] Assembled Ensembl Sequence Region identifier
** @param [r] asmstart [ajuint] Assembled Sequence Region start coordinate
** @param [r] asmend [ajuint] Assembled Sequence Region end coordinate
** @param [r] cmpsrid [ajuint] Component Ensembl Sequence Region identifier
** @param [r] cmpstart [ajuint] Component Sequence Region start coordinate
** @param [r] cmpend [ajuint] Component Sequence Region end coordinate
** @param [r] orientation [ajint] Relative orientation
**
** @return [EnsPAssembly] Ensembl Assembly or NULL
**
** @release 6.4.0
** @@
******************************************************************************/

EnsPAssembly ensAssemblyNewIni(ajuint asmsrid,
                               ajuint asmstart,
                               ajuint asmend,
                               ajuint cmpsrid,
                               ajuint cmpstart,
                               ajuint cmpend,
                               ajint orientation)
{
    EnsPAssembly assembly = NULL;

    if (!asmsrid)
        return NULL;

    if (!cmpsrid)
        return NULL;

    AJNEW0(assembly);

    assembly->Use = 1U;

    assembly->AssembledIdentifier = asmsrid;
    assembly->AssembledStart      = asmstart;
    assembly->AssembledEnd        = asmend;
    assembly->ComponentIdentifier = cmpsrid;
    assembly->ComponentStart      = cmpstart;
    assembly->ComponentEnd        = cmpend;
    assembly->Orientation         = orientation;

    return assembly;
}




/* @func ensAssemblyNewRef ****************************************************
**
** Ensembl Object referencing function, which returns a pointer to the
** Ensembl Object passed in and increases its reference count.
**
** @param [u] assembly [EnsPAssembly] Ensembl Assembly
**
** @return [EnsPAssembly] Ensembl Assembly or NULL
**
** @release 6.2.0
** @@
******************************************************************************/

EnsPAssembly ensAssemblyNewRef(EnsPAssembly assembly)
{
    if (!assembly)
        return NULL;

    assembly->Use++;

    return assembly;
}




/* @section destructors *******************************************************
**
** Destruction destroys all internal data structures and frees the memory
** allocated for an Ensembl Assembly object.
**
** @fdata [EnsPAssembly]
**
** @nam3rule Del Destroy (free) an Ensembl Assembly
**
** @argrule * Passembly [EnsPAssembly*] Ensembl Assembly address
**
** @valrule * [void]
**
** @fcategory delete
******************************************************************************/




/* @func ensAssemblyDel *******************************************************
**
** Default destructor for an Ensembl Assembly.
**
** @param [d] Passembly [EnsPAssembly*] Ensembl Assembly address
**
** @return [void]
**
** @release 6.2.0
** @@
******************************************************************************/

void ensAssemblyDel(EnsPAssembly *Passembly)
{
    EnsPAssembly pthis = NULL;

    if (!Passembly)
        return;

#if defined(AJ_DEBUG) && AJ_DEBUG >= 1
    if (ajDebugTest("ensAssemblyDel"))
    {
        ajDebug("ensAssemblyDel\n"
                "  *Passembly %p\n",
                *Passembly);

        ensAssemblyTrace(*Passembly, 1);
    }
#endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */

    if (!(pthis = *Passembly) || --pthis->Use)
    {
        *Passembly = NULL;

        return;
    }

    ajMemFree((void **) Passembly);

    return;
}




/* @section member retrieval **************************************************
**
** Functions for returning members of an Ensembl Assembly object.
**
** @fdata [EnsPAssembly]
**
** @nam3rule Get Return Assembly attribute(s)
** @nam4rule Assembled Return assembled Sequence Region members
** @nam5rule Identifier Return the assembled
** Ensembl Sequence Region identifier
** @nam5rule Start Return the assembled
** Ensembl Sequence Region start
** @nam5rule End Return the assembled
** Ensembl Sequence Region end
** @nam4rule Component Return component Seuqence Region members
** @nam4rule Identifier Return the component
** Ensembl Sequence Region identifier
** @nam4rule Start Return the component
** Ensembl Sequence Region start
** @nam4rule End Return the component
** Ensembl Sequence Region end
** @nam4rule Orientation Return the relative orientation of assembled
** and component Ensembl Sequence Region objects
**
** @argrule * assembly [const EnsPAssembly] Ensembl Assembly
**
** @valrule Identifier [ajuint] Ensembl Sequence Region identifier or 0U
** @valrule Start [ajuint] Start or 0U
** @valrule End [ajuint] End or 0U
** @valrule Orientation [ajint] Orientation or 0
**
** @fcategory use
******************************************************************************/




/* @func ensAssemblyGetAssembledEnd *******************************************
**
** Get the assembled Ensembl Sequence Region end member of an
** Ensembl Assembly.
**
** @param [r] assembly [const EnsPAssembly] Ensembl Assembly
**
** @return [ajuint] Assembled Ensembl Sequence Region end or 0U
**
** @release 6.2.0
** @@
******************************************************************************/

ajuint ensAssemblyGetAssembledEnd(const EnsPAssembly assembly)
{
    return (assembly) ? assembly->AssembledEnd : 0U;
}




/* @func ensAssemblyGetAssembledIdentifier ************************************
**
** Get the assembled Ensembl Sequence Region identifier member of an
** Ensembl Assembly.
**
** @param [r] assembly [const EnsPAssembly] Ensembl Assembly
**
** @return [ajuint] Assembled Ensembl Sequence Region identifier or 0U
**
** @release 6.4.0
** @@
******************************************************************************/

ajuint ensAssemblyGetAssembledIdentifier(const EnsPAssembly assembly)
{
    return (assembly) ? assembly->AssembledIdentifier : 0U;
}




/* @func ensAssemblyGetAssembledStart *****************************************
**
** Get the assembled Ensembl Sequence Region start member of an
** Ensembl Assembly.
**
** @param [r] assembly [const EnsPAssembly] Ensembl Assembly
**
** @return [ajuint] Assembled Ensembl Sequence Region start or 0U
**
** @release 6.2.0
** @@
******************************************************************************/

ajuint ensAssemblyGetAssembledStart(const EnsPAssembly assembly)
{
    return (assembly) ? assembly->AssembledStart : 0U;
}




/* @func ensAssemblyGetComponentEnd *******************************************
**
** Get the component Ensembl Sequence Region end member of an
** Ensembl Assembly.
**
** @param [r] assembly [const EnsPAssembly] Ensembl Assembly
**
** @return [ajuint] Component Ensembl Sequence Region end or 0U
**
** @release 6.2.0
** @@
******************************************************************************/

ajuint ensAssemblyGetComponentEnd(const EnsPAssembly assembly)
{
    return (assembly) ? assembly->ComponentEnd : 0U;
}




/* @func ensAssemblyGetComponentIdentifier ************************************
**
** Get the component Ensembl Sequence Region identifier member of an
** Ensembl Assembly.
**
** @param [r] assembly [const EnsPAssembly] Ensembl Assembly
**
** @return [ajuint] Component Ensembl Sequence Region identifier or 0U
**
** @release 6.4.0
** @@
******************************************************************************/

ajuint ensAssemblyGetComponentIdentifier(const EnsPAssembly assembly)
{
    return (assembly) ? assembly->ComponentIdentifier : 0U;
}




/* @func ensAssemblyGetComponentStart *****************************************
**
** Get the component Ensembl Sequence Region start member of an
** Ensembl Assembly.
**
** @param [r] assembly [const EnsPAssembly] Ensembl Assembly
**
** @return [ajuint] Component Ensembl Sequence Region start or 0U
**
** @release 6.3.0
** @@
******************************************************************************/

ajuint ensAssemblyGetComponentStart(const EnsPAssembly assembly)
{
    return (assembly) ? assembly->ComponentStart : 0U;
}




/* @func ensAssemblyGetOrientation ********************************************
**
** Get the releative orientation of assembled and component
** Ensembl Sequence Region objects member of an Ensembl Assembly.
**
** @param [r] assembly [const EnsPAssembly] Ensembl Assembly
**
** @return [ajint] Orientation or 0
**
** @release 6.2.0
** @@
******************************************************************************/

ajint ensAssemblyGetOrientation(const EnsPAssembly assembly)
{
    return (assembly) ? assembly->Orientation : 0;
}




/* @section debugging *********************************************************
**
** Functions for reporting of an Ensembl Assembly object.
**
** @fdata [EnsPAssembly]
**
** @nam3rule Trace Report Ensembl Assembly members to debug file
**
** @argrule Trace assembly [const EnsPAssembly] Ensembl Assembly
** @argrule Trace level [ajuint] Indentation level
**
** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise
**
** @fcategory misc
******************************************************************************/




/* @func ensAssemblyTrace *****************************************************
**
** Trace an Ensembl Assembly.
**
** @param [r] assembly [const EnsPAssembly] Ensembl Assembly
** @param [r] level [ajuint] Indentation level
**
** @return [AjBool] ajTrue upon success, ajFalse otherwise
**
** @release 6.2.0
** @@
******************************************************************************/

AjBool ensAssemblyTrace(const EnsPAssembly assembly, ajuint level)
{
    AjPStr indent = NULL;

    if (!assembly)
        return ajFalse;

    indent = ajStrNew();

    ajStrAppendCountK(&indent, ' ', level * 2);

    ajDebug("%SensAssemblyTrace %p\n"
            "%S  Use %u\n"
            "%S  AssembledIdentifier %u\n"
            "%S  AssembledStart %u\n"
            "%S  AssembledEnd %u\n"
            "%S  ComponentIdentifier %u\n"
            "%S  ComponentStart %u\n"
            "%S  ComponentEnd %u\n"
            "%S  Orientation %d\n",
            indent, assembly,
            indent, assembly->Use,
            indent, assembly->AssembledIdentifier,
            indent, assembly->AssembledStart,
            indent, assembly->AssembledEnd,
            indent, assembly->ComponentIdentifier,
            indent, assembly->ComponentStart,
            indent, assembly->ComponentEnd,
            indent, assembly->Orientation);

    ajStrDel(&indent);

    return ajTrue;
}




/* @section calculate *********************************************************
**
** Functions for calculating information from an Ensembl Assembly object.
**
** @fdata [EnsPAssembly]
**
** @nam3rule Calculate Calculate Ensembl Assembly information
** @nam4rule Memsize Calculate the memory size in bytes
**
** @argrule * assembly [const EnsPAssembly] Ensembl Assembly
**
** @valrule Memsize [size_t] Memory size in bytes or 0
**
** @fcategory misc
******************************************************************************/




/* @func ensAssemblyCalculateMemsize ******************************************
**
** Calculate the memory size in bytes of an Ensembl Assembly.
**
** @param [r] assembly [const EnsPAssembly] Ensembl Assembly
**
** @return [size_t] Memory size in bytes or 0
**
** @release 6.4.0
** @@
******************************************************************************/

size_t ensAssemblyCalculateMemsize(const EnsPAssembly assembly)
{
    size_t size = 0;

    if (!assembly)
        return 0;

    size += sizeof (EnsOAssembly);

    return size;
}