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

Sgn 5022 show stored analysis #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 79 additions & 4 deletions lib/CXGN/Chado/Stock.pm
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ sub get_trials {
my $dbh = $self->get_schema()->storage()->dbh();
my $stock_type = $self->get_type->name();

if ($stock_type ne 'accession' && $stock_type ne 'plot'){
die "CXGN::Chado::Stock::get_trials requires either an accession or a plot.\n";
}

my $geolocation_q = "SELECT nd_geolocation_id, description FROM nd_geolocation;";
my $geolocation_h = $dbh->prepare($geolocation_q);
$geolocation_h->execute();
Expand All @@ -630,20 +634,91 @@ sub get_trials {
my $geolocation_type_id = SGN::Model::Cvterm->get_cvterm_row($self->get_schema(), 'project location', 'project_property')->cvterm_id();
my $q;
if ($stock_type eq 'accession'){
$q = "select distinct(project.project_id), project.name, projectprop.value from stock as accession join stock_relationship on (accession.stock_id=stock_relationship.object_id) JOIN stock as plot on (plot.stock_id=stock_relationship.subject_id) JOIN nd_experiment_stock ON (plot.stock_id=nd_experiment_stock.stock_id) JOIN nd_experiment_project USING(nd_experiment_id) JOIN project USING (project_id) FULL OUTER JOIN projectprop ON (project.project_id=projectprop.project_id AND projectprop.type_id=$geolocation_type_id) WHERE accession.stock_id=?;";
} else {
$q = "select distinct(project.project_id), project.name, projectprop.value from stock JOIN nd_experiment_stock USING(stock_id) JOIN nd_experiment_project USING(nd_experiment_id) JOIN project USING (project_id) FULL OUTER JOIN projectprop ON (project.project_id=projectprop.project_id AND projectprop.type_id=$geolocation_type_id) WHERE stock.stock_id=?;";
$q = "SELECT DISTINCT project.project_id, project.name, projectprop.value
FROM stock AS accession
JOIN stock_relationship ON (accession.stock_id=stock_relationship.object_id)
JOIN stock AS plot ON (plot.stock_id=stock_relationship.subject_id)
JOIN nd_experiment_stock ON (plot.stock_id=nd_experiment_stock.stock_id)
JOIN nd_experiment_project USING (nd_experiment_id)
JOIN project USING (project_id)
FULL OUTER JOIN projectprop ON (project.project_id=projectprop.project_id AND projectprop.type_id=$geolocation_type_id)
JOIN cvterm ON (cvterm.cvterm_id=nd_experiment_stock.type_id)
FULL OUTER JOIN breeding_programs ON (breeding_programs.breeding_program_id=project.project_id)
WHERE accession.stock_id=?
AND cvterm.name!='phenotyping_experiment'
nmenda marked this conversation as resolved.
Show resolved Hide resolved
AND cvterm.name!='analysis_experiment'
AND breeding_program_id IS NULL;";
} else { # Odds are if this is not an accession, it is a plot.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it also be a plant or tissue sample? is the query going to work in such cases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure it would not work if those stocks were used but the original code that was there only distinguishes between accessions and non-accession stocks, and I did not want to change that. As far as I can tell though, these functions are only ever called on accessions and plots, so I do not think it matters. Would it be better to throw an error for invalid stock types?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to be explicit about this, and check if the stock is an accession or a plot, and throw an error if neither

$q = "select DISTINCT project.project_id, project.name, projectprop.value from stock
JOIN nd_experiment_stock USING(stock_id)
JOIN nd_experiment_project USING(nd_experiment_id)
JOIN project USING (project_id)
JOIN nd_experiment ON nd_experiment.nd_experiment_id=nd_experiment_project.nd_experiment_id
JOIN cvterm ON cvterm.cvterm_id=nd_experiment.type_id
FULL OUTER JOIN projectprop ON (project.project_id=projectprop.project_id AND projectprop.type_id=$geolocation_type_id)
WHERE stock.stock_id=? AND cvterm.name!='phenotyping_experiment' AND cvterm.name!='analysis_experiment';";
}
my $h = $dbh->prepare($q);
$h->execute($self->get_stock_id());
my @trials;
while (my ($project_id, $project_name, $nd_geolocation_id) = $h->fetchrow_array()) {
push @trials, [ $project_id, $project_name, $nd_geolocation_id, $geolocations{$nd_geolocation_id} ];
next if (!$nd_geolocation_id); #The logic here is that field trials must have a location, this is enforced during their creation.
push @trials, [ $project_id, $project_name, $nd_geolocation_id, $geolocations{$nd_geolocation_id} ];
}

return @trials;
}

=head2 get_stored_analyses

Usage:
Desc: gets the list of stored analyses using this stock (accession)
Args:
Side Effects:
Example:

=cut

sub get_stored_analyses {
nmenda marked this conversation as resolved.
Show resolved Hide resolved
my $self = shift;
my $dbh = $self->get_schema()->storage()->dbh();
my $stock_type = $self->get_type->name();

if ($stock_type ne 'accession') {
die "CXGN::Chado::Stock::get_stored_analyses requires an accession.\n";
}

my $q;
if ($stock_type eq 'accession'){
$q = "SELECT DISTINCT project.project_id, project.name
FROM stock AS accession
JOIN stock_relationship ON (accession.stock_id=stock_relationship.object_id)
JOIN stock AS plot ON (plot.stock_id=stock_relationship.subject_id)
JOIN nd_experiment_stock ON (plot.stock_id=nd_experiment_stock.stock_id)
JOIN nd_experiment_project USING (nd_experiment_id)
JOIN project USING (project_id)
JOIN cvterm ON (cvterm.cvterm_id=nd_experiment_stock.type_id)
WHERE accession.stock_id=?
AND cvterm.name='analysis_experiment';";
} else { #This code doesn't get called anywhere, but is here in case it is needed in the future
$q = "select distinct(project.project_id), project.name from stock
JOIN nd_experiment_stock USING(stock_id)
JOIN nd_experiment_project USING(nd_experiment_id)
JOIN nd_experiment ON nd_experiment.nd_experiment_id=nd_experiment_project.nd_experiment_id
JOIN cvterm ON cvterm.cvterm_id=nd_experiment.type_id
JOIN project USING (project_id)
WHERE stock.stock_id=? AND cvterm.name='analysis_experiment';";
}
my $h = $dbh->prepare($q);
$h->execute($self->get_stock_id());
my @analyses;
while (my ($project_id, $project_name) = $h->fetchrow_array()) {
push @analyses, [ $project_id, $project_name ];
}

return @analyses;
}

sub get_direct_parents {
my $self = shift;
my $stock_id = shift || $self->get_stock_id();
Expand Down