<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::Runnable::HalfwiseHMM

=head1 SYNOPSIS

  #create and fill Bio::Seq object
  my $seqfile = '/nfs/disk65/mq2/temp/bA151E14.seq'; 
  my $seq = Bio::Seq->new();
  my $seqstream = Bio::SeqIO->new(-file => $seqfile, -fmt => 'Fasta');
  $seq = $seqstream->next_seq();
  #create Bio::EnsEMBL::Pipeline::Runnable::HalfwiseHMM object
  my $halfwisehmm = Bio::EnsEMBL::Pipeline::Runnable::HalfwiseHMM->new (-QUERY => $seq);
  $halfwisehmm->workdir($workdir);
  $halfwisehmm->run();
  my @genes = $halfwisehmm->output();
  my @exons = $halfwisehmm->output_exons();
  my $seqfeature = $halfwisehmm->output_singlefeature();

=head1 DESCRIPTION

This package is based on the genscan runnable.
HalfwiseHMM takes a Bio::Seq (or Bio::PrimarySeq) object and runs HalfwiseHMM on it. The
resulting output is parsed to produce a set of Bio::SeqFeatures. 

=head2 Methods:

=over 4

=item new($seq_obj)

=item    HalfwiseHMM($path_to_HalfwiseHMM)

=item    workdir($directory_name)

=item    run()

=item    output()

=back

=head1 CONTACT

ensembl-dev.ebi.ac.uk

=head1 APPENDIX

The rest of the documentation details each of the object methods. 


=cut

package Bio::EnsEMBL::Pipeline::Runnable::HalfwiseHMM;


use vars qw(@ISA);
use strict;
# Object preamble - inherits from Bio::Root::RootI;

use Bio::EnsEMBL::Pipeline::RunnableI;
use Bio::EnsEMBL::FeaturePair;
use Bio::EnsEMBL::SeqFeature;
use Bio::EnsEMBL::Analysis;
use Bio::EnsEMBL::Pipeline::Runnable::FeatureFilter;
use Bio::PrimarySeq; 
use Bio::Seq;
use Bio::SeqIO;
use Bio::Root::RootI;
use Bio::Tools::BPlite;
use Bio::EnsEMBL::Pipeline::Runnable::Blast;



BEGIN {
    require "Bio/EnsEMBL/Pipeline/pipeConf.pl";
}

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

=head2 new

    Title   :   new
    Usage   :   my obj =  Bio::EnsEMBL::Pipeline::Runnable::HalfwiseHMM->new (-QUERY => $seq);
    Function:   Initialises HalfwiseHMMobject
    Returns :   a HalfwiseHMMObject
    Args    :   A Bio::Seq object 
                (blastdb, hmmdb location of exes etc  optional)

=cut

sub new {
    my ($class,@args) = @_;

    my $self = $class->SUPER::new(@args);    

    $self->{'_query'} = undef; #location of Bio::Seq object
    $self->{'_blastprog'} = undef; #location of blast program
    $self->{'_blastdb'} = undef; #location fo blast database
    $self->{'_blastobj'} = undef; #location of blast object
    $self->{'_threshold'} = undef; #threshold value for blast analysis
    $self->{'_blastfplist'} = [];        # an array of feature pairs (the output)
    $self->{'_pfamlist'}    = []; #list of pfam hits
    $self->{'_uniquepfamids'} = [];
    $self->{'_featurelist'} = []; #array of features
    $self->{'_genewise'} = undef; #location of genewise prog
    $self->{'_options'} = undef; #options for genewise program
    $self->{'_workdir'}   = undef;     # location of temp directory
    $self->{'_filename'}  = undef;     # file to store Bio::Seq object
    $self->{'_hmmfilename'} = undef; #file to store protein profile hmms 
    $self->{'_errorfile'} = undef; #file to store any errors hmmfetch throws 
    $self->{'_results'}   = undef;     # file to store results of analysis
    $self->{'_hmmfetch'} = undef; #location of hmmfetch program
    $self->{'_hmmdb'} = undef; #location of hmmdb
    
    print STDERR "args: ", @args, "\n";
    my ($query, $blastprog, $blastdb, $threshold, $genewise, $options, $hmmfetch, $hmmdb) 
	= $self->_rearrange([qw (QUERY BLASTPROG BLASTDB THRESHOLD GENEWISE OPTIONS HMMFETCH HMMDB)], @args);
    
    $self->query($query) if ($query);
    if ($blastprog){
       $self->blast_loc($self->find_executable($blastprog));
    } else {
      $self->blast_loc($self->find_executable('wublastx'));
    }
    if ($blastdb) {
	$self->blastdb($blastdb);
    } else {#note database name must always contain halfwise
	#$self->blastdb("/usr/local/ensembl/halfwise.db");
	$self->blastdb("/nfs/disk100/pubseq/halfwise/halfwise.db");
    }
    if (defined($genewise )){
	$self->genewise_loc($self->find_executable($genewise));
    } else {
	$self->genewise_loc($self->find_executable('genewisedb'));
    }
    if (defined($threshold)) {
	$self->threshold($threshold);
    }
    else
    {
	$self->threshold(1e-6);
    }
    if ($options) {
      $self->options($options);
    } else {
      $self->options(' -init wing -cace -cut 25 -aln 200 -gff -quiet ');  
    }

    if ($hmmfetch){
	$self->hmmfetch($hmmfetch);
    } else {
	$self->hmmfetch('hmmfetch');
    }
    
    if($hmmdb){
	$self->hmmdb($hmmdb);
    } else {
	#$self->hmmdb('/usr/local/ensembl/data/Pfam');
	$self->hmmdb('/nfs/disk100/pubseq/Pfam/DB/Pfam');
    }
    return $self; # success - we hope!
}




#################
#GET/SET METHODS#
#################

=head2 query

    Title   :   query
    Usage   :    $HalfwiseHMM->query($seq);
    Function:   sets the sequence the halfwisehmm object will run on
  and checks it is a Bio::Seq
    Returns :   a seq
    Args    :   A Bio::Seq object 
                

=cut

sub query {
    my ($self, $seq) = @_;
    if ($seq)
    {<commit_msg>alter which paths the blast and pfam dbs are coming from<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::Runnable::HalfwiseHMM

=head1 SYNOPSIS

  #create and fill Bio::Seq object
  my $seqfile = '/nfs/disk65/mq2/temp/bA151E14.seq'; 
  my $seq = Bio::Seq->new();
  my $seqstream = Bio::SeqIO->new(-file => $seqfile, -fmt => 'Fasta');
  $seq = $seqstream->next_seq();
  #create Bio::EnsEMBL::Pipeline::Runnable::HalfwiseHMM object
  my $halfwisehmm = Bio::EnsEMBL::Pipeline::Runnable::HalfwiseHMM->new (-QUERY => $seq);
  $halfwisehmm->workdir($workdir);
  $halfwisehmm->run();
  my @genes = $halfwisehmm->output();
  my @exons = $halfwisehmm->output_exons();
  my $seqfeature = $halfwisehmm->output_singlefeature();

=head1 DESCRIPTION

This package is based on the genscan runnable.
HalfwiseHMM takes a Bio::Seq (or Bio::PrimarySeq) object and runs HalfwiseHMM on it. The
resulting output is parsed to produce a set of Bio::SeqFeatures. 

=head2 Methods:

=over 4

=item new($seq_obj)

=item    HalfwiseHMM($path_to_HalfwiseHMM)

=item    workdir($directory_name)

=item    run()

=item    output()

=back

=head1 CONTACT

ensembl-dev.ebi.ac.uk

=head1 APPENDIX

The rest of the documentation details each of the object methods. 


=cut

package Bio::EnsEMBL::Pipeline::Runnable::HalfwiseHMM;


use vars qw(@ISA);
use strict;
# Object preamble - inherits from Bio::Root::RootI;

use Bio::EnsEMBL::Pipeline::RunnableI;
use Bio::EnsEMBL::FeaturePair;
use Bio::EnsEMBL::SeqFeature;
use Bio::EnsEMBL::Analysis;
use Bio::EnsEMBL::Pipeline::Runnable::FeatureFilter;
use Bio::PrimarySeq; 
use Bio::Seq;
use Bio::SeqIO;
use Bio::Root::RootI;
use Bio::Tools::BPlite;
use Bio::EnsEMBL::Pipeline::Runnable::Blast;



BEGIN {
    require "Bio/EnsEMBL/Pipeline/pipeConf.pl";
}

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

=head2 new

    Title   :   new
    Usage   :   my obj =  Bio::EnsEMBL::Pipeline::Runnable::HalfwiseHMM->new (-QUERY => $seq);
    Function:   Initialises HalfwiseHMMobject
    Returns :   a HalfwiseHMMObject
    Args    :   A Bio::Seq object 
                (blastdb, hmmdb location of exes etc  optional)

=cut

sub new {
    my ($class,@args) = @_;

    my $self = $class->SUPER::new(@args);    

    $self->{'_query'} = undef; #location of Bio::Seq object
    $self->{'_blastprog'} = undef; #location of blast program
    $self->{'_blastdb'} = undef; #location fo blast database
    $self->{'_blastobj'} = undef; #location of blast object
    $self->{'_threshold'} = undef; #threshold value for blast analysis
    $self->{'_blastfplist'} = [];        # an array of feature pairs (the output)
    $self->{'_pfamlist'}    = []; #list of pfam hits
    $self->{'_uniquepfamids'} = [];
    $self->{'_featurelist'} = []; #array of features
    $self->{'_genewise'} = undef; #location of genewise prog
    $self->{'_options'} = undef; #options for genewise program
    $self->{'_workdir'}   = undef;     # location of temp directory
    $self->{'_filename'}  = undef;     # file to store Bio::Seq object
    $self->{'_hmmfilename'} = undef; #file to store protein profile hmms 
    $self->{'_errorfile'} = undef; #file to store any errors hmmfetch throws 
    $self->{'_results'}   = undef;     # file to store results of analysis
    $self->{'_hmmfetch'} = undef; #location of hmmfetch program
    $self->{'_hmmdb'} = undef; #location of hmmdb
    
    print STDERR "args: ", @args, "\n";
    my ($query, $blastprog, $blastdb, $threshold, $genewise, $options, $hmmfetch, $hmmdb) 
	= $self->_rearrange([qw (QUERY BLASTPROG BLASTDB THRESHOLD GENEWISE OPTIONS HMMFETCH HMMDB)], @args);
    
    $self->query($query) if ($query);
    if ($blastprog){
       $self->blast_loc($self->find_executable($blastprog));
    } else {
      $self->blast_loc($self->find_executable('wublastx'));
    }
    if ($blastdb) {
	$self->blastdb($blastdb);
    } else {#note database name must always contain halfwise
	$self->blastdb("/usr/local/ensembl/halfwise.db");
	#$self->blastdb("/nfs/disk100/pubseq/halfwise/halfwise.db");
    }
    if (defined($genewise )){
	$self->genewise_loc($self->find_executable($genewise));
    } else {
	$self->genewise_loc($self->find_executable('genewisedb'));
    }
    if (defined($threshold)) {
	$self->threshold($threshold);
    }
    else
    {
	$self->threshold(1e-6);
    }
    if ($options) {
      $self->options($options);
    } else {
      $self->options(' -init wing -cace -cut 25 -aln 200 -gff -quiet ');  
    }

    if ($hmmfetch){
	$self->hmmfetch($hmmfetch);
    } else {
	$self->hmmfetch('hmmfetch');
    }
    
    if($hmmdb){
	$self->hmmdb($hmmdb);
    } else {
	$self->hmmdb('/usr/local/ensembl/data/Pfam');
	#$self->hmmdb('/nfs/disk100/pubseq/Pfam/DB/Pfam');
    }
    return $self; # success - we hope!
}




#################
#GET/SET METHODS#
#################

=head2 query

    Title   :   query
    Usage   :    $HalfwiseHMM->query($seq);
    Function:   sets the sequence the halfwisehmm object will run on
  and checks it is a Bio::Seq
    Returns :   a seq
    Args    :   A Bio::Seq object 
                

=cut

sub query {
    my ($self, $seq) = @_;
    if ($seq)
    {
{'fraction_non_alphanumeric': 0.1660534012642702, 'fraction_numerical': 0.005660911406736484, 'mean_word_length': 3.6066927422859627, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 123, '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': '5007126', 'n_tokens_mistral': 4038, 'n_tokens_neox': 3715, 'n_words': 896}