<commit_before>
### Bio::EnsEMBL::Pipeline::Runnable::Finished_MiniEst2Genome

package Bio::EnsEMBL::Pipeline::Runnable::Finished_MiniEst2Genome;

use strict;
use Bio::EnsEMBL::Pipeline::Runnable::Finished_Est2Genome;
# Inherit from MiniEst2Genome
use Bio::EnsEMBL::Pipeline::Runnable::MiniEst2Genome;
use Bio::EnsEMBL::DnaDnaAlignFeature;
use vars '@ISA';
@ISA = ('Bio::EnsEMBL::Pipeline::Runnable::MiniEst2Genome');

sub run_blaste2g {
    my ( $self, $est, $features ) = @_;
    
    my $miniseq = $self->make_miniseq(@$features);

    my $hseq    = $self->get_Sequence($est) or $self->throw("Can't fetch sequence for id '$est'");

    my $eg = new Bio::EnsEMBL::Pipeline::Runnable::Finished_Est2Genome(
        -genomic => $miniseq->get_cDNA_sequence,
        -est     => $hseq,
    );
    $eg->run;

     foreach my $fp ( @{$eg->output} ) {

         my @converted = $miniseq->convert_FeaturePair($fp);

         if ( @converted > 1 ) {
             warn "feature converts into '" . scalar(@converted) . "' > 1 features - ignoring\n";
         } else {
            # convert_FeaturePair zaps strand and hseqname,0
            # so we put them back here.
            my $new = $converted[0];

#            $new->seqname( $fp->hseqname );  # 
#            $new->strand( $fp->strand );     #
#            $new->hseqname( $fp->hseqname ); #
#            $new->percent_id( $fp->percent_id ); #
#            $new->feature2->percent_id( $fp->percent_id ); #
# reverse logic here, change the $fp passed to equal the converted [miniseq]
# change seqname, hend, hstart, gsf_start, gsf_end
# hend & hstart appear to only be calculated from the length of the end & start
# producing the same length for the hit as the contig.  not good....
#	    $fp->hend(   $new->hend   );
#	    $fp->hstart( $new->hstart );
	    $fp->end(    $new->end   );
	    $fp->start(  $new->start );
#            $self->add_output(@converted);
#	    print STDERR "CIGAR_STRING : " . $fp->cigar_string . "\n";
#	    print STDERR $fp->gffstring . "\n";
            $self->add_output($fp);
        }
     }
}


sub add_output{
    my($self, @feat_pairs) = @_;
    push( @{ $self->{'_output'} } , @feat_pairs);
}

1;

__END__

=head1 NAME - Bio::EnsEMBL::Pipeline::Runnable::Finished_MiniEst2Genome

=head1 AUTHOR

<NAME><email> <EMAIL>
<commit_msg>Fix a big problem with not doing something useful with est2genome throws.<commit_after>
### Bio::EnsEMBL::Pipeline::Runnable::Finished_MiniEst2Genome

package Bio::EnsEMBL::Pipeline::Runnable::Finished_MiniEst2Genome;

use strict;
use Bio::EnsEMBL::Pipeline::Runnable::Finished_Est2Genome;
# Inherit from MiniEst2Genome
use Bio::EnsEMBL::Pipeline::Runnable::MiniEst2Genome;
use Bio::EnsEMBL::DnaDnaAlignFeature;
use vars '@ISA';
@ISA = ('Bio::EnsEMBL::Pipeline::Runnable::MiniEst2Genome');

sub run_blaste2g {
    my ( $self, $est, $features ) = @_;
    
    my $miniseq = $self->make_miniseq(@$features);

    my $hseq    = $self->get_Sequence($est) or $self->throw("Can't fetch sequence for id '$est'");

    my $eg = new Bio::EnsEMBL::Pipeline::Runnable::Finished_Est2Genome(
        -genomic => $miniseq->get_cDNA_sequence,
        -est     => $hseq,
    );
    $eg->run;

     foreach my $fp ( @{$eg->output} ) {

         my @converted = $miniseq->convert_FeaturePair($fp);

         if ( @converted > 1 ) {
             warn "feature converts into '" . scalar(@converted) . "' > 1 features - ignoring\n";
         } else {
            # convert_FeaturePair zaps strand and hseqname,0
            # so we put them back here.
            my $new = $converted[0];

#            $new->seqname( $fp->hseqname );  # 
#            $new->strand( $fp->strand );     #
#            $new->hseqname( $fp->hseqname ); #
#            $new->percent_id( $fp->percent_id ); #
#            $new->feature2->percent_id( $fp->percent_id ); #
# reverse logic here, change the $fp passed to equal the converted [miniseq]
# change seqname, hend, hstart, gsf_start, gsf_end
# hend & hstart appear to only be calculated from the length of the end & start
# producing the same length for the hit as the contig.  not good....
#	    $fp->hend(   $new->hend   );
#	    $fp->hstart( $new->hstart );
	    $fp->end(    $new->end   );
	    $fp->start(  $new->start );
#            $self->add_output(@converted);
#	    print STDERR "CIGAR_STRING : " . $fp->cigar_string . "\n";
#	    print STDERR $fp->gffstring . "\n";
            $self->add_output($fp);
        }
     }
}

=head2 run

  Title   : run
  Usage   : $self->run()
  Function: Runs est2genome on MiniSeq representation of genomic sequence for each EST
  Returns : none
  Args    : 

=cut

sub run {
    my ($self) = @_;
    
    my ($esthash) = $self->get_all_FeaturesById;
    
    my @ests    = keys %$esthash;
    
    $self->get_all_Sequences(@ests);
    
    my $number_of_errors = 0;
    
    foreach my $est (@ests) {
        my $features = $esthash->{$est};
        my @exons;
        
        next unless (ref($features) eq "ARRAY");
        next unless (scalar(@$features) >= 1);
      
        eval {
            $self->run_blaste2g($est, $features);
        };
      
        if ($@) {
            $number_of_errors++;
            print STDERR "Error running blaste2g on" . $features->[0]->hseqname . " [$@]\n";
        }
        
    }
    # Thought it might be useful to throw at this point if there have been errors.
    # There might have only been a problem with one of the ests.  
    $self->throw("See previous errors...") if $number_of_errors;
    return 1;
}

sub add_output{
    my($self, @feat_pairs) = @_;
    push( @{ $self->{'_output'} } , @feat_pairs);
}

1;

__END__

=head1 NAME - Bio::EnsEMBL::Pipeline::Runnable::Finished_MiniEst2Genome

=head1 AUTHOR

<NAME> B<email> <EMAIL>

{'fraction_non_alphanumeric': 0.1573463007988885, 'fraction_numerical': 0.007467870788468218, 'mean_word_length': 2.691666666666667, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 88, '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': '4263706', 'n_tokens_mistral': 2099, 'n_tokens_neox': 2009, 'n_words': 454}