<commit_before>### Bio::EnsEMBL::Analysis::RunnableDB::Finished

package Bio::EnsEMBL::Analysis::RunnableDB::Finished;

use strict;
use Bio::EnsEMBL::Utils::Exception qw(verbose throw warning);
use Bio::EnsEMBL::Pipeline::SeqFetcher::Finished_Dfetch;

use base 'Bio::EnsEMBL::Analysis::RunnableDB';

my %ana2extdbid = (
					Uniprot_raw => { "." => 2250 },
					Uniprot_SW => { "-" => 2202 , "^\\w+\\.\\d+" => 2200 },
					Uniprot_TR => { "." => 2000 },
					default => { "." => 700 },
					refseq => { "M_" => 1800, "P_" => 1810, "R_" => 1820,  "^(AC|N[CGTWSZ])_" => 1830 }
				  );

sub get_extdb_id {
	my ($self, $logic_name, $hit_name) = @_;
	my $hash;
	# get the right analysis hash
	foreach (keys %ana2extdbid) {
		if( $logic_name =~ /$_/ ) {
			$hash = $ana2extdbid{$_};
		}
	}
	$hash = $ana2extdbid{default} unless $hash;
	# check the hit_name
	foreach (keys %$hash) {
		if( $hit_name =~ /$_/ ){
			return $hash->{$_};
		}
	}

	throw("Cannot get external_db id for hit $hit_name and analysis $logic_name\n");
}

sub write_output {
	my ($self) = @_;
	my $outputs = $self->Bio::EnsEMBL::Analysis::RunnableDB::Finished::output;
    ### code db_version_searched method may be duplicated in several modules
    ### How does it get written into the input_id_analysis table?
    foreach my $runnable ( @{ $self->runnable } ) {
	    my $db_version = $runnable->get_db_version
	      if $runnable->can('get_db_version');
	    $self->db_version_searched($db_version);    # make sure we set this here
    }
    my $dbh = $self->db->dbc->db_handle;
	$dbh->begin_work;
	eval {
	    # We expect an array of arrays from output()
	    foreach my $output (@$outputs) {
	        next unless @$output;   # No feature output
	        my $feat = $output->[0];
	        my $is_align = ref($feat) =~ /AlignFeature$/ ? 1 : 0;

	        # The type of adaptor used to store the data depends
	        # upon the type of the first element of @$output
	        my $adaptor = $self->get_adaptor($feat);
		    # Remove the AlignFeatures already in db from the output and
		    # get rid of the old ones in the db (for dephtfilter features only)
		    my $all = 0;
	        if ($is_align) {
	            $all = 1 if($self->analysis->module =~ /DepthFilter/ );
	            $self->remove_stored_AlignFeatures($adaptor, $output, $all);
	            $self->write_descriptions($output) unless ( $all || $self->analysis->logic_name =~ /refseq/);
	        } else {# Remove all SimpleFeatures
	        	$self->remove_all_features($adaptor);
	        }

		    my $analysis = $self->analysis;
		    my $logic	 = $analysis->logic_name;
	    	my $slice    = $self->query;
		    my $ff       = $self->feature_factory;

	        foreach my $feature (@$output) {
				if($is_align){
					my $hit_name = $feature->hseqname;
					$feature->external_db_id($self->get_extdb_id($logic,$hit_name));
				}
	        	$feature->analysis($analysis);
	        	$feature->slice($slice) if (!$feature->slice);
	        	$ff->validate($feature);
	        }
	        if($adaptor->can('db_version')) {
	        	$adaptor->db_version($self->db_version_searched);
	        }
	        # Store features in the database
	        print STDOUT "Finished: Writting ".scalar(@$output)." new ".ref($feat)." in the database\n";
	        $adaptor->store(@$output) unless !@$output;<commit_msg>fixed typo<commit_after>### Bio::EnsEMBL::Analysis::RunnableDB::Finished

package Bio::EnsEMBL::Analysis::RunnableDB::Finished;

use strict;
use Bio::EnsEMBL::Utils::Exception qw(verbose throw warning);
use Bio::EnsEMBL::Pipeline::SeqFetcher::Finished_Dfetch;

use base 'Bio::EnsEMBL::Analysis::RunnableDB';

my %ana2extdbid = (
					Uniprot_raw => { "." => 2250 },
					Uniprot_SW => { "-" => 2202 , "^\\w+\\.\\d+" => 2200 },
					Uniprot_TR => { "." => 2000 },
					default => { "." => 700 },
					refseq => { "M_" => 1800, "P_" => 1810, "R_" => 1820,  "^(AC|N[CGTWSZ])_" => 1830 }
				  );

sub get_extdb_id {
	my ($self, $logic_name, $hit_name) = @_;
	my $hash;
	# get the right analysis hash
	foreach (keys %ana2extdbid) {
		if( $logic_name =~ /$_/ ) {
			$hash = $ana2extdbid{$_};
		}
	}
	$hash = $ana2extdbid{default} unless $hash;
	# check the hit_name
	foreach (keys %$hash) {
		if( $hit_name =~ /$_/ ){
			return $hash->{$_};
		}
	}

	throw("Cannot get external_db id for hit $hit_name and analysis $logic_name\n");
}

sub write_output {
	my ($self) = @_;
	my $outputs = $self->Bio::EnsEMBL::Analysis::RunnableDB::Finished::output;
    ### code db_version_searched method may be duplicated in several modules
    ### How does it get written into the input_id_analysis table?
    foreach my $runnable ( @{ $self->runnable } ) {
	    my $db_version = $runnable->get_db_version
	      if $runnable->can('get_db_version');
	    $self->db_version_searched($db_version);    # make sure we set this here
    }
    my $dbh = $self->db->dbc->db_handle;
	$dbh->begin_work;
	eval {
	    # We expect an array of arrays from output()
	    foreach my $output (@$outputs) {
	        next unless @$output;   # No feature output
	        my $feat = $output->[0];
	        my $is_align = ref($feat) =~ /AlignFeature$/ ? 1 : 0;

	        # The type of adaptor used to store the data depends
	        # upon the type of the first element of @$output
	        my $adaptor = $self->get_adaptor($feat);
		    # Remove the AlignFeatures already in db from the output and
		    # get rid of the old ones in the db (for dephtfilter features only)
		    my $all = 0;
	        if ($is_align) {
	            $all = 1 if($self->analysis->module =~ /DepthFilter/ );
	            $self->remove_stored_AlignFeatures($adaptor, $output, $all);
	            $self->write_descriptions($output) unless ( $all || $self->analysis->logic_name =~ /refseq/);
	        } else {# Remove all SimpleFeatures
	        	$self->remove_all_features($adaptor);
	        }

		    my $analysis = $self->analysis;
		    my $logic	 = $analysis->logic_name;
	    	my $slice    = $self->query;
		    my $ff       = $self->feature_factory;

	        foreach my $feature (@$output) {
				if($is_align){
					my $hit_name = $feature->hseqname;
					$feature->external_db_id($self->get_extdb_id($logic,$hit_name));
				}
	        	$feature->analysis($analysis);
	        	$feature->slice($slice) if (!$feature->slice);
	        	$ff->validate($feature);
	        }
	        if($adaptor->can('db_version')) {
	        	$adaptor->db_version($self->db_version_searched);
	        }
	        # Store features in the database
	        print STDOUT "Finished: Writing ".scalar(@$output)." new ".ref($feat)." in the database\n";
	        $adaptor->store(@$output) unless !@$output;
{'fraction_non_alphanumeric': 0.16335740072202165, 'fraction_numerical': 0.013237063778580024, 'mean_word_length': 2.879229871645274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 99, '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': '2646289', 'n_tokens_mistral': 2568, 'n_tokens_neox': 2231, 'n_words': 534}