<commit_before>package CoGeX::Dataset;

# Created by DBIx::Class::Schema::Loader v0.03009 @ 2006-12-01 18:13:38

use strict;
use warnings;
use Data::Dumper;
use base 'DBIx::Class';
#use CoGeX::Feature;
use Text::Wrap;

__PACKAGE__->load_components("PK::Auto", "ResultSetManager", "Core");
__PACKAGE__->table("dataset");
__PACKAGE__->add_columns(
  "dataset_id",{ data_type => "INT", default_value => undef, is_nullable => 0, size => 10 },
  "data_source_id",{ data_type => "INT", default_value => 0, is_nullable => 0, size => 10 },
  "organism_id",{ data_type => "INT", default_value => "", is_nullable => 0, size => 10 },
  "name",{ data_type => "VARCHAR", default_value => "", is_nullable => 0, size => 50 },
  "description",
  {
    data_type => "VARCHAR",
    default_value => undef,
    is_nullable => 1,
    size => 255,
  },
  "version",
  {
    data_type => "VARCHAR",
    default_value => undef,
    is_nullable => 1,
    size => 50,
  },
  "link",
  {
    data_type => "TEXT",
    default_value => undef,
    is_nullable => 1,
    size => 65535,
  },
  "date",
  { data_type => "DATETIME", default_value => "", is_nullable => 0, size => 19 },
);

__PACKAGE__->set_primary_key("dataset_id");

__PACKAGE__->has_many("features" => "CoGeX::Feature", 'dataset_id');

__PACKAGE__->has_many("genomic_sequences" => "CoGeX::GenomicSequence", 'dataset_id');

__PACKAGE__->belongs_to("datasource" => "CoGeX::DataSource", 'data_source_id');

__PACKAGE__->belongs_to("organism" => "CoGeX::Organism", 'organism_id');


sub chromosomes : ResultSet {
    my $self = shift;
    my $r1 = $self->search(undef,{
        prefetch =>['genomic_sequences']
    });
    return $r1 if $r1->count;
    # TODO: should probably just return an array here instead of 
    # full objects...
    return $self->search(undef,{
        prefetch =>[{'features' => 'locations' }]
    });

}

sub get_genomic_sequence {
  my $self = shift;
  my %opts = @_;
  my $start = $opts{start} || $opts{begin};
  my $stop = $opts{stop} || $opts{end};
  my $chr = $opts{chr} || $opts{chromosome};
  my $strand = $opts{strand};
  my $skip_length_check = $opts{skip_length_check} || 0;
  my $str = "";
  if (defined $start && defined $stop)
    {
      $chr = "1" unless defined $chr;
      $start = 1 if $start < 1;
      $stop = $start unless $stop;
      return undef unless ($start =~ /^\d+$/ and  $stop =~ /^\d+$/);
      ($start, $stop) = ($stop, $start) if $stop < $start;

      if (! $skip_length_check)
	{
	  my $last = $self->last_chromosome_position($chr);
	  $stop = $last if $stop > $last;
	}
      # make sure two numbers were sent in
      #my $fstart = $start%10000 ? $start - ($start % 10000) + 1 : ($start -1)- (($start-1) % 10000) +1;
      my $fstart = $start - (($start -1) % 10000);
#      print STDERR "start: $start, fstart: $fstart\n";
      my @starts;
#      push (@starts, $fstart) if $fstart == $stop;
      for(my $i=$fstart;$i<=$stop;$i+=10000){
        push(@starts,$i);
      }
      return unless @starts;
      my @seqs = $self->genomic_sequences(
					  {chromosome=>$chr,
					   -and=>[ start=> { 'in', \@starts } ],
					  },
					  {order_by=>"start asc"}
					 )->all;
      return unless @seqs;
#      print STDERR Dumper \@starts;
      $str = join ("", map{$_->sequence_data} @seqs);  
#      print STDERR "!!",$str,"\n";;
      $str = $self->trim_sequence( $str, $seqs[0]->start, $seqs[-1]->stop, $start, $stop );
#      print STDERR "!!",$str,"\n";;
    } 
  elsif ( $chr ) 
    {
    $str = join("",map { $_->sequence_data } $self->genomic_sequences( { 'chromosome' => $chr},
					      {order_by=>"start asc"}
					    ));
    } 
  else 
    {                 # entire sequence
      my $allseqs = $self->genomic_sequences({},{order_by=>"start asc"});
      while ( my $g = $allseqs->next ) {
	$str .= $g->sequence_data;
      }
    }
  $str = $self->reverse_complement($str) if $strand =~ /-/;
  return $str;
}

sub get_genome_sequence
  {
    return shift->get_genomic_sequence(@_);<commit_msg>added check for defined value to supress warning<commit_after>package CoGeX::Dataset;

# Created by DBIx::Class::Schema::Loader v0.03009 @ 2006-12-01 18:13:38

use strict;
use warnings;
use Data::Dumper;
use base 'DBIx::Class';
#use CoGeX::Feature;
use Text::Wrap;

__PACKAGE__->load_components("PK::Auto", "ResultSetManager", "Core");
__PACKAGE__->table("dataset");
__PACKAGE__->add_columns(
  "dataset_id",{ data_type => "INT", default_value => undef, is_nullable => 0, size => 10 },
  "data_source_id",{ data_type => "INT", default_value => 0, is_nullable => 0, size => 10 },
  "organism_id",{ data_type => "INT", default_value => "", is_nullable => 0, size => 10 },
  "name",{ data_type => "VARCHAR", default_value => "", is_nullable => 0, size => 50 },
  "description",
  {
    data_type => "VARCHAR",
    default_value => undef,
    is_nullable => 1,
    size => 255,
  },
  "version",
  {
    data_type => "VARCHAR",
    default_value => undef,
    is_nullable => 1,
    size => 50,
  },
  "link",
  {
    data_type => "TEXT",
    default_value => undef,
    is_nullable => 1,
    size => 65535,
  },
  "date",
  { data_type => "DATETIME", default_value => "", is_nullable => 0, size => 19 },
);

__PACKAGE__->set_primary_key("dataset_id");

__PACKAGE__->has_many("features" => "CoGeX::Feature", 'dataset_id');

__PACKAGE__->has_many("genomic_sequences" => "CoGeX::GenomicSequence", 'dataset_id');

__PACKAGE__->belongs_to("datasource" => "CoGeX::DataSource", 'data_source_id');

__PACKAGE__->belongs_to("organism" => "CoGeX::Organism", 'organism_id');


sub chromosomes : ResultSet {
    my $self = shift;
    my $r1 = $self->search(undef,{
        prefetch =>['genomic_sequences']
    });
    return $r1 if $r1->count;
    # TODO: should probably just return an array here instead of 
    # full objects...
    return $self->search(undef,{
        prefetch =>[{'features' => 'locations' }]
    });

}

sub get_genomic_sequence {
  my $self = shift;
  my %opts = @_;
  my $start = $opts{start} || $opts{begin};
  my $stop = $opts{stop} || $opts{end};
  my $chr = $opts{chr} || $opts{chromosome};
  my $strand = $opts{strand};
  my $skip_length_check = $opts{skip_length_check} || 0;
  my $str = "";
  if (defined $start && defined $stop)
    {
      $chr = "1" unless defined $chr;
      $start = 1 if $start < 1;
      $stop = $start unless $stop;
      return undef unless ($start =~ /^\d+$/ and  $stop =~ /^\d+$/);
      ($start, $stop) = ($stop, $start) if $stop < $start;

      if (! $skip_length_check)
	{
	  my $last = $self->last_chromosome_position($chr);
	  $stop = $last if $stop > $last;
	}
      # make sure two numbers were sent in
      #my $fstart = $start%10000 ? $start - ($start % 10000) + 1 : ($start -1)- (($start-1) % 10000) +1;
      my $fstart = $start - (($start -1) % 10000);
#      print STDERR "start: $start, fstart: $fstart\n";
      my @starts;
#      push (@starts, $fstart) if $fstart == $stop;
      for(my $i=$fstart;$i<=$stop;$i+=10000){
        push(@starts,$i);
      }
      return unless @starts;
      my @seqs = $self->genomic_sequences(
					  {chromosome=>$chr,
					   -and=>[ start=> { 'in', \@starts } ],
					  },
					  {order_by=>"start asc"}
					 )->all;
      return unless @seqs;
#      print STDERR Dumper \@starts;
      $str = join ("", map{$_->sequence_data} @seqs);  
#      print STDERR "!!",$str,"\n";;
      $str = $self->trim_sequence( $str, $seqs[0]->start, $seqs[-1]->stop, $start, $stop );
#      print STDERR "!!",$str,"\n";;
    } 
  elsif ( $chr ) 
    {
    $str = join("",map { $_->sequence_data } $self->genomic_sequences( { 'chromosome' => $chr},
					      {order_by=>"start asc"}
					    ));
    } 
  else 
    {                 # entire sequence
      my $allseqs = $self->genomic_sequences({},{order_by=>"start asc"});
      while ( my $g = $allseqs->next ) {
	$str .= $g->sequence_data;
      }
    }
  $str = $self->reverse_complement($str) if $strand && $strand =~ /-/;
  return $str;
}

sub get_genome_sequence
  {
    return shift->get_genomic_sequence(@_);
{'fraction_non_alphanumeric': 0.196100347739692, 'fraction_numerical': 0.02185792349726776, 'mean_word_length': 3.1382322713257964, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 147, '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': '4136393', 'n_tokens_mistral': 3195, 'n_tokens_neox': 2927, 'n_words': 657}