Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
And I am writing a perl script to take each pair of values, place them in an array element according to whether they fit into a certain range ...for example, Phi (first value) between -180 and -175 and Psi (second value) between 60 and 70.-112.6 115.0 -120.8 153.7 -121.8 118.7 -118.5 142.8 -144.1 146.9 -119.7 124.5 -118.0 119.2
This script now works just fine for a reasonably small test file. But it doesnt fare so well on my actual file (which is about 22MB in size) .. in fact it just sits there and does nothing. I'm not sure quite why this is, would it be because the script as is is just terribly inefficient, or would it be that it simply cant handle large quantities of data, or what?#!/usr/bin/perl use warnings; # from command line. This file is a text file of phi psi angles as sel +ected # from ramachandran_3DplotA.pl script $input = $ARGV[0]; $output = $ARGV[1]; $n = 0; $o = 0; $v = 0; if(($ARGV[0] eq "-h") || ($ARGV[0] eq "")) { print "\n* Ramachandran_3D Plot* program\n"; print "-------------------------------------------\n"; print "Usage: perl ramachandran_3DplotB.pl <input file> <output fi +le>\n"; print "-------------------------------------------\n"; print "Prints out file for use in Graphis plotting program\n\n"; exit(1); } open(FILE, "$input") || die "ERROR: Unable to open $input FILE for rea +ding: $!\n"; open(OUT, ">>$output") || die "ERROR: Unable to open $output FILE for +writing: $!\n"; @file = <FILE>; for($i = -180; $i < 181; $i = $i+5) { $j = $i+5; $n++; $o = 0; for($k = -180; $k < 181; $k = $k+5) { $m = $k+5; $o++; @ranges = ([$i, $j, $k, $m]); @range_counts = (0) x @ranges; for $R (0..$#ranges) { for($f = 0; $f <@file; $f++) { $phi = substr($file[$f], 0, 6); $psi = substr($file[$f], 8, 6); print "$phi $psi\n"; if ($phi >=$ranges[$R][0] and $phi < $ranges[$R][1] and $psi >= $ranges[$R][2] and $psi < $ranges[$R][3]) { ++$range_counts[$R]; } } } for $R (0..$#ranges) { if($v < 73) { printf OUT "%d, ", $range_counts[$R]; $v++; } else { print OUT "\n"; $v = 0; } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: inefficient code? works on small files ok but not larger ones
by dragonchild (Archbishop) on Oct 05, 2004 at 14:44 UTC | |
|
Re: inefficient code? works on small files ok but not larger ones
by davido (Cardinal) on Oct 05, 2004 at 14:46 UTC | |
|
Re: inefficient code? works on small files ok but not larger ones
by tall_man (Parson) on Oct 05, 2004 at 15:57 UTC | |
by graff (Chancellor) on Oct 06, 2004 at 02:42 UTC | |
|
Re: inefficient code? works on small files ok but not larger ones
by duff (Parson) on Oct 05, 2004 at 14:47 UTC | |
|
Re: inefficient code? works on small files ok but not larger ones
by jaco (Pilgrim) on Oct 05, 2004 at 14:39 UTC | |
|
Re: inefficient code? works on small files ok but not larger ones
by mutated (Monk) on Oct 05, 2004 at 16:11 UTC |