GBrowse Persistent Variables

GBrowse uses a few persistent variables to store data for a user. The following is an explanation of the structure of the commonly-used ones:



$session is a blessed Browser2::Session object containing information regarding the current user’s session. It contains the following key->value pairs:


$state is a large hash containing information regarding the current configured state of the browser (hence the name). It contains the following key->value pairs:

Querying the State Variable

To query the value of your state variables, copy and paste the Named Subroutines below to a file called init_code.conf.

    my $t = -1;
    my $toString;
    sub queryVariables {
        my @arg  = @_;
        for(my $i=0; $i<@arg; $i++) {
            if( ref($arg[$i]) eq "HASH" ) {
                my %hash = %{$arg[$i]};
                foreach my $key ( keys %hash ) {
                    if( ref(\$hash{$key}) eq "SCALAR" ) {
                        $toString .= "\t"x$t."HASH key: $key\tvalue: $hash{$key}\n";
                    } else {
                        $toString .= "\t"x$t."HASH key: $key\tvalue: ".ref($hash{$key})."\n";
                        queryVariables( $hash{$key} );
            } elsif( ref($arg[$i]) eq "ARRAY" ) {
                my @array = @{$arg[$i]};
                for(my $j=0; $j<@array; $j++){
                    if( ref(\$array[$j]) eq "SCALAR" ) {
                        $toString .= "\t"x$t."ARRAY element[$j]: $array[$j]\n";
                    } else {
                        $toString .= "\t"x$t."ARRAY element[$j]: ".ref($array[$j])."\n";
                        queryVariables( @array );
        return $toString;
    sub queryStateVariables {
        my $stateVariables = queryVariables( @_ );
        $stateVariables = "<pre>\n".$stateVariables."</pre>n";
        return $stateVariables;

In your GBrowse.conf file, use the include directive to import the named subroutines, by including the init_code.conf file in the [GENERAL] section of the configuration file. Add a reference to the named subroutine queryStateVariables, assigning the return value to one of the html variables.

Displaying the values of the $state variable

#include "path/to/init_code.conf"

# Various places where you can insert your own HTML -- see configuration docs
html1 =
html2 =
html3 = \&queryStateVariables
html4 =
html5 =
html6 =

After refreshing GBrowse, you should see the values of the state hash and the values of any other hashes or arrays that have been referenced.

Querying the state variable should be helpful in creating other subroutines to do more specific things. After you are finished querying the contents of the state variable, you can remove the reference to the subroutine so that the main GBrowse page appears normally.


$globals is essentially an object containing the GBrowse.conf file.