ensembl-hive  2.8.1
ping_ensembl.pl
Go to the documentation of this file.
1 #!/usr/bin/env perl
2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 =head1 CONTACT
18 
19  Please email comments or questions to the Ensembl help desk
20  <http://www.ensembl.org/Help/Contact>.
21 
22 =head1 NAME
23 
24  ping_ensembl.pl
25 
26 =head1 SYNOPSIS
27 
28  # print usage
29  $ ping_ensembl.pl -h
30 
31  # ping Ensembl with default species (Human)
32  $ ping_ensembl.pl
33 
34  # ping Ensembl with user provided species
35  $ ping_ensembl.pl -s "dog"
36 
37  # ping Ensembl with a different version (Human)
38  $ ping_ensembl.pl -db_version 70
39 
40  # ping the US Ensembl mirror
41  $ ping_ensembl.pl -ue
42 
43  # ping Ensembl Genomes with default species (arabidopsis thaliana)
44  $ ping_ensembl.pl -eg
45 
46  # ping Ensembl Genomes with user provided species
47  $ ping_ensembl.pl -eg -s "oryza sativa japonica"
48 
49 =head1 DESCRIPTION
50 
51  This script is used to detect if you can contact the Ensembl database
52  server with your current setup. The program will attempt to print out
53  helpful hints about how to resolve your problems. If they still persist
54  then please contact http://www.ensembl.org/Help/Contact.
55 
56 =head1 SUBROUTINES
57 
58 =cut
59 
60 use strict;
61 use warnings;
62 
63 use File::Temp qw/tempfile/;
64 use Net::FTP;
65 use Getopt::Long;
66 
67 #
68 # Default option values
69 #
70 my $help = 0;
71 my $host = 'ensembldb.ensembl.org';
72 my $user = 'anonymous';
73 my $port = 3306;
74 my $verbose = 0;
75 my $db_version = -1;
76 my $grch37;
77 
78 my $useast = 0;
79 my $ensembl_genomes = 0;
80 my $species = undef;
81 my $api_version = -1;
82 
83 #
84 # Parse command-line arguments
85 #
86 my $options_ok =
87  GetOptions(
88  "ue" => \$useast,
89  "eg" => \$ensembl_genomes,
90  "species=s" => \$species,
91  "db_version=i" => \$db_version,
92  "verbose" => \$verbose,
93  "grch37" => \$grch37,
94  "help" => \$help);
95 ($help or !$options_ok) && usage();
96 
97 $useast and $ensembl_genomes and
98  die "Cannot test Ensembl Genomes on the US mirror.\n" .
99  "Options \"ue\" and \"eg\" are mutually exclusive\n";
100 
101 $useast and $host = "useastdb.ensembl.org";
102 
103 $verbose and $verbose = 1;
104 
105 $grch37 and $port = 3337;
106 
107 if ($ensembl_genomes) {
108  $host = "mysql-eg-publicsql.ebi.ac.uk";
109  $port = 4157;
110  $species = "arabidopsis thaliana"
111  unless defined $species;
112 }
113 
114 eval {
115  require DBI;
116  require DBD::mysql;
117  require Bio::Perl;
118  require Bio::EnsEMBL::Registry;
119  require Bio::EnsEMBL::ApiVersion;
120  require Bio::EnsEMBL::LookUp if $ensembl_genomes;
122  $db_version = $api_version if $db_version == -1; #if it was still -1 then it wasn't set. Default is current API version
123  Bio::EnsEMBL::Registry->load_registry_from_db(
124  -host => $host,
125  -port => $port,
126  -user => $user,
127  -db_version => $db_version,
128  -verbose => $verbose,
129  );
130  $species = "human" unless defined $species;
131  my $species_adaptor = Bio::EnsEMBL::Registry->get_DBAdaptor("$species", 'core');
132  print "Installation is good. Connection to Ensembl works and you can query the $species core database\n";
133 };
134 my $error = $@;
135 
136 # If no error found then see if we've got all of our external modules available
137 if(!$error) {
138  $error = '';
139  eval {
140  foreach my $module (qw/Compara Variation Funcgen/) {
141  my $full_module = "Bio::EnsEMBL::${module}::DBSQL::DBAdaptor";
142  eval "require $full_module;";
143  if($@) {
144  $error .= "\tMissing the checkout $module\n";
145  }
146  }
147  };
148 }
149 
150 # Check the current release of datafiles from the FTP site
151 my $ftp_version = -1;
152 eval {
153  my $ftp = Net::FTP->new('ftp.ensembl.org', Debug => 0);
154  $ftp->login("anonymous",'-anonymous@');
155  $ftp->cwd('/pub');
156  my ($fh, $filename) = tempfile();
157  close($fh);
158  $ftp->get('current_README', $filename);
159  $ftp->quit();
160  open($fh, '<', $filename);
161  local $/ = undef;
162  my $ftp_readme = <$fh>;
163  close($fh);
164  ($ftp_version) = $ftp_readme =~ /Ensembl Release (\d+) Databases/;
165 };
166 
167 # Print all the errors which could have occured
168 if($error) {
169  print "ERROR: Error detected when connecting to Ensembl!\n";
170 
171  if($error =~ /Can't connect to MySQL server on /) {
172  print "\tPlease check if your connection with mysql client works fine. \n";
173  } elsif ($error =~ /Cannot connect to/) {
174  print "\tCannot seem to contact EnsemblDB at '$host' with the username '$user'. Try running 'ping $host' or asking your systems about firewalls against port $port\n";
175  } elsif ($error =~ /DBI/) {
176  print "\tCannot find the DBI perl module. Please install this using your package management system, cpan or cpanm. Please consult http://www.ensembl.org/info/docs/api/api_installation.html\n";
177  }
178  if($error =~ /mysql/) {
179  print "\tCannot find the DBD::mysql perl module. Please install this using your package management system, cpan or cpanm. Also install the mysql libs. Please consult http://www.ensembl.org/info/docs/api/api_installation.html\n";
180  }
181  if($error =~ /Can't locate Bio\/E/) {
182  print "\tLooks like you need to setup your PERL5LIB with the Ensembl API. Please consult http://www.ensembl.org/info/docs/api/api_installation.html\n";
183  }
184  if($error =~ /Can't locate Bio\/Perl/) {
185  print "\tLooks like you need to setup your PERL5LIB with BioPerl. Please consult http://www.ensembl.org/info/docs/api/api_installation.html\n";
186  }
187 
188  if($error =~ /internal name/) {
189  print "\tSpecies was not found. You may have accidentally download the HEAD API version (found API release $db_version & public FTP release is $ftp_version). Please consult http://www.ensembl.org/info/docs/api/api_installation.html\n";
190  }
191  if($error =~ /Species not defined/) {
192  print "\tSpecies was not found. You may have accidentally download the HEAD API version (told to load release $db_version, API version is $api_version & public FTP release is $ftp_version). Please consult http://www.ensembl.org/info/docs/api/api_installation.html\n";
193  }
194  if($error =~ /Missing the checkout/) {
195  print "\tYour core installation was good but supplementary modules cannot be found. If you wish to access these other Ensembl resources add the libraries to your PERL5LIB:\n";
196  print $error;
197  #bail early
198  exit 0;
199  }
200  print '='x80, "\n";
201  print "If the problem persists please send the following error message to helpdesk\@ensembl.org\n";
202  print $error;
203  print '='x80, "\n";
204  exit 1;
205 }
206 
207 
208 =head2 usage
209 
210  Arg [] : None
211  Returntype : None
212  Example :
213  Description : Print script usage string
214  Exceptions : None
215  Caller : General
216 
217 =cut
218 
219 sub usage {
220  my $prog = `basename $0`; chomp($prog);
221 
222  print "Usage: $prog [OPTIONS]\n\n";
223  print "Options:\n";
224  print " -ue Ping Ensembl US mirror\n";
225  print " -eg Ping Ensembl Genomes (can't be used together with \"ue\")\n";
226  print " -species <species> Use species <species> (use double quotes if species name contains spaces)\n";
227  print " -db_version <version> Use the specified version of Ensembl not the API version\n";
228  print " -grch37 Use human assembly GRCh37 rather than the default GRCh38 version\n";
229  print " -verbose Ping output is more verbose. Not recommended for Ensembl genomes\n";
230  print " -help Print this message\n";
231  print "\n\n";
232 
233  exit 1;
234 }
usage
public void usage()
Bio::EnsEMBL::ApiVersion::software_version
public software_version()
Bio::EnsEMBL::Registry
Definition: Registry.pm:113
about
public about()
Bio
Definition: AltAlleleGroup.pm:4
Bio::EnsEMBL::ApiVersion
Definition: ApiVersion.pm:17