fasoli has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I was wondering if you could find the reason for this issue in the code posted below?
I am trying to automate the way I use a program (Gromacs) and edit its outputs. So first I loop through my molecules and issue the Gromacs command (g_angle) which works fine. Then I commented the g_angle command out to test the rest of the script. What I want to do now is open (for reading) the output of the previously used command, to manipulate it and write another file.
However the line open $input, '<', '/Users/athina/check-ma/$ID${l}/F${j}\/gangle-dihedrals-${i}${id}${k}.xvg' or die $!; fails as "no such file or directory" but the file exists.
The line print `ls /Users/athina/check-ma/$ID${l}/F${j}\/gangle-dihedrals-${i}${id}${k}.xvg`; that I've used as a test works fine and returns the file.
What is happening? :( Thank you so much for your time!
#!/usr/bin/perl use warnings; use strict; my $id = "ac"; my $ID = "AC"; my $g_angle = "/usr/local/gromacs/bin/g_angle"; my $i; my $k; my $input; my $output; #disable Gromacs backups because otherwise it fails after writing 99x +copies if(!defined $ENV{GMX_MAXBACKUP}) { $ENV{GMX_MAXBACKUP}=-1 } for ($i=2; $i<=2; $i++) { my $j = sprintf ("%05d", $i); for ($k=15; $k<=15; $k++) { my $l = sprintf ("%04d", $k); my $path = "/Users/athina/check-ma/$ID${l}/F${j}"; my $dashFolder = "/media/data/athina/dash-test/$ID${l}"; #`$g_angle -f $path\/${i}${id}${k}.mdsol.centered.xtc -n /Users/ath +ina/check-ma/$ID${l}/F00001/dihedrals-1${id}${k}.ndx -type dihedral - +all -ov $path\/gangle-dihedrals-${i}${id}${k}.xvg -od $path\/out.xvg` +; print `ls /Users/athina/check-ma/$ID${l}/F${j}\/gangle-dihedrals-${i} +${id}${k}.xvg`; open $input, '<', '/Users/athina/check-ma/$ID${l}/F${j}\/gangle-dih +edrals-${i}${id}${k}.xvg' or die $!; open $output, '>', '/Users/athina/check-ma/$ID${l}/F${j}\/in-dihedr +als-${i}${id}${k}.txt' or die $!; while (my $line = <$input>) { chomp $line; # remove end-of-line character $line =~ s/^\s+//; # strip leading whitespace next unless $line; # skip blank lines # skip first 12 lines next unless $. > 12; # $. contains current line number my @columns = split(/\s+/, $line); # split columns on whitespac +e my $col1 = shift @columns; # column 1 (throw away) my $col2 = shift @columns; # column 2 (throw away) my $col3 = shift @columns; # column 3 (special - keep this one) my $result = sprintf("%8.3f", $col3); # special format for col 3 # loop over remaining columns, appending to result string for my $c (@columns) { my $data = sprintf("%9.3f", $c); $result .= " $data"; } print $output "$result\n"; } ### } ### for k loop } ### for i loop
|
|---|