Our Sponsors



Download BioinformaticsOnline(BOL) Apps in your chrome browser.




Reformat the file names with Perl

  • Public
By Jit 2324 days ago
#!/usr/bin/perl use strict; use warnings; use File::Copy qw(copy);; $| = 1; my %hash; my @files = glob "*.scf"; if (!$ARGV[0]){ print "Table file needed\n USAGE: $0 table\n"; exit;} my $ifh = read_fh($ARGV[0]); while (my $line = <$ifh>) { next if $line =~ /^#/; #next if $. == 1; my ($lichenName, $name, $code) = split /\s+/, $line; next unless defined $lichenName and defined $name and defined $code; $hash{$name}{sps}= $lichenName; $hash{$name}{code}= $code; } #Chec one by one for (0..$#files){ $files[$_] =~ s/\.scf$//; my @pName = split /\_/, $files[$_]; next if ! $hash{$pName[0]}{sps} or !$hash{$pName[0]}{code}; my $newName= "$hash{$pName[0]}{sps}"."_$pName[0]"."_$hash{$pName[0]}{code}"."_$pName[1]"."."."scf"; if ( -f "$files[$_].scf" ) { copy("$files[$_].scf", $newName) or die "Copy failed: $!"; } } sub read_fh { my $filename = shift @_; my $filehandle; open $filehandle, "<$filename" or die $!; return $filehandle; }