annotate tools/rdock/bin/sdfield @ 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 # add extra fields to SD records
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
3 use lib "$ENV{'RBT_ROOT'}/lib";
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
4 use SDRecord;
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
5
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
6 printHelpAndExit() if (scalar(@ARGV) == 0);
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
7 #Parse command line arguments
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
8 my @files;
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
9 my $arg = shift @ARGV;
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
10 printHelpAndExit() if ($arg eq '-h');
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
11 #read records
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
12 my $sdRec = new SDRecord;
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
13 my $nRec=0;
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
14 # if not -h, then must be the FieldName
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
15 my $FieldName = $arg;
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
16 my $FieldVal = shift @ARGV; # and this must be the filed value
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
17 # rest are the filenames
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
18 while ($sdRec->readRec('DATA'=>1,'LINES'=>1)) {
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
19 $sdRec->addData('_REC' => ++$nRec);#add record# as temp data field
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
20 $sdRec->addData('_FILE' => $ARGV);#add filename as temp data field
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
21 $sdRec->addDataAndLines($FieldName => $FieldVal);
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
22 $sdRec->writeRec();#write record
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
23 }
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
24
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
25 sub printHelpAndExit {
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
26 print "\nAdding fields to SD files\n";
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
27 print "Usage:\n";
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
28 print "\tsdfield <Fieldname> <value> <infile[s]>\n";
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
29 print "\t-h\tthis help\n";
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
30 print "\t\n";
b02d74d22d05 planemo upload
marpiech
parents:
diff changeset
31 }