Merge pull request #5191 from solgenomics/topic/quality_control
[sgn.git] / lib / SGN / Controller / Analysis.pm
blob586160830ad50beedd1d5f9e3f8a72de44e7ce23
2 package SGN::Controller::Analysis;
4 use Moose;
5 use URI::FromHash 'uri';
6 use Data::Dumper;
8 BEGIN { extends 'Catalyst::Controller' };
10 sub view_analyses :Path('/analyses') Args(0) {
11 my $self = shift;
12 my $c = shift;
14 my $user_id;
15 if ($c->user()) {
16 $user_id = $c->user->get_object()->get_sp_person_id();
18 if (!$user_id) {
19 $c->res->redirect( uri( path => '/user/login', query => { goto_url => $c->req->uri->path_query } ) );
22 my $schema = $c->dbic_schema("Bio::Chado::Schema", undef, $user_id);
24 $c->stash->{template} = '/analyses/index.mas';
27 sub analysis_detail :Path('/analyses') Args(1) {
28 my $self = shift;
29 my $c = shift;
30 my $analysis_id = shift;
31 my $user = $c->user();
33 my $user_id;
34 if ($c->user()) {
35 $user_id = $c->user->get_object()->get_sp_person_id();
37 if (!$user_id) {
38 $c->res->redirect( uri( path => '/user/login', query => { goto_url => $c->req->uri->path_query } ) );
39 $c->detach();
42 my $bcs_schema = $c->dbic_schema("Bio::Chado::Schema", undef, $user_id);
43 print STDERR "Viewing analysis with id $analysis_id\n";
45 my $a;
46 eval {
47 $a = CXGN::Analysis->new({
48 bcs_schema => $bcs_schema,
49 people_schema => $c->dbic_schema("CXGN::People::Schema", undef, $user_id),
50 metadata_schema => $c->dbic_schema("CXGN::Metadata::Schema", undef, $user_id),
51 phenome_schema => $c->dbic_schema("CXGN::Phenome::Schema", undef, $user_id),
52 trial_id => $analysis_id,
53 });
56 if ($@) {
57 $c->stash->{template} = '/generic_message.mas';
58 $c->stash->{message} = 'The requested analysis ID does not exist in the database or has been deleted.';
59 return;
62 $c->stash->{analysis_id} = $analysis_id;
63 $c->stash->{analysis_name} = $a->name();
64 $c->stash->{analysis_description} = $a->description();
65 $c->stash->{breeding_program_name} = $a->get_breeding_program();
66 $c->stash->{breeding_program_id} = $bcs_schema->resultset("Project::Project")->find({name=>$a->get_breeding_program()})->project_id();
67 $c->stash->{year} = $a->get_year();
68 $c->stash->{trial_stock_type} = 'accession';
69 $c->stash->{trial_phenotype_stock_type} = 'analysis_instance';
70 $c->stash->{has_col_and_row_numbers} = $a->has_col_and_row_numbers();
71 $c->stash->{identifier_prefix} = $c->config->{identifier_prefix};
72 $c->stash->{analysis_metadata} = $a->metadata();
73 $c->stash->{user_can_modify} = $user->check_roles("submitter") || $user->check_roles("curator");
74 $c->stash->{template} = '/analyses/detail.mas';
77 sub analysis_model_detail :Path('/analyses_model') Args(1) {
78 my $self = shift;
79 my $c = shift;
80 my $model_id = shift;
82 my $user_id;
83 if ($c->user()) {
84 $user_id = $c->user->get_object()->get_sp_person_id();
86 if (!$user_id) {
87 $c->res->redirect( uri( path => '/user/login', query => { goto_url => $c->req->uri->path_query } ) );
88 $c->detach();
91 my $bcs_schema = $c->dbic_schema("Bio::Chado::Schema", undef, $user_id);
92 print STDERR "Viewing analysis model with id $model_id\n";
94 my $m = CXGN::AnalysisModel::GetModel->new({
95 bcs_schema=>$bcs_schema,
96 metadata_schema=>$c->dbic_schema("CXGN::Metadata::Schema", undef, $user_id),
97 phenome_schema=>$c->dbic_schema("CXGN::Phenome::Schema", undef, $user_id),
98 nd_protocol_id=>$model_id
99 });
100 my $saved_model_object = $m->get_model();
101 #print STDERR Dumper $saved_model_object;
103 if (!$saved_model_object->{model_id}) {
104 $c->stash->{template} = '/generic_message.mas';
105 $c->stash->{message} = 'The requested model ID does not exist in the database.';
106 return;
109 $c->stash->{model_id} = $saved_model_object->{model_id};
110 $c->stash->{model_name} = $saved_model_object->{model_name};
111 $c->stash->{model_description} = $saved_model_object->{model_description};
112 $c->stash->{model_properties} = $saved_model_object->{model_properties};
113 $c->stash->{model_file_ids} = $saved_model_object->{model_file_ids};
114 $c->stash->{model_type_name} = $saved_model_object->{model_type_name};
115 $c->stash->{model_files} = $saved_model_object->{model_files};
116 $c->stash->{identifier_prefix} = $c->config->{identifier_prefix}."_Model_";
117 $c->stash->{template} = '/analyses/model_detail.mas';