I'm not sure what would be the best title to properly give this request since I probably don't know what I'm really doing in the first place :( sorry. I'm having a problem with what is probably basic Perl structure. I can't figure it out, and a colleague of mine who has more Perl experience is stumped too.

I wrote this script that opens a file, reads in a set of coordinates and then using Math::Interpolate creates a curve. In a loop the curve is interpolated for Y from a range of X-values. Once all the new Y-values have been calculated it moves to the next row and repeats. OK, so far so good. It works as in that it doesn't crash and the data is more or less usable, however, the resulting curve does not pass through the Y-maximum that it should (which was in the control set). So, I need to scale the curve such that no point goes beyond the ceiling that it was given. How can I store this data in an array, calculate its max value, create a scaling factor based on the original max Y-value (Y-maxOld/Y-maxNew), and then multiply each element in that array with this scaling factor (and then repeat for the next set of coordinates)?

I know I can use List::Util qw(max) for finding the max value in an array or list, but I just don't know how to incorporate this.

Here's the code I'm using:
#!/usr/bin/perl use warnings; use Getopt::Long; use Getopt::ArgvFile; use Math::Interpolate qw(derivatives robust_interpolate); use Math::Round; use List::Util qw(max); @peaks = $ARGV[0]; open ( IN, "@peaks" ) or die "Can't open file: $!"; while (<IN>) { chomp; my @fields = split ("\t",$_); my @x=(0,$fields[4]*.25,$fields[4],($fields[3]-($fields[3]*0.25)), +$fields[3]); # these are the training X-values my @y=(0,$fields[6]*0.4,$fields[6],$fields[6]*0.4,0); # these are +the training Y-values my @dy = derivatives(\@x, \@y); my $iter=1; print "fixedStep chrom=$fields[0] start=$fields[1] step=1\n"; while ($iter <= $fields[3]) { my ($r_y, $r_dy) = robust_interpolate($iter, \@x, \@y); my @ynew2 = nearest(0.01,($r_y)); print "@ynew2\n"; $iter ++; } } close IN;

Here's a graph of some real data. The Excel curve is based on three control points, the Math::Interpolate one is based on five controls. The height of the Excel curve is what I need to scale the other one to.

https://www.dropbox.com/s/6dikruncc02427v/Interpolate_example1.pdf

In reply to operate on an array created in a while loop by captainentropy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.