Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Math::Bezier returns Math::Bizarre output

by captainentropy (Initiate)
on Oct 06, 2013 at 19:00 UTC ( #1057184=perlquestion: print w/replies, xml ) Need Help??
captainentropy has asked for the wisdom of the Perl Monks concerning the following question:

NB: dozens of times I attempted to write this post but nothing would work. I was able to successfully write a post title "permission denied", which I have replaced with the current one. I'll keep the following updates in place, in case this is some glitch with the website and this makes any sense for that issue.

Original successful post titled "permission denied"

WTF? This has gone on long enough!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Oh, great. So, after 18hrs of trying and waiting, THAT works. WTH?


Here's the original attempt, none of which will post as written. It returns "permission denied". The preview looks perfect


First post and I find a bug in the website? No attempt has worked except this "permission denied" post. What is wrong with (the format?) of my post? I seek Perl wisdom, not Perl aggravation


I rewrote the whole post using a different text editor, and the same "permission denied" (with the title I was using obviously). And I know the title is fine because I read the page about how to write a title and it conformed (but why would that block my post anyway?).

OK, here's the question I have.

Hi, I'm using Math::Bezier to create smooth curves from a set of three x,y coordinates. I'm not having problems with accomplishing that per se, my program does, essentially, what I need it to. The thing is that 1) to get the interpolated curve to go through the correct maximum y-value (which was fed into the module as one of the three control sets) I have to multiply the resulting y-values by 2. And 2) the shape of the curve is wrong. It comes out as a simple, symmetric parabola (p<0). When I graph the same points in Excel using the "XY Scatter With Smooth Lines" function (which uses Bezier interpolation) it comes out perfect, exactly as it should. So, anyone have an idea what's happening?

Here's an example of what I'm seeing

Let me explain the curves. "Control points Alpha" is just the control set I'm using to evaluate my output. In this case the three XY coordinates are (0,0; 208,67.07; 690,0). "(Excel)" means, duh, graphed in Excel. Math::Bezier Alpha corrected y-max is the resulting curve if I multiply all the y-values of Math::Bezier Alpha original by 2. Control points Beta is adding two more control points (104,33.54; 312,33.54), graphed in Excel. And Math::Bezier Beta is the output of Math::Bezier with the two extra control points. The first curve - "control points Alpha (Excel)" - is exactly what I want to see from my perl script. Hopefully, someone has some experience using Math::Bezier and can tell me what I'm doing wrong. I emailed the author but have not received a reply.

Here's my code, though it works, I'm not sure if it's the Math::Bezier that's at fault, or me. It's probably me but I can't find anyone discussing Math::Bezier anywhere.

#!/usr/bin/perl use warnings; use Getopt::Long; use Getopt::ArgvFile; use Math::Bezier; use Math::Round; # input file is in this format # fields[0] = chr # fields[1] = peak start # fields[2] = peak end # fields[3] = peak length # fields[4] = coordinate of peak max height # fields[5] = read number # fields[6] = score (y-axis value) # fields[7] = enrichment # fields[8] = FDR(%) @peaks = $ARGV[0]; open ( IN, "@peaks" ) or die "Can't open file: $!"; print "track type=wiggle_0 name=track description=center_label visibil +ity=full autoScale=on\n"; while (<IN>) { next if /#/; # remove the header next if /start/; # inlcuding column descriptor chomp; my @fields = split ("\t",$_); print "fixedStep chrom=$fields[0] start=$fields[1] step=1\n"; my $bezier = Math::Bezier->new(0,0,$fields[4],$fields[6],$fields[3 +],0); my @points = $bezier->curve($fields[3]); while (@points) { my ($x,$y) = splice(@points,0,2); my $ynew = nearest(0.01,($y*2)); print "$ynew\n"; } } close IN;


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1057184]
Approved by Happy-the-monk
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2017-02-27 04:48 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (376 votes). Check out past polls.