view galaxy-tools/tools/rdock/bin/sdmodify @ 1:ad4bc82457e5 draft

Deleted selected files
author dzesikah
date Fri, 26 Aug 2016 09:55:15 -0400
parents 4eb3f9cb2a51
children
line wrap: on
line source

#!/usr/bin/perl
# Script to set the first title line equal to a given data field
#
# Usage:  sdmodify -f<DataField> [sdFiles]
#
#         If sdFiles not given, reads from standard input
#         Output is to standard output

use lib "$ENV{'RBT_ROOT'}/lib";

use SDRecord;

my $SDMODKEY = "ID";

#Print help if no command line arguments
printHelpAndExit() if (scalar(@ARGV) == 0);

#Parse command line arguments
my @files;
while (scalar(@ARGV)) {
  my $arg = shift @ARGV;
  printHelpAndExit() if ($arg eq '-h');
  if (index($arg,'-f')==0) {
    $SDMODKEY = substr($arg,2);#modification key
  }
  else {
    push @files,$arg;#must be a filename
  }
}
push @ARGV,@files;#put the filenames back in the arg list

#read records
my $sdRec = new SDRecord;
my $nRec=0;
while ($sdRec->readRec('DATA'=>1,'LINES'=>1)) {
  $sdRec->addData('_REC' => ++$nRec);#add record# as temp data field
  #set the first line equal to the given data field
  my $nLines = scalar (@{$sdRec->{'LINES'}});
  if ($nLines > 0) {
    ${$sdRec->{'LINES'}}[0] = $sdRec->{'DATA'}->{$SDMODKEY};
  }
  $sdRec->writeRec();
}

#!/usr/bin/perl
# Script to set the first title line equal to a given data field
#
# Usage:  sdmodify -f<DataField> [sdFiles]
#
#         If sdFiles not given, reads from standard input
#         Output is to standard output

sub printHelpAndExit {
  print "\nScript to set the first title line equal to a given data field.\n";
  print "\nUsage:\tsdmodify -f<DataField> [sdFiles]\n";
  print "\n\tIf sdFiles not given, reads from standard input.\n";
  print "\n\tOutput is to standard output.\n\n";
  exit;
}