<commit_before>#!/usr/bin/perl -w

# Test script for Bio::ToolBox::Data
# working with a Bio::DB::SeqFeature::Store database
# using in memory database for simplicity here....

use strict;
use Test::More;
use File::Spec;
use FindBin '$Bin';
use Statistics::Lite qw(min max);

BEGIN {
	if (eval {require Bio::DB::SeqFeature::Store::memory; 1}) {
		plan tests => 88;
	}
	else {
		plan skip_all => 'Bio::DB::SeqFeature::Store::memory or DB_File not available';
	}
	$ENV{'BIOTOOLBOX'} = File::Spec->catfile($Bin, "Data", "biotoolbox.cfg");
}

require_ok 'Bio::ToolBox::Data' or 
	BAIL_OUT "Cannot load Bio::ToolBox::Data";


### Collect features from a database
my $infile = File::Spec->catfile($Bin, "Data", "chrI.gff3");
my $Data = Bio::ToolBox::Data->new(
	'db'      => $infile,
	'feature' => 'gene:SGD',
);
isa_ok($Data, 'Bio::ToolBox::Data', 'db collected gene table');

# check metadata
is($Data->feature, 'gene:SGD', 'feature');
is($Data->feature_type, 'named', 'feature type');
is($Data->program, undef, 'program');
is($Data->gff, 0, 'gff format');
is($Data->bed, 0, 'bed format');
is($Data->filename, undef, 'filename');

# check data table
is($Data->number_columns, 3, 'number of columns');
is($Data->last_row, 26, 'last row');

# columns
is($Data->id_column, 0, 'primary ID column');
is($Data->name_column, 1, 'identify name column');
is($Data->type_column, 2, 'identify type column');

# test database
is($Data->database, $infile, 'database name');
my $db = $Data->open_database;
isa_ok($db, 'Bio::DB::SeqFeature::Store', 'opened database');

# since we are dealing with a memory database, the features returned 
# are not in a predictable order suitable for testing
# so we will sort the data table by increasing name
$Data->sort_data(1, 'i');

# test row_stream
my $stream = $Data->row_stream;
isa_ok($stream, 'Bio::ToolBox::Data::Iterator', 'row stream iterator');

# look at first row
my $row = $stream->next_row;
isa_ok($row, 'Bio::ToolBox::Data::Feature', 'row Feature');
ok($row->row_index, 'row index'); # could be anything
is($row->type, 'gene:SGD', 'Feature type');
is($row->name, 'YAL043C', 'Feature name');
cmp_ok($row->id, '>=', 1, 'primary id'); # in memory db, could be anything?<commit_msg>update to fix new error with database collection<commit_after>#!/usr/bin/perl -w

# Test script for Bio::ToolBox::Data
# working with a Bio::DB::SeqFeature::Store database
# using in memory database for simplicity here....

use strict;
use Test::More;
use File::Spec;
use FindBin '$Bin';
use Statistics::Lite qw(min max);

BEGIN {
	if (eval {require Bio::DB::SeqFeature::Store::memory; 1}) {
		plan tests => 88;
	}
	else {
		plan skip_all => 'Bio::DB::SeqFeature::Store::memory or DB_File not available';
	}
	$ENV{'BIOTOOLBOX'} = File::Spec->catfile($Bin, "Data", "biotoolbox.cfg");
}

require_ok 'Bio::ToolBox::Data' or 
	BAIL_OUT "Cannot load Bio::ToolBox::Data";


### Collect features from a database
my $infile = File::Spec->catfile($Bin, "Data", "chrI.gff3");
my $Data = Bio::ToolBox::Data->new(
	'db'      => $infile,
	'feature' => 'gene:SGD',
);
isa_ok($Data, 'Bio::ToolBox::Data', 'db collected gene table');

# check metadata
is($Data->feature, 'gene:SGD', 'feature');
is($Data->feature_type, 'named', 'feature type');
is($Data->program, undef, 'program');
is($Data->gff, 0, 'gff format');
is($Data->bed, 0, 'bed format');
is($Data->filename, undef, 'filename');

# check data table
is($Data->number_columns, 3, 'number of columns');
is($Data->last_row, 33, 'last row'); # this now includes dubious genes as of 1.54

# columns
is($Data->id_column, 0, 'primary ID column');
is($Data->name_column, 1, 'identify name column');
is($Data->type_column, 2, 'identify type column');

# test database
is($Data->database, $infile, 'database name');
my $db = $Data->open_database;
isa_ok($db, 'Bio::DB::SeqFeature::Store', 'opened database');

# since we are dealing with a memory database, the features returned 
# are not in a predictable order suitable for testing
# so we will sort the data table by increasing name
$Data->sort_data(1, 'i');

# test row_stream
my $stream = $Data->row_stream;
isa_ok($stream, 'Bio::ToolBox::Data::Iterator', 'row stream iterator');

# look at first row
my $row = $stream->next_row;
isa_ok($row, 'Bio::ToolBox::Data::Feature', 'row Feature');
ok($row->row_index, 'row index'); # could be anything
is($row->type, 'gene:SGD', 'Feature type');
is($row->name, 'YAL043C', 'Feature name');
cmp_ok($row->id, '>=', 1, 'primary id'); # in memory db, could be anything?
{'fraction_non_alphanumeric': 0.1929902395740905, 'fraction_numerical': 0.008207630878438331, 'mean_word_length': 5.85258358662614, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 59, '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': '4952829', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1532, 'n_words': 462}