6 /phenotypes/phenotype_data.mas - a component for printing table with stats of a phenotype object
17 arrayref of L<Bio::Chado::Schema::Phenotype> objects
21 div id (for using with javascript)
25 applies to qtl populations. Used for adding a link to the qtl page
29 the database id of the object with associated phenotyeps
36 Naama Menda <nm249@cornell.edu>
50 use CXGN::Page::FormattingHelpers qw/ tooltipped_text columnar_table_html /;
52 use Statistics::Descriptive;
53 use Scalar::Util qw(looks_like_number);
61 my %info; # hash of term names, since we can have multiple phenotypes of the same term
62 my $graph_icon = qq |<img src="/documents/img/pop_graph.png"/> |;
65 if ($phenotypes) { ### && UNIVERSAL::isa($phenotypes,"UNIVERSAL")) {
66 foreach my $phenotype (@$phenotypes) {
67 ###while ( my $phenotype = $phenotypes->next ) {
68 #$phenotype is a list of row objects with the following column values
69 # qw/ stock_id value observable observable_id definition method_name type_name accession db_name project_description cv_name unit_name ##
71 #first make sure phenotype_cvterm is a unit.ontology# Not sure this is necessary, since all we have (now) in phenotype_cvterm is units
72 ##### if $phenotype->get_column('cv_name') ne 'unit.ontology' || undef ;
73 my $unit_name = $phenotype->get_column('unit_name');
74 my $type_name = $phenotype->get_column('type_name');
76 if ($type_name eq 'method') {
77 $method_name = $phenotype->get_column('method_name');
78 } elsif ( !$type_name ) {
79 $method_name = 'Trait' ;
80 } else { next; } #skip the row if a phenotypeprop was fetched , but it is not a 'mehtod' type.
82 #push @ { $info{$observable->name."|". $observable->cvterm_id ."|". $definition . "|" . $unit} } , $phenotype;
85 my $observable_name = $phenotype->get_column('observable');
86 my $value = $phenotype->get_column('value') ;
87 push @{ $info{$method_name}{$observable_name}{phenotypes}} , $phenotype->get_column('value') ;
88 $info{$method_name}{$observable_name}{cvterm_id} = $phenotype->get_column('observable_id');
89 $info{$method_name}{$observable_name}{definition} = $phenotype->get_column('definition');
90 $info{$method_name}{$observable_name}{unit} = $unit_name ;
95 #display traits sorted by name
96 ##NEED TO SORT BY cvtermprop or by parent? , then by name######
97 foreach my $method(sort keys %info ) {
98 foreach my $term_name(sort keys %{ $info{$method} } ) {
99 my $term_id = $info{$method}{$term_name}{cvterm_id};
100 my $definition = $info{$method}{$term_name}{definition};
101 my $unit = $info{$method}{$term_name}{unit} ;
102 $unit = " ($unit)" if $unit;
103 $definition .= $definition . $unit if $unit;
105 my @values; # all quantitative data does here
106 my @qual_values; #all qualitative data goes here
107 foreach my $i ( @{ $info{$method}{$term_name}{phenotypes} } ) {
108 my $value = $i ;###->value;
109 if (looks_like_number($value)) { push @values, $value ; }
110 else { push @qual_values, $value ; }
112 my $stat = Statistics::Descriptive::Sparse->new();
113 $stat->add_data(@values);
115 my $mean_value = sprintf("%.2f", $stat->mean);
116 my $min = sprintf("%.2f", $stat->min);
117 my $max = sprintf("%.2f", $stat->max);
119 if (scalar(@values) ) {
120 no warnings 'uninitialized';
121 push @ { $data{$method}{phen} } , [map {$_}
122 ( { width => "320" , content => (tooltipped_text(qq|<a href="/cvterm/$term_id/view">$term_name</a> $unit|, $definition ) ) } , { width => "60", content => $mean_value }, { with => "60" , content => $min } , { width => "60" , content => $max }, { width => "40" , content => scalar(@values) } ) ];
124 push @ { $data{$method}{phen}[$count] } , qq | <a href="/phenome/qtl_analysis.pl?stock_id=$object_id&cvterm_id=$term_id" onClick="Qtl.waitPage()"> $graph_icon</a> | if $has_qtl;
127 if (scalar(@qual_values) ) {
128 push @qual_data, [map {$_}
129 ( (tooltipped_text(qq|<a href="/cvterm/$term_id/view">$term_name</a>|, $definition) ) , join(', ' , @qual_values ) ) ];
132 @ { $data{$method}{headings} } = ("$method" , "Average", "Min", "Max", "Lines/repeats");
133 push @ { $data{$method}{headings} } , 'QTL(s)' if $has_qtl;
138 <script language="javascript">
142 <& /util/import_javascript.mas, classes => [ "CXGN.Phenome.Qtl" ] &>
146 % foreach my $key( sort keys %data ) {
147 % my @data_points = @ { $data{$key}{phen} } if $data{$key}{phen};
148 % my @headings = @ { $data{$key}{headings} };
149 % if (@data_points) {
151 <& /page/columnar_table.mas,
152 headings => \@headings,
153 data => \@data_points,
165 <& /page/columnar_table.mas,
166 headings => ["Qualitative Trait", "Value"],
167 data => \@qual_data ,
177 <& /qtl/waitmessage.mas &>