annotate tools/rdock/bin/sdmodify @ 3:b02d74d22d05 draft default tip

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