Skip to content
Open
Show file tree
Hide file tree
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
37 changes: 37 additions & 0 deletions lib/CXGN/Cvterm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,43 @@ sub _store_cvtermprop {



sub add_parent_terms {
my $self = shift;
my $parent_ids = shift;

my $schema = $self->schema();
my $cvterm_id = $self->cvterm_id();

my $relationship_cv = $schema->resultset("Cv::Cv")->find({ name => 'relationship' });
die "No 'relationship' CV found in the database.\n" unless $relationship_cv;
my $rel_cv_id = $relationship_cv->cv_id();

my $variable_of = $schema->resultset("Cv::Cvterm")->find({ name => 'VARIABLE_OF', cv_id => $rel_cv_id });
my $isa = $schema->resultset("Cv::Cvterm")->find({ name => 'is_a', cv_id => $rel_cv_id });
die "No 'is_a' relationship type found.\n" unless $isa;

my $type_id = $isa->cvterm_id();
if ($variable_of) {
my $has_variable_of = $schema->resultset("Cv::CvtermRelationship")->search({
subject_id => $cvterm_id,
type_id => $variable_of->cvterm_id(),
})->count();
if ($has_variable_of > 0) {
$type_id = $variable_of->cvterm_id();
}
}

$schema->txn_do(sub {
for my $parent_id (@$parent_ids) {
$schema->resultset("Cv::CvtermRelationship")->find_or_create({
subject_id => $cvterm_id,
object_id => $parent_id,
type_id => $type_id,
});
}
});
}

__PACKAGE__->meta->make_immutable;

##########
Expand Down
49 changes: 27 additions & 22 deletions lib/CXGN/Trait.pm
Original file line number Diff line number Diff line change
Expand Up @@ -795,11 +795,11 @@ sub delete_existing_synonyms {

sub interactive_store {
my $self = shift;
my $parent_term = shift;
my $parent_terms_json = shift;

my $schema = $self->bcs_schema();

my $parent_id;
my @parent_ids;

my $name = $self->name() || die "No name found.\n";
my $definition = $self->definition() || die "No definition found.\n";
Expand Down Expand Up @@ -878,17 +878,20 @@ sub interactive_store {

my $db_name = $h->fetchrow_array();

if ($parent_term) {
my $parent_terms = [];
if ($parent_terms_json) {
$parent_terms = decode_json($parent_terms_json);
}

if (@$parent_terms) {
my $lt = CXGN::List::Transform->new();

my $transform = $lt->transform($schema, "traits_2_trait_ids", [$parent_term]);
my $transform = $lt->transform($schema, "traits_2_trait_ids", $parent_terms);

if (@{$transform->{missing}}>0) {
die "Parent term $parent_term could not be found in the database.\n";
if (@{$transform->{missing}} > 0) {
die "Parent term(s) " . join(", ", @{$transform->{missing}}) . " could not be found in the database.\n";
}

my @parent_id_list = @{$transform->{transform}};
$parent_id = $parent_id_list[0];
@parent_ids = @{$transform->{transform}};
} else {
my $ontology_obj = CXGN::Onto->new({
schema => $schema
Expand All @@ -897,7 +900,7 @@ sub interactive_store {

my $root_term_name = $root_nodes[0]->[1] =~ s/\w+:\d+ //r;

$parent_id = $schema->resultset("Cv::Cvterm")->find({
push @parent_ids, $schema->resultset("Cv::Cvterm")->find({
name => $root_term_name,
cv_id => $root_nodes[0]->[0]
})->cvterm_id();
Expand Down Expand Up @@ -947,18 +950,20 @@ sub interactive_store {
dbxref => "$zeroes"."$accession_num"
})->cvterm_id();

if ($format eq "ontology") {
$schema->resultset("Cv::CvtermRelationship")->find_or_create({
object_id => $parent_id,
subject_id => $new_trait_id,
type_id => $isa_id
});
} else {
$schema->resultset("Cv::CvtermRelationship")->find_or_create({
object_id => $parent_id,
subject_id => $new_trait_id,
type_id => $variable_of_id
});
foreach my $pid (@parent_ids) {
if ($format eq "ontology") {
$schema->resultset("Cv::CvtermRelationship")->find_or_create({
object_id => $pid,
subject_id => $new_trait_id,
type_id => $isa_id
});
} else {
$schema->resultset("Cv::CvtermRelationship")->find_or_create({
object_id => $pid,
subject_id => $new_trait_id,
type_id => $variable_of_id
});
}
}

$new_trait = $schema->resultset("Cv::Cvterm")->find({
Expand Down
48 changes: 28 additions & 20 deletions lib/CXGN/Trait/Treatment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,26 @@ sub BUILD {

sub store {
my $self = shift;
my $parent_term = shift;
my $parent_terms_json = shift;

my $schema = $self->bcs_schema();


my $parent_terms = [];
if ($parent_terms_json) {
$parent_terms = decode_json($parent_terms_json);
}
if (!@$parent_terms) {
$parent_terms = ['Experimental treatment ontology|EXPERIMENT_TREATMENT:0000000'];
}

my $lt = CXGN::List::Transform->new();

my $transform = $lt->transform($schema, "traits_2_trait_ids", [$parent_term]);
my $transform = $lt->transform($schema, "traits_2_trait_ids", $parent_terms);

if (@{$transform->{missing}}>0) {
die "Parent term $parent_term could not be found in the database.\n";
if (@{$transform->{missing}} > 0) {
die "Parent term(s) " . join(", ", @{$transform->{missing}}) . " could not be found in the database.\n";
}

my @parent_id_list = @{$transform->{transform}};
my $parent_id = $parent_id_list[0];
my @parent_ids = @{$transform->{transform}};

my $name = $self->name() || die "No name found.\n";
my $definition = $self->definition() || die "No definition found.\n";
Expand Down Expand Up @@ -166,18 +172,20 @@ sub store {
dbxref => "$zeroes"."$accession_num"
})->cvterm_id();

if ($format eq "ontology") {
$schema->resultset("Cv::CvtermRelationship")->find_or_create({
object_id => $parent_id,
subject_id => $new_treatment_id,
type_id => $isa_id
});
} else {
$schema->resultset("Cv::CvtermRelationship")->find_or_create({
object_id => $parent_id,
subject_id => $new_treatment_id,
type_id => $variable_of_id
});
foreach my $pid (@parent_ids) {
if ($format eq "ontology") {
$schema->resultset("Cv::CvtermRelationship")->find_or_create({
object_id => $pid,
subject_id => $new_treatment_id,
type_id => $isa_id
});
} else {
$schema->resultset("Cv::CvtermRelationship")->find_or_create({
object_id => $pid,
subject_id => $new_treatment_id,
type_id => $variable_of_id
});
}
}

$new_treatment = $schema->resultset("Cv::Cvterm")->find({
Expand Down
Loading
Loading