1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#!/usr/bin/perl
# Katharina J. Hoff
# November 14th 2014
# This script is part of WebAUGUSTUS.
# The purpose is to copy user-uploaded parameters to the AUGUSTUS_CONFIG_PATH and rename the parameters according to the job id
use File::Path qw(make_path);
my $usage = "moveParameters.pl parameterdir newid copytodir\n";
# parameterdir is the directory in which the parameter file originally reside, without / at the end
# newid is the new species identifier of the parameter set, e.g. the WebAUGUSTUS job id
# copytodir is the folder in which AUGUSTUS looks for parameter files, without / at the end
if(@ARGV != 3){
print $usage;
exit;
}
# find string that needs to be replaced, i.e. species name
opendir my($dir), $ARGV[0] or die "Could not open directory $ARGV[0]!\n";
my @dirs = readdir $dir;
closedir $dir;
# params in WebAUGUSTUS contains three folders: ., .., and the parameter archive. Determine which is the archive:
my $archC = 0;
foreach(@dirs){
if(not($_ eq ".") and not($_ eq "..")){
$species = $_;
}
$archC++;
}
if($archC > 3){
print STDERR "The parameter archive appears to have contained more than one folder, not sure which one to use!\n";
}
print "Species is $species\n";
my $targetdir = $ARGV[2]."/".$ARGV[1];
# create the target directory
eval { make_path($targetdir) };
if($@){
print STDERR "Could note create directory $targetdir: @$\n";
}
# retrieve files that need to be copied:
my $speciesdir = "$ARGV[0]/$species";
my %filehash;
opendir my($specdir), $speciesdir or die "Could not open directory $ARGV[0]!\n";
while( my $file = readdir($specdir)){
if(not($file =~m/^\./)){
open(INFILE, "<", "$speciesdir/$file") or die ("Could not open file $speciesdir/$file!\n");
$fstr = $file;
$fstr =~ s/$species/$ARGV[1]/;
open(OUTFILE, ">", "$targetdir/$fstr") or die ("Could not open output file $targetdir/$fstr!\n");
while(<INFILE>){
$_=~s/$species/$ARGV[1]/;
print OUTFILE $_;
}
close(INFILE);
close(OUTFILE);
}
}
closedir $specdir;
|