1 package SGN
::Controller
::Genomes
;
5 SGN::Controller::Genomes - controller for genome portal pages
10 use namespace
::autoclean
;
12 use List
::MoreUtils
'uniq';
14 BEGIN{ extends
'Catalyst::Controller' }
16 with
'Catalyst::Component::ApplicationAttribute';
26 sub list_genomes
: Path
( '/genomes' ) Args
(0) {
27 my ( $self, $c ) = @_;
29 my $schema = $c->dbic_schema( 'Bio::Chado::Schema', 'sgn_chado' );
34 $schema->resultset('Organism::Organismprop')
35 ->search({ 'type.name' => 'genome_page' }, { join => 'type' })
36 ->search_related('organism')
40 template
=> '/genomes/index.mas',
44 =head2 view_genome_data
46 Public path: /organism/<organism id or name>/genome
48 Queries for Biosource bs_sample records of type 'sequence_collection'
49 or 'genome_annotation_set', and displays them with file download
54 sub view_genome_data
: Chained
('/organism/find_organism') PathPart
('genome') {
55 my ( $self, $c ) = @_;
57 my $organism = $c->stash->{organism
};
58 $c->throw_404 unless $organism && $organism->search_related('organismprops',
59 { 'type.name' => 'genome_page', 'me.value' => 1 },
63 (my $template_name = '/genomes/'.$organism->species.'.mas') =~ s/ /_/g;
65 # find assemblies for this organism
66 $c->stash->{assembly_list
} = my $assembly_list = [
69 my $h = $self->_bs_sample_to_display_hashref( $c, $s );
70 # also add the associated annotation_sets to it
71 $h->{annotation_sets
} = [ $self->assembly_annotations( $s ) ];
73 } $self->assemblies_for_organism( $organism )->all
76 # find annotation sets for this organism
77 $c->stash->{annotation_list
} = [
79 $self->_bs_sample_to_display_hashref( $c, $_ );
81 # annotation sets are the ones that were found related to the
82 # assemblies, plus ones queried from the db by organism, made
84 sort { $a->metadata && $a->metadata->create_date->epoch <=> $b->metadata && $b->metadata->create_date->epoch
85 || $a->sample_name cmp $b->sample_name
87 $self->uniq_bs_samples(
88 ( map { @
{ $_->{annotation_sets
} || [] } } @
$assembly_list ),
89 $self->annotation_sets_for_organism( $organism )->all
93 # choose which template we will use
94 $c->stash->{template
} =
95 $c->view('Mason')->component_exists( $template_name )
96 ?
$template_name : '/genomes/default.mas';
99 =head2 view_inbred_genomes
101 Public path: /organism/Solanum_lycopersicum/inbred_genomes
106 sub view_inbred_genome
: Path
('/organism/Solanum_lycopersicum/inbred_genomes') {
107 my ( $self, $c ) = @_;
109 $c->stash->{template
} = '/genomes/Solanum_lycopersicum/inbreds.mas';
112 =head2 view_tomato_150
114 Public path: /organism/Solanum_lycopersicum/tomato_150
119 sub view_tomato_150
: Path
('/organism/Solanum_lycopersicum/tomato_150') {
120 my ( $self, $c ) = @_;
122 $c->stash->{template
} = '/genomes/Solanum_lycopersicum/tomato150.mas';
125 =head2 view_tomato_360
127 Public path: /organism/Solanum_lycopersicum/tomato_360
132 sub view_tomato_360
: Path
('/organism/Solanum_lycopersicum/tomato_360') {
133 my ( $self, $c ) = @_;
135 $c->stash->{template
} = '/genomes/Solanum_lycopersicum/tomato360.mas';
138 ####### helper methods ##########
140 sub uniq_bs_samples
{
143 return grep !$seen{$_->sample_id}++, @_
146 sub _bs_sample_to_display_hashref
{
147 my ( $self, $c, $bs_sample ) = @_;
150 name
=> $c->view('BareMason')->render( $c, '/biosource/sample_link.mas', { sample
=> $bs_sample } ),
151 date
=> $bs_sample->metadata ?
$bs_sample->metadata->create_date : undef,
152 description
=> $bs_sample->description,
154 map +{ text
=> $_->basename,
155 url
=> '/metadata/file/'.$_->file_id.'/download',
156 description
=> $_->comment,
158 $self->assembly_files( $bs_sample )
163 sub _annotates_cvterms_rs
{
164 my ( $self, $row ) = @_;
165 my $schema = $row ?
$row->result_source->schema : $self->_app->dbic_schema('CXGN::Biosource::Schema');
167 return $schema->resultset('Cv::Cvterm')
168 ->search_rs({ name
=> 'annotates' });
171 sub assembly_annotations
{
172 my ( $self, $sample_row ) = @_;
174 $sample_row->search_related('bs_sample_relationship_objects',
176 { -in => $self->_annotates_cvterms_rs( $sample_row )
177 ->get_column('cvterm_id')
182 ->search_related('subject')
188 my ( $self, $sample_row ) = @_;
191 $sample_row->search_related('bs_sample_files')
192 ->search_related('file')
197 sub assemblies_for_organism
{
198 my ( $self, $organism ) = @_;
200 my $schema = $organism->result_source->schema;
202 $schema->resultset('BsSample')
204 type_id
=> { -in => [ uniq
map $_->cvterm_id, @
{$self->_assembly_cvterms( $schema )}] },
205 organism_id
=> $organism->organism_id,
209 sub annotation_sets_for_organism
{
210 my ( $self, $organism ) = @_;
211 my $schema = $organism->result_source->schema;
213 $schema->resultset('BsSample')
215 type_id
=> { -in => [ uniq
map $_->cvterm_id, @
{$self->_annotation_cvterms( $schema )}] },
216 organism_id
=> $organism->organism_id,
220 # get the RS of types (i.e. cvterms) that would indicate that we
221 # should list a certain biosource
222 # currently defined as 'all SO children '
223 sub _assembly_cvterms
{
224 my ( $self, $schema ) = @_;
225 my $sc = $schema->resultset('Cv::Cv')
226 ->search({ 'me.name' => ['sequence','SO'] })
227 ->search_related('cvterms', {
228 'cvterms.name' => 'sequence_collection',
231 my @terms = $sc->all;
232 return [ @terms, map $_->recursive_children, @terms ];
235 sub _annotation_cvterms
{
236 my ( $self, $schema ) = @_;
237 my $t = $schema->resultset('Cv::Cvterm')
238 ->search({ 'name' => 'genome_annotation_set' });
241 return [ @terms, map $_->recursive_children, @terms ];