forked from wbyu/estimate_genome_size.pl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jellyplot.pl
executable file
·130 lines (99 loc) · 3.55 KB
/
jellyplot.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!perl
# THIS PROGRAM REQUIRES GNUPLOT TO BE IN YOUR PATH
# http://www.gnuplot.info/
# Copyright (C) 2012,2013 Joseph F. Ryan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
$|++;
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use IO::File;
use POSIX qw(tmpnam);
our $VERSION = 0.03;
our $AUTHOR = 'Joseph F. Ryan <[email protected]>';
our $TMP_CMD_FILE = '';
our $TMP_TAB_FILE = '';
our $GNUPLOT = 'gnuplot';
MAIN: {
my $opt_version = 0;
my $opt_help = 0;
my $opt_results = Getopt::Long::GetOptions( "version" => \$opt_version,
"help" => \$opt_help);
$opt_version && version();
pod2usage({-exitval => 0, -verbose => 2}) if $opt_help;
my $file = $ARGV[0] or usage();
make_cmd_file($file);
if (system("$GNUPLOT $TMP_CMD_FILE\n") == 0) {
print "pdf file written to $file.pdf\n";
} else {
die "system call to $GNUPLOT failed. Is $GNUPLOT in path?\n";
}
}
sub make_cmd_file {
my $file = shift;
my $fh = '';
my $date_str = localtime();
do { $TMP_CMD_FILE = tmpnam() }
until $fh = IO::File->new($TMP_CMD_FILE, O_RDWR|O_CREAT|O_EXCL);
print $fh "set terminal postscript\n";
print $fh "set output \"| ps2pdf - $file.pdf\"\n";
print $fh "set nokey\n";
print $fh "set title 'K-mer plot $file (plot generated on $date_str)'\n";
print $fh "set logscale y\n";
print $fh "set xlabel 'multiplicity'\n";
print $fh "set ylabel 'number-of-distinct k-mers with given multiplicity'\n";
print $fh "plot '$file\n";
}
sub usage {
die "usage: $0 [--version] [--help] HISTO_FILE\n";
}
sub version {
die "jellyplot.pl $VERSION\n";
}
# install atexit-style handler so that when we exit or die,
# we automatically delete this temporary file
END {
if ($TMP_CMD_FILE) {
unlink($TMP_CMD_FILE) or die "Couldn't unlink $TMP_CMD_FILE:$!"
}
if ($TMP_TAB_FILE) {
unlink($TMP_TAB_FILE) or die "Couldn't unlink $TMP_TAB_FILE:$!"
}
}
__END__
=head1 NAME
B<jellyplot.pl> - generate PDF plot of histogram
=head1 AUTHOR
Joseph F. Ryan <[email protected]>
=head1 SYNOPSIS
jellyplot.pl HISTO_FILE
=head1 DESCRIPTION
generate PDF plot of histogram data from jellyfish data. Requires gnuplot
=head1 BUGS
Please report them to <[email protected]>
=head1 COPYRIGHT
Copyright (C) 2012 Joseph F. Ryan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=cut