<commit_before>#
#
# Cared for by <NAME>  <<EMAIL>>
#
# Copyright <NAME>
#
# You may distribute this module under the same terms as perl itself
#
# POD documentation - main docs before the code

=pod 

=head1 NAME

Bio::EnsEMBL::Pipeline::RunnableDB::BlastGenscanPep

=head1 SYNOPSIS

my $db          = Bio::EnsEMBL::DBLoader->new($locator);
my $genscan     = Bio::EnsEMBL::Pipeline::RunnableDB::BlastGenscanPep->new ( 
                                                    -dbobj      => $db,
			                            -input_id   => $input_id
                                                    -analysis   => $analysis );

$genscan->fetch_input();
$genscan->run();
$genscan->output();

=head1 DESCRIPTION

This object runs Bio::EnsEMBL::Pipeline::Runnable::Blast on peptides constructed from 
assembling genscan predicted features to peptide sequence. The resulting blast hits are
written back as FeaturePairs.

The appropriate Bio::EnsEMBL::Analysis object must be passed for
extraction of appropriate parameters. A Bio::EnsEMBL::Pipeline::DBSQL::Obj is
required for database access.

=head1 CONTACT

Describe contact details here

=head1 APPENDIX

The rest of the documentation details each of the object methods. 
Internal methods are usually preceded with a _

=cut

package Bio::EnsEMBL::Pipeline::RunnableDB::BlastGenscanPep;

use strict;

use Bio::EnsEMBL::Pipeline::RunnableDB;
use Bio::EnsEMBL::Pipeline::Runnable::BlastGenscanPep;
use Bio::PrimarySeq;

use vars qw(@ISA);

@ISA = qw(Bio::EnsEMBL::Pipeline::RunnableDB);

=head2 new

    Title   :   new
    Usage   :   $self->new(-DBOBJ       => $db
                           -INPUT_ID    => $id
                           -ANALYSIS    => $analysis);
                           
    Function:   creates a Bio::EnsEMBL::Pipeline::RunnableDB::BlastGenscanPep object
    Returns :   A Bio::EnsEMBL::Pipeline::RunnableDB::BlastGenscanPep object
    Args    :   -dbobj:     A Bio::EnsEMBL::DB::Obj, 
                -input_id:  Contig input id , 
                -analysis:  A Bio::EnsEMBL::Analysis 

=cut

sub new {
    my ($class, @args) = @_;
    my $self = $class->SUPER::new(@args);

    $self->{'_runnable'}    = [];    

    $self->{'_genseq'}      = undef;
    $self->{'_transcripts'} = [];
    $self->{'_parameters'}  = undef;

    $self->{'_featurepairs'}= [];

    $self->throw("Analysis object required") unless (defined($self->analysis));
    
    return $self;
}

=head2 fetch_input

    Title   :   fetch_input
    Usage   :   $self->fetch_input
    Function:   Fetches input data for repeatmasker from the database
    Returns :   none
    Args    :   none

=cut

sub fetch_input {
    my($self) = @_;
    
    $self->throw("No input id") unless defined($self->input_id);

    my $contigid  = $self->input_id;
    print STDERR "Fetching contig $contigid\n";
    my $contig    = $self->dbobj->get_Contig($contigid) 
        or $self->throw("Unable to find contig ($contigid)\n");
    my $genseq    = $contig->primary_seq() 
        or $self->throw("Unable to fetch contig sequence");

    $self->genseq($genseq);
    #need to get features predicted by genscan
    $self->transcripts($contig->get_genscan_peptides);
}

sub transcripts {
    my ($self, @transcripts) = @_;
    
    if (@transcripts)
    {
        foreach (@transcripts)
        {
            $self->throw("Input $_ is not a Bio::EnsEMBL::Transcript\n")
                unless $_->isa("Bio::EnsEMBL::Transcript");
        }
        push (@{$self->{'_transcripts'}}, @transcripts);
    }
    return @{$self->{'_transcripts'}};
}


sub runnable {
    my ($self, @runnable) = @_;
    if (@runnable)
    {
        foreach my $runnable (@runnable)
        {
            $runnable->isa("Bio::EnsEMBL::Pipeline::RunnableI") or
                $self->throw("Input to runnable is not Bio::EnsEMBL::Pipeline::RunnableI");
        }
        push (@{$self->{'_runnable'}}, @runnable);
    }
    return @{$self->{'_runnable'}};
}

=head2 run

    Title   :   run
    Usage   :   $self->run();
    Function:   Runs Bio::EnsEMBL::Pipeline::Runnable::Blast->run()
    Returns :   none
    Args    :   none

=cut

sub run {
    my ($self) = @_;

    #need to pass one peptide at a time
    $self->throw("Input must be fetched before run") unless ($self->genseq);
    print STDERR "Running against ".scalar($self->transcripts)." predictions\n";

    foreach my $transcript ($self->transcripts) {

	my $runnable = Bio::EnsEMBL::Pipeline::Runnable::BlastGenscanPep->new(-genomic   => $self->genseq,
									      -peptide   => $transcript,
									      -database  => $self->analysis->db,
									      -program   => $self->analysis->program,
									      -threshold => $self->threshold,
									      -threshold_type => 'PVALUE');

	$runnable->run();
	$self->runnable($runnable);                                        

    }

}

=head2 output

    Title   :   output
    Usage   :   $self->output();
    Function:   Runs Bio::EnsEMBL::Pipeline::Runnable::Blast->output()
    Returns :   An array of Bio::EnsEMBL::Repeat objects (FeaturePairs)
    Args    :   none

=cut

sub output {
    my ($self) = @_;

    my @output;
    foreach my $run ($self->runnable) {
      push(@output,$run->output);
    }
    return @output;
}

1;<commit_msg>Set threshold parameter on new and added options so that values in the analysisprocess table do percolate down to reach the actual Blast runnable. Output method module modified to save the correct analysis obj with each discovered feature pair.<commit_after>#
#
# Cared for by <NAME>  <<EMAIL>>
#
# Copyright <NAME>
#
# You may distribute this module under the same terms as perl itself
#
# POD documentation - main docs before the code

=pod 

=head1 NAME

Bio::EnsEMBL::Pipeline::RunnableDB::BlastGenscanPep

=head1 SYNOPSIS

my $db          = Bio::EnsEMBL::DBLoader->new($locator);
my $genscan     = Bio::EnsEMBL::Pipeline::RunnableDB::BlastGenscanPep->new ( 
                                                    -dbobj      => $db,
			                            -input_id   => $input_id
                                                    -analysis   => $analysis );

$genscan->fetch_input();
$genscan->run();
$genscan->output();

=head1 DESCRIPTION

This object runs Bio::EnsEMBL::Pipeline::Runnable::Blast on peptides constructed from 
assembling genscan predicted features to peptide sequence. The resulting blast hits are
written back as FeaturePairs.

The appropriate Bio::EnsEMBL::Analysis object must be passed for
extraction of appropriate parameters. A Bio::EnsEMBL::Pipeline::DBSQL::Obj is
required for database access.

=head1 CONTACT

Describe contact details here

=head1 APPENDIX

The rest of the documentation details each of the object methods. 
Internal methods are usually preceded with a _

=cut

package Bio::EnsEMBL::Pipeline::RunnableDB::BlastGenscanPep;

use strict;

use Bio::EnsEMBL::Pipeline::RunnableDB;
use Bio::EnsEMBL::Pipeline::Runnable::BlastGenscanPep;
use Bio::PrimarySeq;

use vars qw(@ISA);

@ISA = qw(Bio::EnsEMBL::Pipeline::RunnableDB);

=head2 new

    Title   :   new
    Usage   :   $self->new(-DBOBJ       => $db
                           -INPUT_ID    => $id
                           -ANALYSIS    => $analysis);
                           
    Function:   creates a Bio::EnsEMBL::Pipeline::RunnableDB::BlastGenscanPep object
    Returns :   A Bio::EnsEMBL::Pipeline::RunnableDB::BlastGenscanPep object
    Args    :   -dbobj:     A Bio::EnsEMBL::DB::Obj, 
                -input_id:  Contig input id , 
                -analysis:  A Bio::EnsEMBL::Analysis 

=cut

sub new {
    my ($class, @args) = @_;
    my $self = $class->SUPER::new(@args);

    $self->{'_runnable'}    = [];    

    $self->{'_genseq'}      = undef;
    $self->{'_transcripts'} = [];
    $self->{'_parameters'}  = undef;

    $self->{'_featurepairs'}= [];

    $self->throw("Analysis object required") unless (defined($self->analysis));
    
    return $self;
}

=head2 fetch_input

    Title   :   fetch_input
    Usage   :   $self->fetch_input
    Function:   Fetches input data for repeatmasker from the database
    Returns :   none
    Args    :   none

=cut

sub fetch_input {
    my($self) = @_;
    
    $self->throw("No input id") unless defined($self->input_id);

    my $contigid  = $self->input_id;
    print STDERR "Fetching contig $contigid\n";
    my $contig    = $self->dbobj->get_Contig($contigid) 
        or $self->throw("Unable to find contig ($contigid)\n");
    my $genseq    = $contig->primary_seq() 
        or $self->throw("Unable to fetch contig sequence");

    $self->genseq($genseq);
    #need to get features predicted by genscan
    $self->transcripts($contig->get_genscan_peptides);
}

sub transcripts {
    my ($self, @transcripts) = @_;
    
    if (@transcripts)
    {
        foreach (@transcripts)
        {
            $self->throw("Input $_ is not a Bio::EnsEMBL::Transcript\n")
                unless $_->isa("Bio::EnsEMBL::Transcript");
        }
        push (@{$self->{'_transcripts'}}, @transcripts);
    }
    return @{$self->{'_transcripts'}};
}


sub runnable {
    my ($self, @runnable) = @_;
    if (@runnable)
    {
        foreach my $runnable (@runnable)
        {
            $runnable->isa("Bio::EnsEMBL::Pipeline::RunnableI") or
                $self->throw("Input to runnable is not Bio::EnsEMBL::Pipeline::RunnableI");
        }
        push (@{$self->{'_runnable'}}, @runnable);
    }
    return @{$self->{'_runnable'}};
}

=head2 run

    Title   :   run
    Usage   :   $self->run();
    Function:   Runs Bio::EnsEMBL::Pipeline::Runnable::Blast->run()
    Returns :   none
    Args    :   none

=cut

sub run {
    my ($self) = @_;

    #need to pass one peptide at a time
    $self->throw("Input must be fetched before run") unless ($self->genseq);
    print STDERR "Running against ".scalar($self->transcripts)." predictions\n";

    foreach my $transcript ($self->transcripts) {

	my $runnable = Bio::EnsEMBL::Pipeline::Runnable::BlastGenscanPep->new(-genomic   => $self->genseq,
									      -peptide   => $transcript,
									      -database  => $self->analysis->db,
									      -program   => $self->analysis->program,
									      -threshold => 1e-6,
                                                                              -options   => $self->parameters,
									      -threshold_type => 'PVALUE');

	$runnable->run();
	$self->runnable($runnable);                                        

    }

}

=head2 output

    Title   :   output
    Usage   :   $self->output();
    Function:   Runs Bio::EnsEMBL::Pipeline::Runnable::Blast->output()
    Returns :   An array of Bio::EnsEMBL::Repeat objects (FeaturePairs)
    Args    :   none

=cut

sub output {
    my ($self) = @_;

    my @output;
    foreach my $run ($self->runnable) {
      my @tmp = $run->output;
      foreach my $f (@tmp) {
	$f->analysis($self->analysis);
      }
      push(@output,@tmp);
    }
    return @output;
}

1;
{'fraction_non_alphanumeric': 0.139220874007846, 'fraction_numerical': 0.002007116139038409, 'mean_word_length': 2.42991239048811, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 144, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1084970', 'n_tokens_mistral': 3789, 'n_tokens_neox': 3449, 'n_words': 827}