ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/yamap/gnu_percent_plotter.pl
Revision: 1.1
Committed: Wed Dec 13 10:44:05 2006 UTC (9 years, 6 months ago) by gawi79
Branch: MAIN
CVS Tags: HEAD
Log Message:
A QuickMine script - require gnuplot

Line File contents
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Config::Simple;
6
7 my (@lines, $lines, $i, $j, $k, @length, $length, @genome, $number_plots, @title, $title, $path, $orfs, %orfs, $percent, $orphans, @orp, @total_orfs, %total_orfs, $index);
8
9 unless (@ARGV ==1) {
10 die "\n\nUsage:\n ./gnu_percent_plotter.pl configfile\nPlease try again.\n\n\n";}
11
12 my $config_file = shift;
13
14 my $cfg = new Config::Simple($config_file);
15 my $debug = 0;
16 # get the record separator from the config file
17 my $record_separator = $cfg->param('PARAMS.record_separator');
18 # convert since use of \t in config file results in literal \t being printed
19
20 if ($record_separator =~ "tab") {$record_separator = "\t"}
21
22 print "RECORD SEP $record_separator\n";
23
24 my $path2output = $cfg->param('PATHS.path2output');
25 open (INPUT, "$path2output/orphan_time.html") or die "can't open orphan_time.html file";
26 open (ORPHAN, "$path2output/orphan_count.html") or die "can't open orphan_count.html file";
27 open OUT, ">$path2output/gnu_percent_plotter.dat";
28 @lines = <INPUT>;
29 close INPUT;
30 @length = split /$record_separator/, $lines[2];
31 my $number_of_genomes = $#lines - 1;
32 print qq{$#lines\n};
33 @orp = <ORPHAN>;
34 close ORPHAN;
35 my $blank = "-";
36 my $dash_check = 0;
37 for ($j = 2; $j <=$#orp; $j++)
38 {
39 @total_orfs = split /$record_separator/, $orp[$j];
40 $total_orfs{$j} = $total_orfs[1];
41 }
42 for ($i = 0; $i<=$#length; $i++)
43 {
44 if ($i == 0)
45 {
46 print OUT qq{0};
47 for ($j = 2; $j <=$#lines; $j++)
48 {
49 print OUT qq{ 100};
50 }
51 print OUT qq{\n};
52 }
53 unless ($i == 0)
54 {
55 $index = $i;
56 print OUT qq{$index};
57 }
58
59 for ($j = 2; $j <=$#lines; $j++)
60 {
61 $dash_check = $i + 1;
62 @genome = split /$record_separator/, $lines[$j];
63 if ($i == 0)
64 {
65 push @title,$genome[$i];
66 }
67 else
68 {
69 chomp $genome[$i];
70
71 if ($j == $dash_check)
72 {
73 print OUT qq{ -};
74
75 }
76 else
77 {
78 $orfs = $total_orfs{$j};
79 $orphans = $genome[$i];
80 print "orphans = $orphans, orfs = $orfs, i = $i\n";
81 $percent = ($orphans/$orfs) * 100;
82 $percent = sprintf("%.2f",$percent);
83 print OUT qq{ $percent};
84 print "$genome[$i]\n";
85 }
86
87
88 }
89 }
90 print OUT qq{\n};
91
92 }
93 close OUT;
94 $number_plots = $#lines;
95 open GNU, ">$path2output/gnu_percent_plotter_commands.dat";
96 print GNU qq{set terminal png small\n};
97 print GNU qq{set output 'percent_plot.png'\n};
98 print GNU qq{set xlabel "Genome Number"\n};
99 print GNU qq{set ylabel "Percentage orphans"\n};
100 print GNU qq{plot [0:$number_of_genomes][0:100] };
101 for ($k = 2; $k <= $number_plots; $k++)
102 {
103 print GNU qq{'$path2output/gnu_percent_plotter.dat' using 1:$k smooth bezier notitle};
104
105 unless ($k == $number_plots)
106 {
107 print GNU qq{,}
108 }
109 }
110 close GNU;
111 chdir "$path2output/";
112 print qq{Plotting graph\n};
113 system "gnuplot $path2output/gnu_percent_plotter_commands.dat";
114 $path = "$path2output/";
115 chdir "$path";
116 system "convert percent_plot.png percent_plot.jpeg";
117 open HTML, ">$path2output/percent_plot.html";
118 print HTML qq{<html><body>};
119 print HTML qq{<img src="percent_plot.jpeg">};
120 print HTML qq{</body></html>};
121 close HTML;
122 if ($debug == 0)
123 {
124 unlink ("gnu_percent_plotter_commands.dat");
125 unlink ("gnu_percent_plotter.dat");
126 unlink ("percent_plot.png");
127 }