<commit_before>#!/usr/bin/env perl

=head1 LICENSE

  Copyright (c) 1999-2011 The European Bioinformatics Institute and
  Genome Research Limited.  All rights reserved.

  This software is distributed under a modified Apache license.
  For license details, please see

    http://www.ensembl.org/info/about/code_licence.html

=head1 CONTACT

  Please email comments or questions to the public Ensembl
  developers list at <<EMAIL>>.

  Questions may also be sent to the Ensembl help desk at
  <<EMAIL>>.

=head1 DESCRIPTION

This script is used to find which genomes have changed between two releases of Ensembl Bacteria

=head1 AUTHOR

dstaines

=head1 MAINTANER

$Author$
=head1 VERSION

$Revision$
=cut

use strict;
use warnings;

use Pod::Usage;
use Bio::EnsEMBL::Utils::CliHelper;
use Bio::EnsEMBL::DBSQL::DBConnection;
use Log::Log4perl qw(:easy);
use Data::Dumper;
use Carp;

Log::Log4perl->easy_init($INFO);
my $logger = get_logger();

my $cli_helper = Bio::EnsEMBL::Utils::CliHelper->new();
# get the basic options for connecting to a database server
my $optsd = [@{$cli_helper->get_dba_opts("prev")}, @{$cli_helper->get_dba_opts()}];

my $opts = $cli_helper->process_args($optsd, \&pod2usage);

my $dbc      = Bio::EnsEMBL::DBSQL::DBConnection->new(-USER => $opts->{user},     -PASS => $opts->{pass},     -HOST => $opts->{host},     -PORT => $opts->{port});
my $prev_dbc = Bio::EnsEMBL::DBSQL::DBConnection->new(-USER => $opts->{prevuser}, -PASS => $opts->{prevpass}, -HOST => $opts->{prevhost}, -PORT => $opts->{prevport});
my $genomes  = genome_details($dbc);
my $prev_genomes = genome_details($prev_dbc);

# new genomes
my $new_genomes = [];
# genomes with new assemblies
my $new_assemblies = [];
# genomes with new genebuilds
my $new_genebuilds = [];
# genomes with updated genebuild version (==annotation)
my $new_annotations = [];
# renamed genomes
my $renamed_genomes = [];
# removed genomes
my $removed_genomes = [];
while (my ($set_chain, $genome) = each %{$genomes->{genomes}}) {
  my $prev_genome = $prev_genomes->{genomes}->{$set_chain};
  if (!defined $prev_genome) {
	push @$new_genomes, $genome;
  } else {
	if ($genome->{name} ne $prev_genome->{name}) {
	  push @$renamed_genomes, {new => $genome, old => $prev_genome};
	}
	if ($genome->{assembly} ne $prev_genome->{assembly}) {
	  push @$new_assemblies, {new => $genome, old => $prev_genome};
	} elsif ($genome->{genebuild_version} ne $prev_genome->{genebuild_version}) {
	  push @$new_annotations, {new => $genome, old => $prev_genome};
	}
  }
}

while (my ($set_chain, $genome) = each %{$prev_genomes->{genomes}}) {
  if (!defined $genomes->{genomes}->{$set_chain}) {
	push @$removed_genomes, $genome;
  }
}

# print to file
# new genomes
# name assembly database species_id
write_to_file(
  $new_genomes,
  "new_genomes.txt",
  [qw/name assembly database species_id/],
  sub {
	return [$_[0]->{name}, $_[0]->{assembly}, $_[0]->{database}, $_[0]->{species_id}];
  });

# updated assemblies
# name old_assembly new_assembly database species_id
write_to_file(
  $new_assemblies,
  "updated_assemblies.txt",
  [qw/name assembly old_assembly  database species_id/],
  sub {
	return [$_[0]->{new}->{name}, $_[0]->{new}->{assembly}, $_[0]->{old}->{assembly}, $_[0]->{new}->{database}, $_[0]->{new}->{species_id}];
  });

# updated annotation
# name assembly old_genebuild new_genebuild database species_id
write_to_file(
  $new_annotations,
  "updated_annotations.txt",
  [qw/name assembly old_genebuild new_genebuild database species_id/],
  sub {
	return [$_[0]->{new}->{name}, $_[0]->{new}->{assembly}, $_[0]->{new}->{genebuild_version}, $_[0]->{old}->{genebuild_version}, $_[0]->{new}->{database}, $_[0]->{new}->{species_id}];
  });

# renamed genomes
# name assembly old_name database species_id
write_to_file(
  $renamed_genomes,
  "renamed_genomes.txt",
  [qw/ name assembly old_name database species_id /],
  sub {
	return [$_[0]->{new}->{name}, $_[0]->{new}->{assembly}, $_[0]->{old}->{name}, $_[0]->{new}->{database}, $_[0]->{new}->{species_id}];
  });

# removed genomes
# name assembly database species_id
write_to_file(
  $removed_genomes,
  "removed_genomes.txt",
  [qw/ name assembly database species_id /],
  sub {
	return [$_[0]->{name}, $_[0]->{assembly}, $_[0]->{database}, $_[0]->{species_id}];
  });

my $report = $genomes->{report};
$report->{new_genomes}     = scalar @$new_genomes;
$report->{new_assemblies}  = scalar @$new_assemblies;
$report->{new_annotations} = scalar @$new_annotations;
$report->{renamed_genomes} = scalar @$renamed_genomes;
$report->{removed_genomes} = scalar @$removed_genomes;

my $summary_file = "summary.txt";
$logger->info("Writing summary to $summary_file");
my $news = <<END;
Release $report->{eg_version} Ensembl Bacteria has been loaded from EMBL-Bank release XXX into $report->{databases} multispecies Ensembl v$report->{ens_version} databases.  The current dataset contains $report->{genomes} genomes ($report->{eubacteria} eubacteria and $report->{archaea} archaea) containing $report->{protein_coding} protein coding genes loaded from $report->{seq_regions} INSDC entries. This release includes $report->{new_genomes} new genomes, $report->{new_assemblies} genomes with updated assemblies, $report->{new_annotations} genomes with updated annotation, $report->{renamed_genomes} genomes where the assigned name has changed, and $report->{removed_genomes} genomes removed since the last release.
END
open my $summary, ">", "$summary_file" || croak "Could not open $summary_file for writing";
print $summary $news;
close $summary;
<commit_msg>added brief note generation<commit_after>#!/usr/bin/env perl

=head1 LICENSE

  Copyright (c) 1999-2011 The European Bioinformatics Institute and
  Genome Research Limited.  All rights reserved.

  This software is distributed under a modified Apache license.
  For license details, please see

    http://www.ensembl.org/info/about/code_licence.html

=head1 CONTACT

  Please email comments or questions to the public Ensembl
  developers list at <<EMAIL>>.

  Questions may also be sent to the Ensembl help desk at
  <<EMAIL>>.

=head1 DESCRIPTION

This script is used to find which genomes have changed between two releases of Ensembl Bacteria

=head1 AUTHOR

dstaines

=head1 MAINTANER

$Author$
=head1 VERSION

$Revision$
=cut

use strict;
use warnings;

use Pod::Usage;
use Bio::EnsEMBL::Utils::CliHelper;
use Bio::EnsEMBL::DBSQL::DBConnection;
use Log::Log4perl qw(:easy);
use Data::Dumper;
use Carp;

Log::Log4perl->easy_init($INFO);
my $logger = get_logger();

my $cli_helper = Bio::EnsEMBL::Utils::CliHelper->new();
# get the basic options for connecting to a database server
my $optsd = [@{$cli_helper->get_dba_opts("prev")}, @{$cli_helper->get_dba_opts()}];

my $opts = $cli_helper->process_args($optsd, \&pod2usage);

my $dbc      = Bio::EnsEMBL::DBSQL::DBConnection->new(-USER => $opts->{user},     -PASS => $opts->{pass},     -HOST => $opts->{host},     -PORT => $opts->{port});
my $prev_dbc = Bio::EnsEMBL::DBSQL::DBConnection->new(-USER => $opts->{prevuser}, -PASS => $opts->{prevpass}, -HOST => $opts->{prevhost}, -PORT => $opts->{prevport});
my $genomes  = genome_details($dbc);
my $prev_genomes = genome_details($prev_dbc);

# new genomes
my $new_genomes = [];
# genomes with new assemblies
my $new_assemblies = [];
# genomes with new genebuilds
my $new_genebuilds = [];
# genomes with updated genebuild version (==annotation)
my $new_annotations = [];
# renamed genomes
my $renamed_genomes = [];
# removed genomes
my $removed_genomes = [];
while (my ($set_chain, $genome) = each %{$genomes->{genomes}}) {
  my $prev_genome = $prev_genomes->{genomes}->{$set_chain};
  if (!defined $prev_genome) {
	push @$new_genomes, $genome;
  } else {
	if ($genome->{name} ne $prev_genome->{name}) {
	  push @$renamed_genomes, {new => $genome, old => $prev_genome};
	}
	if ($genome->{assembly} ne $prev_genome->{assembly}) {
	  push @$new_assemblies, {new => $genome, old => $prev_genome};
	} elsif ($genome->{genebuild_version} ne $prev_genome->{genebuild_version}) {
	  push @$new_annotations, {new => $genome, old => $prev_genome};
	}
  }
}

while (my ($set_chain, $genome) = each %{$prev_genomes->{genomes}}) {
  if (!defined $genomes->{genomes}->{$set_chain}) {
	push @$removed_genomes, $genome;
  }
}

# print to file
# new genomes
# name assembly database species_id
write_to_file(
  $new_genomes,
  "new_genomes.txt",
  [qw/name assembly database species_id/],
  sub {
	return [$_[0]->{name}, $_[0]->{assembly}, $_[0]->{database}, $_[0]->{species_id}];
  });

# updated assemblies
# name old_assembly new_assembly database species_id
write_to_file(
  $new_assemblies,
  "updated_assemblies.txt",
  [qw/name assembly old_assembly  database species_id/],
  sub {
	return [$_[0]->{new}->{name}, $_[0]->{new}->{assembly}, $_[0]->{old}->{assembly}, $_[0]->{new}->{database}, $_[0]->{new}->{species_id}];
  });

# updated annotation
# name assembly old_genebuild new_genebuild database species_id
write_to_file(
  $new_annotations,
  "updated_annotations.txt",
  [qw/name assembly old_genebuild new_genebuild database species_id/],
  sub {
	return [$_[0]->{new}->{name}, $_[0]->{new}->{assembly}, $_[0]->{new}->{genebuild_version}, $_[0]->{old}->{genebuild_version}, $_[0]->{new}->{database}, $_[0]->{new}->{species_id}];
  });

# renamed genomes
# name assembly old_name database species_id
write_to_file(
  $renamed_genomes,
  "renamed_genomes.txt",
  [qw/ name assembly old_name database species_id /],
  sub {
	return [$_[0]->{new}->{name}, $_[0]->{new}->{assembly}, $_[0]->{old}->{name}, $_[0]->{new}->{database}, $_[0]->{new}->{species_id}];
  });

# removed genomes
# name assembly database species_id
write_to_file(
  $removed_genomes,
  "removed_genomes.txt",
  [qw/ name assembly database species_id /],
  sub {
	return [$_[0]->{name}, $_[0]->{assembly}, $_[0]->{database}, $_[0]->{species_id}];
  });

my $report = $genomes->{report};
$report->{new_genomes}     = scalar @$new_genomes;
$report->{new_assemblies}  = scalar @$new_assemblies;
$report->{new_annotations} = scalar @$new_annotations;
$report->{renamed_genomes} = scalar @$renamed_genomes;
$report->{removed_genomes} = scalar @$removed_genomes;

my $summary_file = "summary.txt";
$logger->info("Writing summary to $summary_file");
my $news = <<END;
Release $report->{eg_version} of Ensembl Bacteria has been loaded from EMBL-Bank release XXX into $report->{databases} multispecies Ensembl v$report->{ens_version} databases.  The current dataset contains $report->{genomes} genomes ($report->{eubacteria} bacteria and $report->{archaea} archaea) containing $report->{protein_coding} protein coding genes loaded from $report->{seq_regions} INSDC entries. This release includes $report->{new_genomes} new genomes, $report->{new_assemblies} genomes with updated assemblies, $report->{new_annotations} genomes with updated annotation, $report->{renamed_genomes} genomes where the assigned name has changed, and $report->{removed_genomes} genomes removed since the last release.

Ensembl Bacteria has been updated to include the latest versions of $report->{genomes} genomes ($report->{eubacteria} bacteria and $report->{archaea} archaea) from the INSDC archives.
END
open my $summary, ">", "$summary_file" || croak "Could not open $summary_file for writing";
print $summary $news;
close $summary;

{'fraction_non_alphanumeric': 0.173161699876565, 'fraction_numerical': 0.0072297654734614705, 'mean_word_length': 5.4965635738831615, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 218, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4655274', 'n_tokens_mistral': 4089, 'n_tokens_neox': 3922, 'n_words': 972}