6 AddProtocoltoStoredNIRSRetroactively
10 mx-run AddProtocoltoStoredNIRSRetroactively [options] -H hostname -D dbname -u username [-F]
12 this is a subclass of L<CXGN::Metadata::Dbpatch>
13 see the perldoc of parent class for more details.
16 This patch retroactively adds a protocol for the uploaded NIRS data
17 This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
21 =head1 COPYRIGHT & LICENSE
23 Copyright 2010 Boyce Thompson Institute for Plant Research
25 This program is free software; you can redistribute it and/or modify
26 it under the same terms as Perl itself.
31 package AddProtocoltoStoredNIRSRetroactively
;
34 use Bio
::Chado
::Schema
;
36 use SGN
::Model
::Cvterm
;
38 extends
'CXGN::Metadata::Dbpatch';
41 has
'+description' => ( default => <<'' );
42 This patch retroactively adds a protocol
for the uploaded NIRS data
54 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
56 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
58 print STDOUT
"\nExecuting the SQL commands.\n";
59 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
61 my $high_dim_nirs_protocol_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'high_dimensional_phenotype_nirs_protocol', 'protocol_type')->cvterm_id();
62 my $high_dim_nirs_protocol_prop_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'high_dimensional_phenotype_protocol_properties', 'protocol_property')->cvterm_id();
64 my %nirs_protocol_prop = (device_type
=> 'SCIO');
66 my $protocol = $schema->resultset('NaturalDiversity::NdProtocol')->create({
67 name
=> 'NIRS Protocol',
68 type_id
=> $high_dim_nirs_protocol_cvterm_id,
69 nd_protocolprops
=> [{type_id
=> $high_dim_nirs_protocol_prop_cvterm_id, value
=> encode_json \
%nirs_protocol_prop}]
71 my $protocol_id = $protocol->nd_protocol_id();
73 my $desc_q = "UPDATE nd_protocol SET description=? WHERE nd_protocol_id=?;";
74 my $desc_dbh = $schema->storage->dbh()->prepare($desc_q);
75 $desc_dbh->execute('Default NIRS protocol', $protocol_id);
77 my $protocol_query = "INSERT INTO nd_experiment_protocol ( nd_experiment_id, nd_protocol_id) VALUES (?,?);";
78 my $protocol_dbh = $schema->storage->dbh()->prepare($protocol_query);
80 my $q = "SELECT nd_experiment_id
81 FROM phenome.nd_experiment_md_json
82 JOIN metadata.md_json USING(json_id)
83 WHERE json_type='nirs_spectra';";
84 my $dbh = $schema->storage->dbh()->prepare($q);
86 while (my ($nd_experiment_id) = $dbh->fetchrow_array()) {
87 $protocol_dbh->execute($nd_experiment_id, $protocol_id);
90 print "You're done!\n";