<commit_before>#
# Written by <NAME>
#
# Copyright GRL/EBI 2002
#
# 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::Tools::PseudoGeneTests;


=head1 SYNOPSIS


=head1 DESCRIPTION

For a given protein id, it finds all the genewise modesl that have been built from that protein id.
It will locate cases where there is at least one spliced-case and one or more unspliced 
(or only with frameshifts) transcripts. The latter cases are potential pseudogenes.
For these potential pseudogeens, we find the syntenic region in Mouse and run genewise on that
sequence. If there is no match or very poor alignment, we have a very likely pseudogene.

=head1 CONTACT

Post general queries to B<<EMAIL>>

=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::Tools::PseudoGeneTests;

use strict;
use Bio::EnsEMBL::Exon;
use Bio::EnsEMBL::Transcript;
use Bio::EnsEMBL::Gene;
use Bio::EnsEMBL::Pipeline::Tools::TranscriptUtils;
use Bio::EnsEMBL::Pipeline::Runnable::Blast;
use Bio::EnsEMBL::Pipeline::Runnable::BlastDB;
use Bio::EnsEMBL::Pipeline::Runnable::NewExonerate;
use Bio::EnsEMBL::Pipeline::Config::PseudoGenes::PseudoGenes;
use Bio::EnsEMBL::Pipeline::GeneComparison::ComparativeTools;

use vars qw(@ISA);

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

sub new {
  my ($class,@args) = @_;
  my $self = $class->SUPER::new(@args);
  
  return $self;
}
############################################################
#
# METHOD WITH THE LOGIC OF THE TESTS
#
############################################################

sub pseudogene_test{
  my ( $self, 
       $transcript, 
       $db,
       $compara_db, 
       $focus_db, $focus_species, 
       $target_db, $target_species,
       $target_db2, $target_species2,
       $threshold, $gene_id
     ) = @_;
  
  my ( $frameshift, $polyA, $Met, $spliced_elsewhere, $splice_sites_correct, $mouse_homology, $rat_homology, $break_synteny_mouse, $break_synteny_rat, $repeat );
    
  ############################################################
  # is it spliced?
  print STDERR "\n--- testing for splicing ---\n";
  if ( Bio::EnsEMBL::Pipeline::Tools::TranscriptUtils->is_spliced($transcript) ){
    print STDERR "Spliced:\tYES\n";
  }
  else{
    print STDERR "Spliced:\tNO\n";
  }
  
  ############################################################
  # does it have frameshifts?
  print STDERR "\n--- testing for frameshifts ---\n";
  if ( !Bio::EnsEMBL::Pipeline::Tools::TranscriptUtils->is_spliced($transcript) 
       && 
       scalar( @{$transcript->get_all_Exons} > 1) 
     ){
    print STDERR "Frameshifts:\tYES\n";
    $frameshift = 1;
  }
  else{
    print STDERR "Frameshifts:\tNO\n";
    $frameshift = 0;
  }
  
  ############################################################
  # does it have an in-frame stop codon?
  
  ############################################################
  # has polyA?
  print STDERR "\n--- testing for polyA ---\n";
  if ( $self->has_polyA_track( $transcript, $db )){
    print STDERR "polyA track:\tYES\n";
    $polyA = 1;
  }
  else{
    print STDERR "polyA track:\tNO\n";
    $polyA = 0;
  }
  
  ############################################################
  # starts with Methionine?
  print STDERR "\n--- testing for Met ---\n";
  if ($self->starts_with_Methionine( $transcript ) ){
    print STDERR "starts with Methionine: YES\n";
    $Met = 1;
  }
  else{
    print STDERR "starts with Methionine: NO\n";
    $Met = 0;
  }
  
  ############################################################
  # is the evidence spliced elsewhere in the genome?
  print STDERR "\n--- testing for evidence spliced elsewhere in the genome ---\n";
  
  $spliced_elsewhere = $self->check_for_gene_spliced_elsewhere( $transcript, $db , $transcript->type);
  #if ( $spliced_ones && @$spliced_ones ){
  #  print STDERR "Evidence is spliced elsewhere: YES\n";
  #  $spliced_elsewhere = 1;
  #}
  #else{
  #  print STDERR "Evidence is spliced elsewhere: NO\n";
  #  $spliced_elsewhere = 0;
  #}
  
  ############################################################
  # if is spliced, has it got canonical splice sites?
  print STDERR "\n--- testing for canonical splice sites ---\n";

  # single-exon transcripts get a label '-1'
  $splice_sites_correct = -1;
  if ( scalar( @{$transcript->get_all_Exons} ) > 1 ){
    if ( Bio::EnsEMBL::Pipeline::Tools::TranscriptUtils
	 ->check_splice_sites( $transcript ) ){
      print STDERR "Canonical splice sites:\tYES\n";
      $splice_sites_correct = 1;
    }
    else{
      print STDERR "Canonical splice sites:\tNO\n";
      $splice_sites_correct = 0;
    }
  }

  
  ############################################################
  # has it got homology in mouse
  if ( $target_species ){
    print STDERR "\n--- testing for homology in $target_species ---\n";
    $mouse_homology = Bio::EnsEMBL::Pipeline::GeneComparison::ComparativeTools
      ->test_for_orthology_with_tblastx($transcript, $db, $focus_db, $focus_species, $compara_db, $target_db, $target_species, $threshold, $gene_id );
  }
    
  ############################################################
  # has it got homology in rat?
  if ( $target_species2 ){
    print STDERR "\n--- testing for homology in $target_species2 ---\n";
    $rat_homology = Bio::EnsEMBL::Pipeline::GeneComparison::ComparativeTools
      ->test_for_orthology_with_tblastx($transcript, $db, $focus_db, $focus_species, $compara_db, $target_db2, $target_species2, $threshold, $gene_id );
  }
  
#  ############################################################
#  # Does it break synteny in mouse?<commit_msg>changed output for splice sites check<commit_after>#
# Written by <NAME>
#
# Copyright GRL/EBI 2002
#
# 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::Tools::PseudoGeneTests;


=head1 SYNOPSIS


=head1 DESCRIPTION

For a given protein id, it finds all the genewise modesl that have been built from that protein id.
It will locate cases where there is at least one spliced-case and one or more unspliced 
(or only with frameshifts) transcripts. The latter cases are potential pseudogenes.
For these potential pseudogeens, we find the syntenic region in Mouse and run genewise on that
sequence. If there is no match or very poor alignment, we have a very likely pseudogene.

=head1 CONTACT

Post general queries to B<<EMAIL>>

=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::Tools::PseudoGeneTests;

use strict;
use Bio::EnsEMBL::Exon;
use Bio::EnsEMBL::Transcript;
use Bio::EnsEMBL::Gene;
use Bio::EnsEMBL::Pipeline::Tools::TranscriptUtils;
use Bio::EnsEMBL::Pipeline::Runnable::Blast;
use Bio::EnsEMBL::Pipeline::Runnable::BlastDB;
use Bio::EnsEMBL::Pipeline::Runnable::NewExonerate;
use Bio::EnsEMBL::Pipeline::Config::PseudoGenes::PseudoGenes;
use Bio::EnsEMBL::Pipeline::GeneComparison::ComparativeTools;

use vars qw(@ISA);

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

sub new {
  my ($class,@args) = @_;
  my $self = $class->SUPER::new(@args);
  
  return $self;
}
############################################################
#
# METHOD WITH THE LOGIC OF THE TESTS
#
############################################################

sub pseudogene_test{
  my ( $self, 
       $transcript, 
       $db,
       $compara_db, 
       $focus_db, $focus_species, 
       $target_db, $target_species,
       $target_db2, $target_species2,
       $threshold, $gene_id
     ) = @_;
  
  my ( $frameshift, $polyA, $Met, $spliced_elsewhere, $splice_sites_correct, $mouse_homology, $rat_homology, $break_synteny_mouse, $break_synteny_rat, $repeat );
    
  ############################################################
  # is it spliced?
  print STDERR "\n--- testing for splicing ---\n";
  if ( Bio::EnsEMBL::Pipeline::Tools::TranscriptUtils->is_spliced($transcript) ){
    print STDERR "Spliced:\tYES\n";
  }
  else{
    print STDERR "Spliced:\tNO\n";
  }
  
  ############################################################
  # does it have frameshifts?
  print STDERR "\n--- testing for frameshifts ---\n";
  if ( !Bio::EnsEMBL::Pipeline::Tools::TranscriptUtils->is_spliced($transcript) 
       && 
       scalar( @{$transcript->get_all_Exons} > 1) 
     ){
    print STDERR "Frameshifts:\tYES\n";
    $frameshift = 1;
  }
  else{
    print STDERR "Frameshifts:\tNO\n";
    $frameshift = 0;
  }
  
  ############################################################
  # does it have an in-frame stop codon?
  
  ############################################################
  # has polyA?
  print STDERR "\n--- testing for polyA ---\n";
  if ( $self->has_polyA_track( $transcript, $db )){
    print STDERR "polyA track:\tYES\n";
    $polyA = 1;
  }
  else{
    print STDERR "polyA track:\tNO\n";
    $polyA = 0;
  }
  
  ############################################################
  # starts with Methionine?
  print STDERR "\n--- testing for Met ---\n";
  if ($self->starts_with_Methionine( $transcript ) ){
    print STDERR "starts with Methionine: YES\n";
    $Met = 1;
  }
  else{
    print STDERR "starts with Methionine: NO\n";
    $Met = 0;
  }
  
  ############################################################
  # is the evidence spliced elsewhere in the genome?
  print STDERR "\n--- testing for evidence spliced elsewhere in the genome ---\n";
  
  $spliced_elsewhere = $self->check_for_gene_spliced_elsewhere( $transcript, $db , $transcript->type);
  #if ( $spliced_ones && @$spliced_ones ){
  #  print STDERR "Evidence is spliced elsewhere: YES\n";
  #  $spliced_elsewhere = 1;
  #}
  #else{
  #  print STDERR "Evidence is spliced elsewhere: NO\n";
  #  $spliced_elsewhere = 0;
  #}
  
  ############################################################
  # if is spliced, has it got canonical splice sites?
  print STDERR "\n--- testing for canonical splice sites ---\n";

  # single-exon transcripts get a label '-1'
  $splice_sites_correct = -1;
  if ( scalar( @{$transcript->get_all_Exons} ) > 1 ){
    $splice_sites_correct = Bio::EnsEMBL::Pipeline::Tools::TranscriptUtils->check_splice_sites( $transcript );
    
    if ( $splice_sites_correct ){
      print STDERR "Number of canonical splice sites:$splice_sites_correct\n";
    }
  }

  
  ############################################################
  # has it got homology in mouse
  if ( $target_species ){
    print STDERR "\n--- testing for homology in $target_species ---\n";
    $mouse_homology = Bio::EnsEMBL::Pipeline::GeneComparison::ComparativeTools
      ->test_for_orthology_with_tblastx($transcript, $db, $focus_db, $focus_species, $compara_db, $target_db, $target_species, $threshold, $gene_id );
  }
    
  ############################################################
  # has it got homology in rat?
  if ( $target_species2 ){
    print STDERR "\n--- testing for homology in $target_species2 ---\n";
    $rat_homology = Bio::EnsEMBL::Pipeline::GeneComparison::ComparativeTools
      ->test_for_orthology_with_tblastx($transcript, $db, $focus_db, $focus_species, $compara_db, $target_db2, $target_species2, $threshold, $gene_id );
  }
  
#  ############################################################
#  # Does it break synteny in mouse?
{'fraction_non_alphanumeric': 0.23816555198471293, 'fraction_numerical': 0.004864066707200556, 'mean_word_length': 4.31824480369515, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, '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': '3397106', 'n_tokens_mistral': 3983, 'n_tokens_neox': 3646, 'n_words': 951}