| 1 | #!/usr/bin/perl -w
|
|---|
| 2 |
|
|---|
| 3 | use strict;
|
|---|
| 4 | use File::Copy;
|
|---|
| 5 |
|
|---|
| 6 | my $usage = <<USAGE
|
|---|
| 7 | The script will collect the MassSpectrum.xml files found in a project and copy them to the top level directory with new names, based on the raw file names.
|
|---|
| 8 | Usage: perl RenamePLGSfiles.pl <PLGS project directory>
|
|---|
| 9 |
|
|---|
| 10 | Example: perl RenamePLGSfiles.pl x:/Username/Proj__11739475298910_9281147836835626
|
|---|
| 11 | USAGE
|
|---|
| 12 | ;
|
|---|
| 13 |
|
|---|
| 14 | die $usage unless scalar(@ARGV) == 1;
|
|---|
| 15 |
|
|---|
| 16 | my @dirs = glob("$ARGV[0]/\*");
|
|---|
| 17 |
|
|---|
| 18 | my $counter = 0;
|
|---|
| 19 | foreach my $dir ( @dirs )
|
|---|
| 20 | {
|
|---|
| 21 | next unless -d $dir; # Skip non-directories
|
|---|
| 22 | my $file="$dir/MassSpectrum.xml";
|
|---|
| 23 | if (open(FIN, '<', "$dir/MassSpectrum.xml"))
|
|---|
| 24 | {
|
|---|
| 25 | my $shortname;
|
|---|
| 26 | while (my $line = <FIN> )
|
|---|
| 27 | {
|
|---|
| 28 | if ($line =~ /^<MASS_SPECTRUM.*/)
|
|---|
| 29 | {
|
|---|
| 30 | my $i=rindex $line,"\\";
|
|---|
| 31 | my $j=index $line,".raw";
|
|---|
| 32 | $shortname=substr($line,$i+1,($j-$i-1));
|
|---|
| 33 | }
|
|---|
| 34 | }
|
|---|
| 35 | close(FIN);
|
|---|
| 36 | my $outfile = "$ARGV[0]/$shortname.plgs";
|
|---|
| 37 | print "$outfile\n";
|
|---|
| 38 | copy($file, $outfile);
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|