Hi all,
I'm a complete noob when it comes to scripting. I have had a play with perl and python to do a few simple things to make my life easier. But this task I am really struggling with in either.
I have three files which look like this:
# few lines of header
@more lines of header
0.000 0.040524
0.002 0.495572
0.004 0.486072
0.006 0.586495
0.008 0.720278
... etc....
50
The left hand column is the time (so is the same in each file) and the right hand value is the interesting part which varies.
I want to take these three files and average the value in the right hand value. Ending up with a file that looks like this:
#header (doesn't matter which file it's from)
@header (doesn't matter which file it's from)
0.000 *mean 1-3*
0.002 *mean 1-3*
0.004 *mean 1-3*
0.006 *mean 1-3*
0.006 *mean 1-3*
...
50.000 *mean 1-3*
My problem is that I am struggling to address the three files at the same time. Previously I have done stuff with one of these files using things like this in perl:
or something similar in python:
but I am struggling to do this task with a simple "line in lines" and a split because I am taking things from two files.
I think that the solution should be to take the two files, pick the interesting sections and put them in arrays, then add the three arrays and divide by three. I just can't work out how to do this!
I'm a complete noob when it comes to scripting. I have had a play with perl and python to do a few simple things to make my life easier. But this task I am really struggling with in either.
I have three files which look like this:
# few lines of header
@more lines of header
0.000 0.040524
0.002 0.495572
0.004 0.486072
0.006 0.586495
0.008 0.720278
... etc....
50
The left hand column is the time (so is the same in each file) and the right hand value is the interesting part which varies.
I want to take these three files and average the value in the right hand value. Ending up with a file that looks like this:
#header (doesn't matter which file it's from)
@header (doesn't matter which file it's from)
0.000 *mean 1-3*
0.002 *mean 1-3*
0.004 *mean 1-3*
0.006 *mean 1-3*
0.006 *mean 1-3*
...
50.000 *mean 1-3*
My problem is that I am struggling to address the three files at the same time. Previously I have done stuff with one of these files using things like this in perl:
Code:
while ($line = <FILE>)
{
if ($line =~ m/@/)
{
print $line;
}
elsif ($line =~ m/#/)
{
print $line;
}
else
{
for ($line) {
s/^\s+//;
s/\s+$//;
}
chomp $line;
@words = split(" ",$line);
$col1 = $words[0] / $x;
$col2 = $words[1] * $y;
print "$col1 $col2\n";
}
}
or something similar in python:
Code:
for line in lines:
if re.search( r"#", line ):
print line,
elif re.search( r"@", line ):
print line,
elif line== '\n':
print line,
else:
words = line.split()
time = words[0]
rmsd1 = words[1]
print "%s %s" % (time, rmsd1)
but I am struggling to do this task with a simple "line in lines" and a split because I am taking things from two files.
I think that the solution should be to take the two files, pick the interesting sections and put them in arrays, then add the three arrays and divide by three. I just can't work out how to do this!
Last edited: