Mercurial > repos > marpiech > norwich_docking_tools
comparison galaxy-tools/tools/rdock/bin/sdmodify @ 0:4eb3f9cb2a51 draft
Uploaded
author | dzesikah |
---|---|
date | Fri, 26 Aug 2016 09:53:37 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4eb3f9cb2a51 |
---|---|
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 } |