$support->log_stamped("Determining list of deleted gene, transcript and translation stable IDs by comparing dbs...\n");
# optionally skip ncRNAs
#
# this is the complete list of ncRNA biotype; you might need to update it (the
# code below will try to help you with this)
my @nc_biotypes = qw(
miRNA
miRNA_pseudogene
misc_RNA
misc_RNA_pseudogene
Mt_rRNA
Mt_tRNA
Mt_tRNA_pseudogene
rRNA
rRNA_pseudogene
scRNA
scRNA_pseudogene
snoRNA
snoRNA_pseudogene
snRNA
snRNA_pseudogene
tRNA_pseudogene
);
if ($support->param('skip_ncrna')) {
%skip_biotypes =
map { $_ => 1 } @nc_biotypes;
# make sure we have a complete list of ncRNA biotypes
my $sql = qq(SELECT DISTINCT biotype from gene);
my $sth1 = $dbh_new->prepare($sql);
$sth1->execute;
my @biotypes_db;
while ((my $biotype) = $sth1->fetchrow_array) {
push @biotypes_db, $biotype unless ($skip_biotypes{$biotype});
}
$sth1->finish;
if (@biotypes_db) {
print "These are the non-ncRNA biotypes found in the db:\n";
map { print
" $_\n" } @biotypes_db;
print "\nPlease check that the list of ncRNA biotypes is still complete, otherwise adapt the script.\n";
exit unless $support->user_proceed("Continue?");
}
}
# optionally skip other biotypes
if ($support->param('skip_biotypes')) {
%skip_biotypes =
map { $_ => 1 } $support->param(
'skip_biotypes');
}
# get old and new genes and transcripts from db
my $ga_old = $dba_old->get_GeneAdaptor;
my @genes_old = @{ $ga_old->fetch_all };
my $ga_new = $dba_new->get_GeneAdaptor;
my %genes_new =
map { $_->stable_id => $_ } @{ $ga_new->fetch_all };
my $ta_new = $dba_new->get_TranscriptAdaptor;
my %tsi_new =
map { $_ => 1 } @{ $ta_new->list_stable_ids };
while (my $g_old = shift(@genes_old)) {
# skip biotypes
next if ($skip_biotypes{$g_old->biotype});
my $gsi = $g_old->stable_id;
# mark gene as deleted
unless ($genes_new{$gsi}) {
$gsi_del{$gsi} = 1;
$genes{$gsi} = $g_old;
}
# transcripts
foreach my $tr (@{ $g_old->get_all_Transcripts }) {
# skip biotypes
next if ($skip_biotypes{$tr->biotype});
my $tsi = $tr->stable_id;
unless ($tsi_new{$tsi}) {
# mark transcript and translation as deleted
$tsi_del{$tsi} = 1;
my $tl = $tr->translation;
$tlsi_del{$tl->stable_id} = 1 if ($tl);
# mark gene as modified
$gsi_mod{$gsi} = 1;
$genes_mod{$gsi} = $g_old;
$genes{$gsi} = $g_old;
}
}
}
# create stable ID strings for use in mysql IN statements
$gsi_string = "'".join("', '", keys(%gsi_del))."'";
$gsi_mod_string = "'".join("', '", keys(%gsi_mod))."'";
$tsi_string = "'".join("', '", keys(%tsi_del))."'";
$tlsi_string = "'".join("', '", keys(%tlsi_del))."'";
# stats
my $fmt = "%-15s%6d\n";
$support->log("Deleted objects found:\n", 1);
$support->log(sprintf($fmt, "genes", scalar(keys(%gsi_del))), 2);
$support->log(sprintf($fmt, "transcripts", scalar(keys(%tsi_del))), 2);
$support->log(sprintf($fmt, "translations", scalar(keys(%tlsi_del))), 2);
$support->log("Modified genes found: ".scalar(keys(%gsi_mod))."\n", 1);
$support->log_stamped("Done.\n\n");
}