Skip to content

Commit

Permalink
Actually _use_ the new gnuplot configuration. Issue marbl#218.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianwalenz committed Aug 31, 2016
1 parent a7771c8 commit a2951ae
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 169 deletions.
62 changes: 34 additions & 28 deletions src/pipelines/canu/CorrectReads.pm
Original file line number Diff line number Diff line change
Expand Up @@ -660,25 +660,28 @@ sub expensiveFilter ($$) {
# Plot a scatter plot of the original vs the expected corrected read lengths. Early versions
# also plotted the sorted length vs the other length, but those were not interesting.

if (! -e "$path/$asm.estimate.original-x-correctedLength.png") {
if (! -e "$path/$asm.estimate.original-x-correctedLength.gp") {
my $gnuplot = getGlobal("gnuplot");
my $format = getGlobal("gnuplotImageFormat");

open(F, "> $path/$asm.estimate.original-x-correctedLength.gp");
print F "set title 'original length (x) vs corrected length (y)'\n";
print F "set xlabel 'original read length'\n";
print F "set ylabel 'corrected read length (expected)'\n";
print F "set pointsize 0.25\n";
print F "\n";
print F "set terminal png size 1024,1024\n";
print F "set output '$path/$asm.estimate.original-x-corrected.lg.png'\n";
print F "set terminal $format size 1024,1024\n";
print F "set output '$path/$asm.estimate.original-x-corrected.lg.$format'\n";
print F "plot '$path/$asm.estimate.tn.log' using 2:4 title 'tn', \\\n";
print F " '$path/$asm.estimate.fn.log' using 2:4 title 'fn', \\\n";
print F " '$path/$asm.estimate.fp.log' using 2:4 title 'fp', \\\n";
print F " '$path/$asm.estimate.tp.log' using 2:4 title 'tp'\n";
print F "set terminal png size 256,256\n";
print F "set output '$path/$asm.estimate.original-x-corrected.sm.png'\n";
print F "set terminal $format size 256,256\n";
print F "set output '$path/$asm.estimate.original-x-corrected.sm.$format'\n";
print F "replot\n";
close(F);

if (runCommandSilently($path, "gnuplot < $path/$asm.estimate.original-x-correctedLength.gp > /dev/null 2>&1", 0)) {
if (runCommandSilently($path, "$gnuplot < $path/$asm.estimate.original-x-correctedLength.gp > /dev/null 2>&1", 0)) {
print STDERR "--\n";
print STDERR "-- WARNING: gnuplot failed; no plots will appear in HTML output.\n";
print STDERR "--\n";
Expand Down Expand Up @@ -1118,6 +1121,9 @@ sub dumpCorrectedReads ($$) {

# Scatterplot of lengths.

my $gnuplot = getGlobal("gnuplot");
my $format = getGlobal("gnuplotImageFormat");

open(F, "> $wrk/2-correction/$asm.originalLength-vs-correctedLength.gp") or caExit("", undef);
print F "\n";
print F "set pointsize 0.25\n";
Expand All @@ -1126,37 +1132,37 @@ sub dumpCorrectedReads ($$) {
print F "set xlabel 'original read length'\n";
print F "set ylabel 'expected corrected read length'\n";
print F "\n";
print F "set terminal png size 1024,1024\n";
print F "set output '$wrk/2-correction/$asm.originalLength-vs-expectedLength.lg.png'\n";
print F "set terminal $format size 1024,1024\n";
print F "set output '$wrk/2-correction/$asm.originalLength-vs-expectedLength.lg.$format'\n";
print F "plot [0:$maxReadLen] [0:$maxReadLen] '$wrk/2-correction/$asm.original-expected-corrected-length.dat' using 2:3 title 'original (x) vs expected (y)'\n";
print F "set terminal png size 256,256\n";
print F "set output '$wrk/2-correction/$asm.originalLength-vs-expectedLength.sm.png'\n";
print F "set terminal $format size 256,256\n";
print F "set output '$wrk/2-correction/$asm.originalLength-vs-expectedLength.sm.$format'\n";
print F "replot\n";
print F "\n";
print F "set title 'original read length vs sum of corrected read lengths'\n";
print F "set xlabel 'original read length'\n";
print F "set ylabel 'sum of corrected read lengths'\n";
print F "\n";
print F "set terminal png size 1024,1024\n";
print F "set output '$wrk/2-correction/$asm.originalLength-vs-correctedLength.lg.png'\n";
print F "set terminal $format size 1024,1024\n";
print F "set output '$wrk/2-correction/$asm.originalLength-vs-correctedLength.lg.$format'\n";
print F "plot [0:$maxReadLen] [0:$maxReadLen] '$wrk/2-correction/$asm.original-expected-corrected-length.dat' using 2:4 title 'original (x) vs corrected (y)'\n";
print F "set terminal png size 256,256\n";
print F "set output '$wrk/2-correction/$asm.originalLength-vs-correctedLength.sm.png'\n";
print F "set terminal $format size 256,256\n";
print F "set output '$wrk/2-correction/$asm.originalLength-vs-correctedLength.sm.$format'\n";
print F "replot\n";
print F "\n";
print F "set title 'expected read length vs sum of corrected read lengths'\n";
print F "set xlabel 'expected read length'\n";
print F "set ylabel 'sum of corrected read lengths'\n";
print F "\n";
print F "set terminal png size 1024,1024\n";
print F "set output '$wrk/2-correction/$asm.expectedLength-vs-correctedLength.lg.png'\n";
print F "set terminal $format size 1024,1024\n";
print F "set output '$wrk/2-correction/$asm.expectedLength-vs-correctedLength.lg.$format'\n";
print F "plot [0:$maxReadLen] [0:$maxReadLen] '$wrk/2-correction/$asm.original-expected-corrected-length.dat' using 3:4 title 'expected (x) vs corrected (y)'\n";
print F "set terminal png size 256,256\n";
print F "set output '$wrk/2-correction/$asm.expectedLength-vs-correctedLength.sm.png'\n";
print F "set terminal $format size 256,256\n";
print F "set output '$wrk/2-correction/$asm.expectedLength-vs-correctedLength.sm.$format'\n";
print F "replot\n";
close(F);

if (runCommandSilently("$wrk/2-correction", "gnuplot $wrk/2-correction/$asm.originalLength-vs-correctedLength.gp > /dev/null 2>&1", 0)) {
if (runCommandSilently("$wrk/2-correction", "$gnuplot $wrk/2-correction/$asm.originalLength-vs-correctedLength.gp > /dev/null 2>&1", 0)) {
print STDERR "--\n";
print STDERR "-- WARNING: gnuplot failed; no plots will appear in HTML output.\n";
print STDERR "--\n";
Expand All @@ -1176,28 +1182,28 @@ sub dumpCorrectedReads ($$) {
print F "set boxwidth binwidth\n";
print F "bin(x,width) = width*floor(x/width) + binwidth/2.0\n";
print F "\n";
print F "set terminal png size 1024,1024\n";
print F "set output '$wrk/2-correction/$asm.length-histograms.lg.png'\n";
print F "set terminal $format size 1024,1024\n";
print F "set output '$wrk/2-correction/$asm.length-histograms.lg.$format'\n";
print F "plot [1:$maxReadLen] [0:] \\\n";
print F " '$wrk/2-correction/$asm.original-expected-corrected-length.dat' using (bin(\$2,binwidth)):(1.0) smooth freq with boxes title 'original', \\\n";
print F " '$wrk/2-correction/$asm.original-expected-corrected-length.dat' using (bin(\$3,binwidth)):(1.0) smooth freq with boxes title 'expected', \\\n";
print F " '$wrk/2-correction/$asm.original-expected-corrected-length.dat' using (bin(\$4,binwidth)):(1.0) smooth freq with boxes title 'corrected'\n";
print F "set terminal png size 256,256\n";
print F "set output '$wrk/2-correction/$asm.length-histograms.sm.png'\n";
print F "set terminal $format size 256,256\n";
print F "set output '$wrk/2-correction/$asm.length-histograms.sm.$format'\n";
print F "replot\n";
print F "\n";
print F "set xlabel 'difference between expected and corrected read length, bin width = 250, min=$minDiff, max=$maxDiff'\n";
print F "\n";
print F "set terminal png size 1024,1024\n";
print F "set output '$wrk/2-correction/$asm.length-difference-histograms.lg.png'\n";
print F "set terminal $format size 1024,1024\n";
print F "set output '$wrk/2-correction/$asm.length-difference-histograms.lg.$format'\n";
print F "plot [$minDiff:$maxDiff] [0:] \\\n";
print F " '$wrk/2-correction/$asm.original-expected-corrected-length.dat' using (bin(\$7,binwidth)):(1.0) smooth freq with boxes title 'expected - corrected'\n";
print F "set terminal png size 256,256\n";
print F "set output '$wrk/2-correction/$asm.length-difference-histograms.sm.png'\n";
print F "set terminal $format size 256,256\n";
print F "set output '$wrk/2-correction/$asm.length-difference-histograms.sm.$format'\n";
print F "replot\n";
close(F);

if (runCommandSilently("$wrk/2-correction", "gnuplot $wrk/2-correction/$asm.length-histograms.gp > /dev/null 2>&1", 0)) {
if (runCommandSilently("$wrk/2-correction", "$gnuplot $wrk/2-correction/$asm.length-histograms.gp > /dev/null 2>&1", 0)) {
print STDERR "--\n";
print STDERR "-- WARNING: gnuplot failed; no plots will appear in HTML output.\n";
print STDERR "--\n";
Expand Down
217 changes: 109 additions & 108 deletions src/pipelines/canu/Defaults.pm
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,8 @@ sub setDefaults () {
$global{"gnuplot"} = "gnuplot";
$synops{"gnuplot"} = "Path to the gnuplot executable";

$global{"gnuplotImageFormat"} = "png";
$synops{"gnuplotImageFormat"} = "Image format that gnuplot will generate, used in HTML reports. Default: 'png'";
$global{"gnuplotImageFormat"} = undef;
$synops{"gnuplotImageFormat"} = "Image format that gnuplot will generate, used in HTML reports. Default: based on gnuplot, 'png', 'svg' or 'gif'";

$global{"gnuplotTested"} = 0;
$synops{"gnuplotTested"} = "If set, skip the initial testing of gnuplot";
Expand Down Expand Up @@ -1000,6 +1000,111 @@ sub setDefaults () {



sub gnuplotTest () {
my $gnuplot = getGlobal("gnuplot");
my $format = getGlobal("gnuplotImageFormat");
my $version = undef;

# Check for existence of gnuplot.

open(F, "$gnuplot -V |");
while (<F>) {
chomp;
$version = $_;
$version = $1 if ($version =~ m/^gnuplot\s+(.*)$/);
}
close(F);

if (!defined($version)) {
addCommandLineError("ERROR: Failed to run gnuplot from '$gnuplot'.");
addCommandLineError("ERROR: Set option gnuplot=<path-to-gnuplot> or gnuplotTested=true to skip this test and not generate plots.\n");
return;
}

# Check for existence of a decent output format.

if (!defined($format)) {
my $havePNG = 0;
my $haveSVG = 0;
my $haveGIF = 0;

open(F, "$gnuplot -e 'set terminal' |");
while (<F>) {
s/^\s+//;
s/\s+$//;

my @t = split '\s+', $_;

$havePNG = 1 if ($t[0] eq 'png');
$haveSVG = 1 if ($t[0] eq 'svg');
$haveGIF = 1 if ($t[0] eq 'gif');
}
close(F);

$format = "gif" if ($haveGIF);
$format = "svg" if ($haveSVG);
$format = "png" if ($havePNG);

setGlobal("gnuplotImageFormat", $format);
}

if (!defined($format)) {
addCommandLineError("ERROR: Failed to detect a suitable output format for gnuplot.\n");
addCommandLineError("ERROR: Looked for png, svg and gif, found none of them.\n");
addCommandLineError("Set option gnuplotImageFormat=<type>, or gnuplotTested=true to skip this test and not generate plots.\n");
return;
}

# Test if we can actually make images.

open(F, "> /tmp/gnuplot-$$-test.gp");
print F "set title 'gnuplot test'\n";
print F "set xlabel 'X'\n";
print F "set xlabel 'Y'\n";
print F "\n";
print F "set terminal '$format' size 1024,1024\n";
print F "set output '/tmp/gnuplot-$$-test.1.$format'\n";
print F "\n";
print F "plot [-30:20] sin(x*20) * atan(x)\n\n";
print F "\n";
print F "set terminal '$format' size 256,256\n";
print F "set output '/tmp/gnuplot-$$-test.2.$format'\n";
print F "\n";
print F "bogus line\n";
close(F);

# Dang, we don't have runCommandSilently here, so have to do it the hard way.

system("cd /tmp && $gnuplot /tmp/gnuplot-$$-test.gp > /tmp/gnuplot-$$-test.err 2>&1");

if ((! -e "/tmp/gnuplot-$$-test.1.$format") ||
(! -e "/tmp/gnuplot-$$-test.2.$format")) {
addCommandLineError("ERROR: gnuplot failed to generate images.\n");

open(F, "< /tmp/gnuplot-$$-test.err");
while (<F>) {
chomp;
addCommandLineError("ERROR: gnuplot reports: $_\n");
}
close(F);

addCommandLineError("ERROR: Set option gnuplotImageFormat=<type>, or gnuplotTested=true to skip this test and not generate plots.\n");
return;
}

# Yay, gnuplot works!

print STDERR "-- Detected gnuplot version '$version' (from '$gnuplot') and image format '$format'.\n";
#addCommandLineOption("gnuplotTested=1");

unlink "/tmp/gnuplot-$$-test.gp";
unlink "/tmp/gnuplot-$$-test.err";
unlink "/tmp/gnuplot-$$-test.1.$format";
unlink "/tmp/gnuplot-$$-test.2.$format";
}



sub checkParameters () {

#
Expand Down Expand Up @@ -1282,119 +1387,15 @@ sub checkParameters () {
#

if (getGlobal("gnuPlotTested") == 0) {
my $gnuplot = getGlobal("gnuplot");
my $format = getGlobal("gnuplotImageFormat");
my $version = undef;

# Check for existence of gnuplot.

open(F, "$gnuplot -V |");
while (<F>) {
chomp;
$version = $_;
$version = $1 if ($version =~ m/^gnuplot\s+(.*)$/);
}
close(F);

if (!defined($version)) {
addCommandLineError("ERROR: Failed to run gnuplot from '$gnuplot'.");
addCommandLineError("ERROR: gnuplot reported '$version'\n");
addCommandLineError("ERROR: Set option gnuplot=<path-to-gnuplot> or gnuplotTested=true to skip this test and not generate plots.\n");
}

# Check for existence of a decent output format.

else {
my $havePNG = 0;
my $haveSVG = 0;
my $haveGIF = 0;

open(F, "$gnuplot -e 'set terminal' |");
while (<F>) {
s/^\s+//;
s/\s+$//;

my @t = split '\s+', $_;

$havePNG = 1 if ($t[0] eq 'png');
$haveSVG = 1 if ($t[0] eq 'svg');
$haveGIF = 1 if ($t[0] eq 'gif');
}
close(F);

my $format;

$format = "gif" if ($haveGIF);
$format = "svg" if ($haveSVG);
$format = "png" if ($havePNG);

setGlobal("gnuplotImageFormat", $format);

if (!defined($format)) {
addCommandLineError("ERROR: Failed to detect a suitable output format for gnuplot.\n");
addCommandLineError("ERROR: Looked for png, svg and gif, found none of them.\n");
addCommandLineError("Set option gnuplotImageFormat=<type>, or gnuplotTested=true to skip this test and not generate plots.\n");
}

# Test if we can actually make images.

else {
open(F, "> /tmp/gnuplot-$$-test.gp");
print F "set title 'gnuplot test'\n";
print F "set xlabel 'X'\n";
print F "set xlabel 'Y'\n";
print F "\n";
print F "set terminal '$format' size 1024,1024\n";
print F "set output '/tmp/gnuplot-$$-test.1.$format'\n";
print F "\n";
print F "plot [-30:20] sin(x*20) * atan(x)\n\n";
print F "\n";
print F "set terminal '$format' size 256,256\n";
print F "set output '/tmp/gnuplot-$$-test.2.$format'\n";
print F "\n";
print F "bogus line\n";
close(F);

# Dang, we don't have runCommandSilently here, so have to do it the hard way.

system("cd /tmp && $gnuplot /tmp/gnuplot-$$-test.gp > /tmp/gnuplot-$$-test.err 2>&1");

if ((! -e "/tmp/gnuplot-$$-test.1.$format") ||
(! -e "/tmp/gnuplot-$$-test.2.$format")) {
addCommandLineError("ERROR: gnuplot failed to generate images.\n");

open(F, "< /tmp/gnuplot-$$-test.err");
while (<F>) {
chomp;
addCommandLineError("ERROR: gnuplot reports: $_\n");
}
close(F);

addCommandLineError("ERROR: Set option gnuplotImageFormat=<type>, or gnuplotTested=true to skip this test and not generate plots.\n");
}

# Oh, I just loathe these cascaded if else if else if else if else structures. But, gnuplot works.

else {
print STDERR "-- Detected gnuplot version '$version' (from '$gnuplot') and image format '$format'.\n";
#addCommandLineOption("gnuplotTested=1");
}

unlink "/tmp/gnuplot-$$-test.gp";
unlink "/tmp/gnuplot-$$-test.err";
unlink "/tmp/gnuplot-$$-test.1.$format";
unlink "/tmp/gnuplot-$$-test.2.$format";
}
}
gnuplotTest();
}


#
# Minimap, no valid identities, set legacy
#

if (getGlobal("corOverlapper") eq "minimap") {
setGlobalIfUndef("corLegacyFilter", 1);
setGlobalIfUndef("corLegacyFilter", 1);
}

#
Expand Down
Loading

0 comments on commit a2951ae

Please sign in to comment.