add a db stats page.
[sgn.git] / lib / SGN / Controller / Phenotypes.pm
blob72ec4ab888d50fb10ad812b09404079a9fb4bc40
1 package SGN::Controller::Phenotypes;
3 =head1 NAME
5 SGN::Controller::Phenotypes - Catalyst controller for pages dealing with
6 phenotypes submission and associating them with project, experiments, and stock accessions.
8 =cut
10 use Moose;
11 use namespace::autoclean;
12 use YAML::Any qw/LoadFile/;
14 use URI::FromHash 'uri';
15 use List::Compare;
16 use File::Temp qw / tempfile /;
17 use File::Slurp;
18 use JSON::Any;
20 use CXGN::Chado::Stock;
21 use SGN::View::Stock qw/stock_link stock_organisms stock_types/;
24 BEGIN { extends 'Catalyst::Controller' }
25 with 'Catalyst::Component::ApplicationAttribute';
27 has 'schema' => (
28 is => 'rw',
29 isa => 'DBIx::Class::Schema',
30 lazy_build => 1,
32 sub _build_schema {
33 shift->_app->dbic_schema( 'Bio::Chado::Schema', 'sgn_chado' )
36 has 'default_page_size' => (
37 is => 'ro',
38 default => 20,
41 =head1 PUBLIC ACTIONS
43 =head2 submission_guidelines
45 Public path: /phenotype/submission_guide
47 Display the phenotype submission guidelines page
49 =cut
51 sub submission_guidelines :Path('/phenotype/submission_guide') Args(0) {
52 my ($self, $c) = @_;
53 $c->stash(template => '/phenotypes/submission_guide.mas');
57 sub delete_uploaded_phenotype_files : Path('/breeders/phenotyping/delete/') Args(1) {
58 my $self =shift;
59 my $c = shift;
60 my $json = new JSON;
61 my $file_id = shift;
62 my $decoded;
63 if ($file_id){
64 $decoded = $json->allow_nonref->utf8->decode($file_id);
66 #print STDERR Dumper($file_id);
67 print "File ID: $file_id\n";
68 my $dbh = $c->dbc->dbh();
69 #my $h = $dbh->prepare("delete from metadata.md_files where file_id=?;");
70 my $h = $dbh->prepare("
71 DROP TABLE IF EXISTS temp;
72 CREATE TEMP TABLE temp AS
73 SELECT nd_experiment_id, nd_experiment_md_files_id, phenotype_id FROM metadata.md_files JOIN phenome.nd_experiment_md_files USING(file_id) JOIN nd_experiment_phenotype USING (nd_experiment_id) WHERE file_id=?;
74 DELETE FROM phenome.nd_experiment_md_files WHERE nd_experiment_md_files_id IN (SELECT nd_experiment_md_files_id FROM temp);
75 DELETE FROM nd_experiment where nd_experiment_id IN (SELECT nd_experiment_id FROM temp);
76 DELETE FROM phenotype where phenotype_id IN (SELECT phenotype_id FROM temp);
77 ");
78 my $h2 = $dbh->prepare("UPDATE metadata.md_metadata SET obsolete = 1 where metadata_id IN (SELECT metadata_id from metadata.md_files where file_id=?);");
79 $h->execute($decoded);
80 $h2->execute($decoded);
81 print STDERR "Phenotype file successfully made obsolete (AKA deleted).\n";
82 $c->response->redirect('/breeders/phenotyping');
86 return 1;