From 9f0b101355cba25678c717c7c99e76601b270185 Mon Sep 17 00:00:00 2001 From: preecej Date: Tue, 18 Oct 2011 00:31:22 +0000 Subject: [PATCH] Heat map feature complete. svn path=/; revision=188 --- .../perl_singletons/pathway_gene_swapper.pl | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/preecej/perl_singletons/pathway_gene_swapper.pl b/preecej/perl_singletons/pathway_gene_swapper.pl index c8a8bb7..4b0a288 100644 --- a/preecej/perl_singletons/pathway_gene_swapper.pl +++ b/preecej/perl_singletons/pathway_gene_swapper.pl @@ -22,8 +22,9 @@ that group will extend to any replacement genes. If no group existed previously, and multiple replacement gene boxes are required, a new group will be created. -If an original gene had multiple instances displayed on the pathway -diagram, each instance will be subjected to the replacement process. +If an original gene had multiple instances (homologs) displayed on the pathway +diagram, each instance will be subjected to the replacement process. There +is a "heat-map" option avaliable to help highlight homolog sets. There is also an option to read in an extra column of gene symbols, if the user wishes to provide their own. Otherwise, the application will @@ -43,8 +44,6 @@ Add a comment containing the NCBI species id of the new homolog (for the purpose of multi-species pathway comparison or host-pathogen interaction diagrams). -Add a "heat-map" effect by making large paralog sets "hotter". - =head1 USAGE pathway_gene_swapper.pl -i INPUT_FILE -g GENE_FILE -c CONFIG_FILE -o OUTPUT_FILE -L -v -G -d @@ -58,8 +57,8 @@ pathway_gene_swapper.pl -i INPUT_FILE -g GENE_FILE -c CONFIG_FILE -o OUTPUT_FILE (NOTE: if no path supplied for input files, current working directory is assumed) -s use provided gene symbols instead of config file's LabelPrefix - -h apply a heat-map to any multi-mapped set of paralogs - (NOTE: precludes custom box-coloring for paralogs) + -h apply a heat-map to any multi-mapped set of homologs + (NOTE: precludes custom box-coloring for homologs) -L Remove literature references. -v View verbose information -G Display GPML input/output documents @@ -149,6 +148,7 @@ my %swap_genes; # original and swapped genes my $gpml_doc; # imported GPML data for manipulation and output my %unmapped_genes; # original genes not mapped to homologs my %gradient; # blue-red gradient used for opt. heat map box-coloring +my $max_homolog_count = 0; # count for heat map calibration $Data::Dumper::Pad = "... "; @@ -302,41 +302,34 @@ sub init # --------------------------------------------------------------------------- -=item B -Sets the blue-red gradient +=item B +Accepts: The maximum number of homologs for one gene in this data set +Creates a blue-red gradient and stores it in a hash. +Returns: A hash of RRGGBB color values, keyed to the number set of +possible homologs (1..n). =cut # --------------------------------------------------------------------------- sub set_gradient($) { my @blue_red_array; + for (my $i=0; $i<256; $i++) { push @blue_red_array, [$i, 0, (255-$i)]; } - # print Dumper(@blue_red_array) . "\n\n"; - register_gradient("blue_red",\@blue_red_array); - # print "[Available Gradients]"; - # print Dumper(available_gradients()) . "\n\n"; - # print Dumper(gradient("blue_red")) . "\n\n"; - my %blue_red_gradient; - my $max_grad = $_[0]; my $inc = sprintf("%.2f", 1/$max_grad); my $count = 1; - # print "Increment: $inc\n"; + for (my $i=$inc; $i<=0.99; $i=$i+$inc) { - #print "$i\n"; - #print grad2rgb("blue_red",$i) . "\n"; my $tmp_hex = grad2rgb("blue_red",$i); - $tmp_hex =~ s/\#//; + $tmp_hex =~ s/\#//; $blue_red_gradient{$count} = $tmp_hex; $count++; } - # print "[My Gradient Hash]\n"; - print Dumper(%blue_red_gradient) . "\n\n"; return %blue_red_gradient; } @@ -402,7 +395,6 @@ sub import_data # determine the original gene(s) with the highest # of homologs in the new # gene set - my $max_homolog_count = 0; # count for heat map calibration my @most_popular_genes; # identity of the gene(s) with the highest number of homologs foreach my $orig_gene_key (keys %swap_genes) { @@ -723,7 +715,9 @@ sub swap_genes # makes sure each box is increasingly offset from the original # (in all three dimensions) my $offset_multiplier = 0; - my $gene_suffix_counter = 0; # used to affix numbers to multiple new gene symbols + my $gene_suffix_counter = 0; # used to affix numbers to multiple new gene symbols + # used to track the application of the gradient in reverse + my $new_nodes_dec = scalar(@new_nodes_map) + 1; # for new nodes ary for (@new_nodes_map) @@ -731,6 +725,7 @@ sub swap_genes if (scalar(@new_nodes_map) > 1) { $gene_suffix_counter++; + $new_nodes_dec--; } my $curr_new_node = $$_[0]; @@ -779,18 +774,19 @@ sub swap_genes # change box width and colors () my $curr_graphics = ($curr_new_node->getElementsByTagName("Graphics"))[0]; $curr_graphics->setAttribute("Width",$configs{"BoxWidth"}); - if ($configs{"BoxBorder"}) { - $curr_graphics->setAttribute("Color",$configs{"BoxBorder"}); } - # add "heat" to genes with multiple paralogs + # add "heat" to genes with multiple homologs if ($apply_homolog_heat && ($gene_suffix_counter > 0)) { - $curr_graphics->setAttribute("FillColor",$gradient{$gene_suffix_counter}); + $curr_graphics->setAttribute("FillColor", $gradient{$new_nodes_dec}); + $curr_graphics->setAttribute("Color","8888ff"); } else { if ($configs{"BoxColor"}) { $curr_graphics->setAttribute("FillColor",$configs{"BoxColor"}); } + if ($configs{"BoxBorder"}) { + $curr_graphics->setAttribute("Color",$configs{"BoxBorder"}); } } if ($is_first_homolog) -- 2.34.1