-
Notifications
You must be signed in to change notification settings - Fork 152
/
INSTALL.pl
executable file
·1944 lines (1557 loc) · 57.4 KB
/
INSTALL.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
=head1 LICENSE
Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2024] EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=cut
=head1 CONTACT
Please email comments or questions to the public Ensembl
developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
Questions may also be sent to the Ensembl help desk at
<http://www.ensembl.org/Help/Contact>.
=cut
=head1 NAME
INSTALL.pl - a script to install required code and data for VEP
=cut
use strict;
use FindBin qw($RealBin);
use lib $RealBin.'/modules';
use Getopt::Long;
use File::Path qw(mkpath rmtree);
use File::Copy;
use File::Basename;
use Net::FTP;
use Cwd;
use Scalar::Util qw(looks_like_number);
use Bio::EnsEMBL::VEP::Utils qw(get_version_data get_version_string);
our (
$DEST_DIR,
$ENS_CVS_ROOT,
$API_VERSION,
$DATA_VERSION,
$ASSEMBLY,
$ENS_GIT_ROOT,
$BIOPERL_URL,
$CACHE_URL,
$CACHE_URL_INDEXED,
$CACHE_DIR,
$NO_PLUGINS,
$PLUGINS,
$PLUGIN_URL,
$PLUGINS_DIR,
$FASTA_URL,
$FTP_USER,
$HELP,
$NO_UPDATE,
$SPECIES,
$AUTO,
$QUIET,
$PREFER_BIN,
$CONVERT,
$TEST,
$NO_HTSLIB,
$LIB_DIR,
$HTSLIB_DIR,
$BIODBHTS_DIR,
$REALPATH_DEST_DIR,
$NO_TEST,
$NO_BIOPERL,
$ua,
$CAN_USE_CURL,
$CAN_USE_LWP,
$CAN_USE_HTTP_TINY,
$CAN_USE_ARCHIVE,
$CAN_USE_UNZIP,
$CAN_USE_GZIP,
$CAN_USE_TAR,
$CAN_USE_DBI,
$CAN_USE_DBD_MYSQL,
);
## VERSIONS OF INSTALLED SOFTWARE
## MAY BE UPDATED IF SUCCESSFULLY TESTED
########################################
our $HTSLIB_VERSION = '1.9'; # latest release as of release/98
our $BIOHTS_VERSION = '2.11'; # latest 2.X release as of release/98
our $BIOPERL_VERSION = 'release-1-6-924'; # frozen, no pressing need to update
## BEGIN BLOCK, CHECK WHAT MODULES ETC WE CAN USE
#################################################
BEGIN {
if(eval q{ use LWP::Simple qw(getstore get $ua); 1 }) {
$CAN_USE_LWP = 1;
# set up a user agent's proxy (excluding github)
$ua->env_proxy;
}
if(eval q{ use DBI; 1 }) {
$CAN_USE_DBI = 1;
}
if(eval q{ use DBD::mysql; 1 }) {
$CAN_USE_DBD_MYSQL = 1;
}
$CAN_USE_CURL = 1 if `which curl` =~ /\/curl/;
$CAN_USE_HTTP_TINY = 1 if eval q{ use HTTP::Tiny; 1 };
$CAN_USE_ARCHIVE = 1 if eval q{ use Archive::Extract; 1 };
$CAN_USE_UNZIP = 1 if `which unzip` =~ /\/unzip/;
$CAN_USE_GZIP = 1 if `which gzip` =~ /\/gzip/;
$CAN_USE_TAR = 1 if `which tar` =~ /\/tar/;
}
$| = 1;
# CONFIGURE
###########
# other global data
my @API_MODULES = (
{ name => 'ensembl', path => ' ', test_pm => 'Bio::EnsEMBL::Registry' },
{ name => 'ensembl-variation', path => 'Variation', test_pm => 'Bio::EnsEMBL::Variation::Variation' },
{ name => 'ensembl-funcgen', path => 'Funcgen', test_pm => 'Bio::EnsEMBL::Funcgen::RegulatoryFeature' },
{ name => 'ensembl-compara', path => 'Compara', test_pm => 'Bio::EnsEMBL::Compara::Homology' },
{ name => 'ensembl-io', path => 'IO,Utils', test_pm => 'Bio::EnsEMBL::IO::Parser' },
);
my $ensembl_url_tail = '/archive/';
my $archive_type = '.zip';
my $git_api_root = 'https://api.github.com/repos/Ensembl/';
my $VEP_MODULE_NAME = 'ensembl-vep';
our (@store_species, @indexes, @files, $ftp, $dirname);
my $config = {};
GetOptions(
$config,
'DESTDIR|DEST_DIR|d=s',
'CACHE_VERSION|e=i',
'ASSEMBLY|y=s',
'BIOPERL|BIOPERL_URL|b=s',
'CACHEURL|CACHE_URL|u=s',
'CACHEDIR|CACHE_DIR|c=s',
'FASTAURL|FASTA_URL|f=s',
'HELP|h',
'NO_UPDATE|n',
'SPECIES|s=s',
'NO_PLUGINS',
'PLUGINS|g=s',
'PLUGINSDIR|PLUGINS_DIR|r=s',
'PLUGINURL|PLUGIN_URL=s',
'AUTO|a=s',
'QUIET|q',
'PREFER_BIN|p',
'CONVERT|t',
'TEST',
'NO_HTSLIB|l',
'NO_TEST',
'NO_BIOPERL'
) or die("ERROR: Failed to parse arguments");
# Read configuration from environment variables starting with VEP_
# Priority is given to command-line arguments
sub read_config_from_environment {
my $config = shift;
for my $key (keys %ENV) {
# Look for environment variables that start with VEP_
next unless $key =~ "^VEP_";
# Avoid setting empty strings
my $value = $ENV{$key};
next if $value eq "";
$key =~ s/^VEP_//ig;
# Prioritise previous values
$config->{$key} ||= $value;
}
return $config;
}
$config = read_config_from_environment($config);
# Quick fix: this script should use $config instead of multiple global variables
$DEST_DIR ||= $config->{DESTDIR};
$DATA_VERSION ||= $config->{CACHE_VERSION};
$ASSEMBLY ||= $config->{ASSEMBLY};
$BIOPERL_URL ||= $config->{BIOPERL};
$CACHE_URL ||= $config->{CACHEURL};
$CACHE_DIR ||= $config->{CACHEDIR};
$FASTA_URL ||= $config->{FASTAURL};
$HELP ||= $config->{HELP};
$NO_UPDATE ||= $config->{NO_UPDATE};
$SPECIES ||= $config->{SPECIES};
$NO_PLUGINS ||= $config->{NO_PLUGINS};
$PLUGINS ||= $config->{PLUGINS};
$PLUGINS_DIR ||= $config->{PLUGINSDIR};
$PLUGIN_URL ||= $config->{PLUGINURL};
$AUTO ||= $config->{AUTO};
$QUIET ||= $config->{QUIET};
$PREFER_BIN ||= $config->{PREFER_BIN};
$CONVERT ||= $config->{CONVERT};
$TEST ||= $config->{TEST};
$NO_HTSLIB ||= $config->{NO_HTSLIB};
$NO_TEST ||= $config->{NO_TEST};
$NO_BIOPERL ||= $config->{NO_BIOPERL};
# load version data
our $CURRENT_VERSION_DATA = get_version_data($RealBin.'/.version');
our $VERSION = $CURRENT_VERSION_DATA->{$VEP_MODULE_NAME}->{release};
$VERSION =~ s/release\///;
if($HELP) {
usage();
exit(0);
}
# check user has DBI and DBD::mysql
die(
"ERROR: DBI module not found. VEP requires the DBI perl module to function\n\n".
"http://www.ensembl.org/info/docs/tools/vep/script/vep_download.html#requirements\n"
) unless $CAN_USE_DBI;
warn(
"WARNING: DBD::mysql module not found. VEP can only run in offline (--offline) mode without DBD::mysql installed\n\n".
"http://www.ensembl.org/info/docs/tools/vep/script/vep_download.html#requirements\n"
) unless $CAN_USE_DBD_MYSQL;
my $default_dir_used = check_default_dir();
$LIB_DIR = $DEST_DIR;
$HTSLIB_DIR = $LIB_DIR.'/htslib';
$BIODBHTS_DIR = $LIB_DIR.'/biodbhts';
$REALPATH_DEST_DIR .= Cwd::realpath($DEST_DIR).'/Bio';
$DEST_DIR .= '/Bio';
$dirname = dirname(__FILE__) || '.';
$ENS_GIT_ROOT ||= 'https://github.com/Ensembl/';
$BIOPERL_URL ||= "https://github.com/bioperl/bioperl-live/archive/$BIOPERL_VERSION.zip";
$API_VERSION ||= $CURRENT_VERSION_DATA->{$VEP_MODULE_NAME}->{release};
$DATA_VERSION ||= $API_VERSION;
$CACHE_DIR ||= $ENV{HOME} ? $ENV{HOME}.'/.vep' : 'cache';
$PLUGINS_DIR ||= $CACHE_DIR.'/Plugins';
$FTP_USER ||= 'anonymous';
## Set the indexed cache url if it's been overwritten by the user
$CACHE_URL_INDEXED = $CACHE_URL;
$CACHE_URL ||= "https://ftp.ensembl.org/pub/release-$DATA_VERSION/variation/vep";
$CACHE_URL_INDEXED ||= "https://ftp.ensembl.org/pub/release-$DATA_VERSION/variation/indexed_vep_cache";
$FASTA_URL ||= "https://ftp.ensembl.org/pub/release-$DATA_VERSION/fasta/";
$PLUGIN_URL ||= 'https://raw.githubusercontent.com/Ensembl/VEP_plugins';
# using PREFER_BIN can save memory when extracting archives
$PREFER_BIN = 0 unless defined($PREFER_BIN);
$Archive::Extract::PREFER_BIN = $PREFER_BIN == 0 ? 0 : 1;
$QUIET = 0 unless $AUTO;
# updates to ensembl-vep available?
update() unless $NO_UPDATE;
# auto?
if($AUTO) {
# check
die("ERROR: Failed to parse AUTO string - must contain any of a (API), l (FAIDX/htslib), c (cache), f (FASTA), p (plugins)\n") unless $AUTO =~ /^[alcfp]+$/i;
# require species
if($AUTO =~ /[cf]/i) {
die("ERROR: No species specified\n") unless $SPECIES;
$SPECIES = [split /\,/, $SPECIES];
}
# require plugin list
if($AUTO =~ /p/i) {
die("ERROR: No plugins specified\n") unless $PLUGINS;
$PLUGINS = [split /\,/, $PLUGINS];
}
# run subs
if($AUTO =~ /l/ && $AUTO !~ /a/) {
my $curdir = getcwd;
chdir $curdir;
install_biodbhts();
chdir $curdir;
# remove Bio dir if empty
opendir DIR, $DEST_DIR;
my @files = grep {!/^\./} readdir DIR;
closedir DIR;
if(scalar @files <= 1) {
rmtree($DEST_DIR.'/'.$files[0]);
rmtree($DEST_DIR);
}
}
api() if $AUTO =~ /a/;
cache() if $AUTO =~ /c/;
fasta() if $AUTO =~ /f/;
plugins() if $AUTO =~ /p/;
}
else {
my $api_msg =
" - Install v$API_VERSION of the Ensembl API for use by the VEP. " .
"It will not affect any existing installations of the Ensembl API that you may have.\n";
print "Hello! This installer will help you set up VEP v$API_VERSION, including:\n" .
($NO_UPDATE ? "" : $api_msg) .
" - Download and install cache files from Ensembl's FTP server.\n" .
" - Download FASTA files from Ensembl's FTP server.\n" .
($NO_PLUGINS ? "" : " - Download VEP plugins.\n") . "\n"
unless $QUIET;
# run subs
api() if check_api();
cache();
fasta();
plugins() unless $NO_PLUGINS;
}
# clean up
if(-d "$CACHE_DIR/tmp" && !$TEST) {
rmtree("$CACHE_DIR/tmp") or die "ERROR: Could not delete directory $CACHE_DIR/tmp\n";
}
print "\nAll done\n" unless $QUIET;
##########################################################################
##########################################################################
##########################################################################
# UPDATE
########
sub update() {
my $module = $VEP_MODULE_NAME;
# check for major version update
my $repo_file = "$RealBin/$$.repo_file";
download_to_file(
"$git_api_root$module",
$repo_file
);
my $default_branch;
open IN, $repo_file;
while(<IN>) {
if(/default_branch.+\:.+\"(.+?)\"/) {
$default_branch = $1;
last;
}
}
close IN;
unlink($repo_file);
unless($default_branch) {
print "WARNING: Unable to carry out version check for '$module'\n" unless $QUIET;
return;
}
my $default_branch_number = $default_branch;
$default_branch_number =~ s/release\/// if $default_branch_number;
my $current_branch = $CURRENT_VERSION_DATA->{'ensembl-vep'}->{release};
my $message;
# don't have latest
if($current_branch < $default_branch_number) {
$message =
"Version check reports a newer release of '$module' is available ".
"(installed: $current_branch, available: $default_branch_number)\n";
}
# do have latest, but there might be updates
elsif($current_branch == $default_branch_number) {
my $git_sub = get_vep_sub_version($current_branch);
my $have_sub = $CURRENT_VERSION_DATA->{$module}->{sub};
$message = sprintf(
"Version check reports there are post-release updates available of %s (installed: %s.%.7s, available: %s.%.7s)\n",
$module,
$current_branch, $have_sub,
$current_branch, $git_sub
) unless $git_sub eq $have_sub;
}
if($message) {
print "\n$message\n";
# user has git, suggest they use that instead
if(`which git` && -d $RealBin.'/.git') {
print "We recommend using git to update '$module', by exiting this installer and running:\n\n";
print "\tgit pull\n";
print "\tgit checkout $default_branch\n" if $current_branch ne $default_branch_number;
}
else {
print "You should exit this installer and re-download '$module' if you wish to update\n";
}
print "\nDo you wish to exit so you can get updates (y) or continue (n): ";
my $ok = <>;
if($ok !~ /^n/i) {
print "OK, bye!\n";
print "\nNB: Remember to re-run INSTALL.pl after updating to check for API updates\n";
exit(0);
}
}
else {
return;
}
}
# CHECKS DIR SETUP AND PATHS ETC
################################
sub is_url {
my $url = shift;
return $url =~ /^(http|ftp)/i;
}
sub check_default_dir {
my $this_os = $^O;
my $default_dir_used;
# check if $DEST_DIR is default
if(defined($DEST_DIR)) {
print "Using non-default API installation directory $DEST_DIR.\n";
print "Please note this just specifies the location for downloaded API files. The vep script will remain in its current location where ensembl-vep was unzipped.\n";
if(!defined($AUTO)){
print "Have you \n";
print "1. added $DEST_DIR to your PERL5LIB environment variable?\n";
print "2. added $DEST_DIR/htslib to your PATH environment variable?\n";
if( $this_os eq 'darwin' && !$NO_HTSLIB) {
print "3. added $DEST_DIR/htslib to your DYLD_LIBRARY_PATH environment variable?\n";
}
print "(y/n): ";
my $ok = <>;
if($ok !~ /^y/i) {
print "Exiting. Please \n";
print "1. add $DEST_DIR to your PERL5LIB environment variable\n";
print "2. add $DEST_DIR/htslib to your PATH environment variable\n";
if( $this_os eq 'darwin' && !$NO_HTSLIB) {
print "3. add $DEST_DIR/htslib to your DYLD_LIBRARY_PATH environment variable\n";
}
exit(0);
}
}
else {
print "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n";
print "PLEASE REMEMBER TO \n";
print "1. add $DEST_DIR to your PERL5LIB environment variable\n";
print "2. add $DEST_DIR/htslib to your PATH environment variable\n";
if( $this_os eq 'darwin' && !$NO_HTSLIB) {
print "3. add $DEST_DIR/htslib to your DYLD_LIBRARY_PATH environment variable\n";
print "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
}
}
if( ! -d $DEST_DIR ) {
mkdir $DEST_DIR || die "Could not make destination directory $DEST_DIR"
}
$default_dir_used = 0;
}
else {
$DEST_DIR ||= '.';
$default_dir_used = 1;
my $current_dir = cwd();
if( !$NO_HTSLIB && $this_os eq 'darwin' ) {
print "Installation on OSX requires that you set up some paths before running this installer.\n";
if(!defined($AUTO)){
print "Have you \n";
print "1. added $current_dir/htslib to your DYLD_LIBRARY_PATH environment variable?\n";
print "(y/n): ";
my $ok = <>;
if($ok !~ /^y/i) {
print "Exiting. Please \n";
print "1. add $current_dir/htslib to your DYLD_LIBRARY_PATH environment variable\n";
exit(0);
}
}
else{
print "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
#print "\nPLEASE REMEMBER TO ADD $current_dir/htslib TO YOUR DYLD_LIBRARY_PATH ENVIRONMENT VARIABLE\n";
print "\nPLEASE REMEMBER TO \n";
print "1. add $current_dir/htslib to your DYLD_LIBRARY_PATH environment variable\n";
print "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
}
}
}
return $default_dir_used;
}
# API
#####
sub api() {
setup_dirs();
my $curdir = getcwd;
unless($NO_BIOPERL) {
bioperl();
}
# htslib needs to find bioperl to pass tests
$ENV{PERL5LIB} = $ENV{PERL5LIB} ? $ENV{PERL5LIB}.':'.$DEST_DIR : $DEST_DIR;
unless($NO_HTSLIB) {
chdir $curdir;
install_biodbhts();
}
chdir $curdir;
install_api();
test() unless $NO_TEST;
}
# CHECK EXISTING
################
sub check_api() {
return 0 if $NO_UPDATE;
print "Checking for installed versions of the Ensembl API..." unless $QUIET;
my $has_api = {};
my $updates = {};
my $core_version;
my @unknown_versions = ();
foreach my $module_hash(@API_MODULES) {
my $module = $module_hash->{name};
my $test_pm = $module_hash->{test_pm};
eval "require $test_pm";
$has_api->{$module} = $@ ? 0 : 1;
if($has_api->{$module}) {
my $have_sub = $CURRENT_VERSION_DATA->{$module} ? ($CURRENT_VERSION_DATA->{$module}->{sub} || '') : '';
my $git_sub = get_module_sub_version($module);
if($have_sub) {
$updates->{$module} = [$have_sub, $git_sub] if $have_sub ne $git_sub;
}
else {
push @unknown_versions, $module;
}
if($module eq 'ensembl') {
$core_version = Bio::EnsEMBL::Registry->software_version;
}
}
}
print "done\n";
my $total = 0;
$total += $_ for values %$has_api;
my $message;
if($total == scalar @API_MODULES) {
if(defined($core_version)) {
if(!looks_like_number($API_VERSION)) {
$message = "Your reported version ($API_VERSION) is a non-standard release number";
}
elsif($core_version == $API_VERSION) {
if(scalar keys %$updates) {
$message =
"There are updates available for these modules:\n ".
join(
"\n ",
map {
sprintf(
"%-20s : installed = %.7s, available = %.7s",
$_, $updates->{$_}->[0], $updates->{$_}->[1]
)
} keys %$updates
);
}
else {
$message = "It looks like you already have v$API_VERSION of the API installed.\n";
if(@unknown_versions) {
$message .=
"No version information was available for the following modules:\n".
join("\n", map {" - ".$_} @unknown_versions).
"\nUpdates may be available but you will need to perform these manually.";
}
else {
$message .= "You shouldn't need to install the API";
}
}
}
elsif($core_version > $API_VERSION) {
$message = "It looks like this installer is for an older distribution ($API_VERSION) of the API than you already have ($core_version)";
}
else {
$message = "It looks like you have an older version ($core_version) of the API installed.\nThis installer will install a limited set of the API v$API_VERSION for use by the VEP only";
}
}
else {
$message = "It looks like you have an unidentified version of the API installed.\nThis installer will install a limited set of the API v$API_VERSION for use by the VEP only"
}
}
elsif($total > 0) {
$message = "It looks like you already have the following API modules installed:\n\n".(join "\n", grep {$has_api->{$_}} keys %$has_api)."\n\nEnsembl VEP requires the ensembl, ensembl-io, ensembl-variation, ensembl-compara and ensembl-funcgen modules";
}
if($AUTO =~ /a/ || !defined($message)) {
return 1;
}
else {
print $message unless $QUIET;
print "\n\nSkip to the next step (n) to install cache files\n\nDo you want to continue installing the API (y/n)? ";
my $ok = <>;
if($ok !~ /^y/i) {
print " - skipping API installation\n" unless $QUIET;
return 0;
}
else {
return 1;
}
}
}
# SETUP
#######
sub setup_dirs() {
print "\nSetting up directories\n" unless $QUIET;
# check if install dir exists
if(-e $DEST_DIR) {
my $ok;
if($AUTO) {
$ok = 'y';
}
else {
print "Destination directory $DEST_DIR already exists.\nDo you want to overwrite it (if updating VEP this is probably OK) (y/n)? ";
$ok = <>;
}
if($ok !~ /^y/i) {
print "Exiting\n";
exit(0);
}
else {
unless($default_dir_used || $AUTO) {
print "WARNING: You are using a non-default install directory.\nPressing \"y\" again will remove $DEST_DIR and its contents!!!\nAre you really, really sure (y/n)? ";
$ok = <>;
if($ok !~ /^y/i) {
print "Exiting\n";
exit(0);
}
}
# try to delete the existing dir
rmtree($DEST_DIR) or die "ERROR: Could not delete directory $DEST_DIR\n";
}
}
mkdir($DEST_DIR) or die "ERROR: Could not make directory $DEST_DIR\n";
mkdir($DEST_DIR.'/tmp') or die "ERROR: Could not make directory $DEST_DIR/tmp\n";
}
# INSTALL API
#############
sub install_api() {
print "\nDownloading required Ensembl API files\n" unless $QUIET;
my $release_url_string = looks_like_number($API_VERSION) ? 'release/'.$API_VERSION : $API_VERSION;
my $release_path_string = looks_like_number($API_VERSION) ? 'release-'.$API_VERSION : $API_VERSION;
foreach my $module_hash(@API_MODULES) {
my $module = $module_hash->{name};
# do we need to update this?
my $have_sub = $CURRENT_VERSION_DATA->{$module} ? ($CURRENT_VERSION_DATA->{$module}->{sub} || '') : '';
my $url = $ENS_GIT_ROOT.$module.$ensembl_url_tail.$release_url_string.$archive_type;
print " - fetching $module\n" unless $QUIET;
my $target_file = $DEST_DIR.'/tmp/'.$module.$archive_type;
mkdir($DEST_DIR.'/tmp/') unless -d $DEST_DIR.'/tmp/';
download_to_file($url, $target_file) unless -e $target_file;
print " - unpacking $target_file\n" unless $QUIET;
unpack_arch("$DEST_DIR/tmp/$module$archive_type", "$DEST_DIR/tmp/");
print " - moving files\n" unless $QUIET;
foreach my $module_path (split(',',$module_hash->{path})) {
my $module_dir_suffix = $module_path eq ' ' ? '' : '/'.$module_path;
my $module_dir_from = "$DEST_DIR/tmp/$module\-$release_path_string/modules/Bio/EnsEMBL$module_dir_suffix";
my $module_dir_to = "$DEST_DIR/EnsEMBL$module_dir_suffix";
# If the target directory already exist, we can't overwrite it.
if (-d $module_dir_to) {
# One solution is to move the content of the directory instead.
# However we need to loop over the files/directories within the module directory because the 'move()' method doesn't allow wildcards.
opendir DH, $module_dir_from;
while(my $file_or_dir = readdir DH) {
next if ($file_or_dir =~ /^\.+$/);
move("$module_dir_from/$file_or_dir", "$module_dir_to/$file_or_dir") or die "ERROR: Could not move '$module_dir_from/$file_or_dir'\n".$!;
}
closedir DH;
}
else {
move($module_dir_from, $module_dir_to) or die "ERROR: Could not move the directory '$module_dir_from'\n".$!;
}
}
# now get latest commit from github API
print " - getting version information\n" unless $QUIET;
my $git_sub = get_module_sub_version($module);
mkdir("$RealBin/.version/") unless -d "$RealBin/.version/";
open OUT, ">$RealBin/.version/$module" or die $!;
print OUT "release $API_VERSION\nsub $git_sub\n";
close OUT;
rmtree("$DEST_DIR/tmp/$module\-$release_path_string") or die "ERROR: Failed to remove directory: $!\n";
}
}
sub get_module_sub_version {
my $module = shift;
my $sub_file = "$RealBin/$$\.$module.sub";
my $release_url_string = looks_like_number($API_VERSION) ? 'release/'.$API_VERSION : $API_VERSION;
download_to_file(
"$git_api_root$module/commits?sha=$release_url_string",
$sub_file
);
open IN, $sub_file or die $!;
my $sub;
while(<IN>) {
if(/\"sha\": \"(.+?)\"/) {
$sub = $1;
last;
}
}
close IN;
unlink($sub_file);
return $sub;
}
sub get_vep_sub_version {
my $release = shift || $API_VERSION;
my $sub_file = "$RealBin/$$\.$VEP_MODULE_NAME.sub";
my $release_url_string = looks_like_number($release) ? 'release/'.$release : $release;
download_to_file(
sprintf(
'https://raw.githubusercontent.com/Ensembl/%s/%s/modules/Bio/EnsEMBL/VEP/Constants.pm',
$VEP_MODULE_NAME,
$release_url_string
),
$sub_file
);
open IN, $sub_file or die $!;
my $sub;
while(<IN>) {
if(/VEP_SUB_VERSION \= (.+)\;/) {
$sub = $1;
last;
}
}
close IN;
unlink($sub_file);
return $sub;
}
# HTSLIB download/make
######################
sub install_htslib() {
#actually decided to follow Bio::DB::Sam template
# STEP 0: various dependencies
my $git = `which git`;
$git or die <<END;
'git' command not in path. Please install git and try again.
(or to skip Bio::DB::HTS/htslib install re-run with --NO_HTSLIB)
On Debian/Ubuntu systems you can do this with the command:
apt-get install git
END
`which cc` or die <<END;
'cc' command not in path. Please install it and try again.
(or to skip Bio::DB::HTS/htslib install re-run with --NO_HTSLIB)
On Debian/Ubuntu systems you can do this with the command:
apt-get install build-essential
END
`which make` or die <<END;
'make' command not in path. Please install it and try again.
(or to skip Bio::DB::HTS/htslib install re-run with --NO_HTSLIB)
On Debian/Ubuntu systems you can do this with the command:
apt-get install build-essential
END
# List the required libraries with their packages
my %libs = (
'zlib.h' => 'zlib1g-dev',
'lzma.h' => 'liblzma-dev',
'bzlib.h' => 'libbz2-dev'
);
my $msg = '';
my $this_os = $^O;
if ($this_os ne 'darwin' ) {
my $default_msg = qq{%s library header(s) not found in /usr/include. Please install it and try again.
(or to skip Bio::DB::HTS/htslib install re-run with --NO_HTSLIB)
On Debian/Ubuntu systems you can do this with the command:
apt-get install %s};
my @missing_header = ();
my @missing_library = ();
# Loop over the required libraries
foreach my $lib (sort(keys(%libs))) {
unless(-e '/usr/include/'.$lib){
push(@missing_header, $lib);
push(@missing_library, $libs{$lib});
}
}
my $header_string = join( ', ', @missing_header);
my $install_string = join( ' ', @missing_library);
die(sprintf($default_msg, $header_string, $install_string). "\n\n") if($header_string ne '');
}
# STEP 1: Create a clean directory for building
my $htslib_install_dir = $LIB_DIR;
my $curdir = getcwd;
chdir $htslib_install_dir;
my $actualdir = getcwd;
# STEP 2: Check out HTSLIB / or make this a download?
print(" - checking out HTSLib\n");
system "git clone -b $HTSLIB_VERSION https://github.com/samtools/htslib.git";
-d './htslib' or die "git clone seems to have failed. Could not find $htslib_install_dir/htslib directory";
chdir './htslib';
# Step 3: Build libhts.a
print(" - building HTSLIB in $htslib_install_dir/htslib\n");
print( "In ".getcwd."\n" );
# patch makefile
rename 'Makefile','Makefile.orig' or die "Couldn't rename Makefile to Makefile.orig: $!";
open my $in, '<','Makefile.orig' or die "Couldn't open Makefile for reading: $!";
open my $out,'>','Makefile.new' or die "Couldn't open Makefile.new for writing: $!";
while (<$in>) {
chomp;
if (/^CFLAGS/ && !/-fPIC/) {
s/#.+//; # get rid of comments
$_ .= " -fPIC -Wno-unused -Wno-unused-result";
}
}
continue {
print $out $_,"\n";
}
close $in;
close $out;
rename 'Makefile.new','Makefile' or die "Couldn't rename Makefile.new to Makefile: $!";
system "make";
-e 'libhts.a' or die "Compile didn't complete. No libhts.a library file found";
chdir $curdir;
my $retval = Cwd::realpath("$htslib_install_dir/htslib") ;
}
# INSTALL Bio::DB::HTS
######################
sub install_biodbhts() {
print "Attempting to install Bio::DB::HTS and htslib.\n\n>>> If this fails, try re-running with --NO_HTSLIB\n\n";
my $htslib_location = install_htslib();
rmtree( $DEST_DIR.'/tmp' );
#Now install Bio::DB::HTS proper
my $biodbhts_github_url = "https://github.com/Ensembl/Bio-DB-HTS";
my $biodbhts_zip_github_url = "$biodbhts_github_url/archive/$BIOHTS_VERSION.zip";
my $biodbhts_zip_download_file = $DEST_DIR.'/tmp/biodbhts.zip';
mkdir $DEST_DIR unless -d $DEST_DIR;
mkdir $DEST_DIR.'/tmp';
download_to_file($biodbhts_zip_github_url, $biodbhts_zip_download_file);
print " - unpacking $biodbhts_zip_download_file to $DEST_DIR/tmp/\n" unless $QUIET;
unpack_arch($biodbhts_zip_download_file, "$DEST_DIR/tmp/");
my $tmp_name = -d "$DEST_DIR/tmp/Bio-HTS-$BIOHTS_VERSION" ? "Bio-HTS-$BIOHTS_VERSION" : "Bio-DB-HTS-$BIOHTS_VERSION";
print "$DEST_DIR/tmp/$tmp_name - moving files to $BIODBHTS_DIR\n" unless $QUIET;
rmtree($BIODBHTS_DIR);
move("$DEST_DIR/tmp/$tmp_name", $BIODBHTS_DIR) or die "ERROR: Could not move directory\n".$!;
print( " - making Bio::DB:HTS\n" );
# patch makefile
chdir $BIODBHTS_DIR;
system "perl Build.PL --htslib $htslib_location";
system "./Build";
chdir ".";
#move the library
my $pdir = getcwd;
#Perl modules to go alongside the API
dircopy("lib/Bio",$REALPATH_DEST_DIR);
#The shared object XS library
if( -e "blib/arch/auto/Bio/DB/HTS/HTS.so" ) {
copy( "blib/arch/auto/Bio/DB/HTS/Faidx/Faidx.so", "..")
or die "ERROR: Could not copy shared Faidx.so library:$!\n";
copy( "blib/arch/auto/Bio/DB/HTS/HTS.so", "..")
or die "ERROR: Could not copy shared HTS.so library:$!\n";
}
elsif( -e "blib/arch/auto/Bio/DB/HTS/HTS.bundle" ) {
copy( "blib/arch/auto/Bio/DB/HTS/Faidx/Faidx.bundle", "..")
or die "ERROR: Could not copy shared Faidx.bundle library:$!\n";
copy( "blib/arch/auto/Bio/DB/HTS/HTS.bundle", "..")
or die "ERROR: Could not copy shared HTS.bundle library:$!\n";
}
else {
die "ERROR: Shared Bio::DB:HTS library not found\n";
}
chdir $pdir;
}
sub dircopy {
my ($from, $to) = @_;
opendir FROM, $from;
foreach my $file(grep {!/^\.\.?/} readdir FROM) {
# dir?
if(-d "$from/$file") {