forked from Ensembl/ensembl-vep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INSTALL.pl
executable file
·1792 lines (1419 loc) · 51.6 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-2017] 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_DIR,
$PLUGINS,
$PLUGIN_URL,
$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,
);
## 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-io', path => 'IO', 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);
GetOptions(
'DESTDIR|d=s' => \$DEST_DIR,
'VERSION|v=i' => \$API_VERSION,
'CACHE_VERSION|e=i' => \$DATA_VERSION,
'ASSEMBLY|y=s' => \$ASSEMBLY,
'BIOPERL|b=s' => \$BIOPERL_URL,
'CACHEURL|u=s' => \$CACHE_URL,
'CACHEDIR|c=s' => \$CACHE_DIR,
'FASTAURL|f=s' => \$FASTA_URL,
'HELP|h' => \$HELP,
'NO_UPDATE|n' => \$NO_UPDATE,
'SPECIES|s=s' => \$SPECIES,
'PLUGINS|g=s' => \$PLUGINS,
'PLUGINURL=s' => \$PLUGIN_URL,
'AUTO|a=s' => \$AUTO,
'QUIET|q' => \$QUIET,
'PREFER_BIN|p' => \$PREFER_BIN,
'CONVERT|t' => \$CONVERT,
'TEST' => \$TEST,
'NO_HTSLIB|l' => \$NO_HTSLIB,
'NO_TEST' => \$NO_TEST,
'NO_BIOPERL' => \$NO_BIOPERL
) or die("ERROR: Failed to parse arguments");
# 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/release-1-6-924.zip';
$API_VERSION ||= $CURRENT_VERSION_DATA->{$VEP_MODULE_NAME}->{release};
$DATA_VERSION ||= $API_VERSION;
$CACHE_DIR ||= $ENV{HOME} ? $ENV{HOME}.'/.vep' : 'cache';
$FTP_USER ||= 'anonymous';
$CACHE_URL ||= "ftp://ftp.ensembl.org/pub/release-$DATA_VERSION/variation/VEP";
$FASTA_URL ||= "ftp://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 {
print "\nHello! This installer is configured to install v$API_VERSION of the Ensembl API for use by the VEP.\nIt will not affect any existing installations of the Ensembl API that you may have.\n\nIt will also download and install cache files from Ensembl's FTP server.\n\n" unless $QUIET;
# run subs
api() if check_api();
cache();
fasta();
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 "You may use git to update $module by exiting this installer and running:\n\n";
print "git pull\n";
print "git 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 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";
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);
}
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";
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);
}
}
}
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() {
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 avaiable 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\nThe VEP requires the ensembl, ensembl-io, ensembl-variation 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};
my $module_dir_suffix = $module_hash->{path} ? '/'.$module_hash->{path} : '';
# 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;
move(
"$DEST_DIR/tmp/$module\-$release_path_string/modules/Bio/EnsEMBL$module_dir_suffix",
"$DEST_DIR/EnsEMBL$module_dir_suffix"
) or die "ERROR: Could not move directory\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($API_VERSION) ? 'release/'.$API_VERSION : $API_VERSION;
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
my $this_os = $^O;
if( $this_os ne 'darwin' ) {
-e '/usr/include/zlib.h' or die <<END;
zlib.h library header 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 zlib1g-dev
END
;
}
# 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 1.3.2 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-HTS";
my $biodbhts_zip_github_url = "$biodbhts_github_url/archive/master.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-master" ? 'Bio-HTS-master' : 'Bio-DB-HTS-master';
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;
rename 'Build.PL','Build.PL.orig' or die "Couldn't rename Build to Build.orig: $!";
open my $in, '<','Build.PL.orig' or die "Couldn't open Build.PL.orig for reading: $!";
open my $out,'>','Build.PL.new' or die "Couldn't open Build.PL.new for writing: $!";
while (<$in>) {
chomp;
if (/LIBS/) {
s/#.+//; # get rid of comments
$_ = "LIBS => ['-L../htslib/ -lhts -lz'],";
}
if (/INC/) {
s/#.+//; # get rid of comments
$_ = "INC => '-I. -I../htslib', ";
}
}
continue {
print $out $_,"\n";
}
close $in;
close $out;
rename 'Build.PL.new','Build.PL' or die "Couldn't rename Build.new to Build: $!";
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") {
mkdir("$to/$file") unless -d "$to/$file";
dircopy("$from/$file", "$to/$file");
}
else {
copy("$from/$file", "$to/$file");
}
}
closedir FROM;
}
# INSTALL BIOPERL
#################
sub bioperl() {
# now get BioPerl
print " - fetching BioPerl\n" unless $QUIET;
my $bioperl_file = (split /\//, $BIOPERL_URL)[-1];
my $target_file = $DEST_DIR.'/tmp/'.$bioperl_file;
download_to_file($BIOPERL_URL, $target_file);
print " - unpacking $target_file\n" unless $QUIET;
unpack_arch("$DEST_DIR/tmp/$bioperl_file", "$DEST_DIR/tmp/");
print " - moving files\n" unless $QUIET;
my $bioperl_dir;
if($BIOPERL_URL =~ /github/) {
$bioperl_file =~ s/\.zip//;
$bioperl_dir = "bioperl-live-".$bioperl_file;
}
else {
$bioperl_file =~ /(bioperl.+?)\.tar\.gz/i;
$bioperl_dir = $1;
}
opendir BIO, "$DEST_DIR/tmp/$bioperl_dir/Bio/";
move("$DEST_DIR/tmp/$bioperl_dir/Bio/$_", "$DEST_DIR/$_") for readdir BIO;
closedir BIO;
rmtree("$DEST_DIR/tmp") or die "ERROR: Failed to remove directory $DEST_DIR/tmp\n";
}
# TEST
######
sub test() {
print "\nTesting VEP installation\n" unless $QUIET;
eval q{use Test::Harness; use Test::Exception; };
if(!$@) {
opendir TEST, "$dirname\/t";
my @test_files = map {"$dirname\/t\/".$_} grep {!/^\./ && /\.t$/} readdir TEST;
closedir TEST;
# haplo.pl tests require Set::IntervalTree which is not installed here
eval q{use Set::IntervalTree};
@test_files = grep {!/Haplo/} @test_files if $@;
print "Warning: Tests failed, VEP may not run correctly\n" unless runtests(@test_files);
}
else {
my $test_vep = `perl -I $DEST_DIR $dirname/vep --help 2>&1`;
$test_vep =~ /ENSEMBL VARIANT EFFECT PREDICTOR/ or die "ERROR: Testing VEP script failed with the following error\n$test_vep\n";
}
print " - OK!\n" unless $QUIET;
}
# CACHE FILES
#############
sub cache() {
my $ok;
if($AUTO) {
$ok = $AUTO =~ /c/i ? 'y' : 'n';
}
else {
print "\nThe VEP can either connect to remote or local databases, or use local cache files.\nUsing local cache files is the fastest and most efficient way to run the VEP\n" unless $QUIET;
print "Cache files will be stored in $CACHE_DIR\n" unless $QUIET;
print "Do you want to install any cache files (y/n)? ";
$ok = <>;
}
if($ok !~ /^y/i) {
print "Skipping cache installation\n" unless $QUIET;
return;
}
# check cache dir exists
if(!(-e $CACHE_DIR)) {
if(!$AUTO) {
print "Cache directory $CACHE_DIR does not exists - do you want to create it (y/n)? ";
my $ok = <>;
if($ok !~ /^y/i) {
print "Exiting\n";
exit(0);
}
}