<commit_before>=head1 NAME

BioperlFlattener - configurably transform BioPerl feature objects to arrayrefs

=head1 SYNOPSIS

  my $flattener = BioperlFlattener->new(
                      $track->{"track"},
                      \%style,
                      [],
                      [],
                    );

  my $startCol = BioperlFlattener->startIndex;
  my $endCol = BioperlFlattener->endIndex;

  my $arrayref = $flattener->flatten_to_feature($feature);

=head1 METHODS

=cut

package BioperlFlattener;

use strict;
use warnings;
use JsonGenerator;
use NameHandler;

#in JSON, features are represented by arrays (we could use
#hashes, but then we'd have e.g. "start" and "end" in the JSON
#for every feature, which would take up too much space/bandwidth)
#@featMap maps from feature objects to arrays
my @featMap = (
	       sub {$_[0]->start - 1},
	       sub {int($_[0]->end)},
	       sub {int($_[0]->strand)},
               sub {$_[0]->source_tag},
	      );

my @mapHeaders = ( 'start', 'end', 'strand','source');
#positions of "start" and "end" in @mapHeaders (for NCList)
my $startIndex = 1;
my $endIndex   = 2;
#position of the lazy subfeature file name in the fake feature.
my $lazyIndex = 3;

sub featureLabelSub {
    return $_[0]->display_name if $_[0]->can('display_name');
    return $_[0]->info         if $_[0]->can('info'); # deprecated
    return $_[0]->seq_id       if $_[0]->can('seq_id');
    return eval{$_[0]->primary_tag};
}

my %builtinDefaults =
  (
   "label"        => \&featureLabelSub,
   "autocomplete" => "none",
   "class"        => "feature"
  );

=head2 new( $trackLabel, \%setStyle, \@extraMap, \@extraHeaders )

=cut
<commit_msg>fix off-by-one error in bioperl flattener.  fixes #73.<commit_after>=head1 NAME

BioperlFlattener - configurably transform BioPerl feature objects to arrayrefs

=head1 SYNOPSIS

  my $flattener = BioperlFlattener->new(
                      $track->{"track"},
                      \%style,
                      [],
                      [],
                    );

  my $startCol = BioperlFlattener->startIndex;
  my $endCol = BioperlFlattener->endIndex;

  my $arrayref = $flattener->flatten_to_feature($feature);

=head1 METHODS

=cut

package BioperlFlattener;

use strict;
use warnings;
use JsonGenerator;
use NameHandler;

#in JSON, features are represented by arrays (we could use
#hashes, but then we'd have e.g. "start" and "end" in the JSON
#for every feature, which would take up too much space/bandwidth)
#@featMap maps from feature objects to arrays
my @featMap = (
	       sub {int $_[0]->start },
	       sub {int $_[0]->end   },
	       sub {int $_[0]->strand},
               sub {$_[0]->source_tag},
	      );

my @mapHeaders = ( 'start', 'end', 'strand','source');
#positions of "start" and "end" in @mapHeaders (for NCList)
my $startIndex = 1;
my $endIndex   = 2;
#position of the lazy subfeature file name in the fake feature.
my $lazyIndex = 3;

sub featureLabelSub {
    return $_[0]->display_name if $_[0]->can('display_name');
    return $_[0]->info         if $_[0]->can('info'); # deprecated
    return $_[0]->seq_id       if $_[0]->can('seq_id');
    return eval{$_[0]->primary_tag};
}

my %builtinDefaults =
  (
   "label"        => \&featureLabelSub,
   "autocomplete" => "none",
   "class"        => "feature"
  );

=head2 new( $trackLabel, \%setStyle, \@extraMap, \@extraHeaders )

=cut

{'fraction_non_alphanumeric': 0.1448336767736238, 'fraction_numerical': 0.011480718280836032, 'mean_word_length': 2.746416758544653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '4787769', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1100, 'n_words': 319}