forked from Dfam-consortium/RepeatMasker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·752 lines (669 loc) · 23.6 KB
/
configure
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
#!/usr/bin/env perl
##---------------------------------------------------------------------------##
## File:
## @(#) configure
## Author:
## Robert Hubley <[email protected]>
## Description:
## A configuration utility for the RepeatMasker distribution.
##
#******************************************************************************
#* Copyright (C) Institute for Systems Biology 2003-2019 Developed by
#* Robert Hubley.
#*
#* This work is licensed under the Open Source License v2.1. To view a copy
#* of this license, visit http://www.opensource.org/licenses/osl-2.1.php or
#* see the license.txt file contained in this distribution.
#*
###############################################################################
=head1 NAME
configure - Configure the RepeatMasker distribution
=head1 SYNOPSIS
perl ./configure
=head1 DESCRIPTION
An installation script for the RepeatMasker distribution
=head1 CONFIGURATION OVERRIDES
=head1 SEE ALSO
=over 4
RepeatMasker
=back
=head1 COPYRIGHT
Copyright 2003-2019 Robert Hubley, Institute for Systems Biology
=head1 AUTHOR
Robert Hubley <[email protected]>
=cut
#
# Module Dependence
#
use strict;
use Config;
use Cwd;
use FindBin;
use Getopt::Long;
use Pod::Text;
use Data::Dumper;
use lib $FindBin::Bin;
use RepeatMaskerConfig;
use POSIX qw(:sys_wait_h);
# No output buffering
$|=1;
#
# Release Version
#
my $version = $RepeatMaskerConfig::VERSION;
my $df_version = $RepeatMaskerConfig::DFAM_VERSION;
#
# First...make sure we are running in the same directory
# as the script is located. This avoids problems where
# this script ends up in someones path and they run it
# unqualified from another installation directory.
#
if ( getcwd() ne $FindBin::RealBin ) {
print "\n The RepeatMasker configure script must be run from\n"
. " inside the RepeatMasker installation directory:\n\n"
. " $FindBin::RealBin\n\n"
. " Perhaps this is not the \"configure\" you are looking for?\n\n";
exit;
}
#
# Option processing
# e.g.
# -t: Single letter binary option
# -t=s: String parameters
# -t=i: Number parameters
#
my @getopt_args = ( '-version', '-perlbin=s' );
# Add configuration parameters as additional command-line options
push @getopt_args, RepeatMaskerConfig::getCommandLineOptions();
#
# Get the supplied command line options, and set flags
#
my %options = ();
Getopt::Long::config( "noignorecase", "bundling_override" );
unless ( GetOptions( \%options, @getopt_args ) ) {
usage();
}
#
# Provide the POD text from this file and
# from the config file by merging them
# together. The heading "CONFIGURATION
# OVERRIDES" provides the insertion point
# for the configuration POD.
#
sub usage {
my $p = Pod::Text->new();
$p->output_fh(*STDOUT);
my $pod_str;
open IN,"<$0" or die "Could not open self ($0) for generating documentation!";
while (<IN>){
if ( /^=head1\s+CONFIGURATION OVERRIDES\s*$/ )
{
my $c_pod = RepeatMaskerConfig::getPOD();
if ( $c_pod ) {
$pod_str .= $_ . $c_pod;
}
}else {
$pod_str .= $_;
}
}
close IN;
print "$0 - $version\n";
$p->parse_string_document($pod_str);
exit(1);
}
#
# Resolve configuration settings using the following precedence:
# command line first, then environment, followed by config
# file.
#
RepeatMaskerConfig::resolveConfiguration(\%options);
my $config = $RepeatMaskerConfig::configuration;
##
## Perl interpreter location
##
my $perlLocation = $^X;
if ( $options{'perlbin'} ) {
my $tbin = "";
if ( -d $options{'perlbin'} ) {
if ( -x ( $options{'perlbin'} . "/perl" ) ) {
$tbin = $options{'perlbin'} . "/perl";
}
elsif ( -x ( $options{'perlbin'} . "/bin/perl" ) ) {
$tbin = $options{'perlbin'} . "/bin/perl";
}
else {
die "Could not find perl using supplied -perlbin parameter $options{'perlbin'}\n"
. "as $options{'perlbin'}/perl or $options{'perlbin'}/bin/perl. Please fix\n"
. "and rerun configure.\n";
}
}
elsif ( -x $options{'perlbin'} ) {
$tbin = $options{'perlbin'};
}
if ( $tbin ne $perlLocation ) {
my $optStr;
foreach my $key ( keys %options ) {
if ( $key ne "perlbin" ) {
$optStr .= " -$key " . $options{$key};
}
}
# Rerun with intended version of perl
exec( "$tbin $FindBin::RealBin/configure $optStr" );
}
}
##
## Check for perl version
##
if ( $] && $] < 5.008 ) {
print "RepeatMasker should be used with perl 5.008 or higher.\n"
. "Perl $] is being used to run configure.";
exit;
}
##
## Check for RepeatMasker dependencies
##
BEGIN {
my @modDependencies = (
"Tie::File", "Getopt::Long",
"POSIX", "File::Copy",
"File::Path", "Data::Dumper",
"Cwd", "Storable"
);
my @missingModules = ();
foreach my $module ( @modDependencies ) {
unless ( eval "require " . $module . ";" ) {
push @missingModules, $module;
}
}
if ( @missingModules ) {
print "\nThe following perl modules required by RepeatMasker "
. "are missing from\nyour system. Please install these or "
. "or upgrade your perl version\nto 5.8.x first:\n "
. join( "\n ", @missingModules ) . "\n";
exit;
}
}
#
# Check for XS version of Scalar::Util
#
eval "use Scalar::Util qw(weaken);";
if ( $@ ) {
print "\nThe CPAN module Scalar::Util included in this version of perl\n"
. "is not compiled with the XS option. RepeatMasker requires the\n"
. "XS version of the module. Please reinstall XS Scalar::Util from\n"
. "CPAN and restart the configure process.\n\n";
exit;
}
#
# Check Storable Version
#
my $storableVersion =
`$perlLocation -mStorable -e 'print \$Storable::VERSION' 2>/dev/null`;
if ( $storableVersion < 2.06 ) {
print "\nYour perl installation contains an old Storable CPAN module\n"
. "( version = $storableVersion ). Please upgrade your Storable module "
. "to\nversion 2.06 or higher and then re-run the configure program.\n\n";
exit;
}
#
# Test python3 and h5py
#
system('python3 -c "import h5py"');
if ( $? ) {
die "\nPython3 and the h5py module is a pre-requisite for RepeatMasker.\n"
. "Either python3 could not be found in your path or h5py is not installed.\n"
. "Please very both before rerunning configure.\n\n";
}
##
## Alter perl invocation headers
##
print " -- Setting perl interpreter...\n";
my @progFiles = (
"RepeatMasker",
"DateRepeats",
"ProcessRepeats",
"RepeatProteinMask",
"DupMasker",
"addRepBase.pl",
"util/calcDivergenceFromAlign.pl",
"util/createRepeatLandscape.pl",
"util/maskFile.pl",
"util/rmOutToGFF3.pl",
"util/buildRMLibFromEMBL.pl",
"util/rmToUCSCTables.pl"
);
# perlLocation will be used in shebang lines, so it must be
# an absolute path. However $^X is not always absolute (e.g. macOS).
# In most cases, $Config{perlpath} is still an absolute path.
if ( !File::Spec->file_name_is_absolute($perlLocation) ) {
$perlLocation = $Config{perlpath} . $Config{_exe};
}
if ( ! File::Spec->file_name_is_absolute($perlLocation) || ! -x $perlLocation ) {
die "Could not find an absolute path for the running perl interpreter!\n" .
"Try specifying your perl path manually with the -perlbin option.\n";
}
my $perlLocEsc = $perlLocation;
$perlLocEsc =~ s/\//\\\//g;
foreach my $file ( @progFiles ) {
system(
"$perlLocation -i -0pe \'s/^#\\!.*perl.*/#\\!$perlLocEsc/g\;' $file" );
}
##
## Introduce ourselves
##
system( "clear" );
print "RepeatMasker Configuration Program\n";
my $answer;
my $goodParam;
# So that we can get the engine versions
require NCBIBlastSearchEngine;
require WUBlastSearchEngine;
require CrossmatchSearchEngine;
require HMMERSearchEngine;
##
## RepeatMasker location
##
my $rmLocation = "$FindBin::Bin";
if ( -d "$rmLocation/Libraries" &&
$config->{'LIBDIR'}->{'value'} eq "" ){
$config->{'LIBDIR'}->{'value'} = $rmLocation . "/Libraries";
}
if ( ! RepeatMaskerConfig::validateParam('LIBDIR') ) {
RepeatMaskerConfig::promptForParam('LIBDIR');
}
my $LIBDIR = $config->{'LIBDIR'}->{'value'};
my $c_df_version = $df_version;
$c_df_version =~ s/\.//g;
print "\n\nChecking for libraries...\n\n";
# First check that we have a default library directory, if not try to create it
if ( ! -d "$LIBDIR/famdb" ) {
print " ** Creating library directory $LIBDIR/famdb **\n";
mkdir("$LIBDIR/famdb");
}
## Handle error reporting if we suspect that the famdb folder is corrupt
if ( -e "$LIBDIR/famdb/merge.working" ) {
my $dlTime = `cat $LIBDIR/famdb/merge.working`;
die "It appears a previous attempt to merge Dfam and Repbase failed on $dlTime" .
"The files in $LIBDIR/famdb may be corrupt.\n" .
"Please remove all files from this folder and rerun configure to retry.\n\n";
}
if ( -e "$LIBDIR/famdb/download.working" ) {
my $dlTime = `cat $LIBDIR/famdb/download.working`;
die "It appears a previous attempt to automatically download Dfam $df_version failed on $dlTime" .
"The files in $LIBDIR/famdb may not be complete.\n" .
"Please remove all files from this folder and rerun configure to begin a new download.\n\n";
}
# Check to see if there is an existing rmlib.config file (RepeatMasker's library configuration status file)
my $rmlibConfig = {};
if ( -e "$LIBDIR/famdb/rmlib.config" ) {
$rmlibConfig = readConfig("$LIBDIR/famdb/rmlib.config");
}
$rmlibConfig->{'famdb_files'} = {} if ( ! exists $rmlibConfig->{'famdb_files'} );
# Flag merging of repbase
my $hasRepbase = 0;
$hasRepbase = 1 if ( -s "$LIBDIR/RMRBSeqs.embl" );
# Now compare current files with previously processed files
my ( $hasFamDBRoot, $mergeRB, $rebuildRMLib, $gzip, $famdb_prefix ) = compareFiles( $LIBDIR, $rmlibConfig );
if ( ! $hasFamDBRoot ) {
if ( $gzip ) {
die "The FamDB database in $LIBDIR/famdb appears be compressed (gzipd). Please uncompress the FamDB partitions and rerun configure.\n\n";
}
do {
print " *** No libraries present ***\n\n";
print "Choose:\n";
print " 1. Download minimal Dfam df_version (partition 0) using wget or curl\n";
print " (please see https://dfam.org/releases/current/families/FamDB/README.txt for full list of Dfam partitions.)\n";
print " 2. Exit and download libraries manually (Dfam $df_version or newer).\n";
print "\n\nEnter Selection: ";
$answer = <STDIN>;
$answer =~ s/[\n\r]+//g;
} while ( $answer ne "1" && $answer ne "2" );
if ( $answer eq "2" ) {
print "\n\nPlease download a copy of the Dfam database ( famdb HDF5 format )\n" .
"from: https://www.dfam.org/releases/Dfam_$df_version/families/FamDB\n\n" .
"Minimally you may download just the root partition (file ending\n" .
"with \"*.0.h5\"), uncompress it ( gunzip ), store in the\n" .
"$LIBDIR/famdb folder,\n" .
"and rerun the configure program. See\n" .
" https://www.dfam.org/releases/Dfam_$df_version/families/FamDB/README\n" .
"for more details on the taxanomic coverage of each partition.\n\n\n";
exit(0);
}
system( "clear" );
my $hasWget = `sh -c 'command -v wget'`;
$hasWget =~ s/[\n\r]+//g;
my $hasCurl = `sh -c 'command -v curl'`;
$hasCurl =~ s/[\n\r]+//g;
# Create a sentinel
open OUT,">$LIBDIR/famdb/download.working" or die "Could not open $LIBDIR/famdb/download.working for writing!\n";
print OUT "" . localtime() . "\n";
close OUT;
if ( $hasCurl ne "" ) {
print "Downloading Dfam $df_version root partition using $hasCurl\n";
system("$hasCurl https://www.dfam.org/releases/Dfam_$df_version/families/FamDB/dfam$c_df_version" ."_full.0.h5.gz -o $LIBDIR/famdb/dfam$c_df_version" ."_full.0.h5.gz");
if ( $? ) {
unlink("$LIBDIR/famdb/dfam$c_df_version" . "_full.0.h5.gz") if ( -e "$LIBDIR/famdb/dfam$c_df_version" . "_full.0.h5.gz" );
unlink("$LIBDIR/famdb/download.working");
die "curl failed to download https://www.dfam.org/releases/Dfam_$df_version/families/FamDB/dfam$c_df_version"."_full.0.h5.gz.\n" .
"Please check your connnectivity and try again.\n";
}
}elsif ( $hasWget ne "" ) {
print "Downloading Dfam $df_version root partition using $hasWget\n";
system("$hasWget https://www.dfam.org/releases/Dfam_$df_version/families/FamDB/dfam$c_df_version" . "_full.0.h5.gz -O $LIBDIR/famdb/dfam$c_df_version" . "_full.0.h5.gz");
if ( $? ) {
unlink("$LIBDIR/famdb/dfam$c_df_version" . "_full.0.h5.gz") if ( -e "$LIBDIR/famdb/dfam$c_df_version" . "_full.0.h5.gz" );
unlink("$LIBDIR/famdb/download.working");
die "wget failed to download https://www.dfam.org/releases/Dfam_$df_version/families/FamDB/dfam$c_df_version"."_full.0.h5.gz.\n" .
"Please check your connnectivity and try again.\n";
}
}else {
print "Neither wget nor curl are in this users path. Cannot automatically\n" .
"download the Dfam database.\n\n" .
"Please download a copy of the database ( famdb HDF5 format )\n" .
"from: https://www.dfam.org/releases/Dfam_$df_version/families/FamDB\n" .
"Minimally you may download just the root partition (file ending with \"*.0.h5\"),\n" .
"uncompress it ( gunzip ), and store in $LIBDIR/famdb folder,\n" .
"and rerun the configure program. See\n" .
" https://www.dfam.org/releases/Dfam_$df_version/families/FamDB/README\n" .
"for more details on the taxanomic coverage of each partition.\n\n\n";
}
if ( -s "$LIBDIR/famdb/dfam$c_df_version"."_full.0.h5.gz" ) {
print "Uncompressing Dfam $df_version root partition\n";
defined(my $pid = fork) or die "Couldn't fork: $!";
if (!$pid) { # Child
system("gunzip $LIBDIR/famdb/dfam$c_df_version"."_full.0.h5.gz");
exit;
} else { # Parent
while (! waitpid($pid, WNOHANG)) {
sleep 2;
print ".";
}
}
print "\n";
}else {
die "Failed to download https://www.dfam.org/releases/Dfam_$df_version/families/FamDB/dfam_$c_df_version"."_full.0.h5.gz to the\n" .
"$LIBDIR/famdb folder. Please remove any files from this directory and manually download/uncompress\n" .
"the Dfam FamDB partitions and restart configure.\n";
}
unlink("$LIBDIR/famdb/download.working");
# re-compare current files with previously processed files
( $hasFamDBRoot, $mergeRB, $rebuildRMLib, $gzip, $famdb_prefix ) = compareFiles( $LIBDIR, $rmlibConfig );
}
#print "hasFamDBroot = $hasFamDBRoot\n";
#print "famdb_prefix = $famdb_prefix\n";
#print "mergeRB = $mergeRB\n";
#print "rebuildRMlib = $rebuildRMLib\n";
#print "Dumper: " . Dumper($rmlibConfig) . "\n";
# Installation scenarios
# 1: Both Dfam *and* RepBase RepeatMasker Edition
if ( $mergeRB ) {
#my $dbInfo = `$rmLocation/famdb.py -i $LIBDIR/famdb info`;
#if ( $dbInfo !~ /Database:\s+Dfam\s+withRBRM/ ) {
defined(my $pid = fork) or die "Couldn't fork: $!";
if (!$pid) { # Child
system("$FindBin::RealBin/addRepBase.pl -libdir $LIBDIR");
exit;
} else { # Parent
while (! waitpid($pid, WNOHANG)) {
sleep 2;
print ".";
}
}
print "\n";
if ( -e "$LIBDIR/famdb/merge.working" ) {
die "Merging RepBase failed!";
}
foreach my $partition ( keys( %{$rmlibConfig->{'famdb_files'}} ) ) {
my @stat = stat("$LIBDIR/famdb/$partition");
$rmlibConfig->{'famdb_files'}->{$partition}->{'repbase_merged'} = 1;
$rmlibConfig->{'famdb_files'}->{$partition}->{'size'} = $stat[7];
}
#print "<PRESS ENTER TO CONTINUE - CTRL-C to QUIT>\n";
#$answer = <STDIN>;
#}
# 2: Dfam partioned FamDB only
}else {
print " - Found a FamDB root partition\n\n";
#print "<PRESS ENTER TO CONTINUE>\n";
#$answer = <STDIN>;
}
my $dbInfo = `$rmLocation/famdb.py -i $LIBDIR/famdb info`;
writeConfig($rmlibConfig, "$LIBDIR/famdb/rmlib.config");
if ( ! $options{'trf_prgm'} ) {
print "<PRESS ENTER TO CONTINUE>\n";
$answer = <STDIN>;
RepeatMaskerConfig::promptForParam('TRF_PRGM');
}
##
## Search Engine Configuration
##
if ( ! ( $options{'abblast_dir'} || $options{'rmblast_dir'} || $options{'hmmer_dir'} ||
$options{'crossmatch_dir'} ) ) {
searchEngineMenu();
}else {
# Assumption: if at least one engine is specified on the command line then the intention
# is to not prompt for any engines.
}
if ( $rebuildRMLib ) {
print "Building FASTA version of RepeatMasker.lib ...";
defined(my $pid = fork) or die "Couldn't fork: $!";
if (!$pid) { # Child
# Anthony made a really fast version
system("$rmLocation/famdb.py -i $rmLocation/Libraries/famdb fasta_all > $rmLocation/Libraries/RepeatMasker.lib");
exit;
} else { # Parent
while (! waitpid($pid, WNOHANG)) {
sleep 2;
print ".";
}
}
print "\n";
}
#
# Freeze RMLIB/RepeatPeps library for RepeatModeler use among others
#
if ( RepeatMaskerConfig::validateParam('RMBLAST_DIR') )
{
my $binDir = $config->{'RMBLAST_DIR'}->{'value'};
print "Building RMBlast frozen libraries..\n";
system( "$binDir/makeblastdb -dbtype nucl -in "
. "$LIBDIR/RepeatMasker.lib > /dev/null 2>&1" );
system( "$binDir/makeblastdb -dbtype prot -in "
. "$LIBDIR/RepeatPeps.lib > /dev/null 2>&1" );
}
if ( RepeatMaskerConfig::validateParam('ABBLAST_DIR') )
{
my $binDir = $config->{'ABBLAST_DIR'}->{'value'};
print "Building WUBlast/ABBlast frozen libraries..\n";
system( "$binDir/xdformat -n -I "
. "$LIBDIR/RepeatMasker.lib > /dev/null 2>&1" );
system( "$binDir/xdformat -p -I "
. "$LIBDIR/RepeatPeps.lib > /dev/null 2>&1" );
}
# Save settings
RepeatMaskerConfig::updateConfigFile();
print "The program is installed with a the following repeat libraries:\n";
print "$dbInfo\n";
print "Further documentation on the program may be found here:\n";
print " $rmLocation/repeatmasker.help\n\n";
####################### S U B R O U T I N E S ##############################
sub searchEngineMenu {
my $configFile = shift;
my @searchEngines = (
{
name => "CROSSMATCH_DIR",
desc => "Crossmatch",
defname => "crossmatch",
status => 0,
},
{
name => "RMBLAST_DIR",
desc => "RMBlast",
defname => "rmblast",
status => 0,
},
{
name => "HMMER_DIR",
desc => "HMMER3.1 & DFAM",
defname => "hmmer",
status => 0,
},
{
name => "ABBLAST_DIR",
desc => "ABBlast",
defname => "abblast",
status => 0,
}
);
my $done = 0;
my $defaultEngine = "";
do {
system( "clear" );
print "\n\n\n";
print "Add a Search Engine:\n";
my $i;
for ( $i = 0 ; $i <= $#searchEngines ; $i++ )
{
print " " . ( $i + 1 ) . ". $searchEngines[$i]->{'desc'}: [ ";
if ( $searchEngines[ $i ]->{'status'} == 0 )
{
print "Un-configured ]\n";
} elsif ( $searchEngines[ $i ]->{'status'} == 1 )
{
print "Configured ]\n";
} else
{
print "Configured, Default ]\n";
}
}
print "\n";
print " " . ( $i + 1 ) . ". Done\n";
print "\n\nEnter Selection: ";
$answer = <STDIN>;
$answer =~ s/[\n\r]+//g;
if ( $answer =~ /\d+/ && $answer > 0 && $answer <= ( $#searchEngines + 2 ) )
{
if ( $answer == ( $#searchEngines + 2 ) ) {
if ( $defaultEngine eq "" ) {
print "You must configure at least one search engine!\n";
print "<PRESS ENTER TO CONTINUE - CTRL-C to QUIT>\n";
$answer = <STDIN>;
}
else {
$done = 1;
}
}
else {
RepeatMaskerConfig::promptForParam($searchEngines[$answer-1]->{'name'});
if ( $defaultEngine ne "" ) {
system("clear");
print "\n\n\n";
print "Do you want " . $searchEngines[$answer-1]->{'desc'} . " to be your default\nsearch engine for Repeatmasker? (Y/N) ";
print " [ Y ]: ";
my $isDefault = <STDIN>;
$isDefault =~ s/[\n\r]+//g;
if ( $isDefault =~ /^\s*$/ || $isDefault =~ /\s*[yY]\s*/ )
{
for ( $i = 0 ; $i <= $#searchEngines ; $i++ )
{
$searchEngines[$i]->{'status'} = 1
if ( $searchEngines[$i]->{'status'} == 2 );
}
$searchEngines[ $answer - 1 ]->{'status'} = 2;
$RepeatMaskerConfig::configuration->{'DEFAULT_SEARCH_ENGINE'}->{'value'} = $searchEngines[$answer-1]->{'defname'};
$defaultEngine = $answer;
}else {
$searchEngines[ $answer - 1 ]->{'status'} = 1;
}
}else {
$searchEngines[ $answer - 1 ]->{'status'} = 2;
$defaultEngine = $answer;
}
}
}
else {
print "Invalid selection!\n";
print "<PRESS ENTER TO CONTINUE>\n";
$answer = <STDIN>;
}
} while ( $done == 0 );
}
sub readConfig {
my $fileName = shift;
my $fileContents = "";
my $oldSep = $/;
undef $/;
my $in;
open $in, "$fileName";
$fileContents = <$in>;
$/ = $oldSep;
close $in;
return eval( $fileContents );
}
sub writeConfig {
my $data = shift;
my $fileName = shift;
my $data_dumper = new Data::Dumper( [ $data ] );
$data_dumper->Purity( 1 )->Terse( 1 )->Deepcopy( 1 );
open OUT, ">$fileName";
print OUT $data_dumper->Dump();
close OUT;
}
sub compareFiles {
my $LIBDIR = shift;
my $rmlibConfig = shift;
my $hasFamDBRoot = 0;
my $famdb_prefix = "";
my @famdb_files = ();
my $mergeRB = 0;
my $rebuildRMLib = 0;
my $gzip = 0;
$rmlibConfig->{'files'} = ();
my %seen = ();
opendir DIR, "$LIBDIR/famdb" or die "Could not open $LIBDIR/famdb directory\n";
while ( my $entry = readdir(DIR) ) {
next if ( $entry =~ /^\.+$/ || -d "$LIBDIR/famdb/$entry" );
push @{$rmlibConfig->{'files'}}, $entry;
if ( -s "$LIBDIR/famdb/$entry" && $entry =~ /(\S+)\.(\d+)\.h5$/ ) {
$seen{$entry} = 1;
# FamDB file
if ( $famdb_prefix ne "" && $famdb_prefix ne $1 ) {
die "There appears to be more than one FamDB database in the $LIBDIR/famdb directory: $famdb_prefix and $1\n\n";
}
$famdb_prefix = $1;
if ( $2 eq "0" ) {
$hasFamDBRoot = 1;
}
my @stat = stat("$LIBDIR/famdb/$entry");
if ( exists $rmlibConfig->{'famdb_files'}->{$entry} &&
$rmlibConfig->{'famdb_files'}->{$entry}->{'size'} != $stat[7] ) {
die "There appears to be a problem with the FamDB database. The file $entry has changed size from $rmlibConfig->{'famdb_files'}->{$entry}->{'size'} to $stat[7]. Please remove all files from this directory, download (at a minimum) the root partition of a FamDB database, and re-run configure.\n\n";
} elsif ( exists $rmlibConfig->{'famdb_files'}->{$entry} ) {
if ( $hasRepbase && ! exists $rmlibConfig->{'famdb_files'}->{$entry}->{'repbase_merged'} )
{
$mergeRB = 1;
$rebuildRMLib = 1;
}
}else {
if ( $hasRepbase ) {
$mergeRB = 1
}
$rebuildRMLib = 1;
$rmlibConfig->{'famdb_files'}->{$entry} = {};
$rmlibConfig->{'famdb_files'}->{$entry}->{'size'} = $stat[7];
}
}elsif ( -s "$LIBDIR/famdb/$entry" && $entry =~ /(\S+)\.(\d+)\.h5.gz/ ) {
$gzip = 1;
}
}
# If a partition is deleted make sure we rebuild the RMlib accordingly
foreach my $partition ( keys( %{$rmlibConfig->{'famdb_files'}} ) ) {
if ( ! exists $seen{$partition} ) {
delete $rmlibConfig->{'famdb_files'}->{$partition};
$rebuildRMLib = 1;
}
}
closedir(DIR);
return ( $hasFamDBRoot, $mergeRB, $rebuildRMLib, $gzip, $famdb_prefix );
}
1;