Skip to content

Commit

Permalink
Merge pull request #5199 from solgenomics/topic/tracking_transformation
Browse files Browse the repository at this point in the history
Tracking transformation workflow
  • Loading branch information
lukasmueller authored Nov 20, 2024
2 parents ab33802 + 9a4a369 commit e7f8435
Show file tree
Hide file tree
Showing 65 changed files with 4,610 additions and 418 deletions.
94 changes: 94 additions & 0 deletions db/00187/AddTransformationAndTrackingCvterms.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env perl

=head1 NAME
AddTransformationAndTrackingCvterms.pm
=head1 SYNOPSIS
mx-run ThisPackageName [options] -H hostname -D dbname -u username [-F]
this is a subclass of L<CXGN::Metadata::Dbpatch>
see the perldoc of parent class for more details.
=head1 DESCRIPTION
This patch adds autogenerated_name_metadata, autogenerated_name_format, default_plant_material project_property cvterms, progress_of project_relationship cvterm, tracking_transformation_json, completed_metadata stock_property cvterms.
This subclass uses L<Moose>. The parent class uses L<MooseX::Runnable>
=head1 AUTHOR
Titima Tantikanjana<[email protected]>
=head1 COPYRIGHT & LICENSE
Copyright 2010 Boyce Thompson Institute for Plant Research
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut


package AddTransformationAndTrackingCvterms;

use Moose;
use Bio::Chado::Schema;
use Try::Tiny;
extends 'CXGN::Metadata::Dbpatch';


has '+description' => ( default => <<'' );
Description of this patch goes here
has '+prereq' => (
default => sub {
[],
},

);

sub patch {
my $self=shift;

print STDOUT "Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";

print STDOUT "\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";

print STDOUT "\nExecuting the SQL commands.\n";
my $schema = Bio::Chado::Schema->connect( sub { $self->dbh->clone } );


print STDERR "INSERTING CV TERMS...\n";

my $terms = {
'project_property' => [
'autogenerated_name_metadata',
'autogenerated_name_format',
'default_plant_material',
],
'project_relationship' => [
'progress_of',
],
'stock_property' => [
'tracking_transformation_json',
'completed_metadata',
]
};

foreach my $t (keys %$terms){
foreach (@{$terms->{$t}}){
$schema->resultset("Cv::Cvterm")->create_with({
name => $_,
cv => $t
});
}
}

print "You're done!\n";

}


####
1; #
####
24 changes: 23 additions & 1 deletion lib/CXGN/BreedersToolbox/Projects.pm
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ sub get_trials_by_breeding_program {
my @sorted_by_year_keys = sort { $project_year{$a} cmp $project_year{$b} } keys(%project_year);

foreach my $id_key (@sorted_by_year_keys) {
if (!$projects_that_are_crosses{$id_key} && !$projects_that_are_genotyping_trials{$id_key} && !$projects_that_are_genotyping_trials{$id_key} && !$projects_that_are_treatment_trials{$id_key} && !$projects_that_are_genotyping_data_projects{$id_key} && !$projects_that_are_drone_run_projects{$id_key} && !$projects_that_are_drone_run_band_projects{$id_key} && !$projects_that_are_analyses{$id_key} && !$projects_that_are_sampling_trials{$id_key} && !$projects_that_are_tracking_projects{$id_key}) {
if (!$projects_that_are_crosses{$id_key} && !$projects_that_are_genotyping_trials{$id_key} && !$projects_that_are_genotyping_trials{$id_key} && !$projects_that_are_treatment_trials{$id_key} && !$projects_that_are_genotyping_data_projects{$id_key} && !$projects_that_are_drone_run_projects{$id_key} && !$projects_that_are_drone_run_band_projects{$id_key} && !$projects_that_are_analyses{$id_key} && !$projects_that_are_sampling_trials{$id_key} && !$projects_that_are_tracking_projects{$id_key} && !$projects_that_are_transformation_projects{$id_key}) {
push @$field_trials, [ $id_key, $project_name{$id_key}, $project_description{$id_key}];
} elsif ($projects_that_are_crosses{$id_key}) {
push @$cross_trials, [ $id_key, $project_name{$id_key}, $project_description{$id_key}];
Expand Down Expand Up @@ -852,4 +852,26 @@ sub get_related_treatments {
}


sub get_autogenerated_name_metadata_by_breeding_program {
my $self = shift;
my $schema = $self->schema;
my $breeding_program_id = shift;

my $autogenerated_name_metadata_cvterm = SGN::Model::Cvterm->get_cvterm_row($schema, 'autogenerated_name_metadata', 'project_property');
my $program = $schema->resultset('Project::Project')->find({ project_id => $breeding_program_id});

my $name_metadata_hashes;
my $name_metadata_projectprop_rs = $program->projectprops({type_id => $autogenerated_name_metadata_cvterm->cvterm_id});
if ($name_metadata_projectprop_rs->count == 1){
my $name_metadata_string = $name_metadata_projectprop_rs->first->value();
$name_metadata_hashes = decode_json $name_metadata_string;
} else {
return {error => "Error retrieving autogenerated name metadata!\n"};
}

return {name_metadata => $name_metadata_hashes};

}


1;
95 changes: 80 additions & 15 deletions lib/CXGN/Project.pm
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ sub get_year {
my $rs = $self->bcs_schema->resultset('Project::Project')->search( { 'me.project_id' => $self->get_trial_id() })->search_related('projectprops', { 'projectprops.type_id' => $type_id } );

if ($rs->count() == 0) {
return undef;
return;
}
else {
return $rs->first()->value();
Expand Down Expand Up @@ -944,7 +944,7 @@ sub get_project_type {
}
}
}
return undef;
return;

}

Expand Down Expand Up @@ -1029,21 +1029,21 @@ sub get_breeding_program {
my $self = shift;

my $rs = $self->bcs_schema()->resultset("Project::ProjectRelationship")->search({
subject_project_id => $self->get_trial_id(),
type_id => $self->get_breeding_program_trial_relationship_cvterm_id(),
});
subject_project_id => $self->get_trial_id(),
type_id => $self->get_breeding_program_trial_relationship_cvterm_id(),
});
if ($rs->count() == 0) {
return undef;
return;
}

my $bp_rs = $self->bcs_schema()->resultset("Project::Project")->search({
project_id => $rs->first()->object_project_id()
});
project_id => $rs->first()->object_project_id()
});
if ($bp_rs->count > 0) {
return $bp_rs->first()->name();
return $bp_rs->first()->name();
}

return undef;
return;
}

sub set_breeding_program {
Expand Down Expand Up @@ -1344,7 +1344,7 @@ sub get_transplanting_date {
if ($row){
my $harvest_date = $calendar_funcs->display_start_date($row->value());
return $harvest_date;
}
}
else {
return;
}
Expand All @@ -1363,7 +1363,7 @@ sub set_transplanting_date {
});
$row->value($transplanting_event);
$row->update();
}
}
else{
print STDERR "date format did not pass check while preparing to set transplanting date: $transplanting_date \n";
}
Expand All @@ -1377,14 +1377,14 @@ sub remove_transplanting_date {
my $transplanting_date_cvterm_id = $self->get_transplanting_date_cvterm_id();
my $row = $self->bcs_schema->resultset('Project::Projectprop')->find_or_create({
project_id => $self->get_trial_id(),
type_id => $transplanting_date_cvterm_id,
type_id => $transplanting_date_cvterm_id,
value => $transplanting_event,
});
if ($row){
print STDERR "Removing transplanting date $transplanting_event from trial ".$self->get_trial_id()."\n";
$row->delete();
}
}
}
}
else {
print STDERR "date format did not pass check while preparing to delete transplanting date: $transplanting_date \n";
}
Expand Down Expand Up @@ -5385,6 +5385,71 @@ sub genotyping_protocol_count {
}


=head2 function delete_empty_transformation_project()
Usage:
Desc:
Ret:
Args:
Side Effects:
Example:
=cut

sub delete_empty_transformation_project {
my $self = shift;
my $project_id = $self->get_trial_id();

if ($self->transformation_id_count() > 0) {
return 'Cannot delete transformation project with associated transformation IDs.';
}

my $project_owner_schema = CXGN::Phenome::Schema->connect( sub {$self->bcs_schema->storage->dbh()},{on_connect_do => ['SET search_path TO public,phenome;']});
my $project_owner_row = $project_owner_schema->resultset('ProjectOwner')->find( { project_id=> $project_id });
if ($project_owner_row) {
$project_owner_row->delete();
}

eval {
my $row = $self->bcs_schema->resultset("Project::Project")->find( { project_id=> $project_id });
$row->delete();
print STDERR "deleted project ".$project_id."\n";
};
if ($@) {
print STDERR "An error occurred during deletion: $@\n";
return $@;
}
}

=head2 function transformation_id_count()
Usage:
Desc: The number of transformation ids associated with this transformation project
Ret:
Args:
Side Effects:
Example:
=cut

sub transformation_id_count {
my $self = shift;
my $schema = $self->bcs_schema;
my $project_id = $self->get_trial_id();
my $transformation_experiment_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, "transformation_experiment", "experiment_type")->cvterm_id();

my $q = "SELECT count(nd_experiment_project.nd_experiment_id)
FROM nd_experiment_project
JOIN nd_experiment on (nd_experiment_project.nd_experiment_id = nd_experiment.nd_experiment_id)
WHERE nd_experiment.type_id = ?
AND nd_experiment_project.project_id = ?";
my $h = $self->bcs_schema->storage->dbh()->prepare($q);
$h->execute($transformation_experiment_type_id, $project_id);
my ($count) = $h->fetchrow_array();
return $count;
}




1;
Expand Down
Loading

0 comments on commit e7f8435

Please sign in to comment.