File: newdatatype.pl

package info (click to toggle)
emboss 6.6.0%2Bdfsg-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 571,584 kB
  • sloc: ansic: 460,579; java: 29,383; perl: 13,573; sh: 12,753; makefile: 3,294; csh: 706; asm: 351; xml: 239; pascal: 237; modula3: 8
file content (717 lines) | stat: -rwxr-xr-x 17,075 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl -w

sub filecopyc($$) {
    my($infile, $outfile) = @_;

    my $text = "";

    print "'$infile' => '$outfile'\n";
    open (IN, "$infile" || die "Cannot find '$infile'");
    while(<IN>) {$text .= $_}
    close IN;

    $text =~ s/AjPWxyz/AjP$newtype/g;
    $text =~ s/AjSWxyz/AjS$newtype/g;
    $text =~ s/AjOWxyz/AjO$newtype/g;
    $text =~ s/Wxyz(Data)/$newtype$1/g;
    $text =~ s/ajWxyz/aj$newtype/g;
    $text =~ s/Wxyzdesc/$newdescup/g;
    $text =~ s/wxyzdesc/$newdesc/g;
    $text =~ s/Wxyz/$newtype/g;
    $text =~ s/wxyz/$newname/g;
    $text =~ s/WXYZ/$newcaps/g;
    if($newdescup =~ /^[AEUIOY]/){
	$text =~ s/a $newdesc/an $newdesc/g;
    }

    if(-e "$outfile") {die "$outfile exists"}
    open(OUT, ">$outfile" || die "Cannot open '$outfile'");
    print OUT $text;
    close OUT;

    return 0;
}

sub filecopyh($$) {
    my($infile, $outfile) = @_;

    my $text = "";

    print "'$infile' => '$outfile'\n";
    open (IN, "$infile" || die "Cannot find '$infile'");
    while(<IN>) {$text .= $_}
    close IN;

    $text =~ s/AJWXYZ/AjP$newtypeup/g;
    $text =~ s/AjPWxyz/AjP$newtype/g;
    $text =~ s/AjSWxyz/AjS$newtype/g;
    $text =~ s/AjOWxyz/AjO$newtype/g;
    $text =~ s/Wxyz(Data)/$newtype$1/g;
    $text =~ s/ajWxyz/aj$newtype/g;
    $text =~ s/Wxyzdesc/$newdescup/g;
    $text =~ s/wxyzdesc/$newdesc/g;
    $text =~ s/Wxyz/$newtype/g;
    $text =~ s/wxyz/$newname/g;
    if($newdescup =~ /^[AEUIOY]/){
	$text =~ s/a $newdesc/an $newdesc/g;
    }

    if(-e "$outfile") {die "$outfile exists"}
    open(OUT, ">$outfile" || die "Cannot open '$outfile'");
    print OUT $text;
    close OUT;

    return 0;
}

#$newname = "abcd";
#$newtype = "Abcd"; # ucfirst
#$newdesc = "abcd"; # same name or longer (alignment, sequence, assembly)

foreach $opt (@ARGV) {
    if ($opt =~ /name=(\S+)/) {$newname=$1}
    elsif ($opt =~ /type=(\S+)/) {$newtype=ucfirst($1)}
    elsif ($opt =~ /desc=(.+)/) {$newdesc=$1}
    else {print STDERR "Unknown option '$opt'\n"}
}

if(!defined($newname)){die "name not defined"}
if(!defined($newtype)){$newtype = ucfirst($newname);$newtypeup = uc($newname);}
if(!defined($newdesc)){$newdesc = $newname}
if(!defined($newcaps)){$newcaps = uc($newname)}

$newdescup = ucfirst($newdesc);

chdir;

chdir "devemboss/ajax/core";

$infile = "ajwxyzdata.header";
$outfile = "aj$newname"."data.h";

filecopyh($infile, $outfile);

$infile = "ajwxyz".".header";
$outfile = "aj$newname".".h";

filecopyh($infile, $outfile);

$infile = "ajwxyz"."read.header";
$outfile = "aj$newname"."read.h";

filecopyh($infile, $outfile);

$infile = "ajwxyz"."write.header";
$outfile = "aj$newname"."write.h";

filecopyh($infile, $outfile);

$infile = "ajwxyz".".source";
$outfile = "aj$newname".".c";

filecopyc($infile, $outfile);

$infile = "ajwxyz"."read.source";
$outfile = "aj$newname"."read.c";

filecopyc($infile, $outfile);

$infile = "ajwxyz"."write.source";
$outfile = "aj$newname"."write.c";

filecopyc($infile, $outfile);


#In each file, a standard set of changes
# implemented by reading all into text and then replacing strings throughout
# and testing for lines too long or short in the @func and @data records

# edit ajax.h

# add the 4 core/ajwxyz*.h files in an appropriate places - 
# ajwxyzdata.h after the other data files (before a comment)
# the others together after ajassem*.h (before a comment)


# edit ajutil.c ajReset function

# edit Makefile.am
# add new lines for the .h and .c files

chdir "../ajaxdb";

$infile = "ajwxyz"."db.header";
$outfile = "aj$newname"."db.h";

filecopyh($infile, $outfile);

$infile = "ajwxyz"."db.source";
$outfile = "aj$newname"."db.c";

filecopyc($infile, $outfile);



# edits

# edit Makefile.am

chdir "../../nucleus";

# edit embinit.c
# 2 places to add ajWxyzdbInit();


print "
New datatype $newtype defined.

(1) Edit ajax/core/ajax.h

Insert line in /* input and output data types */:

include \"aj$newname"."data.h\"

Insert lines in /* input and output data types I/O */:

#include \"aj$newname".".h\"
#include \"aj$newname"."read.h\"
#include \"aj$newname"."write.h\"

(2) Edit ajax/core/ajnam.c

Add:

#include \"aj$newname"."read.h\"

Add to namDbTypes

    {\"$newtype\",        \"$newname\",  \"$newdescup\",
    AJDATATYPE_$newcaps"."},

Add new datatype wherever obo appears:

in namAccessTest
        else if(namtype->DataType == AJDATATYPE_$newcaps)
            result = aj$newtype"."accessMethodTest(method);

in namInformatTest

    else if(namtype->DataType == AJDATATYPE_$newcaps)
        result = aj$newtype"."informatTest(format);

in namMethod2Qlinks

        else if(namtype->DataType == AJDATATYPE_$newcaps)
            result = aj$newtype"."accessMethodGetQlinks(method);


in namMethod2Scope

        else if(namtype->DataType == AJDATATYPE_$newcaps)
            result = aj$newtype"."accessMethodGetScope(method);


in namDatatype2Fields

        else if(namtype->DataType == AJDATATYPE_$newcaps)
            result = aj$newtype"."inTypeGetFields(method);


in namDatatype2Qlinks

        else if(namtype->DataType == AJDATATYPE_$newcaps)
            result = aj$newtype"."inTypeGetQlinks(method);


(3) Edit ajax/core/ajfile.h

Edit AjEOutfileType and add

    ** \@value $newdescup data

    ajEOutfileType$newcaps,

(4) Edit ajax/core/ajquerydata.h

Add to AjEDataType

    AJDATATYPE_$newcaps, 

(5) Edit ajax/core/ajutil.c

Add

#include \"aj$newname".".h\"

Add to ajReset

    aj$newtype"."Exit();

(6) Edit ajax/core/Makefile.am

Add:

aj$newname".".c \
aj$newname"."read.c \
aj$newname"."write.c \

Add:
aj$newname".".h \
aj$newname"."data.h \
aj$newname"."read.h \
aj$newname"."write.h \

(7) Edit ajax/ajaxdb/Makefile.am

Add:

aj$newname"."db.c \

aj$newname"."db.h \

(8) Edit nucleus/emboss.h

Insert:

#include \"aj$newname"."db.h\"

(9) Edit nucleus/embinit.c

Insert:

#include \"aj$newname"."db.h\"

Insert in initDball,

    aj$newtype"."dbInit();

(10) Edit nucleus/embexit.c

Insert:

#include \"aj$newname"."db.h\"

Insert in embExit,

    aj$newtype"."dbExit();

(11) Edit ajacd.h

Add

#include \"aj$newname"."data.h\"

Add datatype and functions, following e.g. taxon definitions

AjP$newtype   ajAcdGet$newtype(const char *token);
AjP$newtype"."all   ajAcdGet$newtype"."all(const char *token);
AjPOutfile    ajAcdGetOut$newtype(const char *token);


(12) Edit ajacd.c

Add

#include \"aj$newname"."read.h\"
#include \"aj$newname"."write.h\"

Add datatype and functions, following e.g. taxon definitions

static const AjPStr acdPrompt$newtype(AcdPAcd thys);
static const AjPStr acdPromptOut$newname(AcdPAcd thys);
static void acdHelpText$newtype(const AcdPAcd thys, AjPStr* str);
static void acdDel$newtype(void** PPval);
static void acdSet$newtype(AcdPAcd thys);
static void acdSetOut$newname(AcdPAcd thys);


AcdOAttr acdAttr$newtype"."[] =
{
    {\"entry\", VT_BOOL, AJFALSE, \"N\",
	 \"Read whole entry text\"},
    {\"minreads\", VT_INT, AJFALSE, \"1\",
	 \"Minimum number of inputs\"},
    {\"maxreads\", VT_INT, AJFALSE, \"(INT_MAX)\",
	 \"Maximum number of inputs\"},
    {\"nullok\", VT_BOOL, AJFALSE, \"N\",
	 \"Can accept a null filename as 'no file'\"},
    {NULL, VT_NULL, AJFALSE, NULL,
	 NULL}
};

AcdOAttr acdAttrOut$newname"."[] =
{
    {\"name\", VT_STR, AJFALSE, \"\",
	 \"Default file name\"},
    {\"extension\", VT_STR, AJFALSE, \"\",
	 \"Default file extension\"},
    {\"nulldefault\", VT_BOOL, AJFALSE, \"N\",
	 \"Defaults to 'no file'\"},
    {\"nullok\", VT_BOOL, AJFALSE, \"N\",
	 \"Can accept a null filename as 'no file'\"},
    {NULL, VT_NULL, AJFALSE, NULL,
	 NULL}
};



In AcdOOuttype acdOuttype[] =

    {\"out$newname\",        \"abc\",          ajEOutfileType$newname, 0,
	 acdPromptOut$newname,         aj$newtype"."outformatFind},



AcdOQual acdQual$newtype"."[] =
{
    {\"iformat\",    \"\",  \"string\",  \"Input $newdesc format\"},
    {\"iquery\",     \"\",  \"string\",  \"Input query fields or ID list\"},
    {\"ioffset\",    \"\",  \"integer\", \"Input start position offset\"},
    {\"idbname\",    \"\",  \"string\",  \"User-provided database name\"},
    {NULL, NULL, NULL, NULL}
};


AcdOQual acdQualOut$newname"."[] =
{
    {\"odirectory\", \"\",  \"string\",  \"Output directory\"},
    {\"oformat\",    \"\",  \"string\",  \"$newdescup output format\"},
    {NULL, NULL, NULL, NULL}
};


    {\"$newname\",       \"input\",     acdSecInput,
	 acdAttr$newtype,       acdQual$newtype,
	 acdSet$newtype,        acdHelpText$newtype,   acdDel$newtype,
	 AJTRUE,  AJTRUE,  acdPrompt$newtype,  &acdUseData, &acdUseIn,
	 \"$newdescup\" },

    {\"out$newname\",     \"output\",    acdSecOutput,
	 acdAttrOut$newname,    acdQualOut$newname,
	 acdSetOut$newname,     NULL,                  acdDelOutfile,
	 AJTRUE,  AJTRUE,  acdPromptOut$newname,  &acdUseOutfile, &acdUseOut,
	 \"$newdescup\" },

in section return

** \@nam4rule  Get$newtype   ACD $newdesc datatype
** \@nam4rule  Get$newtype"."all   ACD $newdesc stream datatype
** \@nam4rule  GetOut$newname   ACD $newdesc output datatype
** \@valrule   $newtype         [AjP$newtype]
** \@valrule   $newtype"."all         [AjP$newtype"."all]
** \@valrule   Out$newname      [AjPOutfile]


/* \@func ajAcdGet$newtype *****************************************************
**
** Returns an item of type $newdesc as defined in a named ACD item.
** Called by the application after all ACD values have been set,
** and simply returns what the ACD item already has.
**
** \@param [r] token [const char*] Text token name
** \@return [AjP$newtype] $newdescup object
** \@cre failure to find an item with the right name and type aborts.
**
** \@release 6.6.0
** \@@
******************************************************************************/

AjP$newtype ajAcdGet$newtype(const char *token)
{
    AjP$newtype val = acdGetValueRef(token, \"$newname\");

    return val;
}




/* \@funcstatic acdSet$newtype *************************************************
**
** Using the definition in the ACD file, and any values for the
** item or its associated qualifiers provided on the command line,
** prompts the user if necessary (and possible) and
** sets the actual value for an ACD $newdesc input
**
** Understands all attributes and associated qualifiers for this item type.
**
** \@param [u] thys [AcdPAcd] ACD item.
** \@return [void]
**
** \@release 6.6.0
** \@\@
******************************************************************************/

static void acdSet$newtype(AcdPAcd thys)
{
    AjP$newtype val;
    AjP$newtype"."in $newname"."in;

    AjBool required = ajFalse;
    AjBool ok       = ajFalse;
    AjBool nullok   = ajFalse;
    ajint itry;

    AjPStr infname = NULL;
    
    val = aj$newtype"."New();        /* set the default value */
    $newname"."in = aj$newtype"."inNew();  

    acdAttrToBool(thys, \"nullok\", ajFalse, &nullok);

    required = acdIsRequired(thys);
    acdReplyInitS(thys, infname, &acdReplyDef);
    ajStrDel(&infname);

    acdAttrToBool(thys, \"entry\", ajFalse, &$newname"."in->Input->Text);

    for(itry=acdPromptTry; itry && !ok; itry--)
    {
	ok = ajTrue;	   /* accept the default if nothing changes */

	ajStrAssignS(&acdReply, acdReplyDef);

	if(required)
	    acdUserGet(thys, &acdReply);

	if(!ajStrGetLen(acdReply) && nullok)
        {
            aj$newtype"."inDel(&$newname"."in);
	    break;
	}

	aj$newtype"."inQryS($newname"."in, acdReply);

        ok = aj$newtype"."inRead($newname"."in, val);
    }

    if(!ok)
	acdBadRetry(thys);

    acdInFileSave(acdReply, aj$newtype"."GetId(val), ajTrue);

    thys->Value = val;
    ajStrAssignS(&thys->ValStr, acdReply);
    
    aj$newtype"."inDel(&$newname"."in);

    return;
}



/* \@func ajAcdGetOut$newname **************************************************
**
** Returns an item of type Out$newname as defined in a named ACD item.
** Called by the application after all ACD values have been set,
** and simply returns what the ACD item already has.
**
** \@param [r] token [const char*] Text token name
** \@return [AjPOutfile] File object. The file was already opened by
**         acdSetOut so this just returns the pointer.
** \@cre failure to find an item with the right name and type aborts.
**
** \@release 6.6.0
** \@\@
******************************************************************************/

AjPOutfile ajAcdGetOut$newname(const char *token)
{
    return acdGetValueRef(token, \"out$newname"."\");
}




/* \@funcstatic acdSetOut$newname **********************************************
**
** Using the definition in the ACD file, and any values for the
** item or its associated qualifiers provided on the command line,
** prompts the user if necessary (and possible) and
** sets the actual value for an ACD out$newname item.
**
** Understands all attributes and associated qualifiers for this item type.
**
** The default value (if no other available) is a null string, which
** is invalid.
**
** Associated qualifiers \"-oformat\"
** are stored in the object and applied to the data on output.
**
** \@param [u] thys [AcdPAcd] ACD item.
** \@return [void]
**
** \@release 6.6.0
** \@\@
******************************************************************************/

static void acdSetOut$newname(AcdPAcd thys)
{
    acdSetOutType(thys, \"out$newname"."\");

    return;
}




/* \@funcstatic acdHelpText$newtype ********************************************
**
** Sets the help text for this ACD object to be a $newdesc description
**
** \@param [r] thys [const AcdPAcd] Current ACD object.
** \@param [w] Pstr [AjPStr*] Help text
** \@return [void]
**
** \@release 6.6.0
** \@\@
******************************************************************************/

static void acdHelpText$newtype(const AcdPAcd thys, AjPStr* Pstr)
{
    ajint maxreads;

    ajStrAssignClear(Pstr);

    acdAttrToInt(thys, \"maxreads\", 1, &maxreads);

    if(maxreads <= 1)
        ajStrAssignC(Pstr, \"$newname\");
    else
        ajStrAssignC(Pstr, \"$newname(s)\");

    ajStrFmtTitle(Pstr);

    ajStrAppendC(Pstr,
		 \" filename and optional format, or reference (input query)\");

    return;
}




/* \@funcstatic acdPrompt$newtype **********************************************
**
** Sets the default prompt for this ACD object to be a $newdesc
** prompt with \"first\", \"second\" etc. added.
**
** \@param [u] thys [AcdPAcd] Current ACD object.
** \@return [const AjPStr] Generated standard prompt
**
** \@release 6.6.0
** \@\@
******************************************************************************/

static const AjPStr acdPrompt$newtype"."(AcdPAcd thys)
{
    static ajint count=0;
    AjPStr $newname"."Prompt = NULL;
    AjPStr $newname"."PromptAlt = NULL;
    const AjPStr knowntype;
    ajint maxreads = 0;

    acdAttrToInt(thys, \"maxreads\", 1, &maxreads);

    knowntype = acdKnowntypeDesc(thys);

    $newname"."Prompt = ajStrNewRes(32);
    $newname"."PromptAlt = ajStrNewRes(32);

    if(ajStrGetLen(knowntype))
	ajFmtPrintAppS(&$newname"."PromptAlt, \"\%S \", knowntype);

    ajFmtPrintAppS(&$newname"."PromptAlt, \"$newdesc\");

    if(maxreads > 1)
	ajStrAppendC(&$newname"."PromptAlt, \"(s)\");

    ajFmtPrintS(&$newname"."Prompt, \"Input %S\", $newname"."PromptAlt);

    if(knowntype)
    {
	count++;
	acdPromptStandardS(thys, $newname"."PromptAlt);
    }
    else
	acdPromptStandardAlt(thys, ajStrGetPtr($newname"."Prompt),
			     ajStrGetPtr($newname"."PromptAlt), &count);

    if(!acdAttrTestDefined(thys, \"default\") &&
       acdAttrTestDefined(thys, \"nullok\"))
	acdPromptStandardAppend(thys, \" (optional)\");
    
    ajStrDel(&$newname"."Prompt);
    ajStrDel(&$newname"."PromptAlt);

    return thys->StdPrompt;
}



/* \@funcstatic acdPromptOut$newname"." ****************************************
**
** Sets the default prompt for this ACD object to be a simple
** prompt with \"second\", \"third\" etc. added.
**
** \@param [u] thys [AcdPAcd] Current ACD object.
** \@return [const AjPStr] Generated standard prompt
**
** \@release 6.6.0
** \@\@
******************************************************************************/

static const AjPStr acdPromptOut$newname"."(AcdPAcd thys)
{
    static ajint count=0;

    const AjPStr knowntype;

    knowntype = acdKnowntypeDesc(thys);

    if(ajStrGetLen(knowntype))
    {
	count++;
	acdPromptStandardS(thys, knowntype);
	acdPromptStandardAppend(thys, \" output file\");
    }
    else
	acdPromptStandard(thys, \"$newdesc output file\", &count);

    if(!acdAttrTestDefined(thys, \"default\") &&
       acdAttrTestDefined(thys, \"nullok\"))
	acdPromptStandardAppend(thys, \" (optional)\");
    
    return thys->StdPrompt;
}




/* \@funcstatic acdDel$newtype"." **********************************************
**
** Function with void** prototype to delete ACD $newdesc input data
**
** \@param [d] PPval [void**] Value to be deleted
** \@return [void]
**
** \@release 6.6.0
**
******************************************************************************/

static void acdDel$newtype(void** PPval)
{
    if(!*PPval)
        return;

    aj$newtype"."Del((AjP$newtype"."*)PPval);

    return;
}






";