ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/yamap/genome_percent_plot.pl
Revision: 1.1
Committed: Wed Dec 13 10:41:21 2006 UTC (9 years, 4 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, $genome, $number_plots, @title, $title, $path, $output_png, $output_jpeg, $output_html, $orfs, $percent, @orp, @total_orfs, %total_orfs);
8
9 unless (@ARGV ==1) {
10 die "\n\nUsage:\n ./genome_percent_plot.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 @lines = <INPUT>;
28 close INPUT;
29 my $blank = "-";
30 print qq{\n$blank\n};
31 my $number_of_genomes = $#lines - 2;
32 @orp = <ORPHAN>;
33 close ORPHAN;
34 for ($j = 2; $j <=$#orp; $j++)
35 {
36 @total_orfs = split /$record_separator/, $orp[$j];
37 $total_orfs{$j} = $total_orfs[1];
38 }
39 for ($j = 2; $j <=$#lines; $j++)
40 {
41 @genome = split /$record_separator/, $lines[$j];
42 $title = $genome[0];
43 print "$title";
44 open OUT, ">$path2output/percent_plotter$title.dat";
45 print OUT qq{0 100\n};
46 $i = 1;
47 foreach $genome (@genome)
48 {
49 unless ($genome =~m/$blank/ || $genome =~m/\D/)
50 {
51 $orfs = $total_orfs{$j};
52 $percent = ($genome/$orfs) * 100;
53 print OUT qq{$i $percent\n};
54 $i++;
55 }
56 }
57 close OUT;
58
59
60
61 open GNU, ">$path2output/percent_plotter_commands$title.dat";
62 print GNU qq{set terminal png small\n};
63 $output_png = $title."_orphan_plot.png";
64 print GNU qq{set output '$output_png'\n};
65 print GNU qq{set xlabel "Genome Number"\n};
66 print GNU qq{set ylabel "Percentage orphans"\n};
67 print GNU qq{plot [0:$number_of_genomes][0:100] };
68
69 print GNU qq{'$path2output/percent_plotter$title.dat' using 1:2 smooth bezier title '$title'};
70
71
72 close GNU;
73 chdir "$path2output/";
74 print qq{Plotting graph $title\n};
75 system "gnuplot $path2output/percent_plotter_commands$title.dat";
76 $path = "$path2output";
77 chdir "$path";
78 $output_jpeg = $title."_percent_plot.jpeg";
79 system "convert $output_png $output_jpeg";
80
81 $output_html = $title."_percent_plot.html";
82 open HTML, ">$path2output/$output_html";
83 print HTML qq{<html><body>};
84 print HTML qq{<img src=$output_jpeg>};
85 print HTML qq{</body></html>};
86 close HTML;
87 if ($debug == 0)
88 {
89 unlink ("percent_plotter_commands$title.dat");
90 unlink ("percent_plotter$title.dat");
91 unlink ($output_png);
92 }
93 }