<commit_before>package Bio::EnsEMBL::Pipeline::FASTA::EmailSummary;

use strict;
use warnings;
use base qw/Bio::EnsEMBL::Hive::RunnableDB::NotifyByEmail/;
use Bio::EnsEMBL::Hive::Utils qw/destringify/;

sub fetch_input {
  my ($self) = @_;
  my $dump_dna = $self->jobs('DumpDNA');
  my $copy_dna = $self->jobs('CopyDNA');
  my $dump_genes = $self->jobs('DumpGenes');
  my $blast_dna = $self->jobs('BlastDNAIndex');
  my $blast_gene = $self->jobs('BlastGeneIndex');
  my $blast_pep = $self->jobs('BlastPepIndex');
  my $blat = $self->jobs('BlatDNAIndex', 100);
  my $blat_sm = $self->jobs('BlatSmDNAIndex', 100);
    
  my @args = (
    $dump_dna->{count},
    $copy_dna->{count},
    $dump_genes->{count},
    $blast_dna->{count},
    $blast_gene->{count},
    $blast_pep->{count},
    $blat->{count},
    $blat_sm->{count},
    $self->failed(),
    $self->summary($dump_dna),
    $self->summary($copy_dna),
    $self->summary($dump_genes),
    $self->summary($blast_dna),
    $self->summary($blast_gene),
    $self->summary($blast_pep),
    $self->summary($blat),
    $self->summary($blat_sm),
  );
  
  my $msg = sprintf(<<'MSG', @args);
Your FASTA Pipeline has finished. We have:

  * %d species with new DNA Dumped
  * %d species with copied DNA
  * %d species with genes dumped
  * %d species with BLAST DNA indexes generated
  * %d species with BLAST GENE indexes generated
  * %d species with BLAST PEPTIDE indexes generated
  * %d species with BLAT DNA generated
  * %d species with BLAT SM DNA generated

%s

===============================================================================

Full breakdown follows ...

%s

%s

%s

%s

%s

%s

%s

%s

MSG
}

sub jobs {
  my ($self, $logic_name, $minimum_runtime) = @_;
  my $aa = $self->db->get_AnalysisAdaptor();
  my $aja = $self->db->get_AnalysisJobAdaptor();
  my $analysis = $aa->fetch_by_logic_name($logic_name);
  my $id = $analysis->dbID();
  my @jobs = @{$aja->generic_fetch('j.analysis_id =$id')};
  $_->{input} = destringify($_->input_id()) for @jobs;
  @jobs = 
    sort { $a->{input}->{species} cmp $b->{input}->{species} }
    grep { 1 if ! $minimum_runtime; $minimum_runtime > $_->runtime_msec() }  
    @jobs;
  return {
    analysis => $analysis,
    name => $logic_name,
    jobs => \@jobs,
    count => scalar(@jobs)
  };
}


sub failed {
  my ($self) = @_;<commit_msg> Need double quotes<commit_after>package Bio::EnsEMBL::Pipeline::FASTA::EmailSummary;

use strict;
use warnings;
use base qw/Bio::EnsEMBL::Hive::RunnableDB::NotifyByEmail/;
use Bio::EnsEMBL::Hive::Utils qw/destringify/;

sub fetch_input {
  my ($self) = @_;
  my $dump_dna = $self->jobs('DumpDNA');
  my $copy_dna = $self->jobs('CopyDNA');
  my $dump_genes = $self->jobs('DumpGenes');
  my $blast_dna = $self->jobs('BlastDNAIndex');
  my $blast_gene = $self->jobs('BlastGeneIndex');
  my $blast_pep = $self->jobs('BlastPepIndex');
  my $blat = $self->jobs('BlatDNAIndex', 100);
  my $blat_sm = $self->jobs('BlatSmDNAIndex', 100);
    
  my @args = (
    $dump_dna->{count},
    $copy_dna->{count},
    $dump_genes->{count},
    $blast_dna->{count},
    $blast_gene->{count},
    $blast_pep->{count},
    $blat->{count},
    $blat_sm->{count},
    $self->failed(),
    $self->summary($dump_dna),
    $self->summary($copy_dna),
    $self->summary($dump_genes),
    $self->summary($blast_dna),
    $self->summary($blast_gene),
    $self->summary($blast_pep),
    $self->summary($blat),
    $self->summary($blat_sm),
  );
  
  my $msg = sprintf(<<'MSG', @args);
Your FASTA Pipeline has finished. We have:

  * %d species with new DNA Dumped
  * %d species with copied DNA
  * %d species with genes dumped
  * %d species with BLAST DNA indexes generated
  * %d species with BLAST GENE indexes generated
  * %d species with BLAST PEPTIDE indexes generated
  * %d species with BLAT DNA generated
  * %d species with BLAT SM DNA generated

%s

===============================================================================

Full breakdown follows ...

%s

%s

%s

%s

%s

%s

%s

%s

MSG
}

sub jobs {
  my ($self, $logic_name, $minimum_runtime) = @_;
  my $aa = $self->db->get_AnalysisAdaptor();
  my $aja = $self->db->get_AnalysisJobAdaptor();
  my $analysis = $aa->fetch_by_logic_name($logic_name);
  my $id = $analysis->dbID();
  my @jobs = @{$aja->generic_fetch("j.analysis_id =$id")};
  $_->{input} = destringify($_->input_id()) for @jobs;
  @jobs = 
    sort { $a->{input}->{species} cmp $b->{input}->{species} }
    grep { 1 if ! $minimum_runtime; $minimum_runtime > $_->runtime_msec() }  
    @jobs;
  return {
    analysis => $analysis,
    name => $logic_name,
    jobs => \@jobs,
    count => scalar(@jobs)
  };
}


sub failed {
  my ($self) = @_;
{'fraction_non_alphanumeric': 0.21413367390378885, 'fraction_numerical': 0.002979991485738612, 'mean_word_length': 3.946315789473684, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3308215', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1739, 'n_words': 375}