diff --git a/bin/load_trait_props.pl b/bin/load_trait_props.pl index 70bb2cc4b0..915304d38e 100755 --- a/bin/load_trait_props.pl +++ b/bin/load_trait_props.pl @@ -65,13 +65,13 @@ =head2 TODO sub print_help { - print STDERR "A script to load trait properties\nUsage: load_trait_props.pl -D [database name] -H [database host, e.g., localhost] -I [input file] -o [ontology namespace, e.g., CO] -w\n\t-w\toverwrite existing trait properties if they exist (optional)\n\t-t\ttest run. roll back at the end\n"; + print STDERR "A script to load trait properties\nUsage: load_trait_props.pl -D [database name] -H [database host, e.g., localhost] -I [input file] -o [ontology namespace, e.g., CO] -w\n\t-w\toverwrite existing trait properties if they exist (optional)\n\t-t\ttest run. roll back at the end\n"; } if (!$opt_D || !$opt_H || !$opt_I || !$opt_o) { - print_help(); - die("Exiting: options missing\n"); + print_help(); + die("Exiting: options missing\n"); } # Match a dot, extension .xls / .xlsx @@ -89,7 +89,7 @@ sub print_help { my $excel_obj = $parser->parse($opt_I); if ( !$excel_obj ) { - die "Input file error: ".$parser->error()."\n"; + die "Input file error: ".$parser->error()."\n"; } my $worksheet = ( $excel_obj->worksheets() )[0]; #support only one worksheet @@ -97,84 +97,85 @@ sub print_help { my ( $col_min, $col_max ) = $worksheet->col_range(); if (($col_max - $col_min) < 1 || ($row_max - $row_min) < 1 ) { #must have header and at least one row of phenotypes - die "Input file error: spreadsheet is missing header\n"; + die "Input file error: spreadsheet is missing header\n"; } my $trait_name_head; if ($worksheet->get_cell(0,0)) { - $trait_name_head = $worksheet->get_cell(0,0)->value(); + $trait_name_head = $worksheet->get_cell(0,0)->value(); } if (!$trait_name_head || $trait_name_head ne 'trait_name') { - die "Input file error: no \"trait_name\" in header\n"; + die "Input file error: no \"trait_name\" in header\n"; } my @trait_property_names = qw( - trait_format - trait_default_value - trait_minimum - trait_maximum - trait_categories - trait_details - ); + trait_format + trait_default_value + trait_minimum + trait_maximum + trait_categories + trait_details + ); #check header for property names for (my $column_number = 1; $column_number <= scalar @trait_property_names; $column_number++) { - my $property_name = $trait_property_names[$column_number-1]; - if ( !($worksheet->get_cell(0,$column_number)) || !($worksheet->get_cell(0,$column_number)->value() eq $property_name) ) { - die "Input file error: no \"$property_name\" in header\n"; - } + my $property_name = $trait_property_names[$column_number-1]; + if ( !($worksheet->get_cell(0,$column_number)) || !($worksheet->get_cell(0,$column_number)->value() eq $property_name) ) { + die "Input file error: no \"$property_name\" in header\n"; + } } my @trait_props_data; for my $row ( 1 .. $row_max ) { - my %trait_props; - my $trait_name; - my $current_row = $row+1; - - - if ($worksheet->get_cell($row,0)) { - $trait_name = $worksheet->get_cell($row,0)->value(); - $trait_props{'trait_name'}=$trait_name; - } else { - next; #skip blank lines - } - - my $prop_column = 1; - foreach my $property_name (@trait_property_names) { - if ($worksheet->get_cell($row,$prop_column)) { - if (($worksheet->get_cell($row,$prop_column)->value()) && ($worksheet->get_cell($row,$prop_column)->value() ne '')) { - $trait_props{$property_name}=$worksheet->get_cell($row,$prop_column)->value(); - } + my %trait_props; + my $trait_name; + my $current_row = $row+1; + + + if ($worksheet->get_cell($row,0)) { + $trait_name = $worksheet->get_cell($row,0)->value(); + $trait_props{'trait_name'}=$trait_name; + } else { + next; #skip blank lines } - $prop_column++; - } - - push @trait_props_data, \%trait_props; - + + my $prop_column = 1; + foreach my $property_name (@trait_property_names) { + if ($worksheet->get_cell($row,$prop_column)) { + my $value = $worksheet->get_cell($row,$prop_column)->value(); + if (defined($value) && ($value ne '')) { + $trait_props{$property_name}=$worksheet->get_cell($row,$prop_column)->value(); + } + } + $prop_column++; + } + + push @trait_props_data, \%trait_props; + } my $dbh = CXGN::DB::InsertDBH - ->new({ - dbname => $opt_D, - dbhost => $opt_H, - dbargs => {AutoCommit => 1, - RaiseError => 1}, - }); + ->new({ + dbname => $opt_D, + dbhost => $opt_H, + dbargs => {AutoCommit => 1, + RaiseError => 1}, + }); my $overwrite_existing_props = 0; if ($opt_w){ - $overwrite_existing_props = 1; + $overwrite_existing_props = 1; } my $is_test_run = 0; if ($opt_t){ - $is_test_run = 1; + $is_test_run = 1; } my $chado_schema = Bio::Chado::Schema->connect( sub { $dbh->get_actual_dbh() } ); @@ -187,20 +188,20 @@ sub print_help { my $validate=$trait_props->validate(); if (!$validate) { - die("input data is not valid\n"); + die("input data is not valid\n"); } else { - print STDERR "input data is valid\n"; + print STDERR "input data is valid\n"; } print STDERR "Storing data...\t\t"; my $store = $trait_props->store(); if (!$store){ - if (!$is_test_run) { - die("\n\nerror storing data\n"); - } + if (!$is_test_run) { + die("\n\nerror storing data\n"); + } } else { - print STDERR "successfully stored data\n"; + print STDERR "successfully stored data\n"; } diff --git a/lib/CXGN/Cvterm.pm b/lib/CXGN/Cvterm.pm index e2406ce4b8..83b55e879d 100644 --- a/lib/CXGN/Cvterm.pm +++ b/lib/CXGN/Cvterm.pm @@ -31,58 +31,108 @@ use base qw / CXGN::DB::Object / ; use Try::Tiny; +=head2 accessor schema + +=cut + has 'schema' => ( isa => 'Bio::Chado::Schema', is => 'rw', required => 1 ); +=head2 accessor cvterm + + Returns: Cv::Cvterm DBIx::Class object + +=cut + has 'cvterm' => ( isa => 'Bio::Chado::Schema::Result::Cv::Cvterm', is => 'rw', ); +=head2 accessor cvterm_id + +=cut + has 'cvterm_id' => ( isa => 'Int', is => 'rw', ); +=head2 accessor cv + +=cut + has 'cv' => ( isa => 'Bio::Chado::Schema::Result::Cv::Cv', is => 'rw', ); +=head2 accessor cv_id + +=cut + has 'cv_id' => ( isa => 'Int', is => 'rw', ); +=head2 accessor dbxref + +=cut + has 'dbxref' => ( isa => 'Bio::Chado::Schema::Result::General::Dbxref', is => 'rw', ); +=head2 accessor db + +=cut + has 'db' => ( isa => 'Bio::Chado::Schema::Result::General::Db', is => 'rw', ); +=head2 accessor name + +=cut + has 'name' => ( isa => 'Str', is => 'rw', ); +=head2 accessor definition + +=cut + has 'definition' => ( isa => 'Str', is => 'rw', ); +=head2 accessor is_obsolete + +=cut + + has 'is_obsolete' => ( isa => 'Bool', is => 'rw', default => 0, ); + +=head2 accessor accession + + refers to dbxref.accession column + +=cut + has 'accession' => ( isa => 'Maybe[Str]', is => 'rw', diff --git a/lib/CXGN/Fieldbook/TraitProps.pm b/lib/CXGN/Fieldbook/TraitProps.pm index 439782afb1..d4c56fdd68 100644 --- a/lib/CXGN/Fieldbook/TraitProps.pm +++ b/lib/CXGN/Fieldbook/TraitProps.pm @@ -24,6 +24,7 @@ use Moose; use MooseX::FollowPBP; use Moose::Util::TypeConstraints; use Try::Tiny; +use CXGN::Cvterm; has 'chado_schema' => ( is => 'ro', @@ -113,22 +114,42 @@ sub validate { } my $trait_name = $trait_props->{'trait_name'}; - #make sure that the trait name is valid + my $accession; + + if ($trait_name =~ /(.*)\|(.*$)/) { + $trait_name = $1; + $accession = $2; + } + + print STDERR "Working with trait $trait_name, accession $accession\n"; my $trait_cvterm; - $trait_cvterm = $chado_schema->resultset("Cv::Cvterm") - ->find( { - 'dbxref.db_id' => $db_rs->first()->db_id(), - 'name'=> $trait_name, - }, - { - 'join' => 'dbxref' - } - ); - if (!$trait_cvterm) { - print STDERR "Could not find trait $trait_name\n"; - return; + + if ($accession) { + my $cvterm = CXGN::Cvterm->new( { schema => $chado_schema, accession => $accession }); + $trait_cvterm = $cvterm->cvterm(); + + if (!$cvterm) { + print STDERR "Could not find trait $trait_name (with $accession)\n"; + return; + } } + #make sure that the trait name is valid + else { + $trait_cvterm = $chado_schema->resultset("Cv::Cvterm") + ->find( { + 'dbxref.db_id' => $db_rs->first()->db_id(), + 'name'=> $trait_name, + }, + { + 'join' => 'dbxref' + } + ); + if (!$trait_cvterm) { + print STDERR "Could not find trait $trait_name\n"; + return; + } + } #make sure that the trait prop names are valid foreach my $prop_name (keys %{$trait_props}) { if ($prop_name ne 'trait_name') { @@ -186,18 +207,38 @@ sub store { foreach my $trait_props (@trait_props_data) { + my $trait_name = $trait_props->{'trait_name'}; - - #get the cvterm for the trait - my $trait_cvterm = $chado_schema->resultset("Cv::Cvterm") - ->find( { - 'dbxref.db_id' => $db_rs->first()->db_id(), - 'name'=> $trait_name, - }, - { - 'join' => 'dbxref' - } + my $accession; + + if ($trait_name =~ /(.*)\|(.*$)/) { + $trait_name = $1; + $accession = $2; + } + + my $trait_cvterm; + + if ($accession) { + my $cvterm = CXGN::Cvterm->new( { schema => $chado_schema, accession => $accession }); + $trait_cvterm = $cvterm->cvterm(); + + if (!$cvterm) { + print STDERR "Could not find trait $trait_name (with $accession)\n"; + return; + } + } + else { + #get the cvterm for the trait + my $trait_cvterm = $chado_schema->resultset("Cv::Cvterm") + ->find( { + 'dbxref.db_id' => $db_rs->first()->db_id(), + 'name'=> $trait_name, + }, + { + 'join' => 'dbxref' + } ); + } foreach my $prop_name (keys %{$trait_props}) { if ($prop_name ne 'trait_name') { diff --git a/lib/SGN/Controller/Image.pm b/lib/SGN/Controller/Image.pm index bef95d1baa..e94fa10684 100644 --- a/lib/SGN/Controller/Image.pm +++ b/lib/SGN/Controller/Image.pm @@ -110,7 +110,7 @@ sub store :Path('/image/store') { $image->set_sp_person_id( $c->stash->{person_id} ); - if ((my $err = $image->process_image($temp_image_dir."/".$tempfile, $type, $type_id))<=0) { + if ((my $err = $image->process_image($temp_image_dir."/".$tempfile, $type, $type_id, 1))<=0) { die "An error occurred during the upload. Is the file you are uploading an image file? [$err] "; }