Skip to content

Commit

Permalink
Add configuration options for gnuplot, and auto-detect which image fo…
Browse files Browse the repository at this point in the history
…rmat to use. Report errors too. Issue marbl#218.
  • Loading branch information
brianwalenz committed Aug 31, 2016
1 parent 3208c21 commit a7771c8
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
9 changes: 9 additions & 0 deletions documentation/source/parameter-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ shell <string="/bin/sh">
java <string="java">
A path to a Java application launcher of at least version 1.8.

gnuplot <string="gnuplot">
A path to the gnuplot graphing utility.

gnuplotImageFormat <string="png">
The type of image to generate in gnuplot. By default, canu will use png, svg or gif, in that order.

gnuplotTested <boolean=false>
If set, skip the tests to determine if gnuplot will run, and to decide the image type to generate. This is used when gnuplot fails to run, or isn't even installed, and allows canu to continue execution without generating graphs.

Cleanup Options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
121 changes: 121 additions & 0 deletions src/pipelines/canu/Defaults.pm
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,15 @@ sub setDefaults () {
$global{"java"} = (exists $ENV{"JAVA_HOME"} && -e "$ENV{'JAVA_HOME'}/bin/java") ? "$ENV{'JAVA_HOME'}/bin/java" : "java";
$synops{"java"} = "Java interpreter to use; at least version 1.8; default 'java'";

$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{"gnuplotTested"} = 0;
$synops{"gnuplotTested"} = "If set, skip the initial testing of gnuplot";

##### Cleanup options

$global{"saveOverlaps"} = 0;
Expand Down Expand Up @@ -1268,6 +1277,118 @@ sub checkParameters () {
}
}

#
# Gnuplot?
#

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";
}
}
}


#
# Minimap, no valid identities, set legacy
#
Expand Down

0 comments on commit a7771c8

Please sign in to comment.