BioMart
Web
Toolbar
Summary
BioMart::Web - Class for handling incoming BioMart web-requests
Package variables
Typeglobs (from "local" definitions)
$Storable::Deparse = 1
Privates (from "my" definitions)
$conf_dir;
$logger;
$config;
$tt_processor;
Included modules
CGI::Session
DBI
Data::Dumper
English
File::Basename qw ( dirname basename )
File::Path
List::MoreUtils qw /apply uniq/
Log::Log4perl
Mail::Mailer
Number::Format qw ( :subs )
POSIX qw ( strftime )
Readonly
Storable qw ( store retrieve freeze nfreeze thaw )
Template
Template::Constants qw ( :debug )
Time::HiRes qw /time/
XML::Simple qw ( :strict )
Inherit
Synopsis
use BioMart::Web;
my $webquery = BioMart::Web->new({conf => $path_to_registryfile});
my $q = CGI->new();
$webquery->handle_request($q);
Description
This class handles processing of CGI-requests to build BioMart queries, execute
them and show the results to the user. Only initialization, query-building and
other such logic is done here: all user-interface presentation related things
are handled by Template Toolkit templates.
Methods
Methods description
Usage : my ($filtervalue_hash, $attribute_arrayref) = $self->extract_queryparams($CGI->Vars(), \@filterlist, \@attributelist); Purpose : Extracts information on filter/value pairs and attribute on/off status from a larger collection of parameter/value pairs from a CGI-request. Returns : Reference to hash of filter values keyed to the filternames and an arrayref with list of attribute names. Arguments : Reference to hash of parameter/value data (typically $CGI->Vars() from a CGI object or $session->dataref() from a CGI::Session object. Arrayref of filternames to extract values for (i.e. keys in hashref above). Arrayref of attributenames to extract on/off status for. Throws : none Status : Public Comments : See Also : |
Usage : Purpose : helper method to handleURLRequest Returns : Arguments : Throws : Status : Comments : See Also : |
Usage : Purpose : helper method to handleURLRequest Returns : Arguments : Throws : Status : Comments : See Also : |
Usage : $self->getURLBookmark($registry, $xml, $session); Purpose : handles xml equivalent of the query Returns : url_string Arguments : registryObject, QueryObject, session Throws : BioMart::Exception::* exceptions not caught somewhere deeper. Status : Public Comments : This method is called by SELF. See Also : |
Usage : Purpose : handles URL requests and populates the session object accordingly Returns : Nothing Arguments : URL params Throws : BioMart::Exception::* exceptions not caught somewhere deeper. Status : Public Comments : This method is called by handle_request. See Also : |
Usage : $self->handleXMLRequest($session, $url_string); Purpose : handles xml equivalent of the query Returns : none Arguments : session, url_string Throws : BioMart::Exception::* exceptions not caught somewhere deeper. Status : Public Comments : This method is called by SELF. See Also : |
Usage : $bmweb->handle_request(CGI->new()); Purpose : Main method of class, handles incoming CGI-requests Returns : Nothing Arguments : CGI object representing the request. Throws : BioMart::Exception::* exceptions not caught somewhere deeper. Status : Public Comments : This method is called by the skeleton martview script. See Also : |
Usage : my $js_hash = $self->perlhash2js(\%hash) Purpose : Convert a Perl hash into the Javascript equivalent (via Data::Dumper). Returns : Javascript code representing the hash structure. Arguments : Reference to the hash to be converted. Throws : none Status : Public Comments : See Also : |
Usage : my $query = $self->prepare_martquery({ schema => $schema_name, filters => {'hsapiens_gene_ensembl' => \%values_of_filter}, attributes => {'hsapiens_gene_ensembl' => \@attributes} });
Purpose : Construct BioMart query with provided filters & attributes.
Returns : Reference to a BioMart::Query object
Arguments : Anonymous hash with the following arguments:
schema Name of virtual schema (defaults to 'default' schema).
filters Hashref where the keys are the names of datasets and
the values are hashrefs of filter/value pairs (prepared
by extract_queryparams()).
attributes Hashref where the keys are the names of datasets and
the values are arrayrefs with attribute names (prepared
by extract_queryparams()).
dataset Name of dataset (only required if no filters or attributes
are being passed, typically to get total entrycount for dset).
Throws : BioMart::Exception::Configuration on errors from building the query
Status : Public
Comments :
See Also : extract_queryparams() |
Usage : $webquery->process_template($template,\%vars, $output); Purpose : Process the specified template with Template Toolkit Returns : Nothing if optional output argument is provided. If no output arg is provided, then returns processed text output to caller. Arguments : Filename of template Optional argument hashref Optional output filehandle-like object (e.g. IO::File, \*STDOUT) Throws : BioMart::Exception::Template on processing errors Status : Public Comments : See Also : |
Usage : my $session = $webquery->restore_session($CGI) Purpose : Retrieve stored user session or creates new one Returns : session object, either new or restored. Arguments : CGI request to get session ID parameter from Throws : BioMart::Exception::Session on session errors. Status : Public Comments : See Also : save_session() |
Usage : $webquery->save_session($session, $CGI); Purpose : Save CGI parameters to session, overwriting existing values. Returns : Nothing Arguments : Session object to save to, CGI-object which holds info from current request Throws : None Status : Public Comments : This effectively 'piles up' request parameters into the user session, since saved parameter values are combined with values from other parameters from previous sessions. See Also : restore_session() |
Usage : $self->set_errstr('my error message'); Purpose : Set the error message Returns : Nothing Arguments : String to set the error message to. Throws : Exception if use attempted by a non-BioMart::* class. Status : Private to class hierarchy. Comments : See Also : |
Methods code
sub _new
{
my ($self, @params) = @_;
$self->SUPER::_new(@params);
my (%args_ref) = @params;
$self->attr('errmsg', undef);
exists $args_ref{conf} && -f $args_ref{conf}
|| BioMart::Exception::Configuration->throw("Must provide path to config file as 'conf' argument ($args_ref{conf} is not a file)");
my $conf_dir = dirname($args_ref{conf});
$self->attr('configDir', $conf_dir);
$logger = Log::Log4perl->get_logger(__PACKAGE__);
my $mart_registry;
if(defined($args_ref{registry})) {
$logger->debug("Using existing registry passed to BioMart::Web constructor");
$mart_registry = $args_ref{registry};
}
else {
my $cachefile = $args_ref{conf}.".cached";
if(my $size = -s $cachefile)
{
$logger->debug("Deserializing registry from ".format_bytes($size)." of data in $cachefile");
eval{ $mart_registry = retrieve($cachefile) };
if($@ || !defined($mart_registry)) {
BioMart::Exception::Configuration->throw("Failed deserialization of registry from $cachefile. ".$@||q{} );
}
}
}
$self->attr('mart_registry', $mart_registry);
$self->attr('confDir',$conf_dir);
$self->attr('sessionDir', $args_ref{session_dir} || $conf_dir.'/sessions');
my $tt_dir = $args_ref{tt_dir} || $conf_dir.'/templates';
$self->attr('defaultDir',$args_ref{default_tt_dir} || $tt_dir.'/default');
$self->attr('customDir',$args_ref{custom_tt_dir} || $tt_dir.'/custom');
$self->attr('cachedDir',$args_ref{cached_tt_dir} || $tt_dir.'/cached');
$tt_processor = Template->new({ INCLUDE_PATH => [ $self->get_cached_tt_dir,
$self->get_custom_tt_dir,
$self->get_default_tt_dir ],
DEFAULT => 'notfound.tt',
RELATIVE => 1,
ABSOLUTE => 1,
INTERPOLATE => 1,
EVAL_PERL => 1,
POST_CHOMP => 1,
PRE_CHOMP => 1,
COMPILE_EXT => 'c',
COMPILE_DIR => '/',
CACHE_SIZE => 5
})
|| BioMart::Exception::Template->throw("Error when initalizing TT processor: ".$Template::ERROR);
} |
sub extract_queryparams
{ my ($self,$value_of_param, $filterlist, $attributelist) = @_;
$filterlist ||= [];
$attributelist ||= [];
$logger->debug("#### STARTING extract_queryparams ####");
my %values_of_attributefilter; my @attribute_params_final;
ATTRIBUTE:
foreach my $attributename(@$attributelist) {
next ATTRIBUTE if $attributename =~ /__checkbox\Z/xms;
my ($filtername_prefix) = $attributename =~ /\A(\w+__attribute)\./xms;
$filtername_prefix .= "filter.";
my ($datasetname) = $attributename =~ /\A(\w+?)__/xms;
$attributename =~ s/\A\w+__attribute\.//xms;
my $filtername = $filtername_prefix.$attributename;
my $filtervalue = $value_of_param->{ $filtername };
$logger->debug("Testing if attribute $attributename is an attributefilter");
if ((not defined($filtervalue)) || $filtervalue eq q{}) {
my $real_value;
if($real_value = $value_of_param->{ $filtername.'__list' }) {
$logger->debug("Modifying bool-list filter name/value pair $filtername=>$filtervalue to $filtervalue=>$real_value");
$filtervalue = $real_value; }
elsif($real_value = $value_of_param->{ $filtername.'__text__file' }) {
if (ref($real_value) eq 'ARRAY') { $real_value = @$real_value[0]; }
$real_value =~ m/(.*)__file/; $real_value = $value_of_param->{$1}; $logger->debug("Modifying ID-list filter name/value pair $filtername to $real_value (list from uploaded file)");
my @values = split(/[\n+\s+\,]+/, $real_value); map { s/\A\s+//xms; s/\s+\z//xms; } @values; $filtervalue =\@ values;
}
elsif($real_value = $value_of_param->{ $filtername.'__text' }) {
if (ref($real_value) eq 'ARRAY') { $real_value = @$real_value[0]; }
$logger->debug("Modifying ID-list filter name/value pair $filtername to $real_value (list from textarea)");
my @values = split(/[\n+\s+\,]+/, $real_value); map { s/\A\s+//xms; s/\s+\z//xms; } @values; $filtervalue =\@ values;
}
}
if ((not defined($filtervalue)) || $filtervalue eq q{}) {
$logger->debug("Empty list of values for attributefilter '$filtername', so is not an attributefilter");
$logger->debug("Enabling attribute $attributename instead");
push @attribute_params_final, $attributename;
next ATTRIBUTE;
}
$logger->debug("#### $filtername HAS VALUE $filtervalue####");
$filtervalue =~ s/\A[\s\n\r,]+//xms;
$filtervalue =~ s/[\s\n\r,]\z//xms;
my @filtervalues = ref($filtervalue) eq 'ARRAY' ? @$filtervalue : $filtervalue =~ /\0/ ? split("\0", $filtervalue) : $filtervalue =~ /[\n\r,]/ ? split(/[\n\r\s\,]+/, $filtervalue)
: ( $filtervalue ) ;
if(@filtervalues == 0) {
$logger->debug("Finished with an empty list of values for attributefilter '$filtername', so is not an attributefilter");
$logger->debug("Enabling attribute $attributename instead");
push @attribute_params_final, $attributename;
next ATTRIBUTE;
}
$logger->debug("Enabling attributefilter $attributename with values: '@filtervalues'");
$values_of_attributefilter{ $datasetname }{ $attributename } =\@ filtervalues;
}
my %values_of_filter; FILTER:
foreach my $filtername (@$filterlist) {
$logger->debug("#### DEALING WITH $filtername ####");
my $filtervalue = $value_of_param->{ $filtername };
if ((not defined($filtervalue)) || $filtervalue eq q{}) {
my $real_value;
if($real_value = $value_of_param->{ $filtername.'__list' }) {
if (ref($real_value) eq 'ARRAY') {
$real_value = pop(@$real_value);
}
$filtervalue = $real_value; $logger->debug("Modifying bool-list filter name/value pair $filtername=>$filtervalue to $filtervalue=>$real_value");
}
elsif($real_value = $value_of_param->{ $filtername.'__text__file' }) {
if (ref($real_value) eq 'ARRAY') { $real_value = @$real_value[0]; }
$real_value =~ m/(.*)__file/; $real_value = $value_of_param->{$1}; $logger->debug("Modifying ID-list filter name/value pair $filtername to $real_value (list from uploaded file)");
my @values = split(/[\n+\s+\,]+/, $real_value); map { s/\A\s+//xms; s/\s+\z//xms; } @values; $filtervalue =\@ values;
}
elsif($real_value = $value_of_param->{ $filtername.'__text' }) {
if (ref($real_value) eq 'ARRAY') {
$real_value = "@{$real_value}";
}
$logger->debug("Modifying ID-list filter name/value pair $filtername to $real_value (list from textarea)");
my @values = split(/[\n+\s+\,]+/, $real_value); map { s/\A\s+//xms; s/\s+\z//xms; } @values; $filtervalue =\@ values;
}
}
my ($filtername_prefix) = $filtername =~ /\A(\w+__filter\.)/xms; my ($datasetname) = $filtername =~ /\A(\w+?)__/xms;
if ((not defined($filtervalue)) || $filtervalue eq q{}) {
$logger->debug("Empty list of values ('') for filter '$filtername', skipping this filter");
next FILTER;
}
$logger->debug("#### $filtername HAS VALUE $filtervalue####");
$filtervalue =~ s/\A[\s\n\r,]+//xms;
$filtervalue =~ s/[\s\n\r,]\z//xms;
my @filtervalues = ref($filtervalue) eq 'ARRAY' ? @$filtervalue : $filtervalue =~ /\0/ ? split("\0", $filtervalue) : $filtervalue =~ /[\n\r,]/ ? split(/[\n\r\s\,]+/, $filtervalue)
: ( $filtervalue ) ;
if(@filtervalues == 0) {
$logger->debug("Empty list of values for filter $filtername, skipping this filter");
next FILTER;
}
$filtername =~ s/$filtername_prefix//xms; $logger->debug("Adding values to filter $filtername: '@filtervalues'");
$values_of_filter{ $datasetname }{ $filtername } =\@ filtervalues;
}
return (\%values_of_filter,\@ attribute_params_final,\% values_of_attributefilter); } |
sub filterDisplayType
{
my ($self, $dsName, $interface, $filterName, $session) = @_;
my $registry = $self->get_mart_registry();
foreach my $vSchema (@{$registry->getAllVirtualSchemas()}) {
if ($vSchema->name eq $session->param('schema')){
foreach my $mart (@{$vSchema->getAllMarts()}) {
foreach my $dataset (@{$mart->getAllDatasets()}) {
if ($dataset->name eq $dsName) { foreach my $configurationTree (@{$dataset->getAllConfigurationTrees()}) {
foreach my $filterTree (@{$configurationTree->getAllFilterTrees()}) {
foreach my $group(@{$filterTree->getAllFilterGroups()}) {
foreach my $collection (@{$group->getAllCollections()}) {
foreach my $filter (@{$collection->getAllFilters()}) {
if ($filter->name eq $filterName) {
if($filter->displayType eq 'container') {
foreach ( @{$filter->getAllOptions()} ) {
return "container__LIST" if ($_->filter()->displayType() eq 'list');
return "container__TEXT" if ($_->filter()->displayType() eq 'text'); }
}
}
}
foreach my $filter (@{$collection->getAllFilters()}) {
if ($filter->getAllOptions()) {
foreach ( @{$filter->getAllOptions()} ) {
if ($_->name eq $filterName && $filter->displayType eq 'container') {
return $filter->name.".container__LIST"
if ($_->filter()->displayType() eq 'list');
return $filter->name.".container__TEXT"
if ($_->filter()->displayType() eq 'text');
}
}
}
}
}
}
}
}
}
}
}
}
} } |
sub getFilterCollectionName
{
my ($self, $dsName, $interface, $filterName, $session) = @_;
my $registry = $self->get_mart_registry();
foreach my $vSchema (@{$registry->getAllVirtualSchemas()}) {
if ($vSchema->name eq $session->param('schema')){
foreach my $mart (@{$vSchema->getAllMarts()}) {
foreach my $dataset (@{$mart->getAllDatasets()}) {
if ($dataset->name eq $dsName) { foreach my $configurationTree (@{$dataset->getAllConfigurationTrees()}) {
foreach my $filterTree (@{$configurationTree->getAllFilterTrees()}) {
foreach my $group(@{$filterTree->getAllFilterGroups()}) {
foreach my $collection (@{$group->getAllCollections()}) {
foreach my $filter (@{$collection->getAllFilters()}) {
if ($filter->name eq $filterName)
{
return $collection->name;
}
}
foreach my $filter (@{$collection->getAllFilters()}) {
if ($filter->getAllOptions()) {
foreach ( @{$filter->getAllOptions()} ) {
if ($_->name eq $filterName)
{
return $collection->name;
}
}
}
}
}
}
}
}
}
}
}
}
} } |
sub getSettings
{
my ($self, $attribute) = @_;
my $mart_registry = $self->get_mart_registry();
my $hash = $mart_registry->settingsParams();
foreach(keys %$hash) {
if($_ eq $attribute) {
return %{$hash->{$_}};
}
} } |
sub getURLBookmark
{
my ($self, $registry, $xml, $session) = @_;
my ($url_string, $url_vs, $url_datasetName, $url_interface, $url_attPage, $url_atts, $url_filtPage, $url_filts, $url_visiblePanel);
my @DS;
my @attributes;
my $i=0;
my $config = XMLin($xml, forcearray=> [qw(Query Dataset Attribute
ValueFilter BooleanFilter
Filter Links)], keyattr => []);
$url_vs = $config->{'virtualSchemaName'} || 'default';
$url_string = "?VIRTUALSCHEMANAME=".$url_vs;
$url_atts = "&ATTRIBUTES=";
$url_filts = "&FILTERS=";
$url_visiblePanel = "&VISIBLEPANEL=";
$url_attPage = "_ATT_PAGE_";
$url_filtPage = "_FILT_PAGE_";
foreach my $url_dataset (@{$config->{'Dataset'}}) {
$url_interface = $url_dataset->{'interface'} || 'default';
$url_datasetName = $url_dataset->{'name'};
$DS[$i++] = $url_datasetName;
my $datasetObj = $registry->getDatasetByName($url_vs, $url_dataset->{'name'});
if (!$datasetObj){
BioMart::Exception::Usage->throw ("WITHIN Virtual Schema : $url_vs, Dataset ".$url_dataset->{'name'}." NOT FOUND");
}
my $confTree = $registry->getDatasetByName($url_vs, $url_dataset->{'name'})->getConfigurationTree($url_interface);
if (!$confTree){
BioMart::Exception::Usage->throw ("Cannot find Configuration Tree for $url_vs.".$url_dataset->{'name'});
}
foreach my $attributeNode (@{$url_dataset->{'Attribute'}}) {
$url_atts = $url_atts.$url_datasetName.'.'.$url_interface.'.'.$url_attPage.'.'.$attributeNode->{'name'}.'|';
push @attributes, $attributeNode->{'name'};
}
foreach my $filterNode (@{$url_dataset->{'Filter'}}) {
my $attFilt;
foreach my $attPage (@{$confTree->getAllAttributeTrees()}) {
$attFilt = $attPage->getFilterByName($filterNode->{'name'});
if ($attFilt && $attFilt->isa("BioMart::Configuration::ValueFilter")){
$url_atts = $url_atts.$url_datasetName.'.'.$url_interface.'.'.$url_attPage.'.'.$filterNode->{'name'}.'."'.$filterNode->{'value'}.'"|';
push @attributes, $filterNode->{'name'};
last;
}
}
if(!$attFilt){ if (defined $filterNode->{'excluded'}){
$url_filts = $url_filts.$url_datasetName.'.'.$url_interface.'.'.$url_filtPage.'.'.$filterNode->{'name'}.'.'."excluded".'|'
if ($filterNode->{'excluded'} eq '1');
$url_filts = $url_filts.$url_datasetName.'.'.$url_interface.'.'.$url_filtPage.'.'.$filterNode->{'name'}.'.'."only".'|'
if ($filterNode->{'excluded'} eq '0');
}
elsif (defined $filterNode->{'value'}){
$url_filts = $url_filts.$url_datasetName.'.'.$url_interface.'.'.$url_filtPage.'.'.$filterNode->{'name'}.'."'.$filterNode->{'value'}.'"|';
}
else {
BioMart::Exception::Usage->throw ("Filter ".$filterNode->{'name'}." INVALID, FILTER NEEDS 'excluded' or 'value' attribute");
}
}
}
foreach my $attPage (@{$confTree->getAllAttributeTrees()}) {
my $dirtyFlag = 1;
foreach my $attName (@attributes) {
my $attObj = $attPage->getAttributeByName($attName);
if (!$attObj) {
$attObj = $attPage->getFilterByName($attName);
}
$dirtyFlag = 0 if (!$attObj); }
if ($dirtyFlag == 1) { $url_attPage = $attPage->name();
last;
}
}
foreach my $filterPage (@{$confTree->getAllFilterTrees()}){
$url_filtPage = $filterPage->name() if ($filterPage->hideDisplay ne 'true');
}
$url_atts =~ s/_ATT_PAGE_/$url_attPage/g;
$url_filts =~ s/_FILT_PAGE_/$url_filtPage/g;
}
if ($session->param("mart_mainpanel__current_visible_section") eq $DS[0].'__infopanel') {
$url_visiblePanel .= 'mainpanel';
}
elsif ($session->param("mart_mainpanel__current_visible_section") eq $DS[0].'__attributepanel') {
$url_visiblePanel .= 'attributepanel';
}
elsif ($session->param("mart_mainpanel__current_visible_section") eq $DS[0].'__filterpanel') {
$url_visiblePanel .= 'filterpanel'
}
elsif ($DS[1] && $session->param("mart_mainpanel__current_visible_section") eq $DS[1].'__infopanel') {
$url_visiblePanel .= 'linkpanel';
}
elsif ($DS[1] && $session->param("mart_mainpanel__current_visible_section") eq $DS[1].'__attributepanel') {
$url_visiblePanel .= 'linkattributepanel';
}
elsif ($DS[1] && $session->param("mart_mainpanel__current_visible_section") eq $DS[1].'__filterpanel') {
$url_visiblePanel .= 'linkfilterpanel';
}
elsif ($session->param("mart_mainpanel__current_visible_section") eq 'add_linked_datasetpanel') {
$url_visiblePanel .= 'linkpanel';
}
else { $url_visiblePanel .= "resultspanel";
}
chop($url_atts) if ($url_atts ne "&ATTRIBUTES=");
chop($url_filts) if ($url_filts ne "&FILTERS=");
$url_string .= $url_atts;
$url_string .= $url_filts;
$url_string .= $url_visiblePanel;
return $url_string; } |
sub get_cached_tt_dir
{
my ($self) = @_;
return $self->get('cachedDir'); } |
sub get_conf_Dir()
{
my ($self) = @_;
return $self->get('confDir'); } |
sub get_config_dir
{
my ($self) = @_;
return $self->get('configDir'); } |
sub get_custom_tt_dir
{
my ($self) = @_;
return $self->get('customDir'); } |
sub get_default_tt_dir
{
my ($self) = @_;
return $self->get('defaultDir'); } |
sub get_errstr
{
my ($self) = @_;
return $self->get('errmsg'); } |
sub get_mart_registry()
{
my ($self) = @_;
return $self->get('mart_registry'); } |
sub get_session_dir
{
my ($self) = @_;
return $self->get('sessionDir'); } |
sub handleURLRequest
{
my ($self, $session) = @_;
my $registry = $self->get_mart_registry();
eval {
BioMart::Exception::Usage->throw("please specify both VIRTUALSCHEMANAME and ATTRIBUTES in URL in correct format")
if (!$session->param("url_VIRTUALSCHEMANAME") || !$session->param("url_ATTRIBUTES"));
my $schema = $session->param("url_VIRTUALSCHEMANAME");
my @DS;
my $datasets;
my @attributes;
my @attributeList = split (/\|/, $session->param("url_ATTRIBUTES") );
foreach(@attributeList)
{
my @temp_portions = split (/\./, $_);
if ($temp_portions[4]) {
$temp_portions[4] =~ s/\"//g; $datasets->{$temp_portions[0]}->{$temp_portions[1]}->{'ATTRIBUTES'}->{$temp_portions[2].'.'.$temp_portions[3]} = $temp_portions[4];
}
else{
$datasets->{$temp_portions[0]}->{$temp_portions[1]}->{'ATTRIBUTES'}->{$temp_portions[2].'.'.$temp_portions[3]} = "NULL";
}
my $dsFlag = 0;
foreach my $dsExists (@DS){
$dsFlag = 1 if($dsExists eq $temp_portions[0])
}
push @DS, $temp_portions[0] if (!$dsFlag);
}
my @filterList = split (/\|/, $session->param("url_FILTERS") ) if $session->param("url_FILTERS");
foreach(@filterList)
{
my @temp_portions = split (/\./, $_,5); $temp_portions[4] =~ s/\"//g; $datasets->{$temp_portions[0]}->{$temp_portions[1]}->{'FILTERS'}->{$temp_portions[2].'.'.$temp_portions[3]} = $temp_portions[4];
}
BioMart::Exception::Usage->throw("You cannot have zero OR more than 2 datasets")
if (scalar (@DS) == 0 || scalar (@DS) > 2);
$session->param('schema', $schema);
$session->param('dataset',\@ DS );
foreach my $vSchema (@{$registry->getAllVirtualSchemas()}) {
if ($vSchema->name eq $schema){
foreach my $mart (@{$vSchema->getAllMarts()}) {
foreach my $dataset (@{$mart->getAllDatasets()}) {
if ($dataset->name eq $DS[0]) { $session->param('dataBase', $mart->displayName); }
}
}
}
}
my $atts;
foreach my $dsName(keys %$datasets) {
foreach my $interface(keys %{$datasets->{$dsName}}) {
foreach my $ATTRIBUTES (keys %{$datasets->{$dsName}->{$interface}}) {
if ($ATTRIBUTES eq 'ATTRIBUTES') {
foreach my $attTreeAttribute (keys %{$datasets->{$dsName}->{$interface}->{'ATTRIBUTES'}}) {
my @portions = split(/\./,$attTreeAttribute);
$session->param($dsName.'__attributepage', $portions[0]) if (!$session->param($dsName.'__attributepage'));
my $attributeString = $dsName.'__'.$portions[0].'__attribute'.'.'.$portions[1];
push @{$atts->{$dsName}}, $attributeString;
my $val = $datasets->{$dsName}->{$interface}->{'ATTRIBUTES'}->{$attTreeAttribute};
if ($val ne "NULL") {
$attributeString =~ s/attribute\./attributefilter\./;
$session->param($attributeString, $val);
}
}
}
}
}
my $currentPage = $session->param($dsName.'__attributepage');
$session->param($session->param('schema').'____'.$dsName.'__'.$currentPage.'__attributelist',\@ {$atts->{$dsName}} );
}
my $filts;
my $filterCollections;
foreach my $dsName(keys %$datasets) {
foreach my $interface(keys %{$datasets->{$dsName}}) {
foreach my $FILTERS (keys %{$datasets->{$dsName}->{$interface}}) {
if ($FILTERS eq 'FILTERS') {
foreach my $filtTreeFilter (keys %{$datasets->{$dsName}->{$interface}->{'FILTERS'}}) {
my @portions = split(/\./,$filtTreeFilter);
my $filterString = $dsName.'__filter'.'.'.$portions[1];
push @{$filts->{$dsName}}, $filterString;
my $val = $datasets->{$dsName}->{$interface}->{'FILTERS'}->{$filtTreeFilter};
my @temp_values;
foreach my $val1 (split (/\,/, $val) ) {
push @temp_values, $val1;
}
if ($self->filterDisplayType($dsName, $interface, $portions[1], $session) =~ m/(.*?)\.?container__LIST/ ) { # original filterName as the one received is just options Name # add filter with value <ds>__filter.<filterInternalName>__list = array of values my $realFilterName = $1; $session->param($dsName.'__filter.'.$1.'__list', $val) if ($1); if ($1 && !$session->param($dsName.'__filter.'.$1))
{
$session->param($dsName.'__filter.'.$1, $portions[1]);
}
elsif ($1 && $session->param($dsName.'__filter.'.$1))
{
my @temp_arr;
push @temp_arr, $session->param($dsName.'__filter.'.$1);
push @temp_arr, $portions[1] ;
$session->clear($dsName.'__filter.'.$1);
$session->param($dsName.'__filter.'.$1,\@ temp_arr);
}
$filterString .= '__list';
}
elsif ($self->filterDisplayType($dsName, $interface, $portions[1], $session) =~ m/(.*?)\.?container__TEXT/ ) {
# original filterName as the one received is just options Name # add filter with value <ds>__filter.<filterInternalName>__text = array of values my $realFilterName = $1; $session->param($dsName.'__filter.'.$1.'__text', $val) if ($1); $session->param($dsName.'__filter.'.$1, $portions[1]) if ($1);
$filterString .= '__text';
}
else {
}
if (scalar (@temp_values) > 1) { $session->param($filterString,\@ temp_values); }
else { $session->param($filterString, $temp_values[0]); }
my $collectionName = $self->getFilterCollectionName($dsName, $interface, $portions[1], $session);
my $filtCollectionString = $dsName.'__filtercollection.'.$collectionName;
$filterCollections->{$dsName}->{$filtCollectionString}++; }
}
}
}
$session->param($session->param('schema').'____'.$dsName.'__filterlist',\@ {$filts->{$dsName}} );
my @collectionsArray;
foreach (keys %{$filterCollections->{$dsName}}) {
push @collectionsArray, $_;
}
$session->param($dsName.'__filtercollections',\@ collectionsArray);
}
foreach my $dsName(keys %$datasets) {
foreach my $interface(keys %{$datasets->{$dsName}}) {
foreach my $ATTRIBUTES (keys %{$datasets->{$dsName}->{$interface}}) {
if ($ATTRIBUTES eq 'ATTRIBUTES') {
foreach my $attTreeAttribute (keys %{$datasets->{$dsName}->{$interface}->{'ATTRIBUTES'}}) {
my @portions = split(/\./,$attTreeAttribute);
$session->param($dsName.'__attributepages__current_visible_section', $dsName.'__attributepanel__'.$portions[0])
if (!$session->param($dsName.'__attributepages__current_visible_section'));
}
}
}
}
}
$session->param('URL_REQUEST', '1');
$session->param('exportView_outputformat', 'tsv');
$session->param('preView_outputformat', 'html');
$session->param('datasetmenu_3', $DS[0]);
if ($session->param('url_VISIBLEPANEL') && $session->param('url_VISIBLEPANEL') eq 'mainpanel' ) {
$session->param("mart_mainpanel__current_visible_section", $DS[0].'__infopanel');
$session->param("summarypanel__current_highlighted_branch", $DS[0].'__summarypanel_datasetbranch');
}
elsif ($session->param('url_VISIBLEPANEL') && $session->param('url_VISIBLEPANEL') eq 'attributepanel' ) {
$session->param("mart_mainpanel__current_visible_section", $DS[0].'__attributepanel');
$session->param("summarypanel__current_highlighted_branch", $DS[0].'__summarypanel_attributebranch');
}
elsif ($session->param('url_VISIBLEPANEL') && $session->param('url_VISIBLEPANEL') eq 'filterpanel' ) {
$session->param("mart_mainpanel__current_visible_section", $DS[0].'__filterpanel');
$session->param("summarypanel__current_highlighted_branch", $DS[0].'__summarypanel_filterbranch');
}
elsif ($session->param('url_VISIBLEPANEL') && $session->param('url_VISIBLEPANEL') eq 'linkpanel' ) {
if ($DS[1]) {
$session->param("mart_mainpanel__current_visible_section", $DS[1].'__infopanel');
$session->param("summarypanel__current_highlighted_branch", $DS[1].'__summarypanel_datasetbranch');
}
else { $session->param("mart_mainpanel__current_visible_section", 'add_linked_datasetpanel');
$session->param("summarypanel__current_highlighted_branch", 'show_linked_datasetpanel');
}
}
elsif ($session->param('url_VISIBLEPANEL') && $session->param('url_VISIBLEPANEL') eq 'linkattributepanel' ) {
if ($DS[1]) {
$session->param("mart_mainpanel__current_visible_section", $DS[1].'__attributepanel');
$session->param("summarypanel__current_highlighted_branch", $DS[1].'__summarypanel_attributebranch');
}
else { $session->param("mart_mainpanel__current_visible_section", 'add_linked_datasetpanel');
$session->param("summarypanel__current_highlighted_branch", 'show_linked_datasetpanel');
}
}
elsif ($session->param('url_VISIBLEPANEL') && $session->param('url_VISIBLEPANEL') eq 'linkfilterpanel' ) {
if ($DS[1]) {
$session->param("mart_mainpanel__current_visible_section", $DS[1].'__filterpanel');
$session->param("summarypanel__current_highlighted_branch", $DS[1].'__summarypanel_filterbranch');
}
else { $session->param("mart_mainpanel__current_visible_section", 'add_linked_datasetpanel');
$session->param("summarypanel__current_highlighted_branch", 'show_linked_datasetpanel');
}
}
else { $session->param('resultsButton', '1');
$session->param("mart_mainpanel__current_visible_section", "resultspanel");
}
$session->clear("url_VIRTUALSCHEMANAME");
$session->clear("url_ATTRIBUTES");
$session->clear("url_FILTERS");
$session->clear("url_VISIBLEPANEL");
};
my $ex;
if ( $ex = Exception::Class->caught() )
{
my $errmsg = $ex->error();
$logger->debug("URL Access error: ".$errmsg);
UNIVERSAL::can($ex, 'rethrow') ? $ex->rethrow : die $ex;
return 'exit';
} } |
sub handleXMLRequest
{
my ($self, $session, $url_string) = @_;
$url_string =~ m/.*?VIRTUALSCHEMANAME=(.*?)\&ATTRIBUTES=(.*?)\&FILTERS=(.*?)\&VISIBLEPANEL=(.*)/; $session->param("url_VIRTUALSCHEMANAME", $1);
$session->param("url_ATTRIBUTES", $2);
if ($3) { $session->param('url_FILTERS', $3); }
else { $session->clear("url_FILTERS"); }
if ($4) { $session->param('url_VISIBLEPANEL', $4); }
else { $session->clear("url_VISIBLEPANEL"); }
$session->clear("url_XML"); } |
sub handle_request
{ my ($self, $CGI) = @_;
my $qtime = time();
my $registry = $self->get_mart_registry();
my $confPATH = $self->get_conf_Dir();
$self->set_errstr('');
my $session = $self->restore_session($CGI) || return;
$session->clear("__validationError");
my $form_action = $CGI->url(-absolute => 1) . '/' . $session->id();
$logger->is_debug()
and $logger->info("Incoming CGI-params:\n",Dumper(\%{$CGI->Vars()}));
if($session->param("url_XML"))
{ $self->handleXMLRequest($session,
$self->getURLBookmark($registry, $session->param("url_XML"), $session));
}
if($session->param("url_VIRTUALSCHEMANAME") || $session->param("url_ATTRIBUTES"))
{ my $returnVal = $self->handleURLRequest($session);
return if ($returnVal eq 'exit'); }
my $returnaAfterSave = 0;
if (($CGI->Vars()->{'countButton'}) && $CGI->Vars()->{'countButton'} eq '5')
{
$CGI->Vars()->{'countButton'} = '0';
$returnaAfterSave = 1;
print $CGI->header();
print "<html><body><div id =\"countDivIFrameId\" style=\"display:none;\">ToCountHiddenIFrame</div></body></html>";
}
if (($CGI->Vars()->{'resultsButton'}) && $CGI->Vars()->{'resultsButton'} eq '5')
{
$CGI->Vars()->{'resultsButton'} = '0';
$returnaAfterSave = 1;
print $CGI->header();
print "<html><body><div id =\"resultsDivIFrameId\" style=\"display:none;\">ToResultsHiddenIFrame</div></body></html>";
}
$self->save_session($session, $CGI);
return if ($returnaAfterSave);
$session->param('countButton', '1') if ($CGI->self_url() =~ m/__countByAjax\z/) ; $session->param('resultsButton', '1') if ($CGI->self_url() =~ m/__resultsByAjax\z/) ;
if (!$session->param('GALAXY_URL') && ($session->param('_export') && $session->param('_export') eq '1') ) {
$session->param('resultsButton', '1');
}
my( $def_schema, $def_db, $def_ds, $def_ds_OBJ);
my $reverseName = 0; if (($session->param("mart_mainpanel__current_visible_section") &&
$session->param("mart_mainpanel__current_visible_section") eq "__infopanel")
|| ($session->param("summarypanel__current_highlighted_branch") &&
$session->param("summarypanel__current_highlighted_branch") eq "__summarypanel_datasetbranch"))
{
$session->clear("mart_mainpanel__current_visible_section");
$session->clear("summarypanel__current_highlighted_branch");
}
$session->clear('newQuery');
my %js_datasetpanel_sessions_values = ();
my @schemas;
my @database_names;
my @datasets;
my %build_errors;
my %js_pushactions_of_datasetmenu = ();
my $default_dataset;
my @datasetUnits;
my $unitsHash = ();
my $multiMenuDS = 0;
my $TAG_path;
my $dbName;
my $result_string;
my @dataset_names_in_query = ();
my %entrycount_of_dataset;
my %filtercount_of_dataset;
my $preView_formatter_name;
my $exportView_formatter_name;
my $noFilter = "";
my $countStringForJS="";
my $all_formatters="";
my $exceptionFlag=0;
my %location_path = $self->getSettings('httpdSettings');
$TAG_path = $location_path{'location'};
my $schemas = $registry->getAllVirtualSchemas();
SCHEMA:
foreach my $schema(@$schemas) {
push(@schemas, $schema);
my $schema_name = $schema->name();
my $databases = $registry->getAllDatabaseNames($schema_name, 1);
DATABASE:
foreach my $database_name(@$databases) {
$multiMenuDS = 0;
$unitsHash = ();
my %defDSHash = ();
push @database_names, $database_name;
my $schema__dbName = $schema_name.'____'.$database_name;
push(@{ $js_pushactions_of_datasetmenu{ 'schema' }->{ $schema_name }->{ 'databasemenu' } }, [$schema__dbName, $database_name] );
my $datasets = $registry->getAllDataSetsByDatabaseName($schema_name, $database_name, 1);
my $last_dataset;
DATASET:
foreach my $dataset_name(@$datasets) {
my $dataset = $registry->getDatasetByName($schema_name, $dataset_name)
|| BioMart::Exception::Configuration->throw("Couldn't get dataset $schema_name->$database_name->$dataset_name from registry");
push @datasets, $dataset;
my $conf_tree = $dataset->getConfigurationTree('default');
if ($dataset->displayName !~ m/\|/) { # setting the default dataset to appear as first option in the menu if ($conf_tree->defaultDataset()){ # unshift(@{ $js_pushactions_of_datasetmenu{ 'databasemenu' }->{ $schema__dbName }->{ 'datasetmenu_3' } }, # [$dataset->name, $dataset->displayName()]); $defDSHash{$dataset->displayName()} = $dataset->name();
}
else{
push(@{ $js_pushactions_of_datasetmenu{ 'databasemenu' }->{ $schema__dbName }->{ 'datasetmenu_3' } },
[$dataset->name, $dataset->displayName()]);
}
$default_dataset ||= $dataset;
}
else
{
$multiMenuDS = 1;
my $dsName = $dataset->displayName;
my @dsPortions = split(/\|/,$dsName);
my $menuCount = 1;
$unitsHash->{$dsPortions[0]}->{$dsPortions[1]}->{$dsPortions[2]} = [$dataset->name, $dataset->displayName()];
$unitsHash->{$dsPortions[1]}->{$dsPortions[0]}->{$dsPortions[2]} = [$dataset->name, $dataset->displayName()];
$default_dataset ||= $dataset;
$dsName = $default_dataset->displayName;
@datasetUnits = split(/\|/,$dsName);
}
} if($multiMenuDS == 1)
{
foreach my $one(sort keys %$unitsHash) {
my $temp_one = $schema__dbName.'____'.$one;
push(@{ $js_pushactions_of_datasetmenu{ 'databasemenu' }->{ $schema__dbName }->{ 'datasetmenu_1' } }, [$temp_one,$one]);
foreach my $two (sort keys %{$unitsHash->{$one}}) {
my $temp_two = $temp_one.'____'.$two;
push(@{ $js_pushactions_of_datasetmenu{ 'datasetmenu_1' }->{ $temp_one }->{ 'datasetmenu_2' } }, [$temp_two, $two]);
foreach my $three (sort keys %{$unitsHash->{$one}->{$two}}) {
my @dsName = ();
my $index = 0;
foreach (@{$unitsHash->{$one}->{$two}->{$three}}) {
$dsName[$index++] = $_;
}
my $temp_three = $temp_two.'____'.$three;
push(@{ $js_pushactions_of_datasetmenu{ 'datasetmenu_2' }->{ $temp_two }->{ 'datasetmenu_3' } }, [$three, $three]);
}
}
}
}
my $separator_length = 5; foreach my $dataset_name(@$datasets) {
my $dataset = $registry->getDatasetByName($schema_name, $dataset_name);
if (length($dataset->displayName()) > $separator_length) {
$separator_length = length($dataset->displayName());
}
}
my $separator_added = 0;
my $separator = '-'x$separator_length;
foreach my $dispName(reverse sort keys %defDSHash) {
if (!$separator_added) {
unshift(@{ $js_pushactions_of_datasetmenu{ 'databasemenu' }->{ $schema__dbName }->{ 'datasetmenu_3' } },
['', $separator]); $separator_added = 1;
}
unshift(@{ $js_pushactions_of_datasetmenu{ 'databasemenu' }->{ $schema__dbName }->{ 'datasetmenu_3' } },
[$defDSHash{$dispName}, $dispName]);
}
} } $default_dataset ||= $datasets[0];
if(keys(%{ $js_pushactions_of_datasetmenu{ 'databasemenu' } }) == 0) {
$logger->info("No datasets found in registry, so no templates were built. Returning 0");
return 0;
}
my $schemaCount = $registry->getAllVirtualSchemas();
if (scalar (@{$schemaCount}) == 2) {
my ($visibleVS, $invisibleVS) = 0 ;
foreach my $schema(@$schemaCount) {
$visibleVS++ if($schema->visible());
$invisibleVS++ if(!$schema->visible());
}
$session->clear('mergeVS');
if ($visibleVS == 1 && $invisibleVS == 1) { $session->param('mergeVS', '1'); }
else { $session->param('mergeVS', '0'); }
}
else { $session->param('mergeVS', '0'); }
if($session->param('menuNumber') && $session->param('menuNumber') eq '3')
{
my @schemaDB_units = split (/____/,$session->param('databasemenu'));
$session->param('schema', $schemaDB_units[0]);
$session->param('dataBase', $schemaDB_units[1]);
}
if (!$session->param('schema') && !$session->param('dataBase') && !$session->param('dataset'))
{
print $CGI->header();
$session->param('newQuery', '1');
$js_datasetpanel_sessions_values{'schema'} = '';
$js_datasetpanel_sessions_values{'databasmenu'} = '';
$js_datasetpanel_sessions_values{'datasetmenu_1'} = '';
$js_datasetpanel_sessions_values{'datasetmenu_2'} = '';
$js_datasetpanel_sessions_values{'datasetmenu_3'} = '';
}
else {
if (!$session->param('dataBase') && $session->param('dataset') && $session->param('schema')){
my @schemaDB_units = split (/____/,$session->param('databasemenu'));
$session->param('dataBase', $schemaDB_units[1]);
}
$js_datasetpanel_sessions_values{'schema'} = $session->param('schema');
$js_datasetpanel_sessions_values{'databasemenu'} = $session->param('dataBase');
my $dsName = $session->param('datasetmenu_3');
if($session->param('menuNumber') && ($session->param('menuNumber') eq '3' || $session->param('menuNumber') eq '5' ))
{
my $dsHint1 = $session->param('datasetmenu_1');
my $dsHint2 = $session->param('datasetmenu_2');
my $dsHint3 = $session->param('datasetmenu_3');
my $dsDisplayName;
$dsHint2 =~ m/.*?____.*?____(.*)/; $dsHint2 = $1;
$dsDisplayName = $dsHint2;
$dsDisplayName =~ s/____/\|/;
$dsDisplayName .= '|'.$dsHint3;
my @dsUnits = split (/\|/, $dsDisplayName);
$js_datasetpanel_sessions_values{'datasetmenu_1'} = $dsUnits[0];
$js_datasetpanel_sessions_values{'datasetmenu_2'} = $dsUnits[1];
$js_datasetpanel_sessions_values{'datasetmenu_3'} = $dsUnits[2];
}
else {
my $dsDisplayName;
foreach my $schema (@{$registry->getAllVirtualSchemas()}) {
if($schema->name eq $session->param('schema')) {
foreach my $mart (@{$schema->getAllMarts(1)}) {
if($mart->displayName eq $session->param('dataBase')) {
foreach my $dataset (@{$mart->getAllDatasets(1)}) {
if($dsName eq $dataset->name) {
$dsDisplayName = $dataset->displayName;
}
}
}
}
}
}
$js_datasetpanel_sessions_values{'datasetmenu_3'} = $dsDisplayName;
$js_datasetpanel_sessions_values{'datasetmenu_1'} = '';
$js_datasetpanel_sessions_values{'datasetmenu_2'} = '';
$session->clear('datasetmenu_1');
$session->clear('datasetmenu_2');
}
$session->clear('ds_1_count');
$session->clear('ds_2_count');
$def_schema = $session->param('schema');
$def_db = $session->param('dataBase');
$def_ds = $session->param('dataset');
if($session->param('menuNumber') && $session->param('menuNumber') eq '3')
{
$def_ds = undef; $session->clear('dataset'); my $dsHint1 = $session->param('datasetmenu_1');
my $dsHint2 = $session->param('datasetmenu_2');
my $dsHint3 = $session->param('datasetmenu_3');
my $dsDisplayName;
$dsHint2 =~ m/.*?____.*?____(.*)/; $dsHint2 = $1;
$dsDisplayName = $dsHint2;
$dsDisplayName =~ s/____/\|/;
$dsDisplayName .= '|'.$dsHint3;
my ($tempRemoveSpaces, $tempdsDisplayName);
foreach my $schema (@{$registry->getAllVirtualSchemas()}) {
if($schema->name eq $def_schema) {
foreach my $mart (@{$schema->getAllMarts()}) {
if($mart->displayName eq $def_db) {
foreach my $dataset (@{$mart->getAllDatasets(1)}) {
$tempRemoveSpaces = $dataset->displayName;
$tempdsDisplayName = $dsDisplayName;
$tempRemoveSpaces =~ s/\s//mg; $tempdsDisplayName =~ s/\s//mg;
$tempRemoveSpaces =~ s/\|//mg; $tempdsDisplayName =~ s/\|//mg;
$tempRemoveSpaces =~ s/\(//mg; $tempdsDisplayName =~ s/\(//mg;
$tempRemoveSpaces =~ s/\)//mg; $tempdsDisplayName =~ s/\)//mg;
if($tempRemoveSpaces =~ m/^$tempdsDisplayName/) { foreach my $configurationTree (@{$dataset->getAllConfigurationTrees()}){ if($configurationTree->defaultDataset()) { $def_ds = $dataset->name(); $def_ds_OBJ = $dataset;
}
}
$def_ds ||= $dataset->name();
$def_ds_OBJ ||= $dataset;
$reverseName = 2;
}
}
if(!$reverseName) {
foreach my $dataset (@{$mart->getAllDatasets(1)}) {
my @unitsArray = split('\|', $dsDisplayName);
$tempdsDisplayName = $unitsArray[1].'|'.$unitsArray[0].'|'.$unitsArray[2];
$tempdsDisplayName =~ s/\s//mg;
$tempdsDisplayName =~ s/\|//mg;
$tempdsDisplayName =~ s/\(//mg;
$tempdsDisplayName =~ s/\)//mg;
$tempRemoveSpaces = $dataset->displayName;
$tempRemoveSpaces =~ s/\s//mg; $tempRemoveSpaces =~ s/\|//mg; $tempRemoveSpaces =~ s/\(//mg; $tempRemoveSpaces =~ s/\)//mg;
if($tempRemoveSpaces =~ m/^$tempdsDisplayName/) { foreach my $configurationTree (@{$dataset->getAllConfigurationTrees()}){ if($configurationTree->defaultDataset()) { $def_ds = $dataset->name(); $def_ds_OBJ = $dataset;
}
}
$def_ds ||= $dataset->name();
$def_ds_OBJ ||= $dataset;
$reverseName = 1;
}
}
}
if(!$reverseName) {
foreach my $dataset (@{$mart->getAllDatasets(1)}) {
$tempRemoveSpaces = $dataset->displayName;
$tempdsDisplayName = $dsDisplayName;
$tempRemoveSpaces =~ s/\s//mg; $tempdsDisplayName =~ s/\s//mg;
$tempRemoveSpaces =~ s/\|//mg; $tempdsDisplayName =~ s/\|//mg;
$tempRemoveSpaces =~ s/\(//mg; $tempdsDisplayName =~ s/\(//mg;
$tempRemoveSpaces =~ s/\)//mg; $tempdsDisplayName =~ s/\)//mg;
if($tempRemoveSpaces =~ m/$tempdsDisplayName/) { foreach my $configurationTree (@{$dataset->getAllConfigurationTrees()}){ if($configurationTree->defaultDataset()) { $def_ds = $dataset->name(); $def_ds_OBJ = $dataset;
}
}
$def_ds ||= $dataset->name();
$def_ds_OBJ ||= $dataset;
$reverseName = 1;
}
}
}
}
}
}
}
if ($session->param("mart_mainpanel__current_visible_section") =~ m/__infopanel$/ || $session->param("summarypanel__current_highlighted_branch") =~ m/__summarypanel_datasetbranch$/) { $session->clear("mart_mainpanel__current_visible_section"); $session->clear("summarypanel__current_highlighted_branch");
my $vSection = $def_ds.'__infopanel';
my $summaryBranch = $def_ds.'__summarypanel_datasetbranch';
$session->param("mart_mainpanel__current_visible_section", $vSection);
$session->param("summarypanel__current_highlighted_branch", $summaryBranch);
}
}
else
{
my $datasets_all = $session->param('dataset');
my @dataset_names = ref($datasets_all) ? @$datasets_all : ($datasets_all);
$def_ds = $dataset_names[0]; foreach my $schema (@{$registry->getAllVirtualSchemas()}) {
if($schema->name eq $def_schema) {
foreach my $mart (@{$schema->getAllMarts()}) {
if($mart->displayName eq $def_db) {
foreach my $dataset (@{$mart->getAllDatasets(1)}) {
if($def_ds eq $dataset->name)
{
$def_ds_OBJ = $dataset;
if ($session->param ("reverseName") && $session->param ("reverseName") eq '1')
{ $reverseName = 1; } }
}
}
}
}
}
}
$session->clear('schema');
$session->clear('dataBase');
$session->param('schema', $def_schema);
$session->param('dataBase', $def_db);
$session->param('dataset', $def_ds) if (!$session->param('dataset'));
my $datasets_string = $session->param('dataset');
my $schema_name = $session->param('schema');
my $query_main = BioMart::Query->new(registry => $registry,
virtualSchemaName => $schema_name);
my $qrunner = BioMart::QueryRunner->new();
my @dataset_names = ref($datasets_string) ? @$datasets_string : ($datasets_string);
$logger->debug("Need to query datasets ".join(',',@dataset_names)." for total entry counts for each");
my %backgroundSettings = $self->getSettings('background');
$session->param('__enable_background', ($backgroundSettings{'enable'} eq 'yes') ? 1 : 0);
foreach my $dataset_name(@dataset_names) {
my $vs_dataset_name = $session->param('schema').'____'.$dataset_name;
my $filterlist_string = $session->param($vs_dataset_name.'__filterlist') if ($session->param($vs_dataset_name.'__filterlist'));
my $attributepage = $session->param($dataset_name.'__attributepage') if ($session->param($dataset_name.'__attributepage'));
my $attributelist_string = $session->param($vs_dataset_name.'__'.($attributepage||'').'__attributelist');
if ($filterlist_string){ $logger->debug("FILTERLIST_STRING IS $filterlist_string"); }
else {$logger->debug("FILTERLIST_STRING IS *EMPTY*"); }
my @filterlist = !defined($filterlist_string) ? ()
: ref($filterlist_string) ? @$filterlist_string
: ($filterlist_string);
my @attributelist = !defined($attributelist_string) ? ()
: ref($attributelist_string) ? @$attributelist_string
: ($attributelist_string);
$logger->debug("Enabled filters for dset $dataset_name: ".join('|',@filterlist));
$logger->debug("Enabled attributes for dset $dataset_name: ".join('|',@attributelist));
foreach (@attributelist)
{
if($_ eq 'dummy')
{
undef $_;
}
}
foreach (@filterlist)
{
if($_ eq 'dummy') {
$noFilter = 1;
$session->clear($dataset_name.'__filtercollections'); }
}
my ($values_of_filter, $attributes, $values_of_attributefilter)
= $self->extract_queryparams($session->dataref(),\@ filterlist,\@ attributelist);
push(@dataset_names_in_query, $dataset_name);
if (@dataset_names_in_query == 1)
{
my $atttree = $registry->getConfigTreeForDataset($dataset_name, $schema_name, 'default')->getAttributeTreeByName($attributepage);
if (defined($atttree))
{
$logger->debug("Got outputformats ".$atttree->outFormats()." for attpage $attributepage, in dataset $dataset_name");
my @outputformats = split(',', $atttree->outFormats());
$all_formatters = $atttree->outFormats();
$session->param("export_outputformats",\@ outputformats);
my $preView_session_outformat = $session->param('preView_outputformat');
my $exportView_session_outformat = $session->param('exportView_outputformat');
foreach (@outputformats)
{
if (defined($preView_session_outformat) && $preView_session_outformat eq $_)
{
$preView_formatter_name = uc($preView_session_outformat);
}
if (defined($exportView_session_outformat) && $exportView_session_outformat eq $_)
{
$exportView_formatter_name = uc($exportView_session_outformat);
}
}
$preView_formatter_name = uc($outputformats[0]) if (!$preView_formatter_name);
$exportView_formatter_name = uc($outputformats[0]) if (!$exportView_formatter_name);
}
else
{
my $allAttributeTrees = $registry->getConfigTreeForDataset($dataset_name, $schema_name, 'default')->getAllAttributeTrees();
my $atttree = $allAttributeTrees->[0]; $logger->debug("Got outputformats ".$atttree." for attpage $attributepage, in dataset $dataset_name");
my @outputformats = split(',', $atttree->outFormats());
$all_formatters = $atttree->outFormats();
$session->param("export_outputformats",\@ outputformats);
}
}
if ($session->param('countButton') && $session->param('countButton') eq '1' )
{
$logger->debug("Sending query for execution to get counts only");
my ($entry_count, $total_count) = 'N/A';
my $qrunner_count = BioMart::QueryRunner->new();
my $query_count = $self->prepare_martquery({ schema => $schema_name,
dataset => $dataset_name });
$query_count->count(1);
$qrunner_count->execute($query_count);
$total_count = $qrunner_count->getCount();
$entrycount_of_dataset{$dataset_name} = $total_count || 0;
$session->param('entrycount_of_dataset',\% entrycount_of_dataset);
$query_count = $self->prepare_martquery({ schema => $schema_name,
dataset => $dataset_name,
filters => $values_of_filter});
$query_count->count(1);
$qrunner_count->execute($query_count);
$entry_count = $qrunner_count->getCount();
$filtercount_of_dataset{$dataset_name} = $entry_count || 0;
$session->param('filtercount_of_dataset',\% filtercount_of_dataset);
$logger->debug("COUNT: $entry_count out of TOTAL: $total_count");
$countStringForJS .= '____' if ($countStringForJS); $countStringForJS .= $entry_count || 0;
$countStringForJS .= ' / ';
$countStringForJS .= $total_count || 0;
$countStringForJS .= ' ';
$countStringForJS .= $registry->getConfigTreeForDataset($dataset_name, $schema_name, 'default')->entryLabel || 'Entries';
}
$query_main = $self->prepare_martquery({query => $query_main,
schema => $schema_name,
dataset => $dataset_name,
filters => $values_of_filter,
attributes => {$dataset_name => $attributes},
attributefilters => $values_of_attributefilter});
if($noFilter)
{
$noFilter = $dataset_name.'__filtercollections';
$session->param($noFilter, 'dummy');
undef $noFilter;
}
}
$session->param('ds_1_count', $session->param('summarypanel_filter_count_1_hidden'));
$session->param('ds_2_count', $session->param('summarypanel_filter_count_2_hidden'));
$session->clear('get_count_button');
$logger->debug("Datasetcount added to query: ".scalar(@dataset_names_in_query));
$logger->debug("Datasetcount in session: ".scalar(@dataset_names));
if(defined($query_main)) {
my %lastquery_info;
$lastquery_info{xml} = $query_main->toXML(1,1,1,1);
$lastquery_info{timestamp} = strftime "%Y-%m-%d %H:%M:%S", localtime;
$session->param('lastquery_info',\% lastquery_info);
}
my $showQuery = $session->param('showquery');
if(defined ($showQuery) && defined($query_main) && $showQuery ne '0')
{
if ($showQuery eq '1') {
my $tempered_xml = $query_main->toXML(1,1,1,1);
$tempered_xml =~s/limitStart.*?limitSize\s*=\s*\"\d*\"/formatter =\" $exportView_formatter_name\" header =\" 0\" uniqueRows =\" 0\"/g; $tempered_xml =~s/requestId\s*=\s*\".*\"//g; $tempered_xml =~s/softwareVersion/datasetConfigVersion/g; $tempered_xml =~s/</</g; $tempered_xml =~s/>/>/g; print $CGI->header();
print "<html><body><pre>$tempered_xml</pre></body></html>";
}
if ($showQuery eq '2') {
my $tempered_perlScript = $query_main->toPerl();
$tempered_perlScript =~ s/my \$query_runner = BioMart::QueryRunner->new\(\)\;/\$query->formatter\(\"$exportView_formatter_name\"\)\;\n\nmy \$query_runner = BioMart::QueryRunner->new\(\)\;/;
print $CGI->header();
print "<html><body><pre>$tempered_perlScript</pre></body></html>";
}
if ($showQuery eq '3') {
my $xml = $query_main->toXML(1,1,1,1);
my $url_string = $CGI->url(-full => 1) . $self->getURLBookmark($registry, $xml, $session);
print $CGI->header();
print "<html><body><pre>$url_string</pre></body></html>";
}
$session->clear('showquery'); $session->flush();
return;
}
RUN_QUERY:
if(defined($query_main))
{
$logger->debug("Query has both filters and attributes by now, let's go get some results!");
my $export_subset = $session->param('export_subset') || '10';
undef $export_subset if defined($export_subset) && $export_subset eq q{};
undef $export_subset if ($session->param("do_export"));
my $return_after_eval = 0;
eval {
if ( $session->param('resultsButton') && $session->param('resultsButton') eq '1' )
{
$session->clear('get_results_button'); my $selectedFormatterMenu;
if($session->param('formatterMenu') && $session->param('formatterMenu') eq 'exportView')
{ $selectedFormatterMenu = $exportView_formatter_name; }
else
{ $selectedFormatterMenu = $preView_formatter_name; }
my $formatterName = $selectedFormatterMenu || 'TSV';
my $formatter_class = 'BioMart::Formatter::'.$formatterName;
eval "require $formatter_class" or BioMart::Exception->throw("could not load module $formatter_class: $@");
my $formatter = $formatter_class->new();
$logger->debug("Formatting data as $formatterName");
my $export_saveto = $session->param('export_saveto');
if ($session->param('export_subset') eq 'All'
&& $session->param('showAll') && $session->param('showAll') eq '1')
{
$export_saveto = 'text';
$exportView_formatter_name = $preView_formatter_name;
}
if ($session->param('export_subset') eq 'All' && !$session->param("do_export"))
{
$session->param('export_subset', '10');
}
if ($session->param('do_export') and ($export_saveto eq 'file_bg' or $export_saveto eq 'gz_bg'))
{
$logger->debug("Running in background.");
$session->clear('do_export');
my $background_file = strftime("martquery_%m%d%H%M%S", localtime).'_'.int(rand(1000));
$background_file .= '.'.$formatter->getFileType();
if ($export_saveto eq 'gz_bg') {
$background_file .= '.gz';
}
my %backgroundSettings = $self->getSettings('background');
my $background_file_dirCount = $backgroundSettings{'resultsDirCount'};
my $background_file_hash = 1;
my $background_file_dir = $backgroundSettings{'resultsDir'.$background_file_hash}.'/';
use Digest::MD5 qw(md5_hex);
use File::Path;
(my $background_directory = md5_hex( $background_file )) =~ s/^(\w)(\w\w).*$/$1\/$2/;
$background_file_dir .= $background_directory.'/';
mkpath( $background_file_dir, 0, 0777 );
open (MIME, '>'.$background_file_dir.$background_file.'.mime');
open (BINMODE, '>'.$background_file_dir.$background_file.'.binmode');
if ($export_saveto eq 'gz_bg') {
print MIME 'application/octet-stream';
print BINMODE '1';
}
else {
print MIME $formatter->getMimeType();
print BINMODE $formatter->isBinary();
}
close (MIME);
close (BINMODE);
my $server_url = $CGI->url();
$server_url =~ m{(.*/)martview.*};
$server_url = $1;
my ($hack) = reverse split /\./, $ENV{'SERVER_ADDR'};
my $background_file_url = $server_url.'martresults/'.$hack.'?file='.$background_file;
$session->param("mart_mainpanel__current_visible_section","resultspanel");
$session->param("summarypanel__current_highlighted_branch","show_results");
$result_string =
"<br/>Your results are being compiled in the background.".
"<br/>Your reference is $background_file.".
"<br/><br/>An email will be sent to you when they are ready.";
$SIG{CHLD} = 'IGNORE';
defined (my $pid = fork) or die "Cannot fork: $!\n";
unless ($pid) {
my %mailSettings = $self->getSettings('mailSettings');
my $mailer = new Mail::Mailer $mailSettings{'mailerType'};
my %mail_headers = ();
my $TO = $session->param("background_email");
$TO =~ s/[\r\n].*$//sm;
$mail_headers {From} = $mailSettings{'from'};
$mail_headers {To} = $TO;
$mail_headers {Subject} = $mailSettings{'subject'};
eval {
$logger->debug("Sending query for execution to get full resultset");
$query_main->formatter($exportView_formatter_name);
$query_main->count(0); $qrunner->uniqueRowsOnly(1) if ($session->param('uniqueRowsExportView') && $session->param('uniqueRowsExportView') eq '1');
$qrunner->execute($query_main);
if ($export_saveto eq 'gz_bg') {
$logger->debug("Writing results to ".$background_file_dir.$background_file);
open(FH,">".$background_file_dir.$background_file);
my $fh = BioMart::Web::Zlib->new(\*FH);
$qrunner->printHeader($fh);
$qrunner->printResults($fh, $export_subset);
$qrunner->printFooter($fh);
$fh->close();
close(FH);
}
else {
$logger->debug("Writing results to ".$background_file_dir.$background_file);
open(FH,'>'.$background_file_dir.$background_file);
if ($formatter->isBinary()) {
binmode FH;
}
$qrunner->printHeader(\*FH);
$qrunner->printResults(\*FH, $export_subset);
$qrunner->printFooter(\*FH);
close(FH);
}
};
if ($@) {
my $ex = Exception::Class->caught();
$logger->debug("Serious error: ".$ex);
$mailer->open(\%mail_headers);
print $mailer "Your results file FAILED.\n\n".
"Here is the reason why:\n\n$ex\n\n".
"Please try your request again, or alternatively contact your service provider\nincluding a copy of this email and quoting this reference: $background_file.";
$mailer->close;
}
else {
$mailer->open(\%mail_headers);
print $mailer "Your results are ready and can be downloaded by following this link:\n\n$background_file_url";
$mailer->close;
}
CORE::exit(0);
} }
else {
if ($session->param("do_export")) {
$return_after_eval = 1;
$session->clear('do_export');
$logger->debug("Sending query for execution to get full resultset");
$query_main->formatter($exportView_formatter_name);
$query_main->count(0); if ( ($session->param('uniqueRowsExportView') && $session->param('uniqueRowsExportView') eq '1' )
||($session->param('uniqueRowsPreView') && $session->param('uniqueRowsPreView') eq '1'
&& $session->param('showAll') && $session->param('showAll') eq '1' ) )
{
$qrunner->uniqueRowsOnly(1);
}
$qrunner->execute($query_main);
my $file = 'mart_export';
$file .= '.'.$formatter->getFileType();
if ($export_saveto eq 'gz') {
$file .= '.gz';
}
$logger->debug("Exporting file.");
if ($export_saveto eq 'text') {
print $CGI->header(-type=>$formatter->getMimeType());
}
elsif ($export_saveto eq 'gz') {
print $CGI->header(-type=>'application/octet-stream',
-attachment=>$file);
}
else {
print $CGI->header(-type=>$formatter->getMimeType(),
-attachment=>$file);
}
if ($export_saveto eq 'gz') {
my $fh = BioMart::Web::Zlib->new(\*STDOUT);
$qrunner->printHeader($fh);
$qrunner->printResults($fh, $export_subset);
$qrunner->printFooter($fh);
$fh->close();
}
else {
if ($formatter->isBinary()) {
binmode STDOUT;
}
$qrunner->printHeader(\*STDOUT);
$qrunner->printResults(\*STDOUT, $export_subset);
$qrunner->printFooter(\*STDOUT);
}
undef $/;
}
else {
$session->param("mart_mainpanel__current_visible_section","resultspanel");
$session->param("summarypanel__current_highlighted_branch","show_results");
$logger->debug("Showing in browser.");
if($formatter->isBinary()) {
$result_string = "<br/>Cannot display binary output in this panel.<br/>Choose the target from the menu above & press Go.";
}
elsif(($query_main->formatter($preView_formatter_name)) eq 'MAF_NOPREVIEW') {
$result_string = "<br/>Cannot preview multiple genomic alignments due to the huge amount of data.<br/>Choose the target from the menu above & press Go.<br/>The size of the output expected will be between tens of Mb to a few Gb depending on your filtering";
}
else {
$logger->debug("Showing ".($export_subset||'all')." entries in main panel");
$logger->debug("Sending query for execution to get full resultset");
$query_main->formatter($preView_formatter_name);
$query_main->count(0); $qrunner->uniqueRowsOnly(1) if ($session->param('uniqueRowsPreView') && $session->param('uniqueRowsPreView') eq '1');
$qrunner->execute($query_main);
undef $export_subset if ($export_subset eq 'All');
open(my $result_buffer, '>',\$ result_string);
$qrunner->printHeader($result_buffer);
$qrunner->printResults($result_buffer, $export_subset);
$qrunner->printFooter($result_buffer);
close($result_buffer);
if($preView_formatter_name =~ '^HTML$|^HTML_36$|^GOENRICH$|^FAMILYENRICH$|^EXPRESSIONENRICH$|^SAME$|^DIFF$|^ALL$') {
$result_string =~ s/\A\<\?xml.+\<table/\<table/xms;
$result_string =~ s/\<\/body.+\Z//xms;
$result_string =~ s/\<table\>/\<table\ class=\"mart_table\">/gxms;
$result_string =~ s/\<th\>/\<th\ class=\"mart_th\">/gxms;
$result_string =~ s/\<tr\>/\<tr\ class=\"mart_tr1\">/gxms;
$result_string =~ s/\<td/\<td\ class=\"mart_td\"/gxms;
}
else {
$result_string = "<pre class=\"mart_results\">$result_string</pre>";
}
}
}
}
} };
my $ex;
$exceptionFlag=0;
if ( $ex = Exception::Class->caught('BioMart::Exception::Usage') )
{
$exceptionFlag = 1;
my $errmsg = $ex->error();
print "Validation Error: ", $errmsg;
$logger->debug("Validation error: ".$errmsg);
$session->param("__validationError",$errmsg);
$session->param('mart_mainpanel__current_visible_section', $session->param('track_visible_section'));
}
elsif ($ex = Exception::Class->caught())
{
$exceptionFlag = 1;
my $errmsg = $ex->error();
print "Serious Error: ", $errmsg;
$logger->debug("Serious error: ".$ex);
UNIVERSAL::can($ex, 'rethrow') ? $ex->rethrow : die $ex;
print "Serious Error: ", $errmsg;
}
else
{
$logger->debug("Everything's fine");
}
if ($return_after_eval == 1)
{
return;
}
}
$session->clear('get_count_button'); $qtime = round(time - $qtime, 4);
$logger->info("All Mart counts and main Mart-query executed in ".$qtime);
print $session->header(); $logger->debug("Incoming SESSION-params:\n",Dumper($session));
$dbName = $session->param('dataBase');
$session->clear('dataBase');
}
my $dsOLD = $self->get_conf_Dir()."/templates/default/datasetpanel.ttc";
if (-e $dsOLD) {unlink $dsOLD;}
$dsOLD = $self->get_conf_Dir()."/templates/cached/datasetpanel.ttc";
if (-e $dsOLD) {unlink $dsOLD;}
$dsOLD = $self->get_conf_Dir()."/templates/cached/datasetpanel.tt";
if (-e $dsOLD) {unlink $dsOLD;}
my $PS = new BioMart::Web::PageStub( $session );
$PS->start();
if ( $session->param('countButton') && $session->param('countButton') eq '1')
{
$session->param('countButton', '0') ;
print "$countStringForJS";
}
elsif ($session->param('resultsButton') && $session->param('resultsButton') eq '1' && !$session->param('URL_REQUEST'))
{
$session->param('resultsButton', '0') ;
if ($exceptionFlag != 1)
{
$all_formatters = 'TSV' if ($session->param("GALAXY_URL"));
my @outputformat_displays;
foreach my $formatter(split(/\,/,$all_formatters)){
my $formatter_mod = 'BioMart::Formatter::'.uc($formatter);
if ($formatter_mod->getFormatterDisplayName()){
push @outputformat_displays, $formatter.';'.$formatter_mod->getFormatterDisplayName();
}
else{
push @outputformat_displays, $formatter.';'.uc($formatter);
}
}
my $display_string = join ",",@outputformat_displays;
print lc($preView_formatter_name);
print '____';
print $display_string;
print '____';
print lc($exportView_formatter_name);
print '____';
print $display_string;
print '____';
print $result_string;
}
}
else
{
$session->param('resultsButton', '0') if ($session->param('URL_REQUEST'));
$session->clear('URL_REQUEST');
my $completePage = "";
$self->process_template( "main.tt", {
tbuilder => $self,
js_pushactions_of_datasetmenu =>\% js_pushactions_of_datasetmenu,
js_datasetpanel_sessions_values =>\% js_datasetpanel_sessions_values,
session => $session,
wq => $self,
form_action => $form_action,
sessionDBNAME => $dbName,
datasetOBJ => $def_ds_OBJ,
reverseNAME => $reverseName,
TAG_path => $TAG_path,
result_string => $result_string
},\$ completePage );
print $completePage;
}
$PS->end();
}
1; } |
sub perlhash2js
{ my ($self, $hashref) = @_;
local $Data::Dumper::Pair = ':';
local $Data::Dumper::Indent = 0;
local $Data::Dumper::Terse = 1;
return Dumper($hashref); } |
sub prepare_martquery
{ my ($self, $args) = @_;
$args->{schema} ||= 'default';
$logger->debug("Getting dataset $args->{dataset} in schema $args->{schema} from registry");
my $mart_registry = $self->get_mart_registry();
my $query;
if( defined($args->{query}) ) {
$logger->debug("Using provided query object");
$query = $args->{query};
}
else {
$logger->debug("Creating new query from scratch");
$query = BioMart::Query->new(registry => $mart_registry,
virtualSchemaName => $args->{ 'schema' });
}
my @datasets_in_query = @{ $query->getDatasetNames };
foreach my $dataset_name (keys %{ $args->{ 'attributes' } }) {
my $dataset = $mart_registry->getDatasetByName($args->{ 'schema' }, $dataset_name);
my $dataset_conf = $dataset->getConfigurationTree('default');
$logger->debug("Processing attributes from dataset $args->{schema}\.$dataset_name");
ATTRIBUTE:
$query->setDataset($dataset_name);
foreach my $attributename(@{ $args->{ 'attributes' }->{ $dataset_name } }) {
$logger->debug("Enabling attribute $attributename");
if(defined $attributename)
{ $query->addAttribute($attributename, 'default');
}
}
}
foreach my $dataset_name (keys %{ $args->{ 'attributefilters' } }) {
my $dataset = $mart_registry->getDatasetByName($args->{ 'schema' }, $dataset_name);
my $dataset_conf = $dataset->getConfigurationTree('default');
$logger->debug("Processing attributefilters from dataset $args->{schema}\.$dataset_name");
ATTRIBUTEFILTER:
$query->setDataset($dataset_name);
while(my ($attributename,$filtervalues) = each(%{ $args->{ 'attributefilters' }->{ $dataset_name } })) {
$logger->debug("Enabling attributefilter $attributename to query, setting values to ".join('|',@$filtervalues) );
$query->addAttributeFilter($attributename, $filtervalues, 'default');
}
}
foreach my $dataset_name (keys %{ $args->{ 'filters' } }) {
my $dataset = $mart_registry->getDatasetByName($args->{ 'schema' }, $dataset_name);
my $dataset_conf = $dataset->getConfigurationTree('default');
$logger->debug("Processing filters from dataset $args->{schema}\.$dataset_name");
FILTER:
$query->setDataset($dataset_name);
while(my ($filtername,$filtervalues) = each(%{ $args->{ 'filters' }->{ $dataset_name } })) {
$logger->debug("Enabling filter $filtername to query, setting values to ".join('|',@$filtervalues) );
$query->addFilter($filtername, $filtervalues, 'default'); }
}
if( @{ $query->getDatasetNames() } == 0 ) {
exists($args->{dataset})
|| BioMart::Exception::Query->throw("Can't build query with no filters or attributes unless explicitly receiving the 'dataset' argument explicitly");
$logger->debug("No dataset name for query, explicitly setting to $args->{dataset}");
$query->addDatasetName($args->{dataset},'default');
}
return $query; } |
sub process_template
{ my ($self, $template, $vars, $output) = @_;
$logger->debug("Processing template $template");
$vars->{webquery} = $self;
my $new_start_time = time();
$logger->info("START PROCESSING TEMPLATE $template");
$output ||= q{};
$tt_processor->process($template,$vars,ref($output) ? $output :\$ output)
|| BioMart::Exception::Template->throw("Error in processing template $template: ".$tt_processor->error());
my $time_elapsed = round(time() - $new_start_time);
$logger->info("!!!! $time_elapsed to get process template $template and print to ".(ref($output) || 'string'));
ref($output) || return $output; return; } |
sub restore_session
{ my ($self,$cgi) = @_;
my $self_url = $cgi->self_url();
$self_url =~ s/(__countByAjax|__resultsByAjax)//;
my $full_url = $cgi->url(-full => 1);
$full_url =~ s/(mart\w+)\/[0-9a-f\/]+/\1/;
warn "
$self_url
[$full_url]
";
my ($session_id) = $self_url =~ m{martview/([0-9a-f]+)}xms;
$session_id ||= "foobar";
CGI::Session->find( sub {} );
my $session;
my %sessions = $self->getSettings('sessions');
if($sessions{'driver'} eq 'ensembl') {
$session = BioMart::Web::PageStub::generate_biomart_session( $self, $session_id );
} elsif($sessions{'driver'} eq 'files') {
$session = CGI::Session->new('driver:file', $session_id,
{ Directory=>$self->get_session_dir() })
|| BioMart::Exception::Session->throw(CGI::Session->errstr);
}
elsif ($sessions{'driver'} eq 'mysql')
{
my $dsn = $sessions{'dsn'};
my $user = $sessions{'user'};
my $pass = $sessions{'pass'};
my $dbh = DBI->connect($dsn, $user, $pass, {'RaiseError' => 1});
warn ">>> $session_id ....";
$session = CGI::Session->new("driver:MySQL", $session_id, {Handle=>$dbh})
|| BioMart::Exception::Session->throw(CGI::Session->errstr);
warn "<<< ",$session->id," ....";
}
elsif ($sessions{'driver'} eq 'oracle')
{
my $dsn = $sessions{'dsn'};
my $user = $sessions{'user'};
my $pass = $sessions{'pass'};
my $dbh = DBI->connect($dsn, $user, $pass, {'RaiseError' => 1, 'LongReadLen' => 1000000 });
$session = CGI::Session->new("driver:Oracle", $session_id, {Handle=>$dbh})
|| BioMart::Exception::Session->throw(CGI::Session->errstr);
}
elsif ($sessions{'driver'} eq 'postgres')
{
print "POSTGRES DRIVER Not implemented yet";
}
else {
$session = CGI::Session->new('driver:db_file', $session_id,
{ FileName=>$self->get_session_dir()."/cgisessions.db" })
|| BioMart::Exception::Session->throw(CGI::Session->errstr);
}
if($session->is_new()) {
if ($cgi->param("GALAXY_URL") and !$session->param("GALAXY_URL")) {
$session->param("GALAXY_URL",$cgi->param("GALAXY_URL"));
$session->param('export_saveto','text');
$session->param('preView_outputformat','tsv');
}
if ($cgi->param('VIRTUALSCHEMANAME') || $cgi->param('ATTRIBUTES') )
{
$session->param("url_VIRTUALSCHEMANAME",$cgi->param('VIRTUALSCHEMANAME'));
$session->param("url_ATTRIBUTES", $cgi->param('ATTRIBUTES'));
if ($cgi->param('FILTERS')) { $session->param('url_FILTERS', $cgi->param('FILTERS')); }
else { $session->clear("url_FILTERS"); }
if ($cgi->param('VISIBLEPANEL')) { $session->param('url_VISIBLEPANEL', $cgi->param('VISIBLEPANEL')); }
else { $session->clear("url_VISIBLEPANEL"); }
}
if ($cgi->param('XML') || $cgi->param('xml') || $cgi->param('QUERY') || $cgi->param('query')) {
if ($cgi->param('XML')) {
$session->param('url_XML', $cgi->param('XML'));
}
elsif ($cgi->param('xml')) {
$session->param('url_XML', $cgi->param('xml'));
}
elsif ($cgi->param('QUERY')) {
$session->param('url_XML', $cgi->param('QUERY'));
}
elsif ($cgi->param('query')) {
$session->param('url_XML', $cgi->param('query'));
}
else { $session->clear("url_XML"); }
}
$session->expire($sessions{'expire'});
my %aliases = $self->getSettings('aliases');
$session->param("__dataset",$aliases{'dataset'});
$session->param("__Dataset",$aliases{'Dataset'});
$session->param("__database",$aliases{'database'});
$session->param("__Database",$aliases{'Database'});
$session->param("__schema",$aliases{'schema'});
$session->param("__Schema",$aliases{'Schema'});
$logger->info("Creating new session and rewriting URL to ".$full_url.'/'.$session->id().", then redirecting");
print $cgi->redirect(-uri=>$full_url.'/'.$session->id(),
-status=>"301 Moved Permanently");
return;
}
else {
$logger->info("Restoring existing session ", $session->id());
}
return $session; } |
sub save_session
{ my ($self, $session, $cgi) = @_;
FILE:
foreach my $file_param($cgi->param('upload_file_params')) {
my $fh = $cgi->param($file_param);
next FILE unless ($fh && (ref($fh) eq 'Fh'));
local $INPUT_RECORD_SEPARATOR = undef;
my $file_contents = <$fh>;
$logger->debug("Read content from upload-file $fh (param $file_param):\n$file_contents");
$file_param =~ m/(.*)__file/; $cgi->param($1, $file_contents);
$cgi->delete($file_param);
}
$logger->debug("Saving parameters to session.\n");
my %session_hashref = %{$session->param_hashref()};
foreach my $param_name (keys %session_hashref){
if (($session->param($param_name) and $session->param($param_name) eq 'on') &&
!($cgi->param($param_name))){
$session->param($param_name,'off');
}
}
$session->save_param($cgi);
return; } |
sub set_errstr
{
my ($self, $errmsg) = @_;
$self->set('errmsg',$errmsg); } |
General documentation
AUTHOR - Arek Kasprzyk, Syed Haider, Richard Holland, Damian Smedley, Gudmundur Arni Thorisson | Top |
Usage : my $webquery = BioMart::Web->new({conf => $path_to_registryfile,
registry => $registry});
Purpose : Construct a new instance of this class
Returns : BioMart::Web instance
Arguments : path to Mart registry XML-configfile
reference to BioMart::Registry object (optional)
Throws : BioMart::Exception::Configuration on registry initialization errors
Status : Public
Comments : If registry object is provided in constructor, it will be used instead of
initialization a new registry from scratch. The path to the registry
XML-file is still needed, however.
See Also :