GelBasedReport: RenamePLGSfiles.pl

File RenamePLGSfiles.pl, 996 bytes (added by fredrik, 2 years ago)

Perl script for renaming PLGS files

Line 
1#!/usr/bin/perl -w
2
3use strict;
4use File::Copy;
5
6my $usage = <<USAGE
7The 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.
8Usage: perl RenamePLGSfiles.pl <PLGS project directory>
9
10Example: perl RenamePLGSfiles.pl x:/Username/Proj__11739475298910_9281147836835626
11USAGE
12  ;
13
14die $usage unless scalar(@ARGV) == 1;
15
16my @dirs = glob("$ARGV[0]/\*");
17
18my $counter = 0;
19foreach 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}