debugging
[sgn.git] / lib / CXGN / Transformation / AddTransformationIdentifier.pm
blob2b857c3c0e7d77e61c5e1a627dc113f474a87357
1 =head1 NAME
3 CXGN::Transformation::AddTransformationIdentifier - a module for adding transformation identifier
5 =cut
8 package CXGN::Transformation::AddTransformationIdentifier;
10 use Moose;
11 use MooseX::FollowPBP;
12 use Moose::Util::TypeConstraints;
13 use Try::Tiny;
14 use CXGN::Location::LocationLookup;
15 use CXGN::Trial;
16 use SGN::Model::Cvterm;
17 use Data::Dumper;
19 has 'chado_schema' => (
20 isa => 'DBIx::Class::Schema',
21 is => 'rw',
22 required => 1,
25 has 'dbh' => (
26 is => 'rw',
27 required => 1,
30 has 'phenome_schema' => (
31 is => 'rw',
32 isa => 'DBIx::Class::Schema',
33 predicate => 'has_phenome_schema',
34 required => 1,
37 has 'transformation_identifier' => (
38 isa =>'Str',
39 is => 'rw',
40 required => 1,
43 has 'plant_material' => (
44 isa => 'Str',
45 is => 'rw',
46 required => 1,
49 has 'vector_construct' => (
50 isa => 'Str',
51 is => 'rw',
52 required => 1,
55 has 'notes' => (
56 isa => 'Str',
57 is => 'rw',
60 has 'owner_id' => (
61 isa => 'Int',
62 is => 'rw',
65 has 'transformation_project_id' => (
66 isa =>'Int',
67 is => 'rw',
68 required => 1,
72 sub add_transformation_identifier {
73 my $self = shift;
74 my $schema = $self->get_chado_schema();
75 my $phenome_schema = $self->get_phenome_schema();
76 my $transformation_identifier = $self->get_transformation_identifier();
77 my $plant_material = $self->get_plant_material();
78 my $vector_construct = $self->get_vector_construct();
79 my $transformation_notes = $self->get_notes();
80 my $transformation_project_id = $self->get_transformation_project_id();
81 my $plant_material_stock_id;
82 my $vector_construct_stock_id;
83 my %return;
84 my $transformation_stock_id;
86 my $owner_id = $self->get_owner_id();;
88 my $coderef = sub {
90 my $transformation_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'transformation', 'stock_type')->cvterm_id();
91 my $transformation_experiment_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'transformation_experiment', 'experiment_type')->cvterm_id();
92 my $transformation_project_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'transformation_project', 'project_type')->cvterm_id();
93 my $plant_material_of_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'plant_material_of', 'stock_relationship')->cvterm_id();
94 my $vector_construct_of_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'vector_construct_of', 'stock_relationship')->cvterm_id();
95 # my $transformation_notes_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'transformation_notes', 'stock_property')->cvterm_id();
96 my $accession_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'accession', 'stock_type')->cvterm_id();
97 my $vector_construct_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'vector_construct', 'stock_type')->cvterm_id();
99 my $project_location_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'project location', 'project_property')->cvterm_id();
100 my $geolocation_rs = $schema->resultset("Project::Projectprop")->find({project_id => $transformation_project_id, type_id => $project_location_cvterm_id});
102 my $plant_material_rs = $schema->resultset("Stock::Stock")->find({
103 uniquename => $plant_material,
104 type_id => $accession_cvterm_id,
107 if ($plant_material_rs) {
108 $plant_material_stock_id = $plant_material_rs->stock_id();
111 my $vector_construct_rs = $schema->resultset("Stock::Stock")->find({
112 uniquename => $vector_construct,
113 type_id => $vector_construct_cvterm_id,
116 if ($vector_construct_rs) {
117 $vector_construct_stock_id = $vector_construct_rs->stock_id();
120 my $experiment = $schema->resultset('NaturalDiversity::NdExperiment')->create({
121 nd_geolocation_id => $geolocation_rs->value,
122 type_id => $transformation_experiment_cvterm_id,
124 my $nd_experiment_id = $experiment->nd_experiment_id();
126 my $transformation_identifier_stock = $schema->resultset("Stock::Stock")->find_or_create({
127 name => $transformation_identifier,
128 uniquename => $transformation_identifier,
129 type_id => $transformation_cvterm_id,
132 $transformation_identifier_stock->find_or_create_related('stock_relationship_objects', {
133 type_id => $plant_material_of_cvterm_id,
134 object_id => $transformation_identifier_stock->stock_id(),
135 subject_id => $plant_material_stock_id,
138 $transformation_identifier_stock->find_or_create_related('stock_relationship_objects', {
139 type_id => $vector_construct_of_cvterm_id,
140 object_id => $transformation_identifier_stock->stock_id(),
141 subject_id => $vector_construct_stock_id,
144 $experiment->find_or_create_related('nd_experiment_stocks' , {
145 stock_id => $transformation_identifier_stock->stock_id(),
146 type_id => $transformation_experiment_cvterm_id,
149 $experiment->find_or_create_related('nd_experiment_projects', {
150 project_id => $transformation_project_id,
153 $transformation_stock_id = $transformation_identifier_stock->stock_id();
155 print STDERR "TRANSFORMATION STOCK ID =".Dumper($transformation_stock_id)."\n";
156 my $transaction_error;
157 try {
158 $schema->txn_do($coderef);
159 } catch {
160 print STDERR "Transaction Error: $_\n";
161 $transaction_error = $_;
164 if ($transaction_error){
165 return { error=>$transaction_error };
166 } else {
167 $phenome_schema->resultset("StockOwner")->find_or_create({
168 stock_id => $transformation_stock_id,
169 sp_person_id => $owner_id,
172 return { success=>1, transformation_id=>$transformation_stock_id };
179 #########
181 #########