1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
|
/* @Source acdrelations application
**
** Add relations: attribute to ACD files
** Any existing relations: attributes are replaced.
**
** @author: Copyright (C) Jon Ison (jison@ebi.ac.uk)
** @@
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
*******************************************************************************
**
** ACDRELATIONS documentation
** See http://wwww.emboss.org
**
** Please cite the authors and EMBOSS.
**
** Email jison@ebi.ac.uk.
**
** acdrelations reads ACD files and writes exact copies but (depending on the
** mode it is run in) with relations: attributes either modified (mode 1) or
** added (mode 2).
** Mode 1
** relations: lines in this format:
** relations: "/edam/data/0001773 Tool-specific parameter"
** are replaced with this format:
** relations: "EDAM:0001773 data Tool-specific parameter"
**
**
** Mode 2
** acdrelations reads ACD files and writes exact copies but with a relations:
** attribute added to each data definition. Any existing relations: attributes
** are replaced. Text for relations: is from the EDAM ontology.
**
** acdrelations parameters:
** knowntypes.standards (EMBOSS data file)
** edamtoacd.dat (acdrelations data file)
** ACD file input directory
** ACD file output directory
**
** knowntypes.standards and edamtoacd.dat define the relations: value.
** Values given in knowntypes.standards take precedence over edamtoacd.dat
**
** knowntypes.standards is the standard EMBOSS data file of known types which is annotated with EDAM terms.
** An excerpt:
** aaindex_data | file | "EDAM: Amino acid index" | AAINDEX entry
** aaindex_database | file | "EDAM: AAindex database" | AAINDEX database
** abi_trace | file | "EDAM: ABI sequencing trace" | ABI sequencing trace
**
** edamtoacd.dat is a data file defining terms from the EDAM ontology to use
** as values for relations: attribute in ACD files, for different combinations
** of ACD datatypes / attributes.
** For example:
** #
** align | "EDAM: Sequence alignment data" |
** align | "EDAM: Nucleotide sequence alignment data" | type:"nucleotide"
** align | "EDAM: Protein sequence alignment data" | type:"protein"
** align | "EDAM: Multiple sequence alignment data" | minseqs:"3"
** align | "EDAM: Pairwise sequence alignment data" | minseqs:"2"; maxseqs:"2"
** align | "EDAM: Multiple protein sequence alignment data" | type:"protein"; minseqs:"3"
** align | "EDAM: Multiple nucleotide sequence alignment data" | type:"nucleotide"; minseqs:"3"
** align | "EDAM: Pairwise nucleotide sequence alignment data" | type:"nucleotide"; minseqs:"2"; maxseqs:"2"
** align | "EDAM: Pairwise protein sequence alignment data" | type:"protein"; minseqs:"2"; maxseqs:"2"
** array | "EDAM: Generic float array" |
** #
** arraychar | "EDAM: Generic character array" |
** #
** arrayword | "EDAM: Generic string array" |
** #
**
**
** Meaning of columns is:
** ACD datatype | Attributes that must be specified | Value of relation: attribute | Note
**
** IMPORTANT
** For acdrelations to work correctly, edamtoacd.dat must be correctly formatted and laid out:
** 1. Lines for a given datatype *must* be given in order of number of attributes in the third column (lowest number first)
** 2. The first line for each datatype gives the default value of the relations: attribute and should have no attributes defined.
** 3. The attribute:value pairs must be delimited by ';'.
**
******************************************************************************/
#include "emboss.h"
/******************************************************************************
**
** DATA STRUCTURES
**
******************************************************************************/
/* @datastatic PEdamdat *******************************************************
**
** edamdat object
** Holds a single line from the data file edamtoacd.dat
**
** @alias SEdamdat
** @alias OEdamdat
**
** @attr acdtype [AjPStr] ACD datatype, e.g. "align"
** @attr acdattr [AjPStr*] Array of ACD attribute:value strings e.g. minseqs:"3"
** Strings must contain no whitespace!
** @attr edam [AjPStr] Text to be given after relations: attribute,
** e.g. "EDAM: Multiple sequence alignment data"
** if all relations in acdattr are defined for acdtype.
** @attr n [ajint] Size of acdattr array
** @attr Padding [ajint] Padding to alignment boundaty
******************************************************************************/
typedef struct SEdamdat
{
AjPStr acdtype;
AjPStr* acdattr;
AjPStr edam;
ajint n;
ajint Padding;
} OEdamdat;
#define PEdamdat OEdamdat*
/* @datastatic PEdam **********************************************************
**
** edam object
** Holds all lines from the data file edamtoacd.dat
**
** @alias SEdam
** @alias OEdam
**
** @attr dat [PEdamdat*] Array of PEdamdat objects
** @attr n [ajint] Size of dat array
** @attr Padding [ajint] Padding to alignment boundaty
******************************************************************************/
typedef struct SEdam
{
PEdamdat *dat;
ajint n;
ajint Padding;
} OEdam;
#define PEdam OEdam*
/* @datastatic PKtypedat ******************************************************
**
** ktypedat object
** Holds a single line from the data file knowntypes.standard
**
** @alias SKtypedat
** @alias OKtypedat
**
** @attr acdtype [AjPStr] ACD datatype, e.g. "align"
** @attr ktype [AjPStr] Value of knowntype: attribute: no whitespace!
** @attr edam [AjPStr] Text to be given after relations: attribute,
** e.g. "EDAM: Multiple sequence alignment data"
** if ktype is defined for acdtype.
******************************************************************************/
typedef struct SKtypedat
{
AjPStr acdtype;
AjPStr ktype;
AjPStr edam;
} OKtypedat;
#define PKtypedat OKtypedat*
/* @datastatic PKtype *********************************************************
**
** ktype object
** Holds all lines from the data file knowntypes.standard
**
** @alias SKtype
** @alias OKtype
**
** @attr dat [PKtypedat*] Array of PKtypedat objects
** @attr n [ajint] Size of dat array
** @attr Padding [ajint] Padding to alignment boundaty
******************************************************************************/
typedef struct SKtype
{
PKtypedat *dat;
ajint n;
ajint Padding;
} OKtype;
#define PKtype OKtype*
/******************************************************************************
**
** PROTOTYPES
**
******************************************************************************/
static void acdrelations_writerelations
(AjPFile outf,
AjPStr acdtype,
AjPStr *strarr,
ajint n,
PEdam P,
PKtype T);
static void acdrelations_readdatfile
(AjPFile inf,
PEdam *P);
static void acdrelations_readtypefile
(AjPFile inf,
PKtype *P);
static void acdrelations_procacdfile1
(AjPFile inf,
AjPFile outf);
static void acdrelations_procacdfile2
(AjPFile inf,
AjPFile outf,
PEdam P,
PKtype T);
static PEdamdat acdrelations_EdamdatNew(void);
static PEdam acdrelations_EdamNew(void);
static void acdrelations_EdamdatDel(PEdamdat *P);
static void acdrelations_EdamDel(PEdam *P);
static PKtypedat acdrelations_KtypedatNew(void);
static PKtype acdrelations_KtypeNew(void);
static void acdrelations_KtypedatDel(PKtypedat *P);
static void acdrelations_KtypeDel(PKtype *P);
/* @prog acdrelations ********************************************************
**
** Add relations: attribute to ACD files.
**
*****************************************************************************/
int main(ajint argc, char **argv)
{
/* Variable declarations */
AjPFile inf_edam = NULL; /* Name of EDAM data (input) file */
AjPFile acdoutf = NULL; /* Name of ACD (output) file */
AjPStr mode = NULL;
ajint modei;
AjPList acdinlist = NULL; /* List of ACD file names (input) */
AjPFile acdinf = NULL; /* Name of ACD (input) file */
AjPStr acdname = NULL; /* Name of current acd file */
AjPDirout acdoutdir = NULL; /* Directory for ACD files (output) */
AjPFile inf_ktype = NULL; /* Name of knowntypes.standard file */
PEdam edam = NULL; /* EDAM relations data */
PKtype ktype = NULL; /* Data from knowntype.standard */
/* Read data from acd. */
/* embInitP("acdrelations",argc,argv,"MYEMBOSS"); */
embInit("acdrelations",argc,argv);
/* ACD data handling */
mode = ajAcdGetListSingle("mode");
inf_edam = ajAcdGetDatafile("inedamfile");
inf_ktype = ajAcdGetInfile("intypefile");
acdinlist = ajAcdGetDirlist("indir");
acdoutdir = ajAcdGetOutdir("outdir");
ajStrToInt(mode, &modei);
/* Read data file */
if(modei==2)
{
edam = acdrelations_EdamNew();
ktype = acdrelations_KtypeNew();
acdrelations_readdatfile(inf_edam, &edam);
acdrelations_readtypefile(inf_ktype, &ktype);
}
/* Main application loop. Process each ACD file in turn. */
while(ajListPop(acdinlist,(void **)&acdname))
{
if(!(acdinf = ajFileNewInNameS(acdname)))
ajFatal("Cannot open input ACD file %S\n", acdname);
ajFilenameTrimPath(&acdname);
if(!(acdoutf = ajFileNewOutNameDirS(acdname, acdoutdir)))
ajFatal("Cannot open output ACD file %S\n", acdname);
if(modei==1)
acdrelations_procacdfile1(acdinf, acdoutf);
else if(modei==2)
acdrelations_procacdfile2(acdinf, acdoutf, edam, ktype);
else
ajFatal("Unknown mode");
ajFileClose(&acdinf);
ajFileClose(&acdoutf);
}
/* Clean up and exit */
ajStrDel(&mode);
if(modei==2)
{
ajFileClose(&inf_edam);
ajFileClose(&inf_ktype);
acdrelations_EdamDel(&edam);
acdrelations_KtypeDel(&ktype);
}
ajListFree(&acdinlist);
ajDiroutDel(&acdoutdir);
ajExit();
return 0;
}
/******************************************************************************
**
** FUNCTIONS
**
******************************************************************************/
/* @funcstatic acdrelations_readdatfile ***************************************
**
** Read the data file edamtoacd.dat and write edam object.
**
** @param [u] inf [AjPFile] Handle on edamtoacd.dat
** @param [u] P [PEdam*] edam object to write
** @return [void]
** @@
******************************************************************************/
static void acdrelations_readdatfile
(AjPFile inf,
PEdam *P)
{
AjPStr line = NULL;
const AjPStr tok = NULL;
const AjPStr subtok = NULL;
AjPStr strtmp = NULL;
AjPList strlist = NULL;
AjPStr acdtype = NULL;
AjPStr relations = NULL;
PEdamdat dattmp = NULL;
AjPList datlist = NULL;
if(!P)
ajFatal("Null arg error 1 in acdrelations_readdatfile");
if(!inf)
ajFatal("Null arg error 3 in acdrelations_readdatfile");
/* Allocate memory */
line = ajStrNew();
acdtype = ajStrNew();
relations = ajStrNew();
datlist = ajListNew();
/* Read data from file */
while(ajReadline(inf,&line))
{
/* Discard comment lines */
if(ajStrPrefixC(line,"#"))
continue;
/* Tokenise line, delimited by '|'.
Parse first token (ACD datatype ) */
ajStrAssignS(&acdtype, ajStrParseC(line, "|"));
/* Parse second token (EDAM relations: value ) */
ajStrAssignS(&relations, ajStrParseC(NULL, "|"));
/* Parse third token (attribute:value strings block) */
tok = ajStrParseC(NULL, "|");
/* Create new string list */
strlist = ajListstrNew();
/* Tokenise third token itself into tokens delimited by ' ' (space)
Parse tokens (individual attribute:value strings)*/
if((subtok=ajStrParseC(tok, ";")))
{
strtmp = ajStrNew();
ajStrAssignS(&strtmp, subtok);
ajStrRemoveWhite(&strtmp);
ajListstrPushAppend(strlist, strtmp);
while((subtok=ajStrParseC(NULL, ";")))
{
strtmp = ajStrNew();
ajStrAssignS(&strtmp, subtok);
ajStrRemoveWhite(&strtmp);
ajListstrPushAppend(strlist, strtmp);
}
}
/* Write PEdamdat structure & push onto list */
dattmp = acdrelations_EdamdatNew();
ajStrRemoveWhite(&acdtype);
ajStrAssignS(&dattmp->acdtype, acdtype);
ajStrAssignS(&dattmp->edam, relations);
dattmp->n = (ajuint) ajListstrToarray(strlist, &dattmp->acdattr);
ajListPushAppend(datlist, dattmp);
/* Clear nodes (but not strings) from string list */
ajListstrFree(&strlist);
}
/* Write PEdam structure */
((*P)->n) = (ajuint) ajListToarray(datlist, (void***) &((*P)->dat));
/* Free memory */
ajStrDel(&line);
ajStrDel(&acdtype);
ajStrDel(&relations);
ajListFree(&datlist);
return;
}
/* @funcstatic acdrelations_readtypefile **************************************
**
** Read the data file knowntypes.standard and write ktype object
**
** @param [u] inf [AjPFile] Handle on knowntypes.standard
** @param [u] T [PKtype*] ktype object to write
** @return [void]
** @@
******************************************************************************/
static void acdrelations_readtypefile
(AjPFile inf,
PKtype *T)
{
AjPStr line = NULL;
PKtypedat dattmp = NULL;
AjPList datlist = NULL;
if(!T)
ajFatal("Null arg error 1 in acdrelations_readtypefile");
if(!inf)
ajFatal("Null arg error 3 in acdrelations_readtypefile");
/* Allocate memory */
line = ajStrNew();
datlist = ajListNew();
/* Read data from file */
while(ajReadline(inf,&line))
{
/* Discard comment lines */
if(ajStrPrefixC(line,"#"))
continue;
/* Create object for holding line */
dattmp = acdrelations_KtypedatNew();
/* Tokenise line delimited by '|'
Parse first token (value of knowntype: attribute) */
ajStrAssignS(&dattmp->ktype, ajStrParseC(line, "|"));
ajStrRemoveSetC(&dattmp->ktype, "_");
ajStrRemoveWhite(&dattmp->ktype);
/* Parse second token (ACD datatype) */
ajStrAssignS(&dattmp->acdtype, ajStrParseC(NULL, "|"));
/* Parse third token (EDAM relations: value ) */
ajStrAssignS(&dattmp->edam, ajStrParseC(NULL, "|"));
/* Push line onto list */
ajListPushAppend(datlist, dattmp);
}
/* Write PKtype structure */
((*T)->n) = (ajuint) ajListToarray(datlist, (void***) &((*T)->dat));
/* Free memory */
ajStrDel(&line);
ajListFree(&datlist);
return;
}
/* @funcstatic acdrelations_procacdfile1 ***************************************
**
** Process ACD file and write new ACD file with relations: attributes in new
** format (mode '1' operation).
**
** @param [u] inf [AjPFile] ACD input file
** @param [u] outf [AjPFile] ACD output file
** @return [void]
** @@
******************************************************************************/
static void acdrelations_procacdfile1
(AjPFile inf,
AjPFile outf)
{
AjPStr line = NULL;
AjPStr tmp = NULL;
AjPStr tok = NULL;
AjPStr id = NULL;
AjPStr name = NULL;
AjPStr namespace = NULL;
AjPStrTok parse = NULL;
ajint pos;
/* Allocate memory */
line = ajStrNew();
tmp = ajStrNew();
tok = ajStrNew();
id = ajStrNew();
name = ajStrNew();
namespace = ajStrNew();
/* Read next line */
while(ajReadline(inf,&line))
{
ajFmtScanS(line, "%S", &tok);
/* Write reformatted relations: line */
if(ajStrMatchC(tok, "relations:"))
{
/* Tokenise line segment (from after "relations:") by '"', ' ' and '/'
Discard unwanted tokens */
pos = (ajuint) ajStrFindAnyK(line, ':');
ajStrAssignC(&tmp, line->Ptr+pos);
parse = ajStrTokenNewC(tmp, "\" /");
ajStrTokenNextParse(parse, &tok);
ajStrTokenNextParse(parse, &tok);
/* Get namespace and id tokens */
ajStrTokenNextParse(parse, &namespace);
ajStrTokenNextParse(parse, &id);
/* Get rest of string (name)
Strip whitespace at start and trailing " from name. */
ajStrTokenRestParse(parse, &name);
ajStrRemoveWhiteExcess(&name);
ajStrRemoveSetC(&name, "\"\n");
ajStrTokenDel(&parse);
/* Position of last '/' and last '"' characters respectively. */
ajFmtPrintF(outf, " relations: \"EDAM:%S %S %S\"\n", id, namespace, name);
}
/* Write other lines out as-is */
else
ajFmtPrintF(outf, "%S", line);
}
/* Free memory */
ajStrDel(&line);
ajStrDel(&tmp);
ajStrDel(&tok);
ajStrDel(&id);
ajStrDel(&name);
ajStrDel(&namespace);
return;
}
/* @funcstatic acdrelations_procacdfile2 ***************************************
**
** Process ACD file and write new ACD file with new relations: attributes
** added (replaced if necessary) using mode '2' operation.
**
** @param [u] inf [AjPFile] ACD input file
** @param [u] outf [AjPFile] ACD output file
** @param [u] P [PEdam] edam object
** @param [u] T [PKtype] ktype object
** @return [void]
** @@
******************************************************************************/
static void acdrelations_procacdfile2
(AjPFile inf,
AjPFile outf,
PEdam P,
PKtype T)
{
AjPStr line = NULL;
AjPStr tok = NULL;
AjPStr acdtype = NULL;
AjPStr strtmp = NULL;
AjPList strlist = NULL;
AjPStr *strarr = NULL;
ajint nstr = 0;
/* Allocate memory */
line = ajStrNew();
tok = ajStrNew();
acdtype = ajStrNew();
strlist = ajListstrNew();
/* Read next line */
while(ajReadline(inf,&line))
{
ajFmtScanS(line, "%S", &tok);
/* Write application definition or section definition out as-is */
if(ajStrMatchC(tok, "application:") ||
ajStrMatchC(tok, "section:"))
{
ajFmtPrintF(outf, "%S", line);
while(ajReadline(inf,&line))
{
ajFmtPrintF(outf, "%S", line);
ajFmtScanS(line, "%S", &tok);
if(ajStrMatchC(tok, "]"))
break;
}
}
/* Write variables, endsection definitions and comments out as-is */
else if(ajStrMatchC(tok, "variable:") ||
ajStrMatchC(tok, "endsection:") ||
ajStrMatchC(tok, "#"))
ajFmtPrintF(outf, "%S", line);
/* Write out blank lines as-is */
else if (!ajFmtScanS(line, "%S", &tok))
ajFmtPrintF(outf, "%S", line);
/* Process data definition */
else
/* First line of data definition */
{
/* Process and write datatype line */
ajFmtPrintF(outf, "%S", line);
ajFmtScanS(line, "%S", &acdtype);
ajStrRemoveSetC(&acdtype, ":");
/* Process subsequent (attribute) lines */
while(ajReadline(inf,&line))
{
strtmp = ajStrNew();
ajStrAssignS(&strtmp, line);
ajStrRemoveWhite(&strtmp);
ajListstrPushAppend(strlist, strtmp);
ajFmtScanS(line, "%S", &tok);
/* Reached end of data definition */
if(ajStrMatchC(tok, "]"))
{
nstr = (ajuint) ajListstrToarray(strlist, &strarr);
/* Write relations: line */
acdrelations_writerelations(outf, acdtype, strarr, nstr, P, T);
AJFREE(strarr);
ajListstrFreeData(&strlist);
strlist = ajListstrNew();
ajFmtPrintF(outf, "%S", line);
break;
}
/* Ignore existing relations: lines */
else if(ajStrMatchC(tok, "relations:"))
continue;
ajFmtPrintF(outf, "%S", line);
}
}
}
/* Free memory */
ajStrDel(&line);
ajStrDel(&tok);
ajStrDel(&acdtype);
ajListstrFreeData(&strlist);
return;
}
/* @funcstatic acdrelations_writerelations ************************************
**
** Writes relations: attribute for an ACD data definition
** The relations: values given in knowntypes.standard have highest precedence,
** then the values given in edamtoacd.dat
** Attribute values for a given datatype in edamtoacd.dat are in order of
** increasing precedence, i.e. the last line is highest and the relations:
** value will be used if all conditions are met.
**
** @param [u] outf [AjPFile] ACD output file
** @param [u] acdtype [AjPStr] ACD datatype, e.g. "align"
** @param [u] strarr [AjPStr*] All ACD attribute lines (whitespace removed)
** for the the current ACD data item (of type
** acdtype). One line per array element.
** @param [r] n [ajint] Size of strarr
** @param [u] P [PEdam] edam object to write
** @param [u] T [PKtype] ktype object to read
** @return [void]
** @@
******************************************************************************/
static void acdrelations_writerelations
(AjPFile outf,
AjPStr acdtype,
AjPStr *strarr,
ajint n,
PEdam P,
PKtype T)
{
ajint i = 0;
ajint j = 0;
ajint k = 0;
ajint nmatch = 0;
AjPStr relations = NULL;
AjPStr ktype = NULL; /* Value of knowntype: attribute */
AjBool done = ajFalse;
AjBool donetype = ajFalse;
AjPStr tmpstr = NULL;
if(!outf || !acdtype || !strarr || !n || !P)
ajFatal("NULL args passed to acdrelations_writerelations");
/* Memory allocation */
relations = ajStrNew();
ktype = ajStrNew();
tmpstr = ajStrNew();
/* Loop through all lines in edamtoacd.dat */
for(i=0; i<P->n ;i++)
{
/* Found matching datatype */
if(ajStrMatchS(acdtype, P->dat[i]->acdtype))
{
/* Copy first relations: string defined for this datatype (default) */
ajStrAssignS(&relations, P->dat[i]->edam);
done = ajTrue;
i++;
/* Check next line in edamtoacd.dat */
for( ; i<P->n; i++)
{
/* Datatype still matches */
if(ajStrMatchS(acdtype, P->dat[i]->acdtype))
{
/* Loop through all required attributes for this datatype */
for(nmatch=0, j=0; j<P->dat[i]->n; j++)
{
/* Loop through all attribute lines for the data defininition */
for(k=0; k<n; k++)
if(ajStrMatchS(P->dat[i]->acdattr[j], strarr[k]))
{
nmatch++;
break;
}
}
/* All attribute values match */
if(nmatch == P->dat[i]->n)
ajStrAssignS(&relations, P->dat[i]->edam);
/* Should never happen */
else if (nmatch > P->dat[i]->n)
ajFatal("Terminal weirdness in acdrelations_writerelations");
}
else
break;
}
break;
}
}
/* Check for match of knowntype: attribute against knowntypes.standard.
These have higher precedence than the rules defined in edamtoacd.dat */
for(donetype=ajFalse, i=0; i<n; i++)
{
if(ajStrPrefixC(strarr[i], "knowntype:"))
{
for(j=0;j<T->n; j++)
{
/* No check is made on the "Type" column in knowntypes.standard
as these are not proper ACD datatype names
To check these add
if(ajStrMatchS(acdtype, T->dat[j]->acdtype)) */
ajFmtPrintS(&tmpstr, "knowntype:\"%S\"", T->dat[j]->ktype);
if(ajStrMatchS(tmpstr, strarr[i]))
{
ajStrAssignS(&relations, T->dat[j]->edam);
donetype=ajTrue;
break;
}
}
if(donetype)
break;
}
else
continue;
}
if(!done)
ajFatal("No matching datatype (%S) in acdrelations_writerelations", acdtype);
/* Write relations: attribute line to file */
ajFmtPrintF(outf, " relations:%S\n", relations);
/* Free memory */
ajStrDel(&relations);
ajStrDel(&ktype);
ajStrDel(&tmpstr);
return;
}
/* @funcstatic acdrelations_EdamdatNew ****************************************
**
** edamdat constructor
** The array is NOT allocated
**
** @return [PEdamdat] New object
** @@
******************************************************************************/
static PEdamdat acdrelations_EdamdatNew(void)
{
PEdamdat ret;
AJNEW0(ret);
ret->acdtype = ajStrNew();
ret->edam = ajStrNew();
ret->acdattr = NULL;
ret->n = 0;
return ret;
}
/* @funcstatic acdrelations_EdamNew *******************************************
**
** edam constructor
** The array is NOT allocated
**
** @return [PEdam] New object
** @@
******************************************************************************/
static PEdam acdrelations_EdamNew(void)
{
PEdam ret;
AJNEW0(ret);
ret->dat = NULL;
ret->n = 0;
return ret;
}
/* @funcstatic acdrelations_EdamdatDel ****************************************
**
** edamdat destructor
**
** @param [d] P [PEdamdat*] edamdat object to delete
** @return [void]
** @@
******************************************************************************/
static void acdrelations_EdamdatDel(PEdamdat *P)
{
int i;
if(!P)
ajFatal("Null arg error 1 in acdrelations_EdamdatDel");
else if(!(*P))
ajFatal("Null arg error 2 in acdrelations_EdamdatDel");
ajStrDel(&(*P)->acdtype);
ajStrDel(&(*P)->edam);
if((*P)->n)
{
for(i=0;i<(*P)->n;i++)
ajStrDel(&(*P)->acdattr[i]);
AJFREE((*P)->acdattr);
}
AJFREE(*P);
*P=NULL;
return;
}
/* @funcstatic acdrelations_EdamDel *******************************************
**
** edam destructor
**
** @param [d] P [PEdam*] edam object to delete
** @return [void]
** @@
******************************************************************************/
static void acdrelations_EdamDel(PEdam *P)
{
int i;
if(!P)
ajFatal("Null arg error 1 in acdrelations_EdamDel");
else if(!(*P))
ajFatal("Null arg error 2 in acdrelations_EdamDel");
if((*P)->n)
{
for(i=0;i<(*P)->n;i++)
acdrelations_EdamdatDel(&(*P)->dat[i]);
AJFREE((*P)->dat);
}
AJFREE(*P);
*P=NULL;
return;
}
/* @funcstatic acdrelations_KtypedatNew ***************************************
**
** ktypedat constructor
**
** @return [PKtypedat] New object
** @@
******************************************************************************/
static PKtypedat acdrelations_KtypedatNew(void)
{
PKtypedat ret;
AJNEW0(ret);
ret->acdtype = ajStrNew();
ret->edam = ajStrNew();
ret->ktype = ajStrNew();
return ret;
}
/* @funcstatic acdrelations_KtypeNew ******************************************
**
** ktype constructor
**
** @return [PKtype] New object
** @@
******************************************************************************/
static PKtype acdrelations_KtypeNew(void)
{
PKtype ret;
AJNEW0(ret);
ret->dat = NULL;
ret->n = 0;
return ret;
}
/* @funcstatic acdrelations_KtypedatDel ***************************************
**
** ktypedat destructor
**
** @param [d] P [PKtypedat*] ktypedat object to delete
** @return [void]
** @@
******************************************************************************/
static void acdrelations_KtypedatDel(PKtypedat *P)
{
if(!P)
ajFatal("Null arg error 1 in acdrelations_KtypedatDel");
else if(!(*P))
ajFatal("Null arg error 2 in acdrelations_KtypedatDel");
ajStrDel(&(*P)->acdtype);
ajStrDel(&(*P)->edam);
ajStrDel(&(*P)->ktype);
AJFREE(*P);
*P=NULL;
return;
}
/* @funcstatic acdrelations_KtypeDel ******************************************
**
** ktype destructor
**
** @param [d] P [PKtype*] ktype object to delete
** @return [void]
** @@
******************************************************************************/
static void acdrelations_KtypeDel(PKtype *P)
{
int i;
if(!P)
ajFatal("Null arg error 1 in acdrelations_KtypeDel");
else if(!(*P))
ajFatal("Null arg error 2 in acdrelations_KtypeDel");
if((*P)->n)
{
for(i=0;i<(*P)->n;i++)
acdrelations_KtypedatDel(&(*P)->dat[i]);
AJFREE((*P)->dat);
}
AJFREE(*P);
*P=NULL;
return;
}
|