From de3cebc451a8391fecba51bf7152828b78f47c6d Mon Sep 17 00:00:00 2001 From: Lukas Mueller Date: Thu, 17 Oct 2024 08:33:43 -0400 Subject: [PATCH] add description to upload. --- bin/load_stocks.pl | 50 +++++++++++++--------- lib/CXGN/Stock.pm | 29 +++++++------ .../Stock/ParseUpload/Plugin/AccessionsGeneric.pm | 7 +-- mason/breeders_toolbox/add_accessions_dialogs.mas | 5 ++- 4 files changed, 53 insertions(+), 38 deletions(-) diff --git a/bin/load_stocks.pl b/bin/load_stocks.pl index d15e02e7e6..59d3d3de79 100644 --- a/bin/load_stocks.pl +++ b/bin/load_stocks.pl @@ -144,28 +144,33 @@ my $coderef= sub { die "Species $species_name does not exist in the database! " if !$organism_id; } - my $population_name = $spreadsheet->value_at($accession, "population_name"); + my $population_names = $spreadsheet->value_at($accession, "population_name"); # new: can be more than one, | separated my $synonym_string = $spreadsheet->value_at($accession, "synonyms"); + my $description = $spreadsheet->value_at($accession, "description"); + my @synonyms = split /\|/ , $synonym_string; - my $population; - if ($population_name) { - print "Creating a stock for population $population_name (cvterm = " . $population_cvterm->name . ")\n"; - $population = $stock_rs->find_or_create( - { - 'me.name' => $population_name, - 'me.uniquename' => $population_name, - 'me.organism_id' => $organism_id, - type_id => $population_cvterm->cvterm_id, - }, - { join => 'type' } - ); + my @population_rows; + if ($population_names) { + my @populations = split /\|/, $population_names; + + foreach my $name (@populations) { + print "Creating a stock for population $population_name (cvterm = " . $population_cvterm->name . ")\n"; + my $row = $stock_rs->find_or_create( { + 'me.name' => $name, + 'me.uniquename' => $name, + 'me.organism_id' => $organism_id, + type_id => $population_cvterm->cvterm_id, }, { join => 'type' } + ); + push @population_rows, $row; + } } print "Find or create stock for accesssion $accession\n"; my $stock = $schema->resultset("Stock::Stock")->find_or_create( { organism_id => $organism_id, name => $accession, + description => $description, uniquename => $accession, type_id => $accession_cvterm->cvterm_id(), }); @@ -180,16 +185,19 @@ my $coderef= sub { sp_person_id => $sp_person_id, }); - # the stock belongs to the population: - # add new stock_relationship + # the stock belongs to population(s): + # add new stock_relationship(s) # - if ($population_name) { - print "Accession $accession is member_of population $population_name \n"; - $population->find_or_create_related('stock_relationship_objects', { - type_id => $member_of->cvterm_id(), - subject_id => $stock->stock_id(), - } ); + if ($population_names) { + foreach my $row (@population_rows) { + print "Accession $accession is member_of population ".$row->uniquename(); + $row->find_or_create_related('stock_relationship_objects', { + type_id => $member_of->cvterm_id(), + subject_id => $stock->stock_id(), + } ); + } } + if ($synonym_string) {print "Adding synonyms #" . scalar(@synonyms) . "\n"; } foreach my $syn (@synonyms) { if ($syn && defined($syn) && ($syn ne $accession) ) { diff --git a/lib/CXGN/Stock.pm b/lib/CXGN/Stock.pm index 510398fa13..0adeafdd0f 100644 --- a/lib/CXGN/Stock.pm +++ b/lib/CXGN/Stock.pm @@ -1613,18 +1613,23 @@ sub _store_population_relationship { my $population_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'population','stock_type')->cvterm_id(); my $population_member_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'member_of','stock_relationship')->cvterm_id(); - print STDERR "***STOCK.PM : find_or_create population relationship $population_cvterm_id \n\n"; - my $population = $schema->resultset("Stock::Stock")->find_or_create({ - uniquename => $self->population_name(), - name => $self->population_name(), - organism_id => $self->organism_id(), - type_id => $population_cvterm_id, - }); - $self->stock->find_or_create_related('stock_relationship_subjects', { - type_id => $population_member_cvterm_id, - object_id => $population->stock_id(), - subject_id => $self->stock_id(), - }); + my @populations = split /\|/, $self->population_name(); + + foreach my $population_name (@populations) { + + print STDERR "***STOCK.PM : find_or_create population relationship $population_cvterm_id \n\n"; + my $population_row = $schema->resultset("Stock::Stock")->find_or_create({ + uniquename => $population_name, + name => $population_name, + organism_id => $self->organism_id(), + type_id => $population_cvterm_id, + }); + $self->stock->find_or_create_related('stock_relationship_subjects', { + type_id => $population_member_cvterm_id, + object_id => $population_row->stock_id(), + subject_id => $self->stock_id(), + }); + } } ##Move to a population child object## diff --git a/lib/CXGN/Stock/ParseUpload/Plugin/AccessionsGeneric.pm b/lib/CXGN/Stock/ParseUpload/Plugin/AccessionsGeneric.pm index 474d51c365..9c5dcdee75 100644 --- a/lib/CXGN/Stock/ParseUpload/Plugin/AccessionsGeneric.pm +++ b/lib/CXGN/Stock/ParseUpload/Plugin/AccessionsGeneric.pm @@ -21,7 +21,7 @@ sub _validate_with_plugin { my %missing_accessions; # optional columns = these hard-coded columns plus any editable stock props - my @optional_columns = ('synonyms', 'populationName', 'organizationName', 'locationCode', 'ploidyLevel', 'genomeStructure', 'variety', 'donor', 'donor institute', 'donor PUI', 'countryOfOriginCode', 'state', 'instituteCode', 'instituteName', 'biologicalStatusOfAccessionCode', 'notes', 'accessionNumber', 'germplasmPUI', 'germplasmSeedSource', 'typeOfGermplasmStorageCode', 'acquisitionDate', 'transgenic', 'introgression_parent', 'introgression_backcross_parent', 'introgression_chromosome', 'introgression_start_position_bp', 'introgression_end_position_bp'); + my @optional_columns = ('description', 'synonyms', 'populationName', 'organizationName', 'locationCode', 'ploidyLevel', 'genomeStructure', 'variety', 'donor', 'donor institute', 'donor PUI', 'countryOfOriginCode', 'state', 'instituteCode', 'instituteName', 'biologicalStatusOfAccessionCode', 'notes', 'accessionNumber', 'germplasmPUI', 'germplasmSeedSource', 'typeOfGermplasmStorageCode', 'acquisitionDate', 'transgenic', 'introgression_parent', 'introgression_backcross_parent', 'introgression_chromosome', 'introgression_start_position_bp', 'introgression_end_position_bp'); push @optional_columns, @$editable_stockprops; my $parser = CXGN::File::Parse->new( @@ -149,7 +149,7 @@ sub _parse_with_plugin { my $row_num = $row->{_row}; my $accession = $row->{'accession_name'}; my $synonyms = $row->{'synonyms'} || []; - + my $description = $row->{'description'} || ''; my $stock_id; if(exists($accession_lookup{$accession})){ $stock_id = $accession_lookup{$accession}; @@ -161,7 +161,8 @@ sub _parse_with_plugin { species => $row->{'species_name'}, populationName => $row->{'populationName'}, organizationName => $row->{'organizationName'}, - synonyms => $synonyms + synonyms => $synonyms, + description => $description, ); #For "updating" existing accessions by adding properties. diff --git a/mason/breeders_toolbox/add_accessions_dialogs.mas b/mason/breeders_toolbox/add_accessions_dialogs.mas index f8f1332aec..c7d9764b49 100644 --- a/mason/breeders_toolbox/add_accessions_dialogs.mas +++ b/mason/breeders_toolbox/add_accessions_dialogs.mas @@ -168,7 +168,8 @@ $editable_stock_props_definitions Optional Fields: