File: plotLabel.pl

package info (click to toggle)
snpeff 5.4.b%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 757,500 kB
  • sloc: java: 62,572; perl: 2,279; sh: 1,184; python: 744; xml: 507; makefile: 48
file content (82 lines) | stat: -rwxr-xr-x 2,106 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl
#-------------------------------------------------------------------------------
#
# Plot (using R) 
# Data is feed as a 1 column of numbers 
#
# Note: Any line that does not match a numeric regular expression, is filtered out).
#
#														Pablo Cingolani
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
# Main
#-------------------------------------------------------------------------------

# Parse command line option (file base name)
$base = 'plot';
if( $ARGV[0] ne '' )	{ $base = $ARGV[0]; }
if( $ARGV[1] ne '' )	{ $label = $ARGV[1]; }
print "label:$label\n";

$pngFile = "$base.png";
$txtFile = "$base.txt";

# Read STDIN and create an R vector
open TXT, "> $txtFile" or die "Cannot open output file '$txtFile'\n";
print TXT "label\tx\n";
for( $ln = 0 ; $l = <STDIN> ; ) {
	chomp $l;

	# Does the string have a label and a number? (can be float)
	if( $l =~ /^(\S+)\s+([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)$/ ) { 
		print "$1\t$2\n"; 
		print TXT "$1\t$2\n"; 
	}
}
close TXT;

#---
# Create an R program, save plot as PNG image
#---

open R, "| R --vanilla --slave " or die "Cannot open R program\n";
print R <<EOF;

plotChart <- function( x, labels, title, label ) {
	keep <- (labels == label)
	cat('label:', label, '\t', sum(keep), '\n')
	plot(x, xaxt = "n", col=ifelse(keep, "red", "black"), pch=ifelse(keep, 15, 1))
	axis(1, at=1:length(x), labels=labels)

    # Mean & median calculated over the whola data
    abline( h=mean(x), col='blue', lty=2, lwd=2);
    abline( h=median(x), col='green', lty=2, lwd=2);

	legend("topright",c("Mean","Median"),lty=c(1,1),col=c("blue","green"))

}

png('$pngFile', width = 1024, height = 1024);

data <- read.csv("$txtFile", sep='\\t', header = TRUE);
x <- data\$x
labels <- data\$label
plotChart( x, labels, "All data", '$label' );
print( summary( x ) )

dev.off();
quit( save='no' )
EOF

close R;

#---
# Show figure
#---

$os = `uname`;
$show = "eog"; 
if( $os =~ "Darwin" )	{ $show = "open"; }
`$show $pngFile &`;