Debian Codegraph @

lib/Bio/Chado/NaturalDiversity/Reports.pm

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 package Bio::Chado::NaturalDiversity::Reports;
2 BEGIN {
3 $Bio::Chado::NaturalDiversity::Reports::AUTHORITY = 'cpan:RBUELS';
4 }
5 {
6 $Bio::Chado::NaturalDiversity::Reports::VERSION = '0.20000';
7 }
8
9 =head1 NAME
10
11 Bio::Chado::NaturalDiversity::Reports
12
13 =head1 SYNOPSIS
14
15 use Bio::Chado::NaturalDiversity::Reports
16
17 my $sreport = Bio::Chado::NaturalDiversity::Reports->new;
18 my $data = $sreport->phenotypes_by_trait($phenotypes);
19
20 =head1 DESCRIPTION
21
22 A collection of functions for formatting Chado stock related data in
23 different data structures which can be useful for passing to different
24 programs and software. Because the Chado stock table is the key for
25 storing samples subjected to genotyping and phenotyping experiments,
26 it interacts with several other Chado modules, such as
27 NaturalDiversity for storing the experiment data, Project for storing
28 the metadata about the experiments, Phenotype for the phenotyping
29 values Genotype for the genotyping values.
30
31 This module generates several reports for easier access to such data.
32
33 Note that all data reports heavily rely on the Natural Diversity
34 schema. The results in each report may differ based on how the
35 experiment data is stored in the databse.
36
37 There is no one correct way
38 of loading phenotyping and genotyping data in this module, however
39 there are some examples for 'best practice' in the GMOD Wiki
40 (http://gmod.org/wiki/Chado_Natural_Diversity_Module)
41
42 =head1 METHODS
43
44 =cut
45
46 use strict;
47 use warnings;
48
49 =head2 new
50
51 Make a new Reports object.
52
53 =cut
54
55 sub new {
56 bless {}, shift;
57 }
58
59 =head2 phenotypes_by_trait
60
61 Usage: $self->phenotypes_by_trait($phenotype_rs , { %args } )
62 Desc: generate a report of phenotype values by trait name/accession
63 Args: an arrayref of L<Bio::Chado::Schema::Result::Phenotype::Phenotype> ResultSets
64 [optional] list of args to filter the report. Currently supported args are
65
66 Ret: arrayref of tab delimited data
67
68 =cut
69
70 sub phenotypes_by_trait {
71 my $self = shift;
72 my $phenotypes = shift;
73
74 my $phen_hashref; #hashref of hashes for the phenotype data
75
76 my %cvterms ; #hash for unique cvterms
77 my $replicate = 1;
78 my $cvterm_name;
79 foreach my $rs (@$phenotypes) {
80 while ( my $r = $rs->next ) {
81 my $observable = $r->get_column('observable');
82 next if !$observable;
83 no warnings 'uninitialized';
84 if ($cvterm_name eq $observable) { $replicate ++ ; } else { $replicate = 1 ; }
85 $cvterm_name = $observable;
86 my $accession = $r->get_column('accession');
87 my $db_name = $r->get_column('db_name');
88 my $project = $r->get_column('project_description') ;
89
90 my $hash_key = $project . "|" . $replicate;
91 $phen_hashref->{$hash_key}{accession} = $db_name . ":" . $accession ;
92 $phen_hashref->{$hash_key}{$observable} = $r->get_column('value');
93 $phen_hashref->{$hash_key}{stock_id} = $r->get_column('stock_id');
94 $cvterms{$observable} = $db_name . ":" . $accession ;
95 }
96 }
97 my @data;
98 my $d = "uniquename\tstock_id\t";
99 foreach my $term_name (sort { $cvterms{$a} cmp $cvterms{$b} } keys %cvterms ) {# sort ontology terms
100 my $ontology_id = $cvterms{$term_name};
101 $d .= $ontology_id . "|" . $term_name . "\t" ;
102 }
103 foreach my $key ( sort keys %$phen_hashref ) {
104 #print the unique key (row header)
105 # print some more columns with metadata
106 # print the value by cvterm name
107 $d .= "\n" . $key . "\t" . $phen_hashref->{$key}{stock_id} . "\t" ;
108 foreach my $term_name ( sort { $cvterms{$a} cmp $cvterms{$b} } keys %cvterms ) {
109 $d .= $phen_hashref->{$key}{$term_name} . "\t" ;
110 }
111 }
112 return $d;
113 }
114
115
116 ###
117 1;#
118 ###