comparison tools/rdock/bin/sdmodify @ 0:bc03dbb6eb37 draft

planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
author marpiech
date Mon, 29 Aug 2016 03:38:13 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bc03dbb6eb37
1 #!/usr/bin/perl
2 # Script to set the first title line equal to a given data field
3 #
4 # Usage: sdmodify -f<DataField> [sdFiles]
5 #
6 # If sdFiles not given, reads from standard input
7 # Output is to standard output
8
9 use lib "$ENV{'RBT_ROOT'}/lib";
10
11 use SDRecord;
12
13 my $SDMODKEY = "ID";
14
15 #Print help if no command line arguments
16 printHelpAndExit() if (scalar(@ARGV) == 0);
17
18 #Parse command line arguments
19 my @files;
20 while (scalar(@ARGV)) {
21 my $arg = shift @ARGV;
22 printHelpAndExit() if ($arg eq '-h');
23 if (index($arg,'-f')==0) {
24 $SDMODKEY = substr($arg,2);#modification key
25 }
26 else {
27 push @files,$arg;#must be a filename
28 }
29 }
30 push @ARGV,@files;#put the filenames back in the arg list
31
32 #read records
33 my $sdRec = new SDRecord;
34 my $nRec=0;
35 while ($sdRec->readRec('DATA'=>1,'LINES'=>1)) {
36 $sdRec->addData('_REC' => ++$nRec);#add record# as temp data field
37 #set the first line equal to the given data field
38 my $nLines = scalar (@{$sdRec->{'LINES'}});
39 if ($nLines > 0) {
40 ${$sdRec->{'LINES'}}[0] = $sdRec->{'DATA'}->{$SDMODKEY};
41 }
42 $sdRec->writeRec();
43 }
44
45 #!/usr/bin/perl
46 # Script to set the first title line equal to a given data field
47 #
48 # Usage: sdmodify -f<DataField> [sdFiles]
49 #
50 # If sdFiles not given, reads from standard input
51 # Output is to standard output
52
53 sub printHelpAndExit {
54 print "\nScript to set the first title line equal to a given data field.\n";
55 print "\nUsage:\tsdmodify -f<DataField> [sdFiles]\n";
56 print "\n\tIf sdFiles not given, reads from standard input.\n";
57 print "\n\tOutput is to standard output.\n\n";
58 exit;
59 }