| 1 | /* @source ensgvgenotype ****************************************************** |
| 2 | ** |
| 3 | ** Ensembl Genetic Variation Genotype functions |
| 4 | ** |
| 5 | ** @author Copyright (C) 1999 Ensembl Developers |
| 6 | ** @author Copyright (C) 2006 Michael K. Schuster |
| 7 | ** @version $Revision: 1.20 $ |
| 8 | ** @modified 2009 by Alan Bleasby for incorporation into EMBOSS core |
| 9 | ** @modified $Date: 2013/02/17 13:07:04 $ 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 "ensgvbaseadaptor.h" |
| 34 | #include "ensgvdatabaseadaptor.h" |
| 35 | #include "ensgvgenotype.h" |
| 36 | #include "ensgvvariation.h" |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | /* ========================================================================= */ |
| 42 | /* =============================== constants =============================== */ |
| 43 | /* ========================================================================= */ |
| 44 | |
| 45 | /* @conststatic gvgenotypecodeadaptorKTablenames ****************************** |
| 46 | ** |
| 47 | ** Array of Ensembl Genetic Variation Genotype Code Adaptor SQL table names |
| 48 | ** |
| 49 | ******************************************************************************/ |
| 50 | |
| 51 | static const char *gvgenotypecodeadaptorKTablenames[] = |
| 52 | { |
| 53 | "genotype_code", |
| 54 | "allele_code", |
| 55 | (const char *) NULL |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | /* @conststatic gvgenotypecodeadaptorKColumnnames ***************************** |
| 62 | ** |
| 63 | ** Array of Ensembl Genetic Variation Genotype Code Adaptor SQL column names |
| 64 | ** |
| 65 | ******************************************************************************/ |
| 66 | |
| 67 | static const char *gvgenotypecodeadaptorKColumnnames[] = |
| 68 | { |
| 69 | "genotype_code.genotype_code_id", |
| 70 | "genotype_code.haplotype_id", |
| 71 | "allele_code.allele", |
| 72 | (const char *) NULL |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | /* @conststatic gvgenotypecodeadaptorKDefaultcondition ************************ |
| 79 | ** |
| 80 | ** Ensembl Genetic Variation Genotype Code Adaptor SQL SELECT default condition |
| 81 | ** |
| 82 | ******************************************************************************/ |
| 83 | |
| 84 | static const char *gvgenotypecodeadaptorKDefaultcondition = |
| 85 | "genotype_code.allele_code_id = allele_code.allele_code_id"; |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | /* ========================================================================= */ |
| 91 | /* =========================== global variables ============================ */ |
| 92 | /* ========================================================================= */ |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | /* ========================================================================= */ |
| 98 | /* ============================= private data ============================== */ |
| 99 | /* ========================================================================= */ |
| 100 | |
| 101 | /* @datastatic GvPHaplotype *************************************************** |
| 102 | ** |
| 103 | ** Genetic Variation Haplotype. |
| 104 | ** |
| 105 | ** Associates haplotype identifiers with alleles. |
| 106 | ** |
| 107 | ** @alias GvSHaplotype |
| 108 | ** @alias GvOHaplotype |
| 109 | ** |
| 110 | ** @attr Identifier [ajuint] Identifier |
| 111 | ** @attr Padding [ajuint] Padding to alignment boundary |
| 112 | ** @attr Allele [AjPStr] Allele |
| 113 | ** @@ |
| 114 | ******************************************************************************/ |
| 115 | |
| 116 | typedef struct GvSHaplotype |
| 117 | { |
| 118 | ajuint Identifier; |
| 119 | ajuint Padding; |
| 120 | AjPStr Allele; |
| 121 | } GvOHaplotype; |
| 122 | |
| 123 | #define GvPHaplotype GvOHaplotype* |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | /* ========================================================================= */ |
| 129 | /* =========================== private constants =========================== */ |
| 130 | /* ========================================================================= */ |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | /* ========================================================================= */ |
| 136 | /* =========================== private variables =========================== */ |
| 137 | /* ========================================================================= */ |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | /* ========================================================================= */ |
| 143 | /* =========================== private functions =========================== */ |
| 144 | /* ========================================================================= */ |
| 145 | |
| 146 | static GvPHaplotype gvHaplotypeNewIni(ajuint haplotypeid, AjPStr allele); |
| 147 | |
| 148 | static void gvHaplotypeDel(GvPHaplotype *Pgvh); |
| 149 | |
| 150 | #if defined(AJ_DEBUG) && AJ_DEBUG >= 1 |
| 151 | static AjBool gvhaplotypeTrace(const GvPHaplotype gvh, ajuint level); |
| 152 | #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */ |
| 153 | |
| 154 | static int listGvhaplotypeCompareIdentifierAscending( |
| 155 | const void *item1, |
| 156 | const void *item2); |
| 157 | |
| 158 | static AjBool listGvhaplotypeSortIdentifierAscending(AjPList gvhs); |
| 159 | |
| 160 | static AjBool gvgenotypecodeadaptorFetchAllbyStatement( |
| 161 | EnsPBaseadaptor ba, |
| 162 | const AjPStr statement, |
| 163 | EnsPAssemblymapper am, |
| 164 | EnsPSlice slice, |
| 165 | AjPList gvgcs); |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | /* ========================================================================= */ |
| 171 | /* ======================= All functions by section ======================== */ |
| 172 | /* ========================================================================= */ |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | /* @filesection ensgvgenotype ************************************************* |
| 178 | ** |
| 179 | ** @nam1rule ens Function belongs to the Ensembl library |
| 180 | ** |
| 181 | ******************************************************************************/ |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | /* @funcstatic gvHaplotypeNewIni ********************************************** |
| 187 | ** |
| 188 | ** Genetic Variation Haplotype constructor with initial values. |
| 189 | ** |
| 190 | ** @param [r] haplotypeid [ajuint] Haplotype identifier |
| 191 | ** @param [u] allele [AjPStr] Allele |
| 192 | ** |
| 193 | ** @return [GvPHaplotype] Genetic Variation Haplotype or NULL |
| 194 | ** |
| 195 | ** @release 6.5.0 |
| 196 | ** @@ |
| 197 | ******************************************************************************/ |
| 198 | |
| 199 | static GvPHaplotype gvHaplotypeNewIni(ajuint haplotypeid, AjPStr allele) |
| 200 | { |
| 201 | GvPHaplotype gvh = NULL; |
| 202 | |
| 203 | if (!haplotypeid) |
| 204 | return NULL; |
| 205 | |
| 206 | if (!allele) |
| 207 | return NULL; |
| 208 | |
| 209 | AJNEW0(gvh); |
| 210 | |
| 211 | gvh->Identifier = haplotypeid; |
| 212 | |
| 213 | gvh->Allele = ajStrNewRef(allele); |
| 214 | |
| 215 | return gvh; |
| 216 | } |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | /* @funcstatic gvHaplotypeDel ************************************************* |
| 222 | ** |
| 223 | ** Default destructor for a Genetic Variation Haplotype object. |
| 224 | ** |
| 225 | ** @param [d] Pgvh [GvPHaplotype*] Genetic Variation Haplotype address |
| 226 | ** |
| 227 | ** @return [void] |
| 228 | ** |
| 229 | ** @release 6.5.0 |
| 230 | ** @@ |
| 231 | ******************************************************************************/ |
| 232 | |
| 233 | static void gvHaplotypeDel(GvPHaplotype *Pgvh) |
| 234 | { |
| 235 | GvPHaplotype pthis = NULL; |
| 236 | |
| 237 | if (!Pgvh) |
| 238 | return; |
| 239 | |
| 240 | #if defined(AJ_DEBUG) && AJ_DEBUG >= 1 |
| 241 | if (ajDebugTest("gvHaplotypeDel")) |
| 242 | { |
| 243 | ajDebug("gvHaplotypeDel\n" |
| 244 | " *Pgvh %p\n", |
| 245 | *Pgvh); |
| 246 | |
| 247 | gvhaplotypeTrace(*Pgvh, 1); |
| 248 | } |
| 249 | #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */ |
| 250 | |
| 251 | if (!(pthis = *Pgvh)) |
| 252 | return; |
| 253 | |
| 254 | ajStrDel(&pthis->Allele); |
| 255 | |
| 256 | ajMemFree((void **) Pgvh); |
| 257 | |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | #if defined(AJ_DEBUG) && AJ_DEBUG >= 1 |
| 265 | /* @funcstatic gvhaplotypeTrace *********************************************** |
| 266 | ** |
| 267 | ** Trace an Ensembl Genetic Variation Haplotype. |
| 268 | ** |
| 269 | ** @param [r] gvh [const GvPHaplotype] Ensembl Genetic Variation Haplotype |
| 270 | ** @param [r] level [ajuint] Indentation level |
| 271 | ** |
| 272 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 273 | ** |
| 274 | ** @release 6.5.0 |
| 275 | ** @@ |
| 276 | ******************************************************************************/ |
| 277 | |
| 278 | static AjBool gvhaplotypeTrace(const GvPHaplotype gvh, ajuint level) |
| 279 | { |
| 280 | AjPStr indent = NULL; |
| 281 | |
| 282 | if (!gvh) |
| 283 | return ajFalse; |
| 284 | |
| 285 | indent = ajStrNew(); |
| 286 | |
| 287 | ajStrAppendCountK(&indent, ' ', level * 2); |
| 288 | |
| 289 | ajDebug("%SgvhaplotypeTrace %p\n" |
| 290 | "%S Identifier %u\n" |
| 291 | "%S Allele '%S'\n", |
| 292 | indent, gvh, |
| 293 | indent, gvh->Identifier, |
| 294 | indent, gvh->Allele); |
| 295 | |
| 296 | ajStrDel(&indent); |
| 297 | |
| 298 | return ajTrue; |
| 299 | } |
| 300 | #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */ |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | /* @funcstatic listGvhaplotypeCompareIdentifierAscending ********************** |
| 306 | ** |
| 307 | ** AJAX List of Genetic Variation Haplotype objects comparison function |
| 308 | ** to sort by haplotype identifier in ascending order. |
| 309 | ** |
| 310 | ** @param [r] item1 [const void*] Genetic Variation Haplotype address 1 |
| 311 | ** @param [r] item2 [const void*] Genetic Variation Haplotype address 2 |
| 312 | ** @see ajListSort |
| 313 | ** |
| 314 | ** @return [int] The comparison function returns an integer less than, |
| 315 | ** equal to, or greater than zero if the first argument is |
| 316 | ** considered to be respectively less than, equal to, or |
| 317 | ** greater than the second. |
| 318 | ** |
| 319 | ** @release 6.4.0 |
| 320 | ** @@ |
| 321 | ******************************************************************************/ |
| 322 | |
| 323 | static int listGvhaplotypeCompareIdentifierAscending( |
| 324 | const void *item1, |
| 325 | const void *item2) |
| 326 | { |
| 327 | GvPHaplotype gvh1 = *(GvOHaplotype *const *) item1; |
| 328 | GvPHaplotype gvh2 = *(GvOHaplotype *const *) item2; |
| 329 | |
| 330 | #if defined(AJ_DEBUG) && AJ_DEBUG >= 2 |
| 331 | if (ajDebugTest("listGvhaplotypeCompareIdentifierAscending")) |
| 332 | ajDebug("listGvhaplotypeCompareIdentifierAscending\n" |
| 333 | " gvh1 %p\n" |
| 334 | " gvh2 %p\n", |
| 335 | gvh1, |
| 336 | gvh2); |
| 337 | #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 2 */ |
| 338 | |
| 339 | /* Sort empty values towards the end of the AJAX List. */ |
| 340 | |
| 341 | if (gvh1 && (!gvh2)) |
| 342 | return -1; |
| 343 | |
| 344 | if ((!gvh1) && (!gvh2)) |
| 345 | return 0; |
| 346 | |
| 347 | if ((!gvh1) && gvh2) |
| 348 | return +1; |
| 349 | |
| 350 | if (gvh1->Identifier < gvh2->Identifier) |
| 351 | return -1; |
| 352 | |
| 353 | if (gvh1->Identifier > gvh2->Identifier) |
| 354 | return +1; |
| 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | /* @funcstatic listGvhaplotypeSortIdentifierAscending ************************* |
| 363 | ** |
| 364 | ** Sort an AJAX List of Genetic Variation Haplotype objects by their |
| 365 | ** haplotype identifier in ascending order. |
| 366 | ** |
| 367 | ** @param [u] gvhs [AjPList] AJAX List of Genetic Variation Haplotype objects |
| 368 | ** |
| 369 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 370 | ** |
| 371 | ** @release 6.4.0 |
| 372 | ** @@ |
| 373 | ******************************************************************************/ |
| 374 | |
| 375 | static AjBool listGvhaplotypeSortIdentifierAscending(AjPList gvhs) |
| 376 | { |
| 377 | if (!gvhs) |
| 378 | return ajFalse; |
| 379 | |
| 380 | ajListSort(gvhs, &listGvhaplotypeCompareIdentifierAscending); |
| 381 | |
| 382 | return ajTrue; |
| 383 | } |
| 384 | |
| 385 | |
| 386 | |
| 387 | /* FIXME: Move to strCharCmp in ajstr.c */ |
| 388 | |
| 389 | static int gvCharCmp(const void *arg1, const void *arg2) |
| 390 | { |
| 391 | /* Sort empty values towards the end of the array. */ |
| 392 | |
| 393 | if (arg1 && (!arg2)) |
| 394 | return -1; |
| 395 | |
| 396 | if ((!arg1) && (!arg2)) |
| 397 | return 0; |
| 398 | |
| 399 | if ((!arg1) && arg2) |
| 400 | return +1; |
| 401 | |
| 402 | if(toupper(*((const int *)arg1)) < toupper(*((const int *)arg2))) |
| 403 | return -1; |
| 404 | |
| 405 | if(toupper((*(const int *) arg1)) > toupper(*((const int *) arg2))) |
| 406 | return 1; |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | /* FIXME: Move to ajCharSort in ajstr.c */ |
| 412 | |
| 413 | AjBool ensUtilityCharSort(char *string) |
| 414 | { |
| 415 | if (!string) |
| 416 | return ajFalse; |
| 417 | |
| 418 | qsort(string, strlen(string), sizeof (char), &gvCharCmp); |
| 419 | |
| 420 | return ajTrue; |
| 421 | } |
| 422 | |
| 423 | /* FIXME: Move to baseAmbiguity in ajbase.c */ |
| 424 | |
| 425 | static const char* gvBaseAmbiguity[] = |
| 426 | { |
| 427 | "AC", "M", /* Amino */ |
| 428 | "ACG", "V", /* Not U */ |
| 429 | "ACGT", "N", /* Any */ |
| 430 | "ACT", "H", /* Not G */ |
| 431 | "AG", "R", /* Purine */ |
| 432 | "AGT", "D", /* Not C */ |
| 433 | "AT", "W", /* Weak */ |
| 434 | "CG", "S", /* Strong */ |
| 435 | "CGT", "B", /* Not A */ |
| 436 | "CT", "Y", /* Pyrimidine */ |
| 437 | "GT", "K", /* Keto */ |
| 438 | "C", "C", /* C */ |
| 439 | "A", "A", /* A */ |
| 440 | "T", "T", /* T */ |
| 441 | "G", "G", /* G */ |
| 442 | "-", "-", /* - */ |
| 443 | NULL, NULL |
| 444 | }; |
| 445 | |
| 446 | /* FIXME: Move to ajBaseAmbiguityCharFromString in ajbase.c */ |
| 447 | |
| 448 | char ensUtilityBaseAmbiguityFromString(const char *basestr) |
| 449 | { |
| 450 | char ambiguitychar = '\0'; |
| 451 | |
| 452 | char *temporary = NULL; |
| 453 | |
| 454 | register ajuint i = 0U; |
| 455 | |
| 456 | if (!basestr) |
| 457 | return '\0'; |
| 458 | |
| 459 | temporary = ajCharNewC(basestr); |
| 460 | |
| 461 | ensUtilityCharSort(temporary); |
| 462 | |
| 463 | for (i = 0U; gvBaseAmbiguity[i]; i += 2) |
| 464 | if (strcmp(gvBaseAmbiguity[i], temporary)) |
| 465 | { |
| 466 | ambiguitychar = *gvBaseAmbiguity[i + 1]; |
| 467 | |
| 468 | break; |
| 469 | } |
| 470 | |
| 471 | AJFREE(temporary); |
| 472 | |
| 473 | return ambiguitychar; |
| 474 | } |
| 475 | |
| 476 | /* FIXME: Move to ajBaseAmbiguityCharToString in ajbase.c */ |
| 477 | |
| 478 | const char* ensUtilityBaseAmbiguityToString(char ambiguitychar) |
| 479 | { |
| 480 | const char *basestr = NULL; |
| 481 | |
| 482 | register ajuint i = 0U; |
| 483 | |
| 484 | for (i = 0U; gvBaseAmbiguity[i + 1]; i += 2) |
| 485 | if ((int) *gvBaseAmbiguity[i + 1] == toupper((int) ambiguitychar)) |
| 486 | { |
| 487 | basestr = gvBaseAmbiguity[i]; |
| 488 | |
| 489 | break; |
| 490 | } |
| 491 | |
| 492 | return basestr; |
| 493 | } |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | /* @datasection [EnsPGvgenotype] Ensembl Genetic Variation Genotype *********** |
| 499 | ** |
| 500 | ** @nam2rule Gvgenotype Functions for manipulating |
| 501 | ** Ensembl Genetic Variation Genotype objects |
| 502 | ** |
| 503 | ** @cc Bio::EnsEMBL::Variation::Genotype |
| 504 | ** @cc CVS Revision: 1.8.10.1 |
| 505 | ** @cc CVS Tag: branch-ensembl-68 |
| 506 | ** |
| 507 | ******************************************************************************/ |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | /* @section constructors ****************************************************** |
| 513 | ** |
| 514 | ** All constructors return a new Ensembl Genetic Variation Genotype by pointer. |
| 515 | ** It is the responsibility of the user to first destroy any previous |
| 516 | ** Genetic Variation Genotype. The target pointer does not need to be |
| 517 | ** initialised to NULL, but it is good programming practice to do so anyway. |
| 518 | ** |
| 519 | ** @fdata [EnsPGvgenotype] |
| 520 | ** |
| 521 | ** @nam3rule New Constructor |
| 522 | ** @nam4rule Cpy Constructor with existing object |
| 523 | ** @nam4rule Ini Constructor with initial values |
| 524 | ** @nam4rule Ref Constructor by incrementing the reference counter |
| 525 | ** |
| 526 | ** @argrule Cpy gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 527 | ** @argrule Ini gvga [EnsPGvgenotypeadaptor] |
| 528 | ** Ensembl Genetic Variation Genotype Adaptor |
| 529 | ** @argrule Ini identifier [ajuint] SQL database-internal identifier |
| 530 | ** @argrule Ini gvv [EnsPGvvariation] Ensembl Genetic Variation Variation |
| 531 | ** @argrule Ini alleles [AjPList] AJAX List of AJAX String objects |
| 532 | ** @argrule Ini subhandle [AjPStr] Subhandle |
| 533 | ** @argrule Ini subidentifier [ajuint] Subidentifier |
| 534 | ** @argrule Ref gvg [EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 535 | ** |
| 536 | ** @valrule * [EnsPGvgenotype] Ensembl Genetic Variation Genotype or NULL |
| 537 | ** |
| 538 | ** @fcategory new |
| 539 | ******************************************************************************/ |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | /* @func ensGvgenotypeNewCpy ************************************************** |
| 545 | ** |
| 546 | ** Object-based constructor function, which returns an independent object. |
| 547 | ** |
| 548 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 549 | ** |
| 550 | ** @return [EnsPGvgenotype] Ensembl Genetic Variation Genotype or NULL |
| 551 | ** |
| 552 | ** @release 6.4.0 |
| 553 | ** @@ |
| 554 | ******************************************************************************/ |
| 555 | |
| 556 | EnsPGvgenotype ensGvgenotypeNewCpy(const EnsPGvgenotype gvg) |
| 557 | { |
| 558 | AjIList iter = NULL; |
| 559 | |
| 560 | AjPStr allele = NULL; |
| 561 | |
| 562 | EnsPGvgenotype pthis = NULL; |
| 563 | |
| 564 | if (!gvg) |
| 565 | return NULL; |
| 566 | |
| 567 | AJNEW0(pthis); |
| 568 | |
| 569 | pthis->Use = 1U; |
| 570 | pthis->Identifier = gvg->Identifier; |
| 571 | pthis->Adaptor = gvg->Adaptor; |
| 572 | |
| 573 | pthis->Gvvariation = ensGvvariationNewRef(gvg->Gvvariation); |
| 574 | |
| 575 | /* NOTE: Copy the AJAX List of AJAX String objects */ |
| 576 | |
| 577 | if (gvg->Alleles) |
| 578 | { |
| 579 | pthis->Alleles = ajListstrNew(); |
| 580 | |
| 581 | iter = ajListIterNew(gvg->Alleles); |
| 582 | |
| 583 | while (!ajListIterDone(iter)) |
| 584 | { |
| 585 | allele = ajListstrIterGet(iter); |
| 586 | |
| 587 | ajListstrPushAppend(pthis->Alleles, allele); |
| 588 | } |
| 589 | |
| 590 | ajListIterDel(&iter); |
| 591 | } |
| 592 | |
| 593 | pthis->Subhandle = ajStrNewRef(gvg->Subhandle); |
| 594 | |
| 595 | pthis->Subidentifier = gvg->Subidentifier; |
| 596 | |
| 597 | return pthis; |
| 598 | } |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | /* @func ensGvgenotypeNewIni ************************************************** |
| 604 | ** |
| 605 | ** Constructor for an Ensembl Genetic Variation Genotype with initial values. |
| 606 | ** |
| 607 | ** @cc Bio::EnsEMBL::Storable::new |
| 608 | ** @param [u] gvga [EnsPGvgenotypeadaptor] |
| 609 | ** Ensembl Genetic Variation Genotype Adaptor |
| 610 | ** @param [r] identifier [ajuint] SQL database-internal identifier |
| 611 | ** @cc Bio::EnsEMBL::Variation::Genotype::new |
| 612 | ** @param [u] gvv [EnsPGvvariation] Ensembl Genetic Variation Variation |
| 613 | ** @param [u] alleles [AjPList] AJAX List of AJAX String objects |
| 614 | ** @param [u] subhandle [AjPStr] Subhandle |
| 615 | ** @param [r] subidentifier [ajuint] Subidentifier |
| 616 | ** |
| 617 | ** @return [EnsPGvgenotype] Ensembl Genetic Variation Genotype or NULL |
| 618 | ** |
| 619 | ** @release 6.4.0 |
| 620 | ** @@ |
| 621 | ******************************************************************************/ |
| 622 | |
| 623 | EnsPGvgenotype ensGvgenotypeNewIni(EnsPGvgenotypeadaptor gvga, |
| 624 | ajuint identifier, |
| 625 | EnsPGvvariation gvv, |
| 626 | AjPList alleles, |
| 627 | AjPStr subhandle, |
| 628 | ajuint subidentifier) |
| 629 | { |
| 630 | AjIList iter = NULL; |
| 631 | |
| 632 | AjPStr allele = NULL; |
| 633 | |
| 634 | EnsPGvgenotype gvg = NULL; |
| 635 | |
| 636 | AJNEW0(gvg); |
| 637 | |
| 638 | gvg->Use = 1U; |
| 639 | gvg->Identifier = identifier; |
| 640 | gvg->Adaptor = gvga; |
| 641 | |
| 642 | gvg->Gvvariation = ensGvvariationNewRef(gvv); |
| 643 | |
| 644 | /* NOTE: Copy the AJAX List of AJAX String objects. */ |
| 645 | |
| 646 | if (alleles) |
| 647 | { |
| 648 | gvg->Alleles = ajListstrNew(); |
| 649 | |
| 650 | iter = ajListIterNew(alleles); |
| 651 | |
| 652 | while (!ajListIterDone(iter)) |
| 653 | { |
| 654 | allele = ajListstrIterGet(iter); |
| 655 | |
| 656 | ajListstrPushAppend(gvg->Alleles, allele); |
| 657 | } |
| 658 | |
| 659 | ajListIterDel(&iter); |
| 660 | } |
| 661 | |
| 662 | if (subhandle) |
| 663 | gvg->Subhandle = ajStrNewS(subhandle); |
| 664 | |
| 665 | gvg->Subidentifier = subidentifier; |
| 666 | |
| 667 | return gvg; |
| 668 | } |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | /* @func ensGvgenotypeNewRef ************************************************** |
| 674 | ** |
| 675 | ** Ensembl Object referencing function, which returns a pointer to the |
| 676 | ** Ensembl Object passed in and increases its reference count. |
| 677 | ** |
| 678 | ** @param [u] gvg [EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 679 | ** |
| 680 | ** @return [EnsPGvgenotype] Ensembl Genetic Variation Genotype or NULL |
| 681 | ** |
| 682 | ** @release 6.2.0 |
| 683 | ** @@ |
| 684 | ******************************************************************************/ |
| 685 | |
| 686 | EnsPGvgenotype ensGvgenotypeNewRef(EnsPGvgenotype gvg) |
| 687 | { |
| 688 | if (!gvg) |
| 689 | return NULL; |
| 690 | |
| 691 | gvg->Use++; |
| 692 | |
| 693 | return gvg; |
| 694 | } |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | /* @section destructors ******************************************************* |
| 700 | ** |
| 701 | ** Destruction destroys all internal data structures and frees the memory |
| 702 | ** allocated for an Ensembl Genetic Variation Genotype object. |
| 703 | ** |
| 704 | ** @fdata [EnsPGvgenotype] |
| 705 | ** |
| 706 | ** @nam3rule Del Destroy (free) a Genetic Variation Genotype object |
| 707 | ** |
| 708 | ** @argrule * Pgvg [EnsPGvgenotype*] Ensembl Genetic Variation Genotype address |
| 709 | ** |
| 710 | ** @valrule * [void] |
| 711 | ** |
| 712 | ** @fcategory delete |
| 713 | ******************************************************************************/ |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | /* @func ensGvgenotypeDel ***************************************************** |
| 719 | ** |
| 720 | ** Default destructor for an Ensembl Genetic Variation Genotype. |
| 721 | ** |
| 722 | ** @param [d] Pgvg [EnsPGvgenotype*] Ensembl Genetic Variation Genotype address |
| 723 | ** |
| 724 | ** @return [void] |
| 725 | ** |
| 726 | ** @release 6.2.0 |
| 727 | ** @@ |
| 728 | ******************************************************************************/ |
| 729 | |
| 730 | void ensGvgenotypeDel(EnsPGvgenotype *Pgvg) |
| 731 | { |
| 732 | EnsPGvgenotype pthis = NULL; |
| 733 | |
| 734 | if (!Pgvg) |
| 735 | return; |
| 736 | |
| 737 | #if defined(AJ_DEBUG) && AJ_DEBUG >= 1 |
| 738 | if (ajDebugTest("ensGvgenotypeDel")) |
| 739 | { |
| 740 | ajDebug("ensGvgenotypeDel\n" |
| 741 | " *Pgvg %p\n", |
| 742 | *Pgvg); |
| 743 | |
| 744 | ensGvgenotypeTrace(*Pgvg, 1); |
| 745 | } |
| 746 | #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */ |
| 747 | |
| 748 | if (!(pthis = *Pgvg) || --pthis->Use) |
| 749 | { |
| 750 | *Pgvg = NULL; |
| 751 | |
| 752 | return; |
| 753 | } |
| 754 | |
| 755 | ensGvvariationDel(&pthis->Gvvariation); |
| 756 | |
| 757 | ajListstrFree(&pthis->Alleles); |
| 758 | |
| 759 | ajStrDel(&pthis->Subhandle); |
| 760 | |
| 761 | ajMemFree((void **) Pgvg); |
| 762 | |
| 763 | return; |
| 764 | } |
| 765 | |
| 766 | |
| 767 | |
| 768 | |
| 769 | /* @section member retrieval ************************************************** |
| 770 | ** |
| 771 | ** Functions for returning members of an |
| 772 | ** Ensembl Genetic Variation Genotype object. |
| 773 | ** |
| 774 | ** @fdata [EnsPGvgenotype] |
| 775 | ** |
| 776 | ** @nam3rule Get Return Genetic Variation Genotype attribute(s) |
| 777 | ** @nam4rule Adaptor Return the Ensembl Genetic Variation Genotype Adaptor |
| 778 | ** @nam4rule Alleles Return the ALAX List of AJAX String (allele) objects |
| 779 | ** @nam4rule Gvvariation Return the Ensembl Genetic Variation Variation |
| 780 | ** @nam4rule Identifier Return the SQL database-internal identifier |
| 781 | ** @nam4rule Subhandle Return the subhandle |
| 782 | ** @nam4rule Subidentifier Return the subidentifier |
| 783 | ** |
| 784 | ** @argrule * gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 785 | ** |
| 786 | ** @valrule Adaptor [EnsPGvgenotypeadaptor] |
| 787 | ** Ensembl Genetic Variation Genotype Adaptor or NULL |
| 788 | ** @valrule Alleles [const AjPList] AJAX List of AJAX String objects or NULL |
| 789 | ** @valrule Gvvariation [EnsPGvvariation] |
| 790 | ** Ensembl Genetic Variation Variation or NULL |
| 791 | ** @valrule Identifier [ajuint] SQL database-internal identifier or 0U |
| 792 | ** @valrule Subhandle [AjPStr] Subhandle or NULL |
| 793 | ** @valrule Subidentifier [ajuint] Subidentifier |
| 794 | ** |
| 795 | ** @fcategory use |
| 796 | ******************************************************************************/ |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | /* @func ensGvgenotypeGetAdaptor ********************************************** |
| 802 | ** |
| 803 | ** Get the Ensembl Genetic Variation Genotype Adaptor member of an |
| 804 | ** Ensembl Genetic Variation Genotype. |
| 805 | ** |
| 806 | ** @cc Bio::EnsEMBL::Storable::adaptor |
| 807 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 808 | ** |
| 809 | ** @return [EnsPGvgenotypeadaptor] Ensembl Genetic Variation Genotype Adaptor |
| 810 | ** or NULL |
| 811 | ** |
| 812 | ** @release 6.2.0 |
| 813 | ** @@ |
| 814 | ******************************************************************************/ |
| 815 | |
| 816 | EnsPGvgenotypeadaptor ensGvgenotypeGetAdaptor(const EnsPGvgenotype gvg) |
| 817 | { |
| 818 | return (gvg) ? gvg->Adaptor : NULL; |
| 819 | } |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | /* @func ensGvgenotypeGetAlleles ********************************************** |
| 825 | ** |
| 826 | ** Get the AJAX List of AJAX String (allele) objects of an |
| 827 | ** Ensembl Genetic Variation Genotype. |
| 828 | ** |
| 829 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 830 | ** |
| 831 | ** @return [const AjPList] AJAX List of AJAX String objects or NULL |
| 832 | ** |
| 833 | ** @release 6.2.0 |
| 834 | ** @@ |
| 835 | ******************************************************************************/ |
| 836 | |
| 837 | const AjPList ensGvgenotypeGetAlleles(const EnsPGvgenotype gvg) |
| 838 | { |
| 839 | return (gvg) ? gvg->Alleles : NULL; |
| 840 | } |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | /* @func ensGvgenotypeGetGvvariation ****************************************** |
| 846 | ** |
| 847 | ** Get the Ensembl Genetic Variation Variation member of an |
| 848 | ** Ensembl Genetic Variation Genotype. |
| 849 | ** |
| 850 | ** @cc Bio::EnsEMBL::Variation::Genotype::variation |
| 851 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 852 | ** |
| 853 | ** @return [EnsPGvvariation] Ensembl Genetic Variation Variation or NULL |
| 854 | ** |
| 855 | ** @release 6.2.0 |
| 856 | ** @@ |
| 857 | ******************************************************************************/ |
| 858 | |
| 859 | EnsPGvvariation ensGvgenotypeGetGvvariation(const EnsPGvgenotype gvg) |
| 860 | { |
| 861 | return (gvg) ? gvg->Gvvariation : NULL; |
| 862 | } |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | /* @func ensGvgenotypeGetIdentifier ******************************************* |
| 868 | ** |
| 869 | ** Get the SQL database-internal identifier member of an |
| 870 | ** Ensembl Genetic Variation Genotype. |
| 871 | ** |
| 872 | ** @cc Bio::EnsEMBL::Storable::dbID |
| 873 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 874 | ** |
| 875 | ** @return [ajuint] SQL database-internal identifier or 0U |
| 876 | ** |
| 877 | ** @release 6.2.0 |
| 878 | ** @@ |
| 879 | ******************************************************************************/ |
| 880 | |
| 881 | ajuint ensGvgenotypeGetIdentifier(const EnsPGvgenotype gvg) |
| 882 | { |
| 883 | return (gvg) ? gvg->Identifier : 0U; |
| 884 | } |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | /* @func ensGvgenotypeGetSubhandle ******************************************** |
| 890 | ** |
| 891 | ** Get the subhandle of an Ensembl Genetic Variation Genotype. |
| 892 | ** |
| 893 | ** @cc Bio::EnsEMBL::Variation::Genotype::subsnp_handle |
| 894 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 895 | ** |
| 896 | ** @return [AjPStr] Subhandle or NULL |
| 897 | ** |
| 898 | ** @release 6.2.0 |
| 899 | ** @@ |
| 900 | ******************************************************************************/ |
| 901 | |
| 902 | AjPStr ensGvgenotypeGetSubhandle(const EnsPGvgenotype gvg) |
| 903 | { |
| 904 | return (gvg) ? gvg->Subhandle : NULL; |
| 905 | } |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | /* @func ensGvgenotypeGetSubidentifier **************************************** |
| 911 | ** |
| 912 | ** Get the subidentifier member of an |
| 913 | ** Ensembl Genetic Variation Genotype. |
| 914 | ** |
| 915 | ** @cc Bio::EnsEMBL::Variation::Genotype::subsnp |
| 916 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 917 | ** |
| 918 | ** @return [ajuint] subidentifier or 0U |
| 919 | ** |
| 920 | ** @release 6.2.0 |
| 921 | ** @@ |
| 922 | ******************************************************************************/ |
| 923 | |
| 924 | ajuint ensGvgenotypeGetSubidentifier(const EnsPGvgenotype gvg) |
| 925 | { |
| 926 | return (gvg) ? gvg->Subidentifier : 0U; |
| 927 | } |
| 928 | |
| 929 | |
| 930 | |
| 931 | |
| 932 | /* @section member assignment ************************************************* |
| 933 | ** |
| 934 | ** Functions for assigning members of an |
| 935 | ** Ensembl Genetic Variation Genotype object. |
| 936 | ** |
| 937 | ** @fdata [EnsPGvgenotype] |
| 938 | ** |
| 939 | ** @nam3rule Set Set one member of a Genetic Variation Genotype |
| 940 | ** @nam4rule Adaptor Set the Ensembl Genetic Variation Genotype Adaptor |
| 941 | ** @nam4rule Gvvariation Set the Ensembl Genetic Variation Variation |
| 942 | ** @nam4rule Identifier Set the SQL database-internal identifier |
| 943 | ** @nam4rule Subhandle Set the subhandle |
| 944 | ** @nam4rule Subidentifier Set the subidentifier |
| 945 | ** |
| 946 | ** @argrule * gvg [EnsPGvgenotype] Ensembl Genetic Variation Genotype object |
| 947 | ** @argrule Adaptor gvga [EnsPGvgenotypeadaptor] |
| 948 | ** Ensembl Genetic Variation Genotype Adaptor |
| 949 | ** @argrule Gvvariation gvv [EnsPGvvariation] |
| 950 | ** Ensembl Genetic Variation Variation |
| 951 | ** @argrule Identifier identifier [ajuint] SQL database-internal identifier |
| 952 | ** @argrule Subhandle subhandle [AjPStr] Subhandle |
| 953 | ** @argrule Subidentifier subidentifier [ajuint] Subidentifier |
| 954 | ** |
| 955 | ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise |
| 956 | ** |
| 957 | ** @fcategory modify |
| 958 | ******************************************************************************/ |
| 959 | |
| 960 | |
| 961 | |
| 962 | |
| 963 | /* @func ensGvgenotypeSetAdaptor ********************************************** |
| 964 | ** |
| 965 | ** Set the Ensembl Genetic Variation Genotype Adaptor member of an |
| 966 | ** Ensembl Genetic Variation Genotype. |
| 967 | ** |
| 968 | ** @cc Bio::EnsEMBL::Storable::adaptor |
| 969 | ** @param [u] gvg [EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 970 | ** @param [u] gvga [EnsPGvgenotypeadaptor] |
| 971 | ** Ensembl Genetic Variation Genotype Adaptor |
| 972 | ** |
| 973 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 974 | ** |
| 975 | ** @release 6.2.0 |
| 976 | ** @@ |
| 977 | ******************************************************************************/ |
| 978 | |
| 979 | AjBool ensGvgenotypeSetAdaptor(EnsPGvgenotype gvg, |
| 980 | EnsPGvgenotypeadaptor gvga) |
| 981 | { |
| 982 | if (!gvg) |
| 983 | return ajFalse; |
| 984 | |
| 985 | gvg->Adaptor = gvga; |
| 986 | |
| 987 | return ajTrue; |
| 988 | } |
| 989 | |
| 990 | |
| 991 | |
| 992 | |
| 993 | /* @func ensGvgenotypeSetGvvariation ****************************************** |
| 994 | ** |
| 995 | ** Set the Ensembl Genetic Variation Variation member of an |
| 996 | ** Ensembl Genetic Variation Genotype. |
| 997 | ** |
| 998 | ** @cc Bio::EnsEMBL::Variation::Genotype::variation |
| 999 | ** @param [u] gvg [EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1000 | ** @param [u] gvv [EnsPGvvariation] Ensembl Genetic Variation Variation |
| 1001 | ** |
| 1002 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 1003 | ** |
| 1004 | ** @release 6.2.0 |
| 1005 | ** @@ |
| 1006 | ******************************************************************************/ |
| 1007 | |
| 1008 | AjBool ensGvgenotypeSetGvvariation(EnsPGvgenotype gvg, |
| 1009 | EnsPGvvariation gvv) |
| 1010 | { |
| 1011 | if (!gvg) |
| 1012 | return ajFalse; |
| 1013 | |
| 1014 | ensGvvariationDel(&gvg->Gvvariation); |
| 1015 | |
| 1016 | gvg->Gvvariation = ensGvvariationNewRef(gvv); |
| 1017 | |
| 1018 | return ajTrue; |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | |
| 1023 | |
| 1024 | /* @func ensGvgenotypeSetIdentifier ******************************************* |
| 1025 | ** |
| 1026 | ** Set the SQL database-internal identifier member of an |
| 1027 | ** Ensembl Genetic Variation Genotype. |
| 1028 | ** |
| 1029 | ** @cc Bio::EnsEMBL::Storable::dbID |
| 1030 | ** @param [u] gvg [EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1031 | ** @param [r] identifier [ajuint] SQL database-internal identifier |
| 1032 | ** |
| 1033 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 1034 | ** |
| 1035 | ** @release 6.2.0 |
| 1036 | ** @@ |
| 1037 | ******************************************************************************/ |
| 1038 | |
| 1039 | AjBool ensGvgenotypeSetIdentifier(EnsPGvgenotype gvg, |
| 1040 | ajuint identifier) |
| 1041 | { |
| 1042 | if (!gvg) |
| 1043 | return ajFalse; |
| 1044 | |
| 1045 | gvg->Identifier = identifier; |
| 1046 | |
| 1047 | return ajTrue; |
| 1048 | } |
| 1049 | |
| 1050 | |
| 1051 | |
| 1052 | |
| 1053 | /* @func ensGvgenotypeSetSubhandle ******************************************** |
| 1054 | ** |
| 1055 | ** Set the subhandle member of an |
| 1056 | ** Ensembl Genetic Variation Genotype. |
| 1057 | ** |
| 1058 | ** @cc Bio::EnsEMBL::Variation::Genotype::subsnp_handle |
| 1059 | ** @param [u] gvg [EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1060 | ** @param [u] subhandle [AjPStr] Subhandle |
| 1061 | ** |
| 1062 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 1063 | ** |
| 1064 | ** @release 6.2.0 |
| 1065 | ** @@ |
| 1066 | ******************************************************************************/ |
| 1067 | |
| 1068 | AjBool ensGvgenotypeSetSubhandle(EnsPGvgenotype gvg, |
| 1069 | AjPStr subhandle) |
| 1070 | { |
| 1071 | if (!gvg) |
| 1072 | return ajFalse; |
| 1073 | |
| 1074 | ajStrDel(&gvg->Subhandle); |
| 1075 | |
| 1076 | gvg->Subhandle = ajStrNewRef(subhandle); |
| 1077 | |
| 1078 | return ajTrue; |
| 1079 | } |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | /* @func ensGvgenotypeSetSubidentifier **************************************** |
| 1085 | ** |
| 1086 | ** Set the subidentifier member of an |
| 1087 | ** Ensembl Genetic Variation Genotype. |
| 1088 | ** |
| 1089 | ** @cc Bio::EnsEMBL::Variation::Genotype::subsnp |
| 1090 | ** @param [u] gvg [EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1091 | ** @param [r] subidentifier [ajuint] Subidentifier |
| 1092 | ** |
| 1093 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 1094 | ** |
| 1095 | ** @release 6.2.0 |
| 1096 | ** @@ |
| 1097 | ******************************************************************************/ |
| 1098 | |
| 1099 | AjBool ensGvgenotypeSetSubidentifier(EnsPGvgenotype gvg, |
| 1100 | ajuint subidentifier) |
| 1101 | { |
| 1102 | if (!gvg) |
| 1103 | return ajFalse; |
| 1104 | |
| 1105 | gvg->Subidentifier = subidentifier; |
| 1106 | |
| 1107 | return ajTrue; |
| 1108 | } |
| 1109 | |
| 1110 | |
| 1111 | |
| 1112 | |
| 1113 | /* @section member addition *************************************************** |
| 1114 | ** |
| 1115 | ** Functions for adding members to an |
| 1116 | ** Ensembl Genetic Variation Genotype object. |
| 1117 | ** |
| 1118 | ** @fdata [EnsPGvgenotype] |
| 1119 | ** |
| 1120 | ** @nam3rule Add Add one object to an Ensembl Genetic Variation Genotype |
| 1121 | ** @nam4rule Allele Add an allele |
| 1122 | ** @nam4rule Allelenumber Add a numbered allele |
| 1123 | ** @nam4rule Gvgenotypecode Add all alleles of an |
| 1124 | ** Ensembl Genetic Variation Genotype Code |
| 1125 | ** |
| 1126 | ** @argrule * gvg [EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1127 | ** @argrule Allele allele [AjPStr] Allele |
| 1128 | ** @argrule Allelenumber number [ajuint] Number |
| 1129 | ** @argrule Allelenumber allele [AjPStr] Allele |
| 1130 | ** @argrule Gvgenotypecode gvgc [EnsPGvgenotypecode] |
| 1131 | ** Ensembl Genetic Variation Genotype Code |
| 1132 | ** |
| 1133 | ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise |
| 1134 | ** |
| 1135 | ** @fcategory modify |
| 1136 | ******************************************************************************/ |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | /* @func ensGvgenotypeAddAllele *********************************************** |
| 1142 | ** |
| 1143 | ** Add an allele to an Ensembl Genetic Variation Genotype. |
| 1144 | ** |
| 1145 | ** @param [u] gvg [EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1146 | ** @param [u] allele [AjPStr] Allele |
| 1147 | ** |
| 1148 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 1149 | ** |
| 1150 | ** @release 6.5.0 |
| 1151 | ** @@ |
| 1152 | ******************************************************************************/ |
| 1153 | |
| 1154 | AjBool ensGvgenotypeAddAllele(EnsPGvgenotype gvg, |
| 1155 | AjPStr allele) |
| 1156 | { |
| 1157 | if (!gvg) |
| 1158 | return ajFalse; |
| 1159 | |
| 1160 | if (!allele) |
| 1161 | return ajFalse; |
| 1162 | |
| 1163 | if (!gvg->Alleles) |
| 1164 | gvg->Alleles = ajListstrNew(); |
| 1165 | |
| 1166 | ajListstrPushAppend(gvg->Alleles, ajStrNewRef(allele)); |
| 1167 | |
| 1168 | return ajTrue; |
| 1169 | } |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | /* @func ensGvgenotypeAddAllelenumber ***************************************** |
| 1175 | ** |
| 1176 | ** Add a numbered allele to an Ensembl Genetic Variation Genotype. |
| 1177 | ** |
| 1178 | ** @param [u] gvg [EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1179 | ** @param [r] number [ajuint] Number |
| 1180 | ** @param [u] allele [AjPStr] Allele |
| 1181 | ** |
| 1182 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 1183 | ** |
| 1184 | ** @release 6.5.0 |
| 1185 | ** @@ |
| 1186 | ******************************************************************************/ |
| 1187 | |
| 1188 | AjBool ensGvgenotypeAddAllelenumber(EnsPGvgenotype gvg, |
| 1189 | ajuint number, |
| 1190 | AjPStr allele) |
| 1191 | { |
| 1192 | register ajulong i = 0U; |
| 1193 | |
| 1194 | AjPStr string = NULL; |
| 1195 | |
| 1196 | if (!gvg) |
| 1197 | return ajFalse; |
| 1198 | |
| 1199 | if (!allele) |
| 1200 | return ajFalse; |
| 1201 | |
| 1202 | if (!gvg->Alleles) |
| 1203 | gvg->Alleles = ajListstrNew(); |
| 1204 | |
| 1205 | for (i = ajListGetLength(gvg->Alleles); i <= number; i++) |
| 1206 | ajListPushAppend(gvg->Alleles, NULL); |
| 1207 | |
| 1208 | ajListPeekNumber(gvg->Alleles, number - 1, (void **) &string); |
| 1209 | |
| 1210 | ajStrDel(&string); |
| 1211 | |
| 1212 | string = ajStrNewRef(allele); |
| 1213 | |
| 1214 | return ajTrue; |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | /* @func ensGvgenotypeAddGvgenotypecode *************************************** |
| 1221 | ** |
| 1222 | ** Add alleles from an Ensembl Genetic Variation Genotype Code to an |
| 1223 | ** Ensembl Genetic Variation Genotype. |
| 1224 | ** |
| 1225 | ** @param [u] gvg [EnsPGvgenotype] |
| 1226 | ** Ensembl Genetic Variation Genotype |
| 1227 | ** @param [u] gvgc [EnsPGvgenotypecode] |
| 1228 | ** Ensembl Genetic Variation Genotype Code |
| 1229 | ** |
| 1230 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 1231 | ** |
| 1232 | ** @release 6.5.0 |
| 1233 | ** @@ |
| 1234 | ******************************************************************************/ |
| 1235 | |
| 1236 | AjBool ensGvgenotypeAddGvgenotypecode(EnsPGvgenotype gvg, |
| 1237 | EnsPGvgenotypecode gvgc) |
| 1238 | { |
| 1239 | AjIList iter = NULL; |
| 1240 | |
| 1241 | AjPStr allele = NULL; |
| 1242 | |
| 1243 | if (!gvg) |
| 1244 | return ajFalse; |
| 1245 | |
| 1246 | if (!gvgc) |
| 1247 | return ajFalse; |
| 1248 | |
| 1249 | if (!gvg->Alleles) |
| 1250 | gvg->Alleles = ajListstrNew(); |
| 1251 | |
| 1252 | iter = ajListIterNewread(ensGvgenotypecodeGetAlleles(gvgc)); |
| 1253 | |
| 1254 | while (!ajListIterDone(iter)) |
| 1255 | { |
| 1256 | allele = ajListstrIterGet(iter); |
| 1257 | |
| 1258 | if (allele) |
| 1259 | ajListstrPushAppend(gvg->Alleles, ajStrNewRef(allele)); |
| 1260 | } |
| 1261 | |
| 1262 | ajListIterDel(&iter); |
| 1263 | |
| 1264 | return ajTrue; |
| 1265 | } |
| 1266 | |
| 1267 | |
| 1268 | |
| 1269 | |
| 1270 | /* @section debugging ********************************************************* |
| 1271 | ** |
| 1272 | ** Functions for reporting of an Ensembl Genetic Variation Genotype object. |
| 1273 | ** |
| 1274 | ** @fdata [EnsPGvgenotype] |
| 1275 | ** |
| 1276 | ** @nam3rule Trace Report Ensembl Genetic Variation Genotype members to |
| 1277 | ** debug file |
| 1278 | ** |
| 1279 | ** @argrule Trace gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1280 | ** @argrule Trace level [ajuint] Indentation level |
| 1281 | ** |
| 1282 | ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise |
| 1283 | ** |
| 1284 | ** @fcategory misc |
| 1285 | ******************************************************************************/ |
| 1286 | |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | /* @func ensGvgenotypeTrace *************************************************** |
| 1291 | ** |
| 1292 | ** Trace an Ensembl Genetic Variation Genotype. |
| 1293 | ** |
| 1294 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1295 | ** @param [r] level [ajuint] Indentation level |
| 1296 | ** |
| 1297 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 1298 | ** |
| 1299 | ** @release 6.2.0 |
| 1300 | ** @@ |
| 1301 | ******************************************************************************/ |
| 1302 | |
| 1303 | AjBool ensGvgenotypeTrace(const EnsPGvgenotype gvg, ajuint level) |
| 1304 | { |
| 1305 | AjIList iter = NULL; |
| 1306 | |
| 1307 | AjPStr allele = NULL; |
| 1308 | AjPStr indent = NULL; |
| 1309 | |
| 1310 | if (!gvg) |
| 1311 | return ajFalse; |
| 1312 | |
| 1313 | indent = ajStrNew(); |
| 1314 | |
| 1315 | ajStrAppendCountK(&indent, ' ', level * 2); |
| 1316 | |
| 1317 | ajDebug("%SensGvgenotypeTrace %p\n" |
| 1318 | "%S Use %u\n" |
| 1319 | "%S Identifier %u\n" |
| 1320 | "%S Adaptor %p\n" |
| 1321 | "%S Gvvariation %p\n" |
| 1322 | "%S Alleles %p\n" |
| 1323 | "%S Subhandle '%S'\n" |
| 1324 | "%S Subidentifier %u\n", |
| 1325 | indent, gvg, |
| 1326 | indent, gvg->Use, |
| 1327 | indent, gvg->Identifier, |
| 1328 | indent, gvg->Adaptor, |
| 1329 | indent, gvg->Gvvariation, |
| 1330 | indent, gvg->Alleles, |
| 1331 | indent, gvg->Subhandle, |
| 1332 | indent, gvg->Subidentifier); |
| 1333 | |
| 1334 | ensGvvariationTrace(gvg->Gvvariation, level + 1); |
| 1335 | |
| 1336 | iter = ajListIterNew(gvg->Alleles); |
| 1337 | |
| 1338 | while (!ajListIterDone(iter)) |
| 1339 | { |
| 1340 | allele = ajListstrIterGet(iter); |
| 1341 | |
| 1342 | ajDebug("%S Allele '%S'\n", indent, allele); |
| 1343 | } |
| 1344 | |
| 1345 | ajListIterDel(&iter); |
| 1346 | |
| 1347 | ajStrDel(&indent); |
| 1348 | |
| 1349 | return ajTrue; |
| 1350 | } |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | |
| 1355 | /* @section calculate ********************************************************* |
| 1356 | ** |
| 1357 | ** Functions for calculating information from an |
| 1358 | ** Ensembl Genetic Variation Genotype object. |
| 1359 | ** |
| 1360 | ** @fdata [EnsPGvgenotype] |
| 1361 | ** |
| 1362 | ** @nam3rule Calculate Calculate Ensembl Genetic Variation Genotype information |
| 1363 | ** @nam4rule Allelenumber Calculate a numbered allele |
| 1364 | ** @nam4rule Memsize Calculate the memory size in bytes |
| 1365 | ** |
| 1366 | ** @argrule * gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1367 | ** @argrule Allelenumber number [ajuint] Allele number |
| 1368 | ** |
| 1369 | ** @valrule Allelenumber [const AjPStr] Allele or NULL |
| 1370 | ** @valrule Memsize [size_t] Memory size in bytes or 0 |
| 1371 | ** |
| 1372 | ** @fcategory misc |
| 1373 | ******************************************************************************/ |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | /* @func ensGvgenotypeCalculateAllelenumber *********************************** |
| 1379 | ** |
| 1380 | ** Calculate a numbered allele of an Ensembl Genetic Variation Genotype. |
| 1381 | ** |
| 1382 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1383 | ** @param [r] number [ajuint] Allele number |
| 1384 | ** |
| 1385 | ** @return [const AjPStr] Allele or NULL |
| 1386 | ** |
| 1387 | ** @release 6.6.0 |
| 1388 | ** @@ |
| 1389 | ******************************************************************************/ |
| 1390 | |
| 1391 | const AjPStr ensGvgenotypeCalculateAllelenumber(const EnsPGvgenotype gvg, |
| 1392 | ajuint number) |
| 1393 | { |
| 1394 | AjPStr allele = NULL; |
| 1395 | |
| 1396 | if (!gvg) |
| 1397 | return NULL; |
| 1398 | |
| 1399 | if (!number) |
| 1400 | return NULL; |
| 1401 | |
| 1402 | ajListPeekNumber(gvg->Alleles, number, (void **) &allele); |
| 1403 | |
| 1404 | return (const AjPStr) allele; |
| 1405 | } |
| 1406 | |
| 1407 | |
| 1408 | |
| 1409 | |
| 1410 | /* @func ensGvgenotypeCalculateMemsize **************************************** |
| 1411 | ** |
| 1412 | ** Calculate the memory size in bytes of an |
| 1413 | ** Ensembl Genetic Variation Genotype. |
| 1414 | ** |
| 1415 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1416 | ** |
| 1417 | ** @return [size_t] Memory size in bytes or 0 |
| 1418 | ** |
| 1419 | ** @release 6.4.0 |
| 1420 | ** @@ |
| 1421 | ******************************************************************************/ |
| 1422 | |
| 1423 | size_t ensGvgenotypeCalculateMemsize(const EnsPGvgenotype gvg) |
| 1424 | { |
| 1425 | size_t size = 0; |
| 1426 | |
| 1427 | AjIList iter = NULL; |
| 1428 | |
| 1429 | AjPStr allele = NULL; |
| 1430 | |
| 1431 | if (!gvg) |
| 1432 | return 0; |
| 1433 | |
| 1434 | size += sizeof (EnsOGvgenotype); |
| 1435 | |
| 1436 | size += sizeof (AjOList); |
| 1437 | |
| 1438 | iter = ajListIterNew(gvg->Alleles); |
| 1439 | |
| 1440 | while (!ajListIterDone(iter)) |
| 1441 | { |
| 1442 | allele = ajListstrIterGet(iter); |
| 1443 | |
| 1444 | if (allele) |
| 1445 | { |
| 1446 | size += sizeof (AjOStr); |
| 1447 | |
| 1448 | size += ajStrGetRes(allele); |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | ajListIterDel(&iter); |
| 1453 | |
| 1454 | if (gvg->Subhandle) |
| 1455 | { |
| 1456 | size += sizeof (AjOStr); |
| 1457 | |
| 1458 | size += ajStrGetRes(gvg->Subhandle); |
| 1459 | } |
| 1460 | |
| 1461 | return size; |
| 1462 | } |
| 1463 | |
| 1464 | |
| 1465 | |
| 1466 | |
| 1467 | /* @section fetch ********************************************************* |
| 1468 | ** |
| 1469 | ** Functions for fetching information from an |
| 1470 | ** Ensembl Genetic Variation Genotype object. |
| 1471 | ** |
| 1472 | ** @fdata [EnsPGvgenotype] |
| 1473 | ** |
| 1474 | ** @nam3rule Fetch Fetch Ensembl Genetic Variation Genotype information |
| 1475 | ** @nam4rule Allele Fetch an allele |
| 1476 | ** @nam5rule Number Fetch the allele with number |
| 1477 | ** @nam5rule String Fetch the allel string |
| 1478 | ** |
| 1479 | ** @argrule * gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1480 | ** @argrule AlleleNumber number [ajuint] Number |
| 1481 | ** @argrule AlleleNumber Pallele [AjPStr*] Allele |
| 1482 | ** @argrule AlleleString Pstring [AjPStr*] Allele string |
| 1483 | ** |
| 1484 | ** @valrule Allele [AjBool] ajTrue upon success, ajFalse otherwise |
| 1485 | ** |
| 1486 | ** @fcategory misc |
| 1487 | ******************************************************************************/ |
| 1488 | |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 | /* @func ensGvgenotypeFetchAlleleNumber *************************************** |
| 1493 | ** |
| 1494 | ** Fetch the allele with number of an Ensembl Genetic Variation Genotype. |
| 1495 | ** |
| 1496 | ** @cc Bio::EnsEMBL::Variation::Genotype::allele |
| 1497 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1498 | ** @param [r] number [ajuint] Number |
| 1499 | ** @param [u] Pallele [AjPStr*] Allele |
| 1500 | ** |
| 1501 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 1502 | ** |
| 1503 | ** @release 6.2.0 |
| 1504 | ** @@ |
| 1505 | ******************************************************************************/ |
| 1506 | |
| 1507 | AjBool ensGvgenotypeFetchAlleleNumber(const EnsPGvgenotype gvg, |
| 1508 | ajuint number, |
| 1509 | AjPStr *Pallele) |
| 1510 | { |
| 1511 | AjPStr allele = NULL; |
| 1512 | |
| 1513 | if (!gvg) |
| 1514 | return ajFalse; |
| 1515 | |
| 1516 | if (!Pallele) |
| 1517 | return ajFalse; |
| 1518 | |
| 1519 | if (*Pallele) |
| 1520 | ajStrAssignClear(Pallele); |
| 1521 | else |
| 1522 | *Pallele = ajStrNew(); |
| 1523 | |
| 1524 | ajListPeekNumber(gvg->Alleles, number, (void **) &allele); |
| 1525 | |
| 1526 | ajStrAssignS(Pallele, allele); |
| 1527 | |
| 1528 | return ajTrue; |
| 1529 | } |
| 1530 | |
| 1531 | |
| 1532 | |
| 1533 | |
| 1534 | /* @func ensGvgenotypeFetchAlleleString *************************************** |
| 1535 | ** |
| 1536 | ** Fetch a string of alleles separated by '|' characters of an |
| 1537 | ** Ensembl Genetic Variation Genotype. |
| 1538 | ** |
| 1539 | ** @param [r] gvg [const EnsPGvgenotype] Ensembl Genetic Variation Genotype |
| 1540 | ** @param [u] Pstring [AjPStr*] Allele string |
| 1541 | ** |
| 1542 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 1543 | ** |
| 1544 | ** @release 6.2.0 |
| 1545 | ** @@ |
| 1546 | ******************************************************************************/ |
| 1547 | |
| 1548 | AjBool ensGvgenotypeFetchAlleleString(const EnsPGvgenotype gvg, |
| 1549 | AjPStr *Pstring) |
| 1550 | { |
| 1551 | AjIList iter = NULL; |
| 1552 | |
| 1553 | AjPStr allele = NULL; |
| 1554 | |
| 1555 | if (!gvg) |
| 1556 | return ajFalse; |
| 1557 | |
| 1558 | if (!Pstring) |
| 1559 | return ajFalse; |
| 1560 | |
| 1561 | if (*Pstring) |
| 1562 | ajStrAssignClear(Pstring); |
| 1563 | else |
| 1564 | *Pstring = ajStrNew(); |
| 1565 | |
| 1566 | iter = ajListIterNew(gvg->Alleles); |
| 1567 | |
| 1568 | while (!ajListIterDone(iter)) |
| 1569 | { |
| 1570 | allele = ajListstrIterGet(iter); |
| 1571 | |
| 1572 | ajStrAppendS(Pstring, allele); |
| 1573 | |
| 1574 | if (!ajListIterDone(iter)) |
| 1575 | ajStrAppendK(Pstring, '|'); |
| 1576 | } |
| 1577 | |
| 1578 | ajListIterDel(&iter); |
| 1579 | |
| 1580 | return ajTrue; |
| 1581 | } |
| 1582 | |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | /* @datasection [EnsPGvgenotypecode] Ensembl Genetic Variation Genotype Code ** |
| 1587 | ** |
| 1588 | ** @nam2rule Gvgenotypecode Functions for manipulating |
| 1589 | ** Ensembl Genetic Variation Genotype Code objects |
| 1590 | ** |
| 1591 | ** @cc Bio::EnsEMBL::Variation::GenotypeCode |
| 1592 | ** @cc CVS Revision: 1.2 |
| 1593 | ** @cc CVS Tag: branch-ensembl-68 |
| 1594 | ** |
| 1595 | ******************************************************************************/ |
| 1596 | |
| 1597 | |
| 1598 | |
| 1599 | |
| 1600 | /* @section constructors ****************************************************** |
| 1601 | ** |
| 1602 | ** All constructors return a new Ensembl Genetic Variation Genotype Code |
| 1603 | ** by pointer. |
| 1604 | ** It is the responsibility of the user to first destroy any previous |
| 1605 | ** Genetic Variation Genotype Code. The target pointer does not need to be |
| 1606 | ** initialised to NULL, but it is good programming practice to do so anyway. |
| 1607 | ** |
| 1608 | ** @fdata [EnsPGvgenotypecode] |
| 1609 | ** |
| 1610 | ** @nam3rule New Constructor |
| 1611 | ** @nam4rule Cpy Constructor with existing object |
| 1612 | ** @nam4rule Ini Constructor with initial values |
| 1613 | ** @nam4rule Ref Constructor by incrementing the reference counter |
| 1614 | ** |
| 1615 | ** @argrule Cpy gvgc [const EnsPGvgenotypecode] |
| 1616 | ** Ensembl Genetic Variation Genotype Code |
| 1617 | ** @argrule Ini gvgca [EnsPGvgenotypecodeadaptor] |
| 1618 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 1619 | ** @argrule Ini identifier [ajuint] SQL database-internal identifier |
| 1620 | ** @argrule Ini alleles [AjPList] AJAX List of AJAX String (allele) objects |
| 1621 | ** @argrule Ref gvgc [EnsPGvgenotypecode] |
| 1622 | ** Ensembl Genetic Variation Genotype Code |
| 1623 | ** |
| 1624 | ** @valrule * [EnsPGvgenotypecode] |
| 1625 | ** Ensembl Genetic Variation Genotype Code or NULL |
| 1626 | ** |
| 1627 | ** @fcategory new |
| 1628 | ******************************************************************************/ |
| 1629 | |
| 1630 | |
| 1631 | |
| 1632 | |
| 1633 | /* @func ensGvgenotypecodeNewCpy ********************************************** |
| 1634 | ** |
| 1635 | ** Object-based constructor function, which returns an independent object. |
| 1636 | ** |
| 1637 | ** @param [r] gvgc [const EnsPGvgenotypecode] |
| 1638 | ** Ensembl Genetic Variation Genotype Code |
| 1639 | ** |
| 1640 | ** @return [EnsPGvgenotypecode] |
| 1641 | ** Ensembl Genetic Variation Genotype Code or NULL |
| 1642 | ** |
| 1643 | ** @release 6.5.0 |
| 1644 | ** @@ |
| 1645 | ******************************************************************************/ |
| 1646 | |
| 1647 | EnsPGvgenotypecode ensGvgenotypecodeNewCpy(const EnsPGvgenotypecode gvgc) |
| 1648 | { |
| 1649 | AjIList iter = NULL; |
| 1650 | |
| 1651 | AjPStr allele = NULL; |
| 1652 | |
| 1653 | EnsPGvgenotypecode pthis = NULL; |
| 1654 | |
| 1655 | if (!gvgc) |
| 1656 | return NULL; |
| 1657 | |
| 1658 | AJNEW0(pthis); |
| 1659 | |
| 1660 | pthis->Use = 1U; |
| 1661 | pthis->Identifier = gvgc->Identifier; |
| 1662 | pthis->Adaptor = gvgc->Adaptor; |
| 1663 | |
| 1664 | /* NOTE: Copy the AJAX List of AJAX String (allele) objects */ |
| 1665 | |
| 1666 | if (gvgc->Alleles && ajListGetLength(gvgc->Alleles)) |
| 1667 | { |
| 1668 | pthis->Alleles = ajListstrNew(); |
| 1669 | |
| 1670 | iter = ajListIterNew(gvgc->Alleles); |
| 1671 | |
| 1672 | while (!ajListIterDone(iter)) |
| 1673 | { |
| 1674 | allele = ajListstrIterGet(iter); |
| 1675 | |
| 1676 | if (allele) |
| 1677 | ajListstrPushAppend(pthis->Alleles, ajStrNewS(allele)); |
| 1678 | } |
| 1679 | |
| 1680 | ajListIterDel(&iter); |
| 1681 | } |
| 1682 | |
| 1683 | return pthis; |
| 1684 | } |
| 1685 | |
| 1686 | |
| 1687 | |
| 1688 | |
| 1689 | /* @func ensGvgenotypecodeNewIni ********************************************** |
| 1690 | ** |
| 1691 | ** Constructor for an Ensembl Genetic Variation Genotype Code |
| 1692 | ** with initial values. |
| 1693 | ** |
| 1694 | ** @cc Bio::EnsEMBL::Storable::new |
| 1695 | ** @param [u] gvgca [EnsPGvgenotypecodeadaptor] |
| 1696 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 1697 | ** @param [r] identifier [ajuint] SQL database-internal identifier |
| 1698 | ** @cc Bio::EnsEMBL::Variation::GenotypeCode::new |
| 1699 | ** @param [u] alleles [AjPList] AJAX List of AJAX String (allele) objects |
| 1700 | ** |
| 1701 | ** @return [EnsPGvgenotypecode] |
| 1702 | ** Ensembl Genetic Variation Genotype Code or NULL |
| 1703 | ** |
| 1704 | ** @release 6.5.0 |
| 1705 | ** @@ |
| 1706 | ******************************************************************************/ |
| 1707 | |
| 1708 | EnsPGvgenotypecode ensGvgenotypecodeNewIni(EnsPGvgenotypecodeadaptor gvgca, |
| 1709 | ajuint identifier, |
| 1710 | AjPList alleles) |
| 1711 | { |
| 1712 | AjIList iter = NULL; |
| 1713 | |
| 1714 | AjPStr allele = NULL; |
| 1715 | |
| 1716 | EnsPGvgenotypecode gvgc = NULL; |
| 1717 | |
| 1718 | AJNEW0(gvgc); |
| 1719 | |
| 1720 | gvgc->Use = 1U; |
| 1721 | gvgc->Identifier = identifier; |
| 1722 | gvgc->Adaptor = gvgca; |
| 1723 | |
| 1724 | /* NOTE: Copy the AJAX List of AJAX String (allele) objects */ |
| 1725 | |
| 1726 | if (alleles && ajListGetLength(alleles)) |
| 1727 | { |
| 1728 | gvgc->Alleles = ajListstrNew(); |
| 1729 | |
| 1730 | iter = ajListIterNew(alleles); |
| 1731 | |
| 1732 | while (!ajListIterDone(iter)) |
| 1733 | { |
| 1734 | allele = ajListstrIterGet(iter); |
| 1735 | |
| 1736 | if (allele) |
| 1737 | ajListstrPushAppend(gvgc->Alleles, ajStrNewS(allele)); |
| 1738 | } |
| 1739 | |
| 1740 | ajListIterDel(&iter); |
| 1741 | } |
| 1742 | |
| 1743 | return gvgc; |
| 1744 | } |
| 1745 | |
| 1746 | |
| 1747 | |
| 1748 | |
| 1749 | /* @func ensGvgenotypecodeNewRef ********************************************** |
| 1750 | ** |
| 1751 | ** Ensembl Object referencing function, which returns a pointer to the |
| 1752 | ** Ensembl Object passed in and increases its reference count. |
| 1753 | ** |
| 1754 | ** @param [u] gvgc [EnsPGvgenotypecode] |
| 1755 | ** Ensembl Genetic Variation Genotype Code |
| 1756 | ** |
| 1757 | ** @return [EnsPGvgenotypecode] |
| 1758 | ** Ensembl Genetic Variation Genotype Code or NULL |
| 1759 | ** |
| 1760 | ** @release 6.5.0 |
| 1761 | ** @@ |
| 1762 | ******************************************************************************/ |
| 1763 | |
| 1764 | EnsPGvgenotypecode ensGvgenotypecodeNewRef(EnsPGvgenotypecode gvgc) |
| 1765 | { |
| 1766 | if (!gvgc) |
| 1767 | return NULL; |
| 1768 | |
| 1769 | gvgc->Use++; |
| 1770 | |
| 1771 | return gvgc; |
| 1772 | } |
| 1773 | |
| 1774 | |
| 1775 | |
| 1776 | |
| 1777 | /* @section destructors ******************************************************* |
| 1778 | ** |
| 1779 | ** Destruction destroys all internal data structures and frees the memory |
| 1780 | ** allocated for an Ensembl Genetic Variation Genotype Code object. |
| 1781 | ** |
| 1782 | ** @fdata [EnsPGvgenotypecode] |
| 1783 | ** |
| 1784 | ** @nam3rule Del Destroy (free) a Genetic Variation Genotype Code object |
| 1785 | ** |
| 1786 | ** @argrule * Pgvgc [EnsPGvgenotypecode*] |
| 1787 | ** Ensembl Genetic Variation Genotype Code address |
| 1788 | ** |
| 1789 | ** @valrule * [void] |
| 1790 | ** |
| 1791 | ** @fcategory delete |
| 1792 | ******************************************************************************/ |
| 1793 | |
| 1794 | |
| 1795 | |
| 1796 | |
| 1797 | /* @func ensGvgenotypecodeDel ************************************************* |
| 1798 | ** |
| 1799 | ** Default destructor for an Ensembl Genetic Variation Genotype Code. |
| 1800 | ** |
| 1801 | ** @param [d] Pgvgc [EnsPGvgenotypecode*] |
| 1802 | ** Ensembl Genetic Variation Genotype Code address |
| 1803 | ** |
| 1804 | ** @return [void] |
| 1805 | ** |
| 1806 | ** @release 6.5.0 |
| 1807 | ** @@ |
| 1808 | ******************************************************************************/ |
| 1809 | |
| 1810 | void ensGvgenotypecodeDel(EnsPGvgenotypecode *Pgvgc) |
| 1811 | { |
| 1812 | EnsPGvgenotypecode pthis = NULL; |
| 1813 | |
| 1814 | if (!Pgvgc) |
| 1815 | return; |
| 1816 | |
| 1817 | #if defined(AJ_DEBUG) && AJ_DEBUG >= 1 |
| 1818 | if (ajDebugTest("ensGvgenotypecodeDel")) |
| 1819 | { |
| 1820 | ajDebug("ensGvgenotypecodeDel\n" |
| 1821 | " *Pgvgc %p\n", |
| 1822 | *Pgvgc); |
| 1823 | |
| 1824 | ensGvgenotypecodeTrace(*Pgvgc, 1); |
| 1825 | } |
| 1826 | #endif /* defined(AJ_DEBUG) && AJ_DEBUG >= 1 */ |
| 1827 | |
| 1828 | if (!(pthis = *Pgvgc) || --pthis->Use) |
| 1829 | { |
| 1830 | *Pgvgc = NULL; |
| 1831 | |
| 1832 | return; |
| 1833 | } |
| 1834 | |
| 1835 | ajListstrFreeData(&pthis->Alleles); |
| 1836 | |
| 1837 | ajMemFree((void **) Pgvgc); |
| 1838 | |
| 1839 | return; |
| 1840 | } |
| 1841 | |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 | /* @section member retrieval ************************************************** |
| 1846 | ** |
| 1847 | ** Functions for returning members of an |
| 1848 | ** Ensembl Genetic Variation Genotype Code object. |
| 1849 | ** |
| 1850 | ** @fdata [EnsPGvgenotypecode] |
| 1851 | ** |
| 1852 | ** @nam3rule Get Return Genetic Variation Genotype Code attribute(s) |
| 1853 | ** @nam4rule Adaptor Return the Ensembl Genetic Variation Genotype Code Adaptor |
| 1854 | ** @nam4rule Alleles Return the alleles |
| 1855 | ** @nam4rule Identifier Return the SQL database-internal identifier |
| 1856 | ** |
| 1857 | ** @argrule * gvgc [const EnsPGvgenotypecode] |
| 1858 | ** Ensembl Genetic Variation Genotype Code |
| 1859 | ** |
| 1860 | ** @valrule Adaptor [EnsPGvgenotypecodeadaptor] |
| 1861 | ** Ensembl Genetic Variation Genotype Code Adaptor or NULL |
| 1862 | ** @valrule Alleles [const AjPList] |
| 1863 | ** AJAX List of AJAX String (allele) objects or NULL |
| 1864 | ** @valrule Identifier [ajuint] SQL database-internal identifier or 0U |
| 1865 | ** |
| 1866 | ** @fcategory use |
| 1867 | ******************************************************************************/ |
| 1868 | |
| 1869 | |
| 1870 | |
| 1871 | |
| 1872 | /* @func ensGvgenotypecodeGetAdaptor ****************************************** |
| 1873 | ** |
| 1874 | ** Get the Ensembl Genetic Variation Genotype Code Adaptor member of an |
| 1875 | ** Ensembl Genetic Variation Genotype Code. |
| 1876 | ** |
| 1877 | ** @param [r] gvgc [const EnsPGvgenotypecode] |
| 1878 | ** Ensembl Genetic Variation Genotype Code |
| 1879 | ** |
| 1880 | ** @return [EnsPGvgenotypecodeadaptor] |
| 1881 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 1882 | ** or NULL |
| 1883 | ** |
| 1884 | ** @release 6.5.0 |
| 1885 | ** @@ |
| 1886 | ******************************************************************************/ |
| 1887 | |
| 1888 | EnsPGvgenotypecodeadaptor ensGvgenotypecodeGetAdaptor( |
| 1889 | const EnsPGvgenotypecode gvgc) |
| 1890 | { |
| 1891 | return (gvgc) ? gvgc->Adaptor : NULL; |
| 1892 | } |
| 1893 | |
| 1894 | |
| 1895 | |
| 1896 | |
| 1897 | /* @func ensGvgenotypecodeGetAlleles ****************************************** |
| 1898 | ** |
| 1899 | ** Get the alleles member of an |
| 1900 | ** Ensembl Genetic Variation Genotype Code. |
| 1901 | ** |
| 1902 | ** @param [r] gvgc [const EnsPGvgenotypecode] |
| 1903 | ** Ensembl Genetic Variation Genotype Code |
| 1904 | ** |
| 1905 | ** @return [const AjPList] AJAX List of AJAX String (allele) objects or NULL |
| 1906 | ** |
| 1907 | ** @release 6.5.0 |
| 1908 | ** @@ |
| 1909 | ******************************************************************************/ |
| 1910 | |
| 1911 | const AjPList ensGvgenotypecodeGetAlleles( |
| 1912 | const EnsPGvgenotypecode gvgc) |
| 1913 | { |
| 1914 | return (gvgc) ? gvgc->Alleles : NULL; |
| 1915 | } |
| 1916 | |
| 1917 | |
| 1918 | |
| 1919 | |
| 1920 | /* @func ensGvgenotypecodeGetIdentifier *************************************** |
| 1921 | ** |
| 1922 | ** Get the SQL database-internal identifier member of an |
| 1923 | ** Ensembl Genetic Variation Genotype Code. |
| 1924 | ** |
| 1925 | ** @param [r] gvgc [const EnsPGvgenotypecode] |
| 1926 | ** Ensembl Genetic Variation Genotype Code |
| 1927 | ** |
| 1928 | ** @return [ajuint] SQL database-internal identifier or 0U |
| 1929 | ** |
| 1930 | ** @release 6.5.0 |
| 1931 | ** @@ |
| 1932 | ******************************************************************************/ |
| 1933 | |
| 1934 | ajuint ensGvgenotypecodeGetIdentifier( |
| 1935 | const EnsPGvgenotypecode gvgc) |
| 1936 | { |
| 1937 | return (gvgc) ? gvgc->Identifier : 0U; |
| 1938 | } |
| 1939 | |
| 1940 | |
| 1941 | |
| 1942 | |
| 1943 | /* @section member assignment ************************************************* |
| 1944 | ** |
| 1945 | ** Functions for assigning members of an |
| 1946 | ** Ensembl Genetic Variation Genotype Code object. |
| 1947 | ** |
| 1948 | ** @fdata [EnsPGvgenotypecode] |
| 1949 | ** |
| 1950 | ** @nam3rule Set Set one member of a Genetic Variation Genotype Code |
| 1951 | ** @nam4rule Adaptor Set the Ensembl Genetic Variation Genotype Code Adaptor |
| 1952 | ** @nam4rule Genotype Set the genotype |
| 1953 | ** @nam4rule Identifier Set the SQL database-internal identifier |
| 1954 | ** |
| 1955 | ** @argrule * gvgc [EnsPGvgenotypecode] |
| 1956 | ** Ensembl Genetic Variation Genotype Code object |
| 1957 | ** @argrule Adaptor gvgca [EnsPGvgenotypecodeadaptor] |
| 1958 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 1959 | ** @argrule Alleles genotype [AjPList] |
| 1960 | ** AJAX List of AJAX String (allele) objects |
| 1961 | ** @argrule Identifier identifier [ajuint] SQL database-internal identifier |
| 1962 | ** |
| 1963 | ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise |
| 1964 | ** |
| 1965 | ** @fcategory modify |
| 1966 | ******************************************************************************/ |
| 1967 | |
| 1968 | |
| 1969 | |
| 1970 | |
| 1971 | /* @func ensGvgenotypecodeSetAdaptor ****************************************** |
| 1972 | ** |
| 1973 | ** Set the Ensembl Genetic Variation Genotype Code Adaptor member of an |
| 1974 | ** Ensembl Genetic Variation Genotype Code. |
| 1975 | ** |
| 1976 | ** @param [u] gvgc [EnsPGvgenotypecode] |
| 1977 | ** Ensembl Genetic Variation Genotype Code |
| 1978 | ** @param [u] gvgca [EnsPGvgenotypecodeadaptor] |
| 1979 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 1980 | ** |
| 1981 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 1982 | ** |
| 1983 | ** @release 6.5.0 |
| 1984 | ** @@ |
| 1985 | ******************************************************************************/ |
| 1986 | |
| 1987 | AjBool ensGvgenotypecodeSetAdaptor(EnsPGvgenotypecode gvgc, |
| 1988 | EnsPGvgenotypecodeadaptor gvgca) |
| 1989 | { |
| 1990 | if (!gvgc) |
| 1991 | return ajFalse; |
| 1992 | |
| 1993 | gvgc->Adaptor = gvgca; |
| 1994 | |
| 1995 | return ajTrue; |
| 1996 | } |
| 1997 | |
| 1998 | |
| 1999 | |
| 2000 | |
| 2001 | /* @func ensGvgenotypecodeSetIdentifier *************************************** |
| 2002 | ** |
| 2003 | ** Set the SQL database-internal identifier member of an |
| 2004 | ** Ensembl Genetic Variation Genotype Code. |
| 2005 | ** |
| 2006 | ** @param [u] gvgc [EnsPGvgenotypecode] |
| 2007 | ** Ensembl Genetic Variation Genotype Code |
| 2008 | ** @param [r] identifier [ajuint] SQL database-internal identifier |
| 2009 | ** |
| 2010 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 2011 | ** |
| 2012 | ** @release 6.5.0 |
| 2013 | ** @@ |
| 2014 | ******************************************************************************/ |
| 2015 | |
| 2016 | AjBool ensGvgenotypecodeSetIdentifier(EnsPGvgenotypecode gvgc, |
| 2017 | ajuint identifier) |
| 2018 | { |
| 2019 | if (!gvgc) |
| 2020 | return ajFalse; |
| 2021 | |
| 2022 | gvgc->Identifier = identifier; |
| 2023 | |
| 2024 | return ajTrue; |
| 2025 | } |
| 2026 | |
| 2027 | |
| 2028 | |
| 2029 | |
| 2030 | /* @section member addition *************************************************** |
| 2031 | ** |
| 2032 | ** Functions for adding members to an |
| 2033 | ** Ensembl Genetic Variation Genotype Code object. |
| 2034 | ** |
| 2035 | ** @fdata [EnsPGvgenotypecode] |
| 2036 | ** |
| 2037 | ** @nam3rule Add Add one object to an Ensembl Genetic Variation Genotype Code |
| 2038 | ** @nam4rule Allele Add an allele |
| 2039 | ** |
| 2040 | ** @argrule * gvgc [EnsPGvgenotypecode] Ensembl Genetic Variation Genotype Code |
| 2041 | ** @argrule Allele allele [AjPStr] Allele |
| 2042 | ** |
| 2043 | ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise |
| 2044 | ** |
| 2045 | ** @fcategory modify |
| 2046 | ******************************************************************************/ |
| 2047 | |
| 2048 | |
| 2049 | |
| 2050 | |
| 2051 | /* @func ensGvgenotypecodeAddAllele ******************************************* |
| 2052 | ** |
| 2053 | ** Add an allele to an Ensembl Genetic Variation Genotype Code. |
| 2054 | ** |
| 2055 | ** @param [u] gvgc [EnsPGvgenotypecode] |
| 2056 | ** Ensembl Genetic Variation Genotype Code |
| 2057 | ** @param [u] allele [AjPStr] Allele |
| 2058 | ** |
| 2059 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 2060 | ** |
| 2061 | ** @release 6.5.0 |
| 2062 | ** @@ |
| 2063 | ******************************************************************************/ |
| 2064 | |
| 2065 | AjBool ensGvgenotypecodeAddAllele(EnsPGvgenotypecode gvgc, AjPStr allele) |
| 2066 | { |
| 2067 | if (!gvgc) |
| 2068 | return ajFalse; |
| 2069 | |
| 2070 | if (!allele) |
| 2071 | return ajFalse; |
| 2072 | |
| 2073 | if (!gvgc->Alleles) |
| 2074 | gvgc->Alleles = ajListstrNew(); |
| 2075 | |
| 2076 | ajListstrPushAppend(gvgc->Alleles, allele); |
| 2077 | |
| 2078 | return ajTrue; |
| 2079 | } |
| 2080 | |
| 2081 | |
| 2082 | |
| 2083 | |
| 2084 | /* @section debugging ********************************************************* |
| 2085 | ** |
| 2086 | ** Functions for reporting of an |
| 2087 | ** Ensembl Genetic Variation Genotype Code object. |
| 2088 | ** |
| 2089 | ** @fdata [EnsPGvgenotypecode] |
| 2090 | ** |
| 2091 | ** @nam3rule Trace Report Ensembl Genetic Variation Genotype Code members to |
| 2092 | ** debug file |
| 2093 | ** |
| 2094 | ** @argrule Trace gvgc [const EnsPGvgenotypecode] |
| 2095 | ** Ensembl Genetic Variation Genotype Code |
| 2096 | ** @argrule Trace level [ajuint] Indentation level |
| 2097 | ** |
| 2098 | ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise |
| 2099 | ** |
| 2100 | ** @fcategory misc |
| 2101 | ******************************************************************************/ |
| 2102 | |
| 2103 | |
| 2104 | |
| 2105 | |
| 2106 | /* @func ensGvgenotypecodeTrace *********************************************** |
| 2107 | ** |
| 2108 | ** Trace an Ensembl Genetic Variation Genotype Code. |
| 2109 | ** |
| 2110 | ** @param [r] gvgc [const EnsPGvgenotypecode] |
| 2111 | ** Ensembl Genetic Variation Genotype Code |
| 2112 | ** @param [r] level [ajuint] Indentation level |
| 2113 | ** |
| 2114 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 2115 | ** |
| 2116 | ** @release 6.5.0 |
| 2117 | ** @@ |
| 2118 | ******************************************************************************/ |
| 2119 | |
| 2120 | AjBool ensGvgenotypecodeTrace(const EnsPGvgenotypecode gvgc, ajuint level) |
| 2121 | { |
| 2122 | AjIList iter = NULL; |
| 2123 | |
| 2124 | AjPStr allele = NULL; |
| 2125 | AjPStr indent = NULL; |
| 2126 | |
| 2127 | if (!gvgc) |
| 2128 | return ajFalse; |
| 2129 | |
| 2130 | indent = ajStrNew(); |
| 2131 | |
| 2132 | ajStrAppendCountK(&indent, ' ', level * 2); |
| 2133 | |
| 2134 | ajDebug("%SensGvgenotypecodeTrace %p\n" |
| 2135 | "%S Use %u\n" |
| 2136 | "%S Identifier %u\n" |
| 2137 | "%S Adaptor %p\n" |
| 2138 | "%S Alleles %p\n", |
| 2139 | indent, gvgc, |
| 2140 | indent, gvgc->Use, |
| 2141 | indent, gvgc->Identifier, |
| 2142 | indent, gvgc->Adaptor, |
| 2143 | indent, gvgc->Alleles); |
| 2144 | |
| 2145 | iter = ajListIterNew(gvgc->Alleles); |
| 2146 | |
| 2147 | while (!ajListIterDone(iter)) |
| 2148 | { |
| 2149 | allele = ajListstrIterGet(iter); |
| 2150 | |
| 2151 | ajDebug("%S Allele '%S'\n", indent, allele); |
| 2152 | } |
| 2153 | |
| 2154 | ajListIterDel(&iter); |
| 2155 | |
| 2156 | ajStrDel(&indent); |
| 2157 | |
| 2158 | return ajTrue; |
| 2159 | } |
| 2160 | |
| 2161 | |
| 2162 | |
| 2163 | |
| 2164 | /* @section calculate ********************************************************* |
| 2165 | ** |
| 2166 | ** Functions for calculating information from an |
| 2167 | ** Ensembl Genetic Variation Genotype Code object. |
| 2168 | ** |
| 2169 | ** @fdata [EnsPGvgenotypecode] |
| 2170 | ** |
| 2171 | ** @nam3rule Calculate |
| 2172 | ** Calculate Ensembl Genetic Variation Genotype Code information |
| 2173 | ** @nam4rule Memsize Calculate the memory size in bytes |
| 2174 | ** |
| 2175 | ** @argrule * gvgc [const EnsPGvgenotypecode] |
| 2176 | ** Ensembl Genetic Variation Genotype Code |
| 2177 | ** |
| 2178 | ** @valrule Memsize [size_t] Memory size in bytes or 0 |
| 2179 | ** |
| 2180 | ** @fcategory misc |
| 2181 | ******************************************************************************/ |
| 2182 | |
| 2183 | |
| 2184 | |
| 2185 | |
| 2186 | /* @func ensGvgenotypecodeCalculateMemsize ************************************ |
| 2187 | ** |
| 2188 | ** Calculate the memory size in bytes of an |
| 2189 | ** Ensembl Genetic Variation Genotype Code. |
| 2190 | ** |
| 2191 | ** @param [r] gvgc [const EnsPGvgenotypecode] |
| 2192 | ** Ensembl Genetic Variation Genotype Code |
| 2193 | ** |
| 2194 | ** @return [size_t] Memory size in bytes or 0 |
| 2195 | ** |
| 2196 | ** @release 6.5.0 |
| 2197 | ** @@ |
| 2198 | ******************************************************************************/ |
| 2199 | |
| 2200 | size_t ensGvgenotypecodeCalculateMemsize(const EnsPGvgenotypecode gvgc) |
| 2201 | { |
| 2202 | size_t size = 0; |
| 2203 | |
| 2204 | AjIList iter = NULL; |
| 2205 | |
| 2206 | AjPStr allele = NULL; |
| 2207 | |
| 2208 | if (!gvgc) |
| 2209 | return 0; |
| 2210 | |
| 2211 | size += sizeof (EnsOGvgenotypecode); |
| 2212 | |
| 2213 | size += sizeof (AjOList); |
| 2214 | |
| 2215 | iter = ajListIterNew(gvgc->Alleles); |
| 2216 | |
| 2217 | while (!ajListIterDone(iter)) |
| 2218 | { |
| 2219 | allele = ajListstrIterGet(iter); |
| 2220 | |
| 2221 | if (allele) |
| 2222 | { |
| 2223 | size += sizeof (AjOStr); |
| 2224 | |
| 2225 | size += ajStrGetRes(allele); |
| 2226 | } |
| 2227 | } |
| 2228 | |
| 2229 | ajListIterDel(&iter); |
| 2230 | |
| 2231 | return size; |
| 2232 | } |
| 2233 | |
| 2234 | |
| 2235 | |
| 2236 | |
| 2237 | /* @datasection [EnsPGvgenotypecodeadaptor] Ensembl Genetic Variation Genotype |
| 2238 | ** Code Adaptor |
| 2239 | ** |
| 2240 | ** @nam2rule Gvgenotypecodeadaptor Functions for manipulating |
| 2241 | ** Ensembl Genetic Variation Genotype Code Adaptor objects |
| 2242 | ** |
| 2243 | ** @cc Bio::EnsEMBL::Variation::DBSQL::GenotypeCodeAdaptor |
| 2244 | ** @cc CVS Revision: 1.3 |
| 2245 | ** @cc CVS Tag: branch-ensembl-68 |
| 2246 | ** |
| 2247 | ******************************************************************************/ |
| 2248 | |
| 2249 | |
| 2250 | |
| 2251 | |
| 2252 | /* @funcstatic gvgenotypecodeadaptorFetchAllbyStatement *********************** |
| 2253 | ** |
| 2254 | ** Fetch all Ensembl Genetic Variation Genotype Code objects via an |
| 2255 | ** SQL statement. |
| 2256 | ** |
| 2257 | ** @cc Bio::EnsEMBL::Variation::DBSQL::GenotypeCodeAdaptor:: |
| 2258 | ** _objs_from_sth |
| 2259 | ** @param [u] ba [EnsPBaseadaptor] Ensembl Base Adaptor |
| 2260 | ** @param [r] statement [const AjPStr] SQL statement |
| 2261 | ** @param [uN] am [EnsPAssemblymapper] Ensembl Assembly Mapper |
| 2262 | ** @param [uN] slice [EnsPSlice] Ensembl Slice |
| 2263 | ** @param [u] gvgcs [AjPList] AJAX List of Ensembl Genetic Variation |
| 2264 | ** Genotype Code objects |
| 2265 | ** |
| 2266 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 2267 | ** |
| 2268 | ** @release 6.5.0 |
| 2269 | ** @@ |
| 2270 | ******************************************************************************/ |
| 2271 | |
| 2272 | static AjBool gvgenotypecodeadaptorFetchAllbyStatement( |
| 2273 | EnsPBaseadaptor ba, |
| 2274 | const AjPStr statement, |
| 2275 | EnsPAssemblymapper am, |
| 2276 | EnsPSlice slice, |
| 2277 | AjPList gvgcs) |
| 2278 | { |
| 2279 | register ajuint i = 0U; |
| 2280 | |
| 2281 | ajuint identifier = 0U; |
| 2282 | ajuint haplotypeid = 0U; |
| 2283 | ajuint ploidy = 0U; |
| 2284 | |
| 2285 | AjPList gvhs = NULL; |
| 2286 | |
| 2287 | AjPSqlstatement sqls = NULL; |
| 2288 | AjISqlrow sqli = NULL; |
| 2289 | AjPSqlrow sqlr = NULL; |
| 2290 | |
| 2291 | AjPStr allele = NULL; |
| 2292 | |
| 2293 | EnsPDatabaseadaptor dba = NULL; |
| 2294 | |
| 2295 | EnsPGvgenotypecode gvgc = NULL; |
| 2296 | EnsPGvgenotypecodeadaptor gvgca = NULL; |
| 2297 | |
| 2298 | GvPHaplotype gvh = NULL; |
| 2299 | |
| 2300 | if (ajDebugTest("gvgenotypecodeadaptorFetchAllbyStatement")) |
| 2301 | ajDebug("gvgenotypecodeadaptorFetchAllbyStatement\n" |
| 2302 | " ba %p\n" |
| 2303 | " statement %p\n" |
| 2304 | " am %p\n" |
| 2305 | " slice %p\n" |
| 2306 | " gvgcs %p\n", |
| 2307 | ba, |
| 2308 | statement, |
| 2309 | am, |
| 2310 | slice, |
| 2311 | gvgcs); |
| 2312 | |
| 2313 | if (!ba) |
| 2314 | return ajFalse; |
| 2315 | |
| 2316 | if (!statement) |
| 2317 | return ajFalse; |
| 2318 | |
| 2319 | if (!gvgcs) |
| 2320 | return ajFalse; |
| 2321 | |
| 2322 | gvhs = ajListNew(); |
| 2323 | |
| 2324 | dba = ensBaseadaptorGetDatabaseadaptor(ba); |
| 2325 | |
| 2326 | gvgca = ensRegistryGetGvgenotypecodeadaptor(dba); |
| 2327 | |
| 2328 | ploidy = ensGvbaseadaptorLoadPloidy(gvgca); |
| 2329 | |
| 2330 | sqls = ensDatabaseadaptorSqlstatementNew(dba, statement); |
| 2331 | |
| 2332 | sqli = ajSqlrowiterNew(sqls); |
| 2333 | |
| 2334 | while (!ajSqlrowiterDone(sqli)) |
| 2335 | { |
| 2336 | identifier = 0U; |
| 2337 | haplotypeid = 0U; |
| 2338 | allele = ajStrNew(); |
| 2339 | |
| 2340 | sqlr = ajSqlrowiterGet(sqli); |
| 2341 | |
| 2342 | ajSqlcolumnToUint(sqlr, &identifier); |
| 2343 | ajSqlcolumnToUint(sqlr, &haplotypeid); |
| 2344 | ajSqlcolumnToStr(sqlr, &allele); |
| 2345 | |
| 2346 | if (ensGvgenotypecodeGetIdentifier(gvgc) != identifier) |
| 2347 | { |
| 2348 | /* Deal with haplotypes of the previous object. */ |
| 2349 | |
| 2350 | listGvhaplotypeSortIdentifierAscending(gvhs); |
| 2351 | |
| 2352 | i = 0U; |
| 2353 | |
| 2354 | while (ajListPop(gvhs, (void **) &gvh)) |
| 2355 | { |
| 2356 | if (i < ploidy) |
| 2357 | ensGvgenotypecodeAddAllele(gvgc, gvh->Allele); |
| 2358 | |
| 2359 | gvHaplotypeDel(&gvh); |
| 2360 | } |
| 2361 | |
| 2362 | /* New object. */ |
| 2363 | |
| 2364 | gvgc = ensGvgenotypecodeNewIni(gvgca, identifier, (AjPList) NULL); |
| 2365 | |
| 2366 | ajListPushAppend(gvgcs, (void *) gvgc); |
| 2367 | } |
| 2368 | |
| 2369 | /* |
| 2370 | ** Add the allele under its haplotype identifier to the |
| 2371 | ** temporary AJAX List. |
| 2372 | */ |
| 2373 | |
| 2374 | gvh = gvHaplotypeNewIni(haplotypeid, allele); |
| 2375 | |
| 2376 | ajListPushAppend(gvhs, (void *) gvh); |
| 2377 | |
| 2378 | ajStrDel(&allele); |
| 2379 | } |
| 2380 | |
| 2381 | ajSqlrowiterDel(&sqli); |
| 2382 | |
| 2383 | ensDatabaseadaptorSqlstatementDel(dba, &sqls); |
| 2384 | |
| 2385 | /* Add allele strings to the last object. */ |
| 2386 | |
| 2387 | listGvhaplotypeSortIdentifierAscending(gvhs); |
| 2388 | |
| 2389 | i = 0U; |
| 2390 | |
| 2391 | while (ajListPop(gvhs, (void **) &gvh)) |
| 2392 | { |
| 2393 | if (i < ploidy) |
| 2394 | ensGvgenotypecodeAddAllele(gvgc, gvh->Allele); |
| 2395 | |
| 2396 | gvHaplotypeDel(&gvh); |
| 2397 | } |
| 2398 | |
| 2399 | ajListFree(&gvhs); |
| 2400 | |
| 2401 | return ajTrue; |
| 2402 | } |
| 2403 | |
| 2404 | |
| 2405 | |
| 2406 | |
| 2407 | /* @section constructors ****************************************************** |
| 2408 | ** |
| 2409 | ** All constructors return a new Ensembl Genetic Variation Genotype Code |
| 2410 | ** Adaptor by pointer. |
| 2411 | ** It is the responsibility of the user to first destroy any previous |
| 2412 | ** Genetic Variation Genotype Code Adaptor. |
| 2413 | ** The target pointer does not need to be initialised to NULL, |
| 2414 | ** but it is good programming practice to do so anyway. |
| 2415 | ** |
| 2416 | ** @fdata [EnsPGvgenotypecodeadaptor] |
| 2417 | ** |
| 2418 | ** @nam3rule New Constructor |
| 2419 | ** |
| 2420 | ** @argrule New dba [EnsPDatabaseadaptor] Ensembl Database Adaptor |
| 2421 | ** |
| 2422 | ** @valrule * [EnsPGvgenotypecodeadaptor] |
| 2423 | ** Ensembl Genetic Variation Genotype Code Adaptor or NULL |
| 2424 | ** |
| 2425 | ** @fcategory new |
| 2426 | ******************************************************************************/ |
| 2427 | |
| 2428 | |
| 2429 | |
| 2430 | |
| 2431 | /* @func ensGvgenotypecodeadaptorNew ****************************************** |
| 2432 | ** |
| 2433 | ** Default constructor for an |
| 2434 | ** Ensembl Genetic Variation Genotype Code Adaptor. |
| 2435 | ** |
| 2436 | ** Ensembl Object Adaptors are singleton objects in the sense that a single |
| 2437 | ** instance of an Ensembl Object Adaptor connected to a particular database is |
| 2438 | ** sufficient to instantiate any number of Ensembl Objects from the database. |
| 2439 | ** Each Ensembl Object will have a weak reference to the Object Adaptor that |
| 2440 | ** instantiated it. Therefore, Ensembl Object Adaptors should not be |
| 2441 | ** instantiated directly, but rather obtained from the Ensembl Registry, |
| 2442 | ** which will in turn call this function if neccessary. |
| 2443 | ** |
| 2444 | ** @see ensRegistryGetDatabaseadaptor |
| 2445 | ** @see ensRegistryGetGvgenotypecodeadaptor |
| 2446 | ** |
| 2447 | ** @cc Bio::EnsEMBL::Variation::DBSQL::GenotypeCodeAdaptor::new |
| 2448 | ** @param [u] dba [EnsPDatabaseadaptor] Ensembl Database Adaptor |
| 2449 | ** |
| 2450 | ** @return [EnsPGvgenotypecodeadaptor] |
| 2451 | ** Ensembl Genetic Variation Genotype Code Adaptor or NULL |
| 2452 | ** |
| 2453 | ** @release 6.5.0 |
| 2454 | ** @@ |
| 2455 | ******************************************************************************/ |
| 2456 | |
| 2457 | EnsPGvgenotypecodeadaptor ensGvgenotypecodeadaptorNew( |
| 2458 | EnsPDatabaseadaptor dba) |
| 2459 | { |
| 2460 | EnsPGvdatabaseadaptor gvdba = NULL; |
| 2461 | |
| 2462 | if (ajDebugTest("ensGvgenotypecodeadaptorNew")) |
| 2463 | ajDebug("ensGvgenotypecodeadaptorNew\n" |
| 2464 | " dba %p\n", |
| 2465 | dba); |
| 2466 | |
| 2467 | if (!dba) |
| 2468 | return NULL; |
| 2469 | |
| 2470 | gvdba = ensRegistryGetGvdatabaseadaptor(dba); |
| 2471 | |
| 2472 | if (!gvdba) |
| 2473 | return NULL; |
| 2474 | |
| 2475 | return ensGvbaseadaptorNew( |
| 2476 | gvdba, |
| 2477 | gvgenotypecodeadaptorKTablenames, |
| 2478 | gvgenotypecodeadaptorKColumnnames, |
| 2479 | (const EnsPBaseadaptorLeftjoin) NULL, |
| 2480 | gvgenotypecodeadaptorKDefaultcondition, |
| 2481 | (const char *) NULL, |
| 2482 | &gvgenotypecodeadaptorFetchAllbyStatement); |
| 2483 | } |
| 2484 | |
| 2485 | |
| 2486 | |
| 2487 | |
| 2488 | /* @section destructors ******************************************************* |
| 2489 | ** |
| 2490 | ** Destruction destroys all internal data structures and frees the memory |
| 2491 | ** allocated for an Ensembl Genetic Variation Genotype Code Adaptor |
| 2492 | ** object. |
| 2493 | ** |
| 2494 | ** @fdata [EnsPGvgenotypecodeadaptor] |
| 2495 | ** |
| 2496 | ** @nam3rule Del Destroy (free) an |
| 2497 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 2498 | ** |
| 2499 | ** @argrule * Pgvgca [EnsPGvgenotypecodeadaptor*] |
| 2500 | ** Ensembl Genetic Variation Genotype Code Adaptor address |
| 2501 | ** |
| 2502 | ** @valrule * [void] |
| 2503 | ** |
| 2504 | ** @fcategory delete |
| 2505 | ******************************************************************************/ |
| 2506 | |
| 2507 | |
| 2508 | |
| 2509 | |
| 2510 | /* @func ensGvgenotypecodeadaptorDel ****************************************** |
| 2511 | ** |
| 2512 | ** Default destructor for an |
| 2513 | ** Ensembl Genetic Variation Genotype Code Adaptor. |
| 2514 | ** |
| 2515 | ** Ensembl Object Adaptors are singleton objects that are registered in the |
| 2516 | ** Ensembl Registry and weakly referenced by Ensembl Objects that have been |
| 2517 | ** instantiated by it. Therefore, Ensembl Object Adaptors should never be |
| 2518 | ** destroyed directly. Upon exit, the Ensembl Registry will call this function |
| 2519 | ** if required. |
| 2520 | ** |
| 2521 | ** @param [d] Pgvgca [EnsPGvgenotypecodeadaptor*] |
| 2522 | ** Ensembl Genetic Variation Genotype Code Adaptor address |
| 2523 | ** |
| 2524 | ** @return [void] |
| 2525 | ** |
| 2526 | ** @release 6.5.0 |
| 2527 | ** @@ |
| 2528 | ******************************************************************************/ |
| 2529 | |
| 2530 | void ensGvgenotypecodeadaptorDel( |
| 2531 | EnsPGvgenotypecodeadaptor *Pgvgca) |
| 2532 | { |
| 2533 | ensGvbaseadaptorDel(Pgvgca); |
| 2534 | |
| 2535 | return; |
| 2536 | } |
| 2537 | |
| 2538 | |
| 2539 | |
| 2540 | |
| 2541 | /* @section member retrieval ************************************************** |
| 2542 | ** |
| 2543 | ** Functions for returning members of an |
| 2544 | ** Ensembl Genetic Variation Genotype Code Adaptor object. |
| 2545 | ** |
| 2546 | ** @fdata [EnsPGvgenotypecodeadaptor] |
| 2547 | ** |
| 2548 | ** @nam3rule Get |
| 2549 | ** Return Ensembl Genetic Variation Genotype Code Adaptor attribute(s) |
| 2550 | ** @nam4rule Baseadaptor Return the Ensembl Base Adaptor |
| 2551 | ** @nam4rule Databaseadaptor Return the Ensembl Database Adaptor |
| 2552 | ** @nam4rule Gvbaseadaptor Return the Ensembl Genetic Variation Base Adaptor |
| 2553 | ** |
| 2554 | ** @argrule * gvgca [EnsPGvgenotypecodeadaptor] |
| 2555 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 2556 | ** |
| 2557 | ** @valrule Baseadaptor [EnsPBaseadaptor] |
| 2558 | ** Ensembl Base Adaptor or NULL |
| 2559 | ** @valrule Databaseadaptor [EnsPDatabaseadaptor] |
| 2560 | ** Ensembl Database Adaptor or NULL |
| 2561 | ** @valrule Gvbaseadaptor [EnsPGvbaseadaptor] |
| 2562 | ** Ensembl Genetic Variation Base Adaptor or NULL |
| 2563 | ** |
| 2564 | ** @fcategory use |
| 2565 | ******************************************************************************/ |
| 2566 | |
| 2567 | |
| 2568 | |
| 2569 | |
| 2570 | /* @func ensGvgenotypecodeadaptorGetBaseadaptor ******************************* |
| 2571 | ** |
| 2572 | ** Get the Ensembl Base Adaptor member of an |
| 2573 | ** Ensembl Genetic Variation Genotype Code Adaptor. |
| 2574 | ** |
| 2575 | ** @param [u] gvgca [EnsPGvgenotypecodeadaptor] |
| 2576 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 2577 | ** |
| 2578 | ** @return [EnsPBaseadaptor] Ensembl Base Adaptor or NULL |
| 2579 | ** |
| 2580 | ** @release 6.5.0 |
| 2581 | ** @@ |
| 2582 | ******************************************************************************/ |
| 2583 | |
| 2584 | EnsPBaseadaptor ensGvgenotypecodeadaptorGetBaseadaptor( |
| 2585 | EnsPGvgenotypecodeadaptor gvgca) |
| 2586 | { |
| 2587 | return ensGvbaseadaptorGetBaseadaptor( |
| 2588 | ensGvgenotypecodeadaptorGetGvbaseadaptor(gvgca)); |
| 2589 | } |
| 2590 | |
| 2591 | |
| 2592 | |
| 2593 | |
| 2594 | /* @func ensGvgenotypecodeadaptorGetDatabaseadaptor *************************** |
| 2595 | ** |
| 2596 | ** Get the Ensembl Database Adaptor member of an |
| 2597 | ** Ensembl Genetic Variation Genotype Code Adaptor. |
| 2598 | ** |
| 2599 | ** @param [u] gvgca [EnsPGvgenotypecodeadaptor] |
| 2600 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 2601 | ** |
| 2602 | ** @return [EnsPDatabaseadaptor] Ensembl Database Adaptor or NULL |
| 2603 | ** |
| 2604 | ** @release 6.5.0 |
| 2605 | ** @@ |
| 2606 | ******************************************************************************/ |
| 2607 | |
| 2608 | EnsPDatabaseadaptor ensGvgenotypecodeadaptorGetDatabaseadaptor( |
| 2609 | EnsPGvgenotypecodeadaptor gvgca) |
| 2610 | { |
| 2611 | return ensGvbaseadaptorGetDatabaseadaptor( |
| 2612 | ensGvgenotypecodeadaptorGetGvbaseadaptor(gvgca)); |
| 2613 | } |
| 2614 | |
| 2615 | |
| 2616 | |
| 2617 | |
| 2618 | /* @func ensGvgenotypecodeadaptorGetGvbaseadaptor ***************************** |
| 2619 | ** |
| 2620 | ** Get the Ensembl Genetic Variation Base Adaptor member of an |
| 2621 | ** Ensembl Genetic Variation Genotype Code Adaptor. |
| 2622 | ** |
| 2623 | ** @param [u] gvgca [EnsPGvgenotypecodeadaptor] |
| 2624 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 2625 | ** |
| 2626 | ** @return [EnsPGvbaseadaptor] Ensembl Genetic Variation Base Adaptor or NULL |
| 2627 | ** |
| 2628 | ** @release 6.5.1 |
| 2629 | ** @@ |
| 2630 | ******************************************************************************/ |
| 2631 | |
| 2632 | EnsPGvbaseadaptor ensGvgenotypecodeadaptorGetGvbaseadaptor( |
| 2633 | EnsPGvgenotypecodeadaptor gvgca) |
| 2634 | { |
| 2635 | return gvgca; |
| 2636 | } |
| 2637 | |
| 2638 | |
| 2639 | |
| 2640 | |
| 2641 | /* @section object retrieval ************************************************** |
| 2642 | ** |
| 2643 | ** Functions for fetching Ensembl Genetic Variation Genotype Code objects |
| 2644 | ** from an Ensembl SQL database. |
| 2645 | ** |
| 2646 | ** @fdata [EnsPGvgenotypecodeadaptor] |
| 2647 | ** |
| 2648 | ** @nam3rule Fetch Fetch Ensembl Genetic Variation Genotype Code |
| 2649 | ** object(s) |
| 2650 | ** @nam4rule All Fetch all Ensembl Genetic Variation Genotype Code |
| 2651 | ** objects |
| 2652 | ** @nam4rule Allby Fetch all Ensembl Genetic Variation Genotype Code |
| 2653 | ** objects matching a criterion |
| 2654 | ** @nam5rule Identifiers Fetch all by an AJAX Table of AJAX unsigned integer |
| 2655 | ** (Ensembl Genetic Variation Genotype Code identifier) key data and |
| 2656 | ** Ensembl Genetic Variation Genotype Code object value data |
| 2657 | ** @nam5rule Identifier Fetch by an SQL database-internal identifier |
| 2658 | ** |
| 2659 | ** @argrule * gvgca [EnsPGvgenotypecodeadaptor] |
| 2660 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 2661 | ** @argrule AllbyIdentifiers gvgcs [AjPTable] AJAX Table of |
| 2662 | ** AJAX unsigned integer |
| 2663 | ** (Ensembl Genetic Variation Genotype Code identifier) key data and |
| 2664 | ** Ensembl Genetic Variation Genotype Code object value data |
| 2665 | ** @argrule Identifier identifier [ajuint] SQL database-internal identifier |
| 2666 | ** @argrule By Pggcs [EnsPGvgenotypecode*] |
| 2667 | ** Ensembl Genetic Variation Genotype Code address |
| 2668 | ** |
| 2669 | ** @valrule * [AjBool] ajTrue upon success, ajFalse otherwise |
| 2670 | ** |
| 2671 | ** @fcategory use |
| 2672 | ******************************************************************************/ |
| 2673 | |
| 2674 | |
| 2675 | |
| 2676 | |
| 2677 | /* @func ensGvgenotypecodeadaptorFetchAllbyIdentifiers ************************ |
| 2678 | ** |
| 2679 | ** Fetch all Ensembl Genetic Variation Genotype Code objects by an |
| 2680 | ** AJAX Table of AJAX unsigned integer |
| 2681 | ** (Ensembl Genetic Variation Genotype Code identifier) key data and |
| 2682 | ** Ensembl Genetic Variation Genotype Code object value data |
| 2683 | ** |
| 2684 | ** The caller is responsible for deleting the |
| 2685 | ** Ensembl Genetic Variation Population Genotype objects before deleting the |
| 2686 | ** AJAX Table. |
| 2687 | ** |
| 2688 | ** @cc Bio::EnsEMBL::Variation::DBSQL::GenotypeCodeAdaptor:: |
| 2689 | ** fetch_all_by_dbID_list |
| 2690 | ** @param [u] gvgca [EnsPGvgenotypecodeadaptor] |
| 2691 | ** Ensembl Genetic Variation Genotype Code Adaptor |
| 2692 | ** @param [u] gvgcs [AjPTable] AJAX Table of AJAX unsigned integer |
| 2693 | ** (Ensembl Genetic Variation Genotype Code identifier) and |
| 2694 | ** Ensembl Genetic Variation Genotype Code objects |
| 2695 | ** |
| 2696 | ** @return [AjBool] ajTrue upon success, ajFalse otherwise |
| 2697 | ** |
| 2698 | ** @release 6.5.0 |
| 2699 | ** @@ |
| 2700 | ******************************************************************************/ |
| 2701 | |
| 2702 | AjBool ensGvgenotypecodeadaptorFetchAllbyIdentifiers( |
| 2703 | EnsPGvgenotypecodeadaptor gvgca, |
| 2704 | AjPTable gvgcs) |
| 2705 | { |
| 2706 | return ensBaseadaptorFetchAllbyIdentifiers( |
| 2707 | ensGvgenotypecodeadaptorGetBaseadaptor(gvgca), |
| 2708 | (EnsPSlice) NULL, |
| 2709 | (ajuint (*)(const void *)) &ensGvgenotypecodeGetIdentifier, |
| 2710 | gvgcs); |
| 2711 | } |