1 package CXGN
::Pedigree
::AddCrossInfo
;
5 CXGN::Pedigree::AddCrossInfo - a module to add cross information such as date of pollination, number of flowers pollinated, number of fruits set as stock properties for cross.
9 my $cross_add_info = CXGN::Pedigree::AddCrossInfo->new({ chado_schema => $chado_schema, cross_name => $cross_name, key => $info_type, value => $value, data_type => $data_type} );
10 $cross_add_info->add_info();
14 Adds cross properties in json string format to stock of type cross. The cross must already exist in the database. This module is intended to be used in independent loading scripts and interactive dialogs.
18 Jeremy D. Edwards (jde22@cornell.edu)
19 Titima Tantikanjana (tt15@cornell.edu)
24 use MooseX
::FollowPBP
;
25 use Moose
::Util
::TypeConstraints
;
27 use CXGN
::Stock
::StockLookup
;
28 use SGN
::Model
::Cvterm
;
32 has
'chado_schema' => (
34 isa
=> 'DBIx::Class::Schema',
35 predicate
=> 'has_chado_schema',
38 has
'cross_name' => (isa
=>'Str', is
=> 'rw', predicate
=> 'has_cross_name', required
=> 1,);
39 has
'key' => (isa
=>'Str', is
=> 'rw', predicate
=> 'has_key', required
=> 1,);
40 has
'value' => (isa
=>'Str', is
=> 'rw', predicate
=> 'has_value', required
=> 1,);
41 has
'data_type' => (isa
=>'Str', is
=> 'rw', predicate
=> 'has_type', required
=> 1,);
45 my $schema = $self->get_chado_schema();
46 my $transaction_error;
48 #add all cross info in a single transaction
51 #get cross (stock of type cross)
52 my $cross_stock = $self->_get_cross($self->get_cross_name());
54 print STDERR
"Cross could not be found\n";
58 # get cvterm of cross info type (crossing_metadata_json or cross_additional_info)
59 my $cross_info_type = $self->get_data_type();
60 # print STDERR "DATA TYPE =".Dumper($cross_info_type)."\n";
61 my $cross_info_cvterm;
62 if (($cross_info_type eq 'crossing_metadata_json') || ($cross_info_type eq 'cross_additional_info')) {
63 $cross_info_cvterm = SGN
::Model
::Cvterm
->get_cvterm_row($schema, $cross_info_type, 'stock_property');
65 print STDERR
"Invalid type"."\n";
69 my $cross_json_string;
70 my $cross_json_hash = {};
71 my $previous_stockprop_rs = $cross_stock->stockprops({type_id
=>$cross_info_cvterm->cvterm_id});
72 if ($previous_stockprop_rs->count == 1){
73 $cross_json_string = $previous_stockprop_rs->first->value();
74 $cross_json_hash = decode_json
$cross_json_string;
75 $cross_json_string = _generate_property_hash
($self->get_key, $self->get_value, $cross_json_hash);
76 $previous_stockprop_rs->first->update({value
=>$cross_json_string});
77 } elsif ($previous_stockprop_rs->count > 1) {
78 print STDERR
"More than one found!\n";
81 $cross_json_string = _generate_property_hash
($self->get_key, $self->get_value, $cross_json_hash);
82 $cross_stock->create_stockprops({$cross_info_cvterm->name() => $cross_json_string});
84 # print STDERR "CROSS JSON STRING =".Dumper($cross_json_string)."\n";
87 #try to add all cross info in a transaction
89 $schema->txn_do($coderef);
91 $transaction_error = $_;
94 if ($transaction_error) {
95 print STDERR
"Transaction error storing information for cross: $transaction_error\n";
102 sub _generate_property_hash
{
105 my $cross_json_hash = shift;
106 $cross_json_hash->{$key} = $value;
107 #print STDERR Dumper $cross_json_hash;
108 my $cross_json_string = encode_json
$cross_json_hash;
109 return $cross_json_string;
115 my $cross_name = shift;
116 my $schema = $self->get_chado_schema();
117 my $stock_lookup = CXGN
::Stock
::StockLookup
->new(schema
=> $schema);
119 my $cross_cvterm = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'cross', 'stock_type');
121 $stock_lookup->set_stock_name($cross_name);
122 $stock = $stock_lookup->get_cross_exact();
125 print STDERR
"Cross name does not exist\n";