Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve related stock section on stock details page and add related seedlot info specific to plot and plant details pages ("source of" or "derived from" type) #4755

Merged
merged 10 commits into from
Dec 11, 2023
47 changes: 43 additions & 4 deletions lib/CXGN/Stock/RelatedStocks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ sub get_trial_related_stock {
my $plant_of_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'plant_of', 'stock_relationship')->cvterm_id();
my $subplot_of_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'subplot_of', 'stock_relationship')->cvterm_id();
my $plant_of_subplot_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'plant_of_subplot', 'stock_relationship')->cvterm_id();
my $seed_transaction_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'seed transaction', 'stock_relationship')->cvterm_id();
# my $seed_transaction_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'seed transaction', 'stock_relationship')->cvterm_id();
my $tissue_sample_of_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'tissue_sample_of', 'stock_relationship')->cvterm_id();

my $q = "SELECT stock.stock_id, stock.uniquename, cvterm.name FROM stock_relationship
INNER JOIN stock ON (stock_relationship.subject_id = stock.stock_id)
INNER JOIN cvterm ON (stock.type_id = cvterm.cvterm_id)
WHERE stock_relationship.object_id = ? AND (stock_relationship.type_id = ?
OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? OR stock_relationship.type_id = ?)
OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? )

UNION ALL

SELECT stock.stock_id, stock.uniquename, cvterm.name FROM stock_relationship
INNER JOIN stock ON (stock_relationship.object_id = stock.stock_id)
INNER JOIN cvterm ON (stock.type_id = cvterm.cvterm_id)
WHERE stock_relationship.subject_id = ? AND (stock_relationship.type_id = ?
OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? OR stock_relationship.type_id = ?) ";
OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? OR stock_relationship.type_id = ? ) ";

my $h = $schema->storage->dbh()->prepare($q);

$h->execute($stock_id, $plot_of_type_id, $plant_of_type_id, $subplot_of_type_id, $plant_of_subplot_type_id, $seed_transaction_type_id, $tissue_sample_of_type_id, $stock_id, $plot_of_type_id, $plant_of_type_id, $subplot_of_type_id, $plant_of_subplot_type_id, $seed_transaction_type_id, $tissue_sample_of_type_id);
$h->execute($stock_id, $plot_of_type_id, $plant_of_type_id, $subplot_of_type_id, $plant_of_subplot_type_id, $tissue_sample_of_type_id, $stock_id, $plot_of_type_id, $plant_of_type_id, $subplot_of_type_id, $plant_of_subplot_type_id, $tissue_sample_of_type_id);

my @trial_related_stock =();
while(my($stock_id, $stock_name, $cvterm_name) = $h->fetchrow_array()){
Expand Down Expand Up @@ -175,4 +175,43 @@ sub get_cross_of_progeny {
}


sub get_plot_plant_related_seedlots {
my $self = shift;
my $stock_id = $self->stock_id;
my $schema = $self->dbic_schema();
my $seed_transaction_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'seed transaction', 'stock_relationship')->cvterm_id();

my @related_seedlots;

my $q1 = "SELECT distinct(stock.stock_id), stock.uniquename, cvterm.name FROM stock_relationship
INNER JOIN stock ON (stock_relationship.subject_id = stock.stock_id)
INNER JOIN cvterm ON (stock.type_id = cvterm.cvterm_id)
WHERE stock_relationship.object_id = ? AND stock_relationship.type_id = ? ";

my $h1 = $schema->storage->dbh()->prepare($q1);

$h1->execute($stock_id, $seed_transaction_type_id);

while(my($stock_id, $stock_name, $stock_type) = $h1->fetchrow_array()){
push @related_seedlots, ['source of', $stock_type, $stock_id, $stock_name]
}

my $q2 = "SELECT distinct(stock.stock_id), stock.uniquename, cvterm.name FROM stock_relationship
INNER JOIN stock ON (stock_relationship.object_id = stock.stock_id)
INNER JOIN cvterm ON (stock.type_id = cvterm.cvterm_id)
WHERE stock_relationship.subject_id = ? AND stock_relationship.type_id = ? ";

my $h2 = $schema->storage->dbh()->prepare($q2);

$h2->execute($stock_id, $seed_transaction_type_id);

while(my($stock_id, $stock_name, $stock_type) = $h2->fetchrow_array()){
push @related_seedlots, ['derived from', $stock_type, $stock_id, $stock_name]
}

return\@related_seedlots;

}


1;
14 changes: 11 additions & 3 deletions lib/CXGN/Stock/Seedlot/ParseUpload/Plugin/SeedlotHarvestedXLS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ sub _validate_with_plugin {
$box_name = $worksheet->get_cell($row,6)->value();
}

if (!defined $seedlot_name && !defined $cross_name) {
last;
}

if (!$seedlot_name || $seedlot_name eq '' ) {
push @error_messages, "Cell A$row_name: seedlot_name missing.";
}
Expand Down Expand Up @@ -263,6 +267,11 @@ sub _parse_with_plugin {
$cross_name =~ s/^\s+|\s+$//g;
$seen_cross_names{$cross_name}++;
}

if (!defined $seedlot_name && !defined $cross_name) {
last;
}

}
my $cross_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'cross', 'stock_type')->cvterm_id();
my $seedlot_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'seedlot', 'stock_type')->cvterm_id();
Expand Down Expand Up @@ -325,9 +334,8 @@ sub _parse_with_plugin {
$box_name =~ s/^\s+|\s+$//g;
}

#skip blank lines
if (!$seedlot_name && !$cross_name && !$description) {
next;
if (!defined $seedlot_name && !defined $cross_name) {
last;
}


Expand Down
20 changes: 15 additions & 5 deletions lib/CXGN/Stock/Seedlot/ParseUpload/Plugin/SeedlotXLS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ sub _validate_with_plugin {
$source = $worksheet->get_cell($row, 8)->value();
$source =~ s/^\s+|\s+$//g;
}

if (!defined $seedlot_name && !defined $accession_name) {
last;
}

if (!$seedlot_name || $seedlot_name eq '' ) {
push @error_messages, "Cell A$row_name: seedlot_name missing.";
}
Expand Down Expand Up @@ -304,7 +309,13 @@ sub _parse_with_plugin {
$accession_name =~ s/^\s+|\s+$//g; #trim whitespace from front and end...
$seen_accession_names{$accession_name}++;
}

if (!defined $seedlot_name && !defined $accession_name) {
last;
}

}

my $accession_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'accession', 'stock_type')->cvterm_id();
my $seedlot_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'seedlot', 'stock_type')->cvterm_id();
my $synonym_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'stock_synonym', 'stock_property')->cvterm_id();
Expand Down Expand Up @@ -379,15 +390,14 @@ sub _parse_with_plugin {
$source = $worksheet->get_cell($row, 8)->value();
}

if (!defined $seedlot_name && !defined $accession_name) {
last;
}

$seedlot_name =~ s/^\s+|\s+$//g; #trim whitespace from front and end...
$accession_name =~ s/^\s+|\s+$//g; #trim whitespace from front and end...
$source =~ s/^\s+|\s+$//g; # also trim

#skip blank lines
if (!$seedlot_name && !$accession_name && !$description) {
next;
}

my $accession_stock_id;
if ($acc_synonyms_lookup{$accession_name}){
my @accession_names = keys %{$acc_synonyms_lookup{$accession_name}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ sub _validate_with_plugin {
$new_seedlot_box_name = $worksheet->get_cell($row,6)->value();
}

if (!defined $from_seedlot_name && !defined $to_new_seedlot_name) {
last;
}

if (!$from_seedlot_name || $from_seedlot_name eq '' ) {
push @error_messages, "Cell A$row_name: from_seedlot_name missing.";
} else {
Expand Down Expand Up @@ -335,9 +339,8 @@ sub _parse_with_plugin {
$new_seedlot_quality = $worksheet->get_cell($row,8)->value();
}

#skip blank lines
if (!$to_new_seedlot_name && !$from_seedlot_name) {
next;
if (!defined $to_new_seedlot_name && !defined $from_seedlot_name) {
last;
}

my $from_seedlot_rs = $schema->resultset("Stock::Stock")->find({
Expand Down
9 changes: 6 additions & 3 deletions lib/CXGN/Stock/Seedlot/ParseUpload/Plugin/SeedlotsToPlots.pm
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ sub _validate_with_plugin {
$transaction_description = $worksheet->get_cell($row,5)->value();
}

if (!defined $from_seedlot_name && !defined $to_plot_name) {
last;
}

if (!$from_seedlot_name || $from_seedlot_name eq '' ) {
push @error_messages, "Cell A$row_name: from_seedlot_name missing.";
} else {
Expand Down Expand Up @@ -280,9 +284,8 @@ sub _parse_with_plugin {
$transaction_description = $worksheet->get_cell($row,5)->value();
}

#skip blank lines
if (!$to_plot_name && !$from_seedlot_name) {
next;
if (!defined $from_seedlot_name && !defined $to_plot_name) {
last;
}

my $from_seedlot_rs = $schema->resultset("Stock::Stock")->find({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ sub _validate_with_plugin {
$transaction_description = $worksheet->get_cell($row,5)->value();
}

if (!defined $from_seedlot_name && !defined $to_seedlot_name) {
last;
}

if (!$from_seedlot_name || $from_seedlot_name eq '' ) {
push @error_messages, "Cell A$row_name: from_seedlot_name missing.";
} else {
Expand Down Expand Up @@ -270,9 +274,8 @@ sub _parse_with_plugin {
$transaction_description = $worksheet->get_cell($row,5)->value();
}

#skip blank lines
if (!$to_seedlot_name && !$from_seedlot_name) {
next;
if (!defined $from_seedlot_name && !defined $to_seedlot_name) {
last;
}

my $from_seedlot_rs = $schema->resultset("Stock::Stock")->find({
Expand Down
95 changes: 82 additions & 13 deletions lib/SGN/Controller/AJAX/Stock.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1924,15 +1924,65 @@ sub get_trial_related_stock:Chained('/stock/get_stock') PathPart('datatables/tri
my $trial_related_stock = CXGN::Stock::RelatedStocks->new({dbic_schema => $schema, stock_id =>$stock_id});
my $result = $trial_related_stock->get_trial_related_stock();
my @stocks;
my @accessions;
my @crosses;
my @family_names;
my @plots;
my @subplots;
my @plants;
my @tissue_samples;
my @seedlots;
my @others;
foreach my $r (@$result){
my ($stock_id, $stock_name, $cvterm_name) = @$r;
my $url;
if ($cvterm_name eq 'seedlot'){
$url = qq{<a href = "/breeders/seedlot/$stock_id">$stock_name</a>};
} else {
$url = qq{<a href = "/stock/$stock_id/view">$stock_name</a>};
}
push @stocks, [$url, $cvterm_name, $stock_name];
my ($stock_id, $stock_name, $cvterm_name) = @$r;
my $url;

if ($cvterm_name eq 'cross') {
$url = qq{<a href = "/cross/$stock_id">$stock_name</a>};
} elsif ($cvterm_name eq 'family_name') {
$url = qq{<a href = "/family/$stock_id/">$stock_name</a>};
} else {
$url = qq{<a href = "/stock/$stock_id/view">$stock_name</a>};
}

if ($cvterm_name eq 'accession') {
push @accessions, [$cvterm_name, $url, $stock_name];
} elsif ($cvterm_name eq 'cross') {
push @crosses, [$cvterm_name, $url, $stock_name];
} elsif ($cvterm_name eq 'family_name') {
push @family_names, [$cvterm_name, $url, $stock_name];
} elsif ($cvterm_name eq 'plot') {
push @plots, [$cvterm_name, $url, $stock_name];
} elsif ($cvterm_name eq 'subplot') {
push @subplots, [$cvterm_name, $url, $stock_name];
} elsif ($cvterm_name eq 'plant') {
push @plants, [$cvterm_name, $url, $stock_name];
}
}

if (scalar(@accessions) > 0) {
push @stocks, @accessions;
}
if (scalar(@crosses) > 0) {
push @stocks, @crosses;
}
if (scalar(@family_names) > 0) {
push @stocks, @family_names;
}
if (scalar(@plots) > 0) {
push @stocks, @plots;
}
if (scalar(@subplots) > 0) {
push @stocks, @subplots;
}
if (scalar(@plants) > 0) {
push @stocks, @plants;
}
if (scalar(@seedlots) > 0) {
push @stocks, @seedlots;
}
if (scalar(@others) > 0) {
push @stocks, @others;
}

$c->stash->{rest}={data=>\@stocks};
Expand Down Expand Up @@ -2019,13 +2069,32 @@ sub get_stock_for_tissue:Chained('/stock/get_stock') PathPart('datatables/stock_

my ($stock_id, $stock_name, $cvterm_name) = @$r;

push @stocks, [qq{<a href = "/stock/$stock_id/view">$stock_name</a>}, $cvterm_name, $stock_name];
push @stocks, [$cvterm_name, qq{<a href = "/stock/$stock_id/view">$stock_name</a>}, $stock_name];
}

$c->stash->{rest}={data=>\@stocks};

}


sub get_plot_plant_related_seedlots:Chained('/stock/get_stock') PathPart('datatables/plot_plant_related_seedlots') Args(0){
my $self = shift;
my $c = shift;
my $stock_id = $c->stash->{stock_row}->stock_id();

my $schema = $c->dbic_schema("Bio::Chado::Schema", 'sgn_chado');
my $progenies = CXGN::Stock::RelatedStocks->new({dbic_schema => $schema, stock_id =>$stock_id});
my $result = $progenies->get_plot_plant_related_seedlots();
my @stocks;
foreach my $r (@$result){
my ($transaction_type, $stock_type, $stock_id, $stock_name) = @$r;
push @stocks, [$transaction_type, $stock_type, qq{<a href = "/breeders/seedlot/$stock_id">$stock_name</a>}, $stock_name];
}

$c->stash->{rest}={data=>\@stocks};
}


sub get_stock_datatables_genotype_data : Chained('/stock/get_stock') :PathPart('datatables/genotype_data') : ActionClass('REST') { }

sub get_stock_datatables_genotype_data_GET {
Expand Down Expand Up @@ -2277,7 +2346,7 @@ sub stock_additional_file_upload :Chained('/stock/get_stock') PathPart('upload_a
$c->stash->{rest} = {error=>$result->{error}};
$c->detach();
}

$c->stash->{rest} = { success => 1, file_id => $result->{file_id} };
}

Expand All @@ -2294,11 +2363,11 @@ sub get_accession_additional_file_uploaded :Chained('/stock/get_stock') PathPart
my @file_array;
my %file_info;

my $q = "SELECT file_id, m.create_date, p.sp_person_id, p.username, basename, dirname, filetype
my $q = "SELECT file_id, m.create_date, p.sp_person_id, p.username, basename, dirname, filetype
FROM phenome.stock_file
JOIN metadata.md_files using(file_id)
JOIN metadata.md_files using(file_id)
LEFT JOIN metadata.md_metadata as m using(metadata_id)
LEFT JOIN sgn_people.sp_person as p ON (p.sp_person_id=m.create_person_id)
LEFT JOIN sgn_people.sp_person as p ON (p.sp_person_id=m.create_person_id)
WHERE stock_id=? and m.obsolete = 0 and metadata.md_files.filetype='accession_additional_file_upload' ORDER BY file_id ASC";

my $h = $c->dbc->dbh()->prepare($q);
Expand Down
Loading
Loading