« blib/lib/Bio/Graphics/Browser2/DataBase.pm
↑ Summary
blib/lib/Bio/Graphics/Browser2/DataLoader/bigwig.pm »
| 1 | #!/usr/local/bin/perl | ||
| 2 | # $Id: make_das_conf.pl,v 1.1 2008-10-16 17:01:27 lstein Exp $ | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use Bio::Das 1.03; | ||
| 6 | use Getopt::Long; | ||
| 7 | |||
| 8 | my @COLORS = qw(cyan blue red yellow green wheat turquoise orange); # default colors | ||
| 9 | my $color = 0; # position in color cycle | ||
| 10 | my %known_aggregators = map {$_=>1} qw(clone match processed_transcript wormbase_gene | ||
| 11 | orf reftranscript waba_alignment | ||
| 12 | coding cds alignment transcript | ||
| 13 | ucsc_assembly ucsc_ensgene ucsc_refgene | ||
| 14 | ucsc_sanger22 ucsc_sanger22pseudo | ||
| 15 | ucsc_softberry ucsc_twinscan ucsc_unigene); | ||
| 16 | my $proxy; | ||
| 17 | |||
| 18 | GetOptions('proxy=s' => \$proxy) or usage_statement(); | ||
| 19 | |||
| 20 | my $url = shift; | ||
| 21 | $url or usage_statement(); | ||
| 22 | $url =~ m!^http:.+das(/\w+)?$! or usage_statement("This doesn't look like a DAS URL to me."); | ||
| 23 | $ENV{HTTP_PROXY} ||= $proxy; | ||
| 24 | |||
| 25 | list_sources($url) && exit 0 if $url =~ m!das/?$!; | ||
| 26 | generate_config_file($url); | ||
| 27 | |||
| 28 | exit 0; | ||
| 29 | |||
| 30 | sub usage_statement { | ||
| 31 | my $error = shift; | ||
| 32 | $error .= "\n" if $error; | ||
| 33 | |||
| 34 | die <<END; | ||
| 35 | ${error}Usage: $0 <das URL to load> | ||
| 36 | |||
| 37 | Options: -proxy <http proxy to use> | ||
| 38 | |||
| 39 | This utility attempts to contact a DAS source and to create a starter | ||
| 40 | configuration file for gbrowse. If you don\'t know the list of data sources | ||
| 41 | it will retrieve them and ask you to select one. | ||
| 42 | |||
| 43 | If you need an HTTP proxy, set the HTTP_PROXY environment variable to | ||
| 44 | the host and port number, in the form "http://proxy.host:port/", or | ||
| 45 | pass the proxy URL to the -proxy option. | ||
| 46 | END | ||
| 47 | ; } | ||
| 48 | |||
| 49 | sub list_sources { | ||
| 50 | my $url = shift; | ||
| 51 | my $das = Bio::Das->new($url); | ||
| 52 | warn "proxy = $ENV{HTTP_PROXY}"; | ||
| 53 | $das->proxy($ENV{HTTP_PROXY}) if $ENV{HTTP_PROXY}; | ||
| 54 | my @sources = $das->sources or bad_request_exit($das); | ||
| 55 | print "The following DAS URLs are available at this server. Please call the script again\n"; | ||
| 56 | print "using one of the following URLs:\n\n"; | ||
| 57 | for my $s (@sources) { | ||
| 58 | print $s->url,"\n"; | ||
| 59 | print "\t",$s->description,"\n\n"; | ||
| 60 | } | ||
| 61 | 1; | ||
| 62 | } | ||
| 63 | |||
| 64 | sub generate_config_file { | ||
| 65 | my $url = shift; | ||
| 66 | my ($server,$dsn) = $url=~ m[^(.+/das)/(\w+)]; | ||
| 67 | my $das = Bio::Das->new($server=>$dsn); | ||
| 68 | |||
| 69 | $das->proxy($ENV{HTTP_PROXY}) if $ENV{HTTP_PROXY}; | ||
| 70 | |||
| 71 | my @sources = $das->sources or bad_request_exit($das); | ||
| 72 | my ($source) = grep {$_->id eq $das->default_dsn} @sources; | ||
| 73 | |||
| 74 | my @types = $das->types or bad_request_exit($das); | ||
| 75 | $source or bad_request_exit($das); | ||
| 76 | |||
| 77 | my %seenit; | ||
| 78 | my @aggregators = grep {!$seenit{$_}++} | ||
| 79 | map { | ||
| 80 | my ($method,$source) = split ':'; | ||
| 81 | $known_aggregators{$method} ? $method : "$method\{$method\}" | ||
| 82 | } @types; | ||
| 83 | my $aggregators = join "\n ",@aggregators; | ||
| 84 | |||
| 85 | my $description = $source->description; | ||
| 86 | my $mapmaster = $source->master; | ||
| 87 | my @entry_points = sort {"$a" cmp "$b"} $das->entry_points; | ||
| 88 | foreach (@entry_points) { # remove coordinates | ||
| 89 | s/:\d+,\d+$//; | ||
| 90 | } | ||
| 91 | |||
| 92 | my $proxy = $ENV{HTTP_PROXY} ? "-proxy $ENV{HTTP_PROXY}" : ''; | ||
| 93 | |||
| 94 | # top part of the config file | ||
| 95 | print <<END; | ||
| 96 | [GENERAL] | ||
| 97 | description = $description | ||
| 98 | db_adaptor = Bio::Das | ||
| 99 | db_args = -source $server | ||
| 100 | -dsn $dsn | ||
| 101 | $proxy | ||
| 102 | |||
| 103 | # examples to show in the introduction | ||
| 104 | examples = @entry_points | ||
| 105 | |||
| 106 | das mapmaster = $mapmaster | ||
| 107 | |||
| 108 | aggregators = $aggregators | ||
| 109 | |||
| 110 | ######################## | ||
| 111 | # Default glyph settings | ||
| 112 | ######################## | ||
| 113 | |||
| 114 | [TRACK DEFAULTS] | ||
| 115 | glyph = segments | ||
| 116 | height = 10 | ||
| 117 | bgcolor = lightgrey | ||
| 118 | fgcolor = black | ||
| 119 | font2color = blue | ||
| 120 | label density = 25 | ||
| 121 | bump density = 100 | ||
| 122 | label = 1 | ||
| 123 | description = 1 | ||
| 124 | |||
| 125 | END | ||
| 126 | ; | ||
| 127 | |||
| 128 | for my $type (@types) { | ||
| 129 | my $method = $type->method || $type; | ||
| 130 | my $source = $type->source; | ||
| 131 | my $label = uc ($type eq $method ? $type : "${type}_${method}"); | ||
| 132 | $label =~ s/:/_/g; | ||
| 133 | my $desc = $source ? "These are ${method} features from $source." : "These are ${method} features."; | ||
| 134 | my $key = $type; | ||
| 135 | my $category = $type->category; | ||
| 136 | my $idx = $color++ % @COLORS; | ||
| 137 | print <<END; | ||
| 138 | [$label] | ||
| 139 | feature = $type | ||
| 140 | bgcolor = $COLORS[$idx] | ||
| 141 | das category = $category | ||
| 142 | key = $key | ||
| 143 | citation = $desc | ||
| 144 | |||
| 145 | END | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | sub bad_request_exit { | ||
| 150 | my $das = shift; | ||
| 151 | my $error = $das->error; | ||
| 152 | die <<END; | ||
| 153 | $error | ||
| 154 | |||
| 155 | An error was encountered while processing the DAS request. Are you sure this | ||
| 156 | is an operational DAS server? | ||
| 157 | END | ||
| 158 | } | ||
| 159 | |||
| 160 | # boilerplate | ||
| 161 | __END__ |