Skip to content

Commit 40f4af1

Browse files
committed
Remove unused organisms after updating
After updating genes using the latest species_strain_map, clean up unused organisms. Refs #2831
1 parent 9b325f2 commit 40f4af1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

etc/reapply_species_strain_map.pl

+21
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,29 @@ BEGIN
102102
$gene->update();
103103
}
104104
}
105+
106+
# Remove unused organisms
107+
$organism_rs = $curs_schema->resultset('Organism');
108+
109+
while (defined (my $organism = $organism_rs->next())) {
110+
if ($organism->genes()->count() == 0 &&
111+
$organism->genotypes()->count() == 0) {
112+
my $strain_rs = $organism->strains();
113+
114+
while (defined (my $strain = $strain_rs->next())) {
115+
if ($strain->genotypes()->count() == 0) {
116+
$strain->delete();
117+
}
118+
}
119+
120+
if ($strain_rs->count() == 0) {
121+
$organism->delete();
122+
}
123+
}
124+
}
105125
};
106126

127+
107128
my $load_util = Canto::Track::LoadUtil->new(schema => $schema);
108129

109130

0 commit comments

Comments
 (0)