From 809d7aa5827f79231b3e961178524a02abb0df62 Mon Sep 17 00:00:00 2001 From: nickmorales Date: Thu, 31 Aug 2017 15:39:59 -0400 Subject: [PATCH] tests pass --- .../Phenotypes/ParseUpload/Plugin/FieldBook.pm | 17 ++++- lib/CXGN/Phenotypes/StorePhenotypes.pm | 6 -- lib/CXGN/Stock.pm | 2 +- lib/CXGN/Trial/TrialDesignStore.pm | 3 +- .../fieldbook/fieldbook_phenotype_plants_file.csv | 2 +- t/unit_fixture/CXGN/BreedersToolbox/Projects.t | 2 +- t/unit_fixture/CXGN/Trial/AddPlants.t | 89 +++++++++++++++++----- t/unit_fixture/CXGN/Uploading/Phenotype.t | 3 +- 8 files changed, 94 insertions(+), 30 deletions(-) diff --git a/lib/CXGN/Phenotypes/ParseUpload/Plugin/FieldBook.pm b/lib/CXGN/Phenotypes/ParseUpload/Plugin/FieldBook.pm index 3bf9702ad..413020c99 100644 --- a/lib/CXGN/Phenotypes/ParseUpload/Plugin/FieldBook.pm +++ b/lib/CXGN/Phenotypes/ParseUpload/Plugin/FieldBook.pm @@ -44,11 +44,26 @@ sub validate { } # Check header row contents - if ($header_row[0] ne "\"plot_id\"" || $header_row[0] ne "\"plot_name\"" || $header_row[0] ne "\"plant_name\"" || $header_row[0] ne "\"subplot_name\""){ + if ($header_row[0] ne "\"plot_id\"" && $header_row[0] ne "\"plot_name\"" && $header_row[0] ne "\"plant_name\"" && $header_row[0] ne "\"subplot_name\""){ $parse_result{'error'} = "File contents incorrect. First column in header must be plot_id, plot_name, plant_name, or subplot_name."; return \%parse_result; } + if($data_level ne 'plots' && $data_level ne 'plants' && $data_level ne 'subplots'){ + $parse_result{'error'} = "You must specify if you are uploading plot, plant, or subplot level phenotypes."; + return \%parse_result; + } + if($data_level eq 'plots' && ($header_row[0] ne "\"plot_id\"" && $header_row[0] ne "\"plot_name\"")){ + $parse_result{'error'} = "File contents incorrect. First column in header must be plot_id or plot_name if you are uploading plot level phenotypes."; + return \%parse_result; + } elsif ($data_level eq 'plants' && $header_row[0] ne "\"plant_name\""){ + $parse_result{'error'} = "File contents incorrect. First column in header must be plot_id or plot_name if you are uploading plant level phenotypes."; + return \%parse_result; + } elsif ($data_level eq 'subplots' && $header_row[0] ne "\"subplot_name\""){ + $parse_result{'error'} = "File contents incorrect. First column in header must be plot_id or plot_name if you are uploading subplot level phenotypes."; + return \%parse_result; + } + my %header_column_info; foreach my $header_cell (@header_row) { $header_cell =~ s/\"//g; #substr($header_cell,1,-1); #remove double quotes diff --git a/lib/CXGN/Phenotypes/StorePhenotypes.pm b/lib/CXGN/Phenotypes/StorePhenotypes.pm index 643f77bcc..a3aefca43 100644 --- a/lib/CXGN/Phenotypes/StorePhenotypes.pm +++ b/lib/CXGN/Phenotypes/StorePhenotypes.pm @@ -128,13 +128,7 @@ sub create_hash_lookups { my %trait_objs; my @trait_list = @{$self->trait_list}; my @stock_list = @{$self->stock_list}; - - my $t = CXGN::List::Transform->new(); - my $stock_id_list = $t->transform($schema, 'stocks_2_stock_ids', \@stock_list); - $self->stock_id_list($stock_id_list->{'transform'}); - my @cvterm_ids; - my @stock_list = @{$self->stock_list}; my $t = CXGN::List::Transform->new(); my $stock_id_list = $t->transform($schema, 'stocks_2_stock_ids', \@stock_list); diff --git a/lib/CXGN/Stock.pm b/lib/CXGN/Stock.pm index 7dd912d71..29bdee3a3 100644 --- a/lib/CXGN/Stock.pm +++ b/lib/CXGN/Stock.pm @@ -945,7 +945,7 @@ sub _retrieve_populations { subject_id => $self->stock_id(), }); if ($rs->count == 0) { - print STDERR "No population saved for this stock!\n"; + #print STDERR "No population saved for this stock!\n"; } else { my @population_names; diff --git a/lib/CXGN/Trial/TrialDesignStore.pm b/lib/CXGN/Trial/TrialDesignStore.pm index 1f4e53847..cb8a25cfd 100644 --- a/lib/CXGN/Trial/TrialDesignStore.pm +++ b/lib/CXGN/Trial/TrialDesignStore.pm @@ -119,7 +119,8 @@ sub validate_design { 'range_number', 'row_number', 'col_number', - 'plant_names' + 'plant_names', + 'plot_num_per_block' ); } elsif ($design_type eq 'splitplot'){ @valid_properties = ( diff --git a/t/data/fieldbook/fieldbook_phenotype_plants_file.csv b/t/data/fieldbook/fieldbook_phenotype_plants_file.csv index 0d74a4d58..f127a6476 100644 --- a/t/data/fieldbook/fieldbook_phenotype_plants_file.csv +++ b/t/data/fieldbook/fieldbook_phenotype_plants_file.csv @@ -1,4 +1,4 @@ -"plot_id","range","plant","plot","rep","accession","is_a_control","trait","value","timestamp","person","location","number" +"plant_name","range","plant","plot","rep","accession","is_a_control","trait","value","timestamp","person","location","number" "test_trial21_plant_1","1","1","2","1","test_accession1","","dry matter content|CO_334:0000092","42","2016-01-07 12:08:24-0500","johndoe","42.4472 ; -76.4676","1" "test_trial21_plant_2","1","2","2","1","test_accession1","","dry matter content|CO_334:0000092","42","2016-01-07 12:08:24-0500","johndoe","42.4472 ; -76.4676","1" "test_trial22_plant_1","1","1","3","1","test_accession2","","dry matter content|CO_334:0000092","45","2016-01-07 12:08:26-0500","johndoe","42.4472 ; -76.4676","1" diff --git a/t/unit_fixture/CXGN/BreedersToolbox/Projects.t b/t/unit_fixture/CXGN/BreedersToolbox/Projects.t index 04332bcb8..0dee0bb66 100644 --- a/t/unit_fixture/CXGN/BreedersToolbox/Projects.t +++ b/t/unit_fixture/CXGN/BreedersToolbox/Projects.t @@ -224,7 +224,7 @@ is_deeply($all_locations, [ '32.6136', '-115.864', '109', - 5456 + 5458 ] ], 'get all locations'); diff --git a/t/unit_fixture/CXGN/Trial/AddPlants.t b/t/unit_fixture/CXGN/Trial/AddPlants.t index 3f940d852..4d074317f 100644 --- a/t/unit_fixture/CXGN/Trial/AddPlants.t +++ b/t/unit_fixture/CXGN/Trial/AddPlants.t @@ -308,14 +308,14 @@ is(@contents->[0]->[0]->{'sheets'}, '1', "check that type of file is correct"); my $columns = @contents->[0]->[1]->{'cell'}; #print STDERR Dumper scalar(@$columns); -ok(scalar(@$columns) == 7, "check number of col in created file."); +ok(scalar(@$columns) == 9, "check number of col in created file."); #print STDERR Dumper $columns; is_deeply($columns, [ [], [ undef, - 'plot_id', + 'plot_name', 'test_trial21', 'test_trial22', 'test_trial23', @@ -334,7 +334,7 @@ is_deeply($columns, [ ], [ undef, - 'range', + 'block_number', '1', '1', '1', @@ -353,7 +353,7 @@ is_deeply($columns, [ ], [ undef, - 'plot', + 'plot_number', '1', '2', '3', @@ -372,7 +372,7 @@ is_deeply($columns, [ ], [ undef, - 'rep', + 'rep_number', '1', '1', '1', @@ -391,7 +391,15 @@ is_deeply($columns, [ ], [ undef, - 'accession', + 'row_number' + ], + [ + undef, + 'col_number' + ], + [ + undef, + 'accession_name', 'test_accession4', 'test_accession5', 'test_accession3', @@ -442,13 +450,13 @@ is(@contents->[0]->[0]->{'sheets'}, '1', "check that type of file is correct"); my $columns = @contents->[0]->[1]->{'cell'}; #print STDERR Dumper scalar(@$columns); -ok(scalar(@$columns) == 8, "check number of col in created file."); +ok(scalar(@$columns) == 11, "check number of col in created file."); #print STDERR Dumper $columns; is_deeply($columns->[1], [ undef, - 'plot_id', + 'plant_name', 'test_trial21_plant_1', 'test_trial21_plant_2', 'test_trial22_plant_1', @@ -483,7 +491,42 @@ is_deeply($columns->[1], [ is_deeply($columns->[2], [ undef, - 'range', + 'plot_name', + 'test_trial21', + 'test_trial21', + 'test_trial22', + 'test_trial22', + 'test_trial23', + 'test_trial23', + 'test_trial24', + 'test_trial24', + 'test_trial25', + 'test_trial25', + 'test_trial26', + 'test_trial26', + 'test_trial27', + 'test_trial27', + 'test_trial28', + 'test_trial28', + 'test_trial29', + 'test_trial29', + 'test_trial210', + 'test_trial210', + 'test_trial211', + 'test_trial211', + 'test_trial212', + 'test_trial212', + 'test_trial213', + 'test_trial213', + 'test_trial214', + 'test_trial214', + 'test_trial215', + 'test_trial215' + ], "check 2nd col"); + +is_deeply($columns->[3], [ + undef, + 'block_number', '1', '1', '1', @@ -516,9 +559,9 @@ is_deeply($columns->[2], [ '1' ], "check contents of second col"); -is_deeply($columns->[3],[ +is_deeply($columns->[4],[ undef, - 'plant', + 'plant_number', '1', '2', '1', @@ -551,9 +594,9 @@ is_deeply($columns->[3],[ '2' ], "check contents of third col"); -is_deeply($columns->[4], [ +is_deeply($columns->[5], [ undef, - 'plot', + 'plot_number', '1', '1', '2', @@ -586,9 +629,9 @@ is_deeply($columns->[4], [ '15' ], "check contents of fourth col"); -is_deeply($columns->[5], [ +is_deeply($columns->[6], [ undef, - 'rep', + 'rep_number', '1', '1', '1', @@ -621,9 +664,19 @@ is_deeply($columns->[5], [ '3' ], "check contents of fifth col"); -is_deeply($columns->[6],[ +is_deeply($columns->[7], [ + undef, + 'row_number' + ], "check contents"); + +is_deeply($columns->[8], [ + undef, + 'col_number' + ], "check contents"); + +is_deeply($columns->[9],[ undef, - 'accession', + 'accession_name', 'test_accession4', 'test_accession4', 'test_accession5', @@ -656,7 +709,7 @@ is_deeply($columns->[6],[ 'test_accession2' ], "check contents of sixth col"); -is_deeply($columns->[7],[ +is_deeply($columns->[10],[ undef, 'is_a_control' ], "check contents of 7th col"); diff --git a/t/unit_fixture/CXGN/Uploading/Phenotype.t b/t/unit_fixture/CXGN/Uploading/Phenotype.t index 68db9fdee..4ada7f670 100644 --- a/t/unit_fixture/CXGN/Uploading/Phenotype.t +++ b/t/unit_fixture/CXGN/Uploading/Phenotype.t @@ -718,6 +718,7 @@ ok($validate_file != 1, "Check if parse validate fieldbook fails for datacollect $parser = CXGN::Phenotypes::ParseUpload->new(); $filename = "t/data/fieldbook/fieldbook_phenotype_file.csv"; $validate_file = $parser->validate('field book', $filename, 1, 'plots', $f->bcs_schema); +print STDERR Dumper $validate_file; ok($validate_file == 1, "Check if parse validate works for fieldbook"); $parsed_file = $parser->parse('field book', $filename, 1, 'plots', $f->bcs_schema); @@ -3106,7 +3107,7 @@ while (my $rs = $exp_md_files_table_tail->next() ) { $parser = CXGN::Phenotypes::ParseUpload->new(); $filename = "t/data/fieldbook/fieldbook_phenotype_plants_file.csv"; -$validate_file = $parser->validate('field book', $filename, 1, 'plots', $f->bcs_schema); +$validate_file = $parser->validate('field book', $filename, 1, 'plants', $f->bcs_schema); ok($validate_file == 1, "Check if parse validate works for plant fieldbook file"); $parsed_file = $parser->parse('field book', $filename, 1, 'plots', $f->bcs_schema); -- 2.11.4.GIT