None available.
sub build_features
{
my ( $self, $opts ) = @_;
my $segment = $opts->{'segment'} || return ();
my $segment_start = $opts->{'start'};
my $segment_end = $opts->{'end'};
my $biomart = $self->{'BioMart'};
my $query = BioMart::Query->new(
'registry' => $biomart->{'registry'},
'virtualSchemaName' => $biomart->{'virtualSchema'}
);
$query->setDataset($biomart->{'dataset'});
my $atts = $biomart->{'attributes'};
foreach my $att ( @{$atts} ) {
$query->addAttribute($att->name());
}
$query->addFilter($biomart->{'filters'}[0]->name(), [$segment]);
if ( $segment_start && $segment_end ) {
$query->addFilter($biomart->{'filters'}[1]->name(), [$segment_start]);
$query->addFilter($biomart->{'filters'}[2]->name(), [$segment_end]);
}
my $reqKeys = REQUIREDKEYS;
my $defaults = DEFAULTS;
my @features = ();
my $query_runner = BioMart::QueryRunner->new();
$query->formatter('TSV'); $query_runner->execute($query);
my $result_buffer;
open( my $RESULTS, '>',\$ result_buffer );
$query_runner->printResults($RESULTS);
close($RESULTS);
my @rows = split /\n/, $result_buffer;
ROW: foreach my $rowLine (@rows) {
my @row = split /\t/, $rowLine;
my $feature = {};
my $good = 0;
KEY: foreach my $reqKey ( @{$reqKeys} ) {
my $pos = $biomart->{'required_keys'}{$reqKey};
next KEY unless ( $row[$pos] );
$good++;
}
next ROW unless ($good);
my $i = 0;
while ( $i < scalar(@row) ) {
my $key = $biomart->{'feature_keys'}[$i];
$feature->{$key} = $row[$i]
|| $defaults->{$key}; $i++;
}
push @features, $feature;
}
return @features;
}
1; } |
sub init
{
my ($self) = @_;
$self->{'capabilities'}{'features'} = '1.0';
my $biomart = $self->{'BioMart'};
my $confPath = $self->config()->{'registryPath'}
|| die "BioMart DAS requires the path to a Configuration File "
. "using the registryPath ini entry\n";
my $reqParams = REQPARAMS;
foreach my $title ( @{$reqParams} ) {
$biomart->{$title} = $self->config()->{$title};
}
die "BioMart DAS requires a mart and dataset in the ini file\n"
unless ( defined( $biomart->{'mart'} )
&& defined( $biomart->{'dataset'} )
&& defined( $biomart->{'linkName'} )
&& defined( $biomart->{'feature_keys'} ) );
unless ( defined( $biomart->{'virtualSchema'} ) ) {
$biomart->{'virtualSchema'} = DEFAULTVSCHEMA;
}
$biomart->{'feature_keys'} =
[ ( split /,/, $biomart->{'feature_keys'} ) ];
my $initializer =
BioMart::Initializer->new( 'registryFile'=>"$confPath",
'init_batchsize'=>INIT_BATCHSIZE,
'max_batchsize'=>MAX_BATCHSIZE,
'action'=>"update")
or die "Could not load Initializer $!\n";
$biomart->{'registry'} = $initializer->getRegistry();
my $dataset =
$biomart->{'registry'}
->getDatasetByName( $biomart->{'virtualSchema'},
$biomart->{'dataset'} );
my @importables = @{$dataset->getImportables( $biomart->{'linkName'} )};
my @exportables = @{$dataset->getExportables( $biomart->{'linkName'} )};
die "BioMart DAS Configuration must include an "
. "Importable-Exportable pair named by "
. $biomart->{'linkName'} . "\n"
unless ( @importables && @exportables );
print keys(%{$importables[0]})."\n";
my $filts = $importables[0]->getAllFilters();
die "BioMart DAS Compliant Importables "
. "must contain at least one filter\n"
unless ( scalar( @{$filts} ) >= 1 );
foreach my $filt ( @${filts} ) {
warn( "Recieved filt " . $filt->name . "\n" );
}
my $atts = $exportables[0]->getAllAttributes();
die "BioMart DAS Compliant Exportables "
. "must contain the same number of "
. "attributes as keys in the feature_keys INI specification\n"
unless (
scalar( @{$atts} ) ==
scalar( @{ $biomart->{'feature_keys'} } ) );
my $reqKeys = REQUIREDKEYS;
my $i = 0;
foreach my $key ( @{ $biomart->{'feature_keys'} } ) {
$biomart->{'required_keys'}{$key} = $i++
if ( grep { ( $_ eq $key ) } @{$reqKeys} );
}
die "BioMart DAS Compliant feature_keys list "
. "must contain at least "
. join( ",", @{$reqKeys} ) . "\n"
unless (
scalar( keys %{ $biomart->{'required_keys'} } ) ==
scalar( @{$reqKeys} ) );
$biomart->{'attributes'} = $atts;
$biomart->{'filters'} = $filts;
$self->{'BioMart'}=$biomart; } |