-
Notifications
You must be signed in to change notification settings - Fork 0
/
displayDMRmCRF.pl
executable file
·115 lines (95 loc) · 2.5 KB
/
displayDMRmCRF.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
#! /usr/bin/perl -w
#----------------------------------------------------------#
# Copyright (C) 2008 UC Santa Cruz, Santa Cruz CA #
# All Rights Reserved. #
# #
# Author: Ting Wang #
# Send all comments to [email protected] #
# #
# DISCLAIMER: THIS SOFTWARE IS PROVIDED "AS IS" #
# WITHOUT WARRANTY OF ANY KIND. #
#----------------------------------------------------------#
use strict;
use GD;
my $usage = '
displayDMRmCRF.pl <DMR mCRF value file> <output jpg file>
';
die $usage unless @ARGV;
my ( $val_f, $fig_f, ) = @ARGV;
my $numVal = 7;
# Cutoff values
my $c1 = 0.25;
my $c2 = 0.5;
my $c3 = 0.75;
# get status calls
my @status;
my @line;
open ( IN, $val_f ) || die "Cannot open $val_f";
while ( <IN> )
{
chomp;
@line = split;
push @status, [ @line ];
for ( my $i=0; $i<@line; $i++)
{
# call
if ( $status[$#status][$i] < $c1 )
{
$status[$#status][$i] = 0;
}
elsif ( ( $status[$#status][$i] >= $c1 ) && ( $status[$#status][$i] < $c2 ) )
{
$status[$#status][$i] = 1;
}
elsif ( ( $status[$#status][$i] >= $c2 ) && ( $status[$#status][$i] < $c3 ) )
{
$status[$#status][$i] = 2;
}
elsif ( ( $status[$#status][$i] >= $c3 ) )
{
$status[$#status][$i] = 3;
}
}
}
close IN;
###############
# Creat Image #
###############
my $jpg = $fig_f;
my $wid = 10* $numVal;
my $X = $wid;
my $Y = $#status+1;
my $image = GD::Image->new($X, $Y);
my $white = $image->colorAllocate(255,255,255);
my $black = $image->colorAllocate( 0, 0, 0);
my %red;
$red{0} = $black;
$red{1} = $image->colorAllocate( 85, 0, 0);
$red{2} = $image->colorAllocate(170, 0, 0);
$red{3} = $image->colorAllocate(255, 0, 0);
$image->transparent($white);
$image->interlaced('true');
#Background
$image->filledRectangle( 0, 0, $X, $Y, $white );
#Frame
#$image->rectangle( 2, 2, $X-2, $Y-2, $blue );
my $cur_x;
my $cur_y;
my $color;
for ( my $i=0; $i<=$#status; $i++ )
{
$cur_y = $i;
for ( my $j=0; $j< $numVal; $j++ )
{
$cur_x = $j*10;
$color = $red{$status[$i][$j]};
$image->filledRectangle( $cur_x, $cur_y, $cur_x+10, $cur_y+1, $color );
}
}
#JPEG output
my $jpeg_data = $image->jpeg([50]);
open ( DISPLAY, ">$jpg" ) || die "Cannot open $jpg.";
binmode DISPLAY;
print DISPLAY $jpeg_data;
close DISPLAY;
exit;