From 40f4af189a651790f9e6d7057e8dcce942bee266 Mon Sep 17 00:00:00 2001 From: Kim Rutherford Date: Tue, 11 Jun 2024 11:29:13 +1200 Subject: [PATCH] Remove unused organisms after updating After updating genes using the latest species_strain_map, clean up unused organisms. Refs pombase/canto#2831 --- etc/reapply_species_strain_map.pl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/etc/reapply_species_strain_map.pl b/etc/reapply_species_strain_map.pl index 2e47d5c19..2ece7e3a2 100755 --- a/etc/reapply_species_strain_map.pl +++ b/etc/reapply_species_strain_map.pl @@ -102,8 +102,29 @@ BEGIN $gene->update(); } } + + # Remove unused organisms + $organism_rs = $curs_schema->resultset('Organism'); + + while (defined (my $organism = $organism_rs->next())) { + if ($organism->genes()->count() == 0 && + $organism->genotypes()->count() == 0) { + my $strain_rs = $organism->strains(); + + while (defined (my $strain = $strain_rs->next())) { + if ($strain->genotypes()->count() == 0) { + $strain->delete(); + } + } + + if ($strain_rs->count() == 0) { + $organism->delete(); + } + } + } }; + my $load_util = Canto::Track::LoadUtil->new(schema => $schema);