<commit_before># EnsEMBL Gene reading writing adaptor for mySQL
#
# Copyright EMBL-EBI 2001
#
# Author: <NAME>
# 
# Date : 15.07.2002
#

=head1 NAME

Bio::EnsEMBL::DBSQL::GeneLiteAdaptor - MySQL Database queries to retrieve genes quickly from denormalized tables.

=head1 SYNOPSIS

=head1 CONTACT

  <NAME>: <EMAIL>
  <NAME>  : <EMAIL>

=head1 APPENDIX

=cut

use strict;

package Bio::EnsEMBL::Lite::GeneAdaptor;

use Bio::EnsEMBL::DBSQL::BaseAdaptor;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Gene;


use vars '@ISA';


@ISA = ('Bio::EnsEMBL::DBSQL::BaseAdaptor');

my $MAX_TRANSCRIPT_LENGTH=3000000;


=head2 fetch_by_Slice

  Arg  1    : Bio::EnsEMBL::Slice $slice
              The slice we want genes on
  Function  : retrieve all the genes on this slice. 
              uses www_transcript to get info
  Returntype: list of Bio::EnsEMBL::Gene
  Exceptions: none
  Caller    : Bio::EnsEMBL::Slice

=cut

sub fetch_by_Slice {
  my ( $self, $slice ) = @_;
  my @out;
  my $core_DBAdaptor = $self->db->core_DBAdaptor();

  my $sth = $self->prepare
    ( "SELECT id, transcript_id, chr_name, chr_start, chr_end, chr_strand,
              transcript_name, translation_id, translation_name, gene_id,
              type, gene_name, db, exon_structure, external_name,
              external_db, coding_start, coding_end 
        FROM  transcript
        WHERE chr_name = ? and chr_start <= ? and chr_start >= ? and
              chr_end >= ?"
    );
    
  eval {
    $sth->execute( $slice->chr_name, $slice->chr_end, $slice->chr_start-$MAX_TRANSCRIPT_LENGTH, $slice->chr_start );
  };

  return () if($@);

  # have to make gene, transcripts, translation, db_link for gene and exons

  my %exon_cache = ();
  my %gene_cache = ();

  my ( $gene, $transcript, $translation ); 

  while( my $hr = $sth->fetchrow_hashref() ) {

    if( !exists $gene_cache{ $hr->{gene_id} } ) {
      $gene = Bio::EnsEMBL::Gene->new();
      $gene->stable_id( $hr->{'gene_name'} );
      $gene->dbID( $hr->{'gene_id'} );
      $gene->source( $hr->{'db'} );
      $gene->adaptor( $core_DBAdaptor->get_GeneAdaptor() );
      $gene_cache{ $hr->{gene_id} } = $gene;

      print STDERR "Created Gene\n";

    } else {
      $gene = $gene_cache{ $hr->{gene_id} };
    }

    # create exons from exon_structure entry
    my @exons = ();
    my @lengths = split( ":", $hr->{'exon_structure'} );
    my ( $start, $end );

    # lowest chr coord  exon first
    $start = $hr->{'chr_start'} - $slice->chr_start + 1;
    $end = $start + $lengths[0] - 1;
    shift( @lengths );

    my $exon;
    if( ! exists $exon_cache{ "$start-$end" } ) {
      $exon = Bio::EnsEMBL::Exon->new
	( $start, $end, $hr->{'chr_strand'}*$slice->strand());
      #  we need dbIDs for Exons !!!
      #   $exon->dbID( );
      $exon->contig( $slice );
      $exon->adaptor( $core_DBAdaptor->get_ExonAdaptor() );
      $exon_cache{"$start-$end"} = $exon;
      print STDERR "\tCreated Exon\n";
    } else {
      $exon = $exon_cache{"$start-$end"};
    }
    $exon->contig( $slice );
    push( @exons, $exon );

    # now the rest of the exons
    while( @lengths ) {
      my $intron_length = shift( @lengths );
      my $exon_length = shift( @lengths );
      
      $start = $end + $intron_length + 1;
      $end = $start + $exon_length - 1;

      if( ! exists $exon_cache{ "$start-$end" } ) {
	$exon = Bio::EnsEMBL::Exon->new
	  ( $start, $end, $hr->{'chr_strand'});
	$exon->contig( $slice );
	$exon->adaptor( $core_DBAdaptor->get_ExonAdaptor() );
	$exon_cache{"$start-$end"} = $exon;
	print STDERR "\tCreated Exon\n";
      } else {
	$exon = $exon_cache{"$start-$end"};
      }

      push( @exons, $exon );
    }
    
    # create the transcript 
    my $transcript = Bio::EnsEMBL::Transcript->new();
    $transcript->adaptor( $core_DBAdaptor->get_TranscriptAdaptor() );
    $transcript->dbID( $hr->{'transcript_id'});
    $transcript->coding_start( $hr->{'coding_start'} );
    $transcript->coding_end( $hr->{'coding_end'} );


    $transcript->stable_id( $hr->{ 'transcript_name' });
    $transcript->type( $hr->{ 'transcript_type' } );
    $transcript->external_name( $hr->{'external_name'} );
    $transcript->external_db( $hr->{'external_db' } );
      
    # Add the exons
    if( $hr->{'chr_strand'} != 1 ) {
      @exons = reverse( @exons );
    }

    for my $exon ( @exons ) {
      $transcript->add_Exon( $exon );
    }

    # translation ..
    my $translation = Bio::EnsEMBL::Translation->new();
    $translation->adaptor( $core_DBAdaptor->get_TranslationAdaptor() );
    $translation->stable_id( $hr->{'translation_name'} );
    $translation->dbID( $hr->{'translation_id'} );
    $transcript->translation( $translation ); 

    $gene->add_Transcript($transcript);

    # we need start and end Exon
    # hope they are lazy loaded ... nope they are not!!!
  }
<commit_msg>coding_start/end corrected<commit_after># EnsEMBL Gene reading writing adaptor for mySQL
#
# Copyright EMBL-EBI 2001
#
# Author: <NAME>
# 
# Date : 15.07.2002
#

=head1 NAME

Bio::EnsEMBL::DBSQL::GeneLiteAdaptor - MySQL Database queries to retrieve genes quickly from denormalized tables.

=head1 SYNOPSIS

=head1 CONTACT

  <NAME>: <EMAIL>
  <NAME>  : <EMAIL>

=head1 APPENDIX

=cut

use strict;

package Bio::EnsEMBL::Lite::GeneAdaptor;

use Bio::EnsEMBL::DBSQL::BaseAdaptor;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Gene;


use vars '@ISA';


@ISA = ('Bio::EnsEMBL::DBSQL::BaseAdaptor');

my $MAX_TRANSCRIPT_LENGTH=3000000;


=head2 fetch_by_Slice

  Arg  1    : Bio::EnsEMBL::Slice $slice
              The slice we want genes on
  Function  : retrieve all the genes on this slice. 
              uses www_transcript to get info
  Returntype: list of Bio::EnsEMBL::Gene
  Exceptions: none
  Caller    : Bio::EnsEMBL::Slice

=cut

sub fetch_by_Slice {
  my ( $self, $slice ) = @_;
  my @out;
  my $core_DBAdaptor = $self->db->core_DBAdaptor();

  my $sth = $self->prepare
    ( "SELECT id, transcript_id, chr_name, chr_start, chr_end, chr_strand,
              transcript_name, translation_id, translation_name, gene_id,
              type, gene_name, db, exon_structure, external_name,
              external_db, coding_start, coding_end 
        FROM  transcript
        WHERE chr_name = ? and chr_start <= ? and chr_start >= ? and
              chr_end >= ?"
    );
    
  eval {
    $sth->execute( $slice->chr_name, $slice->chr_end, $slice->chr_start-$MAX_TRANSCRIPT_LENGTH, $slice->chr_start );
  };

  return () if($@);

  # have to make gene, transcripts, translation, db_link for gene and exons

  my %exon_cache = ();
  my %gene_cache = ();

  my ( $gene, $transcript, $translation ); 

  while( my $hr = $sth->fetchrow_hashref() ) {

    if( !exists $gene_cache{ $hr->{gene_id} } ) {
      $gene = Bio::EnsEMBL::Gene->new();
      $gene->stable_id( $hr->{'gene_name'} );
      $gene->dbID( $hr->{'gene_id'} );
      $gene->source( $hr->{'db'} );
      $gene->adaptor( $core_DBAdaptor->get_GeneAdaptor() );
      $gene_cache{ $hr->{gene_id} } = $gene;

      print STDERR "Created Gene\n";

    } else {
      $gene = $gene_cache{ $hr->{gene_id} };
    }

    # create exons from exon_structure entry
    my @exons = ();
    my @lengths = split( ":", $hr->{'exon_structure'} );
    my ( $start, $end );

    # lowest chr coord  exon first
    $start = $hr->{'chr_start'} - $slice->chr_start + 1;
    $end = $start + $lengths[0] - 1;
    shift( @lengths );

    my $exon;
    if( ! exists $exon_cache{ "$start-$end" } ) {
      $exon = Bio::EnsEMBL::Exon->new
	( $start, $end, $hr->{'chr_strand'}*$slice->strand());
      #  we need dbIDs for Exons !!!
      #   $exon->dbID( );
      $exon->contig( $slice );
      $exon->adaptor( $core_DBAdaptor->get_ExonAdaptor() );
      $exon_cache{"$start-$end"} = $exon;
      print STDERR "\tCreated Exon\n";
    } else {
      $exon = $exon_cache{"$start-$end"};
    }
    $exon->contig( $slice );
    push( @exons, $exon );

    # now the rest of the exons
    while( @lengths ) {
      my $intron_length = shift( @lengths );
      my $exon_length = shift( @lengths );
      
      $start = $end + $intron_length + 1;
      $end = $start + $exon_length - 1;

      if( ! exists $exon_cache{ "$start-$end" } ) {
	$exon = Bio::EnsEMBL::Exon->new
	  ( $start, $end, $hr->{'chr_strand'});
	$exon->contig( $slice );
	$exon->adaptor( $core_DBAdaptor->get_ExonAdaptor() );
	$exon_cache{"$start-$end"} = $exon;
	print STDERR "\tCreated Exon\n";
      } else {
	$exon = $exon_cache{"$start-$end"};
      }

      push( @exons, $exon );
    }
    
    # create the transcript 
    my $transcript = Bio::EnsEMBL::Transcript->new();
    $transcript->adaptor( $core_DBAdaptor->get_TranscriptAdaptor() );
    $transcript->dbID( $hr->{'transcript_id'});
    $transcript->coding_start( $hr->{'coding_start'} -$slice->chr_start() + 1);
    $transcript->coding_end( $hr->{'coding_end'} -$slice->chr_start() - 1);


    $transcript->stable_id( $hr->{ 'transcript_name' });
    $transcript->type( $hr->{ 'transcript_type' } );
    $transcript->external_name( $hr->{'external_name'} );
    $transcript->external_db( $hr->{'external_db' } );
      
    # Add the exons
    if( $hr->{'chr_strand'} != 1 ) {
      @exons = reverse( @exons );
    }

    for my $exon ( @exons ) {
      $transcript->add_Exon( $exon );
    }

    # translation ..
    my $translation = Bio::EnsEMBL::Translation->new();
    $translation->adaptor( $core_DBAdaptor->get_TranslationAdaptor() );
    $translation->stable_id( $hr->{'translation_name'} );
    $translation->dbID( $hr->{'translation_id'} );
    $transcript->translation( $translation ); 

    $gene->add_Transcript($transcript);

    # we need start and end Exon
    # hope they are lazy loaded ... nope they are not!!!
  }

{'fraction_non_alphanumeric': 0.17515629804243107, 'fraction_numerical': 0.006559393256123809, 'mean_word_length': 3.0624479600333054, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 149, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4138562', 'n_tokens_mistral': 3865, 'n_tokens_neox': 3587, 'n_words': 741}