-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathRepModelConfig.pm
More file actions
677 lines (648 loc) · 26.6 KB
/
Copy pathRepModelConfig.pm
File metadata and controls
677 lines (648 loc) · 26.6 KB
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
#!/usr/bin/perl
##---------------------------------------------------------------------------##
## File:
## @(#) RepModelConfig.pm
## Author:
## Arian Smit <asmit@systemsbiology.org>
## Robert Hubley <rhubley@systemsbiology.org>
## Description:
## This is the main configuration file for the RepeatModeler
## program suite. Before you can run the programs included
## in this package you will need to run the "./configure" program
## to modify this file or manually edit in an editor.
##
#******************************************************************************
#* Copyright (C) Institute for Systems Biology 2004-2019 Developed by
#* Arian Smit and 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.
#*
###############################################################################
package RepModelConfig;
use FindBin;
use File::Basename;
use Data::Dumper;
require Exporter;
@EXPORT_OK = qw();
%EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
@ISA = qw(Exporter);
my $CLASS = "RepModelConfig";
BEGIN {
##----------------------------------------------------------------------##
## CONFIGURE THE FOLLOWING PARAMETERS FOR YOUR INSTALLATION ##
## ##
## This file may be hand edited or preferably, modified with the ##
## the use of the "configure" script. ##
## ##
## In the following section default values for paths/programs ##
## may be hardcoded. Each parameter appears in a block of text ##
## below as: ##
## ##
## PARAMETER_NAME => { ##
## ... ##
## value => "/usr/local/bin/foo" ##
## } ##
## ##
## only change the "value" field for each parameter. If you are ##
## unsure of how to edit this file, simply use the the ./configure ##
## script provided with the package to perform the same task. For ##
## more details on configuring this package please see the README ##
## file. ##
## ##
## STCFG --do-not-remove--
$configuration = {
'CDHIT_DIR' => {
'command_line_override' => 'cdhit_dir',
'description' => 'The path to the installation of the CD-Hit sequence clustering package.',
'environment_override' => 'CDHIT_DIR',
'expected_binaries' => [
'cd-hit'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 1,
'value' => '/usr/local/cd-hit-4.8.1'
},
'FAMDB_DIR' => {
'command_line_override' => 'famdb_dir',
'description' => 'The path to the installation of the FamDB program (V3.0.0) or higher.',
'environment_override' => 'FAMDB_DIR',
'expected_binaries' => [
'famdb.py'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 1,
'value' => '/usr/local/FamDB-Dfam-4.0_RB'
},
'GENOMETOOLS_DIR' => {
'command_line_override' => 'genometools_dir',
'description' => 'The path to the installation of the GenomeTools package.',
'environment_override' => 'GENOMETOOLS_DIR',
'expected_binaries' => [
'gt'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 0,
'value' => '/usr/local/genometools-1.6.2/bin'
},
'LTR_RETRIEVER_DIR' => {
'command_line_override' => 'ltr_retriever_dir',
'description' => 'The path to the installation of the LTR_Retriever v2.9.0 structural LTR analysis package.',
'environment_override' => 'LTR_RETRIEVER_DIR',
'expected_binaries' => [
'LTR_retriever'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 0,
'value' => '/usr/local/LTR_retriever-2.9.0'
},
'MAFFT_DIR' => {
'command_line_override' => 'mafft_dir',
'description' => 'The path to the installation of the MAFFT multiple alignment program.',
'environment_override' => 'MAFFT_DIR',
'expected_binaries' => [
'mafft'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 0,
'value' => '/usr/local/mafft/bin'
},
'NINJA_DIR' => {
'command_line_override' => 'ninja_dir',
'description' => 'The path to the installation of the Ninja phylogenetic analysis package.',
'environment_override' => 'NINJA_DIR',
'expected_binaries' => [
'Ninja'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 0,
'value' => '/usr/local/Ninja-0.98-cluster_only'
},
'RECON_DIR' => {
'command_line_override' => 'recon_dir',
'description' => 'The path to the installation of the RECON de-novo repeatfinding program.',
'environment_override' => 'RECON_DIR',
'expected_binaries' => [
'eledef',
'eleredef'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 1,
'value' => '/usr/local/RECON'
},
'REPEATAFTERME_DIR' => {
'command_line_override' => 'repeatafterme_dir',
'description' => 'The path to the installation of the RepeatAfterMe ( 0.0.7 or higher ) extension program.',
'environment_override' => 'REPEATAFTERME_DIR',
'expected_binaries' => [
'RAMExtend'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 1,
'value' => '/usr/local/RepeatAfterMe'
},
'REPEATMASKER_DIR' => {
'command_line_override' => 'repeatmasker_dir',
'description' => 'The path to the installation of RepeatMasker (4.2.4 or higher).',
'environment_override' => 'REPEATMASKER_DIR',
'expected_binaries' => [
'RepeatMasker'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 1,
'value' => '/usr/local/RepeatMasker-4.2.4-Dfam-4.0_RB'
},
'RMBLAST_DIR' => {
'command_line_override' => 'rmblast_dir',
'description' => 'The path to the installation of RMBlast (2.17.1 or higher).',
'environment_override' => 'RMBLAST_DIR',
'expected_binaries' => [
'rmblastn',
'dustmasker',
'makeblastdb',
'blastdbcmd',
'blastdb_aliastool',
'blastn'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 1,
'value' => '/usr/local/rmblast/bin'
},
'RSCOUT_DIR' => {
'command_line_override' => 'rscout_dir',
'description' => 'The path to the installation of the RepeatScout ( 1.0.7 or higher ) de-novo repeatfinding program.',
'environment_override' => 'RSCOUT_DIR',
'expected_binaries' => [
'RepeatScout',
'build_lmer_table'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 1,
'value' => '/home/rhubley/projects/RepeatScout-1.0.7'
},
'TRF_DIR' => {
'command_line_override' => 'trf_dir',
'description' => 'The full path to TRF program. TRF must be named "trf". ( 4.0.9 or higher )',
'environment_override' => 'TRF_DIR',
'expected_binaries' => [
'trf'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 1,
'value' => '/usr/local/bin'
},
'UCSCTOOLS_DIR' => {
'command_line_override' => 'ucsctools_dir',
'description' => 'The path to the installation directory of the UCSC TwoBit Tools (twoBitToFa, faToTwoBit, twoBitInfo etc).',
'environment_override' => 'UCSCTOOLS_PRGM',
'expected_binaries' => [
'twoBitToFa',
'faToTwoBit',
'twoBitInfo'
],
'expected_files' => [],
'param_type' => 'directory',
'required' => 1,
'value' => '/usr/local/ucscTools'
}
};
## EDCFG --do-not-remove--
## ##
## END CONFIGURATION AREA ##
##----------------------------------------------------------------------##
##----------------------------------------------------------------------##
## Do not edit below this line ##
##----------------------------------------------------------------------##
#
# Current version of the software
#
$VERSION = "2.0.9";
#
# Set this flag to default to debug mode for the entire package
#
$DEBUGALL = 0;
#
# Prompt for a specific parameter and update the object
#
sub promptForParam {
my $param = shift;
my $screenHdr = shift;
if ( !exists $configuration->{$param} ) {
return;
}
# Grab defaults
my $defaultValue;
if ( $configuration->{$param}->{'param_type'} eq "directory" ) {
if ( exists $configuration->{$param}->{'expected_binaries'}
&& @{ $configuration->{$param}->{'expected_binaries'} } )
{
my $binary = $configuration->{$param}->{'expected_binaries'}->[ 0 ];
$defaultValue = `/usr/bin/which $binary`;
if ( $defaultValue !~ /\/usr\/bin\/which:/ ) {
$defaultValue =~ s/[\n\r\s]+//g;
$defaultValue =~ s/^(.*)\/$binary/$1/;
}
else {
$defaultValue = "";
}
}
if ( $defaultValue eq ""
&& exists $configuration->{$param}->{'value'}
&& -d $configuration->{$param}->{'value'} )
{
$defaultValue = $configuration->{$param}->{'value'};
}
}
elsif ( $configuration->{$param}->{'param_type'} eq "program" ) {
# The program type is used in cases where a single
# script/binary is referenced and may not have the
# exact name we expect. TRF is a good example of this
# as the binary is often distributed with names like:
# trf409.linux64 etc..
if ( exists $configuration->{$param}->{'value'} ) {
my ( $binary, $dirs, $suffix ) =
fileparse( $configuration->{$param}->{'value'} );
$defaultValue = `/usr/bin/which $binary`;
if ( $defaultValue !~ /\/usr\/bin\/which:/ ) {
$defaultValue =~ s/[\n\r\s]+//g;
}
else {
$defaultValue = $configuration->{$param}->{'value'};
}
}
}
my $value = "";
my $validParam;
do {
$validParam = 1;
system( "clear" );
if ( $screenHdr ) {
print "$screenHdr\n";
}
else {
print "\n\n\n\n";
}
print "" . $configuration->{$param}->{'description'} . "\n";
# Prompt and get the value
if ( $defaultValue ) {
print "$param [$defaultValue]: ";
}
else {
print "$param: ";
}
$value = <STDIN>;
$value =~ s/[\n\r]+//g;
if ( $value eq "" && $defaultValue ) {
$value = $defaultValue;
}
if ( $configuration->{$param}->{'param_type'} eq "directory" ) {
if ( -d $value ) {
foreach my $file (
@{ $configuration->{$param}->{'expected_files'} // [] } )
{
if ( !-s "$value/$file" ) {
print "\nCould not find the required file \"$file\" inside\n"
. "the directory \"$value\"!\n\n";
$validParam = 0;
last;
}
}
foreach my $binary (
@{ $configuration->{$param}->{'expected_binaries'} // [] } )
{
if ( !-x "$value/$binary" ) {
print "\nCould not find the required program \"$binary\" inside\n"
. "the directory \"$value\"!\n\n";
$validParam = 0;
last;
}
elsif ( -d "$value/$binary" ) {
print "\nCould not find the required program \"$binary\" inside\n"
. "the directory \"$value\"! It appears to be the name of a\n"
. "subdirectory.\n\n";
$validParam = 0;
last;
}
}
}
else {
print "\nCould not find the \"$value\" directory.\n\n";
$validParam = 0;
}
}
elsif ( $configuration->{$param}->{'param_type'} eq "program" ) {
if ( !-x $value ) {
print "\nThe program \"$value\" doesn't appear to exist\n"
. "or it's not executable!\n\n";
$validParam = 0;
}
elsif ( -d $value ) {
print "\nThe value \"$value\" appears to be a directory rather\n"
. "than an executable binary or script!\n\n";
$validParam = 0;
}
}
if ( $validParam == 0 ) {
print "<PRESS ENTER TO CONTINUE, CTRL-C TO BREAK>\n";
<STDIN>;
}
} while ( $validParam == 0 );
$configuration->{$param}->{'value'} = $value;
#my $version = &getDependencyVersion($param);
#if ( $version ) {
# $configuration->{$param}->{'version'} = $version;
#}
}
#
# Validate parameter
#
sub validateParam {
my $param = shift;
my $new_setting = shift;
if ( !exists $configuration->{$param} ) {
return 0;
}
my $value = $configuration->{$param}->{'value'};
$value = $new_setting if ( defined $new_setting );
# Always assume the "good" in parameters...
my $validParam = 1;
if ( $configuration->{$param}->{'param_type'} eq "directory" ) {
if ( -d $value ) {
foreach my $file (
@{ $configuration->{$param}->{'expected_files'} // [] } )
{
if ( !-s "$value/$file" ) {
$validParam = 0;
last;
}
}
foreach my $binary (
@{ $configuration->{$param}->{'expected_binaries'} // [] } )
{
if ( !-x "$value/$binary" ) {
$validParam = 0;
last;
}
elsif ( -d "$value/$binary" ) {
$validParam = 0;
last;
}
}
}
else {
$validParam = 0;
}
}
elsif ( $configuration->{$param}->{'param_type'} eq "program" ) {
if ( !-x $value ) {
$validParam = 0;
}
elsif ( -d $value ) {
$validParam = 0;
}
}
# TODO Validate versions
#if ( $validParam ) {
# my $version = &getDependencyVersion($param);
# if ( $version ) {
# $configuration->{$param}->{'version'} = $version;
# }
#}
return $validParam;
}
#
# Update this file ( beware: self modifying code ) new
# paramter settings.
#
sub updateConfigFile {
open IN, "<$CLASS.pm" or die;
open OUT, ">new-$CLASS.pm" or die;
my $inCfg;
$Data::Dumper::Sortkeys = 1;
while ( <IN> ) {
if ( /##\s+STCFG/ ) {
$inCfg = 1;
print OUT;
my $cStr = Dumper( $configuration );
$cStr =~ s/\$VAR1/ \$configuration/;
print OUT "$cStr\n";
}
elsif ( /##\s+EDCFG/ ) {
$inCfg = 0;
print OUT;
}
elsif ( !$inCfg ) {
print OUT;
}
}
close IN;
close OUT;
rename( "$CLASS.pm", "$CLASS.pm.bak" );
rename( "new-$CLASS.pm", "$CLASS.pm" );
}
#
# Create a GetOpt list for the command-line parameters defined
# in this configuration file. These may be appended to a program's
# existing GetOpt parameter as:
#
# push @getopt_args, RepModelConfig::getCommandLineOptions();
#
sub getCommandLineOptions {
my @options = ();
foreach my $param ( keys %$configuration ) {
if ( exists $configuration->{$param}->{'command_line_override'} ) {
push @options,
"-" . $configuration->{$param}->{'command_line_override'} . "=s";
}
}
return @options;
}
#
# Get POD documentation to add to the existing program POD stored in
# the main script.
#
sub getPOD {
my $pod_str;
foreach my $param ( keys %$configuration ) {
if ( exists $configuration->{$param}->{'command_line_override'} ) {
$pod_str .= "=item -"
. $configuration->{$param}->{'command_line_override'}
. " <string>\n\n";
$pod_str .= $configuration->{$param}->{'description'} . "\n\n";
}
}
if ( $pod_str ) {
return ( "\n=over 4\n\n" . $pod_str . "=back\n\n" );
}
return;
}
#
# After GetOpt has filled in the options hash simply pass it to
# this function to perform resolution. The following precedence
# is used:
#
# 1. Command Line Parameter
# 2. Environment Variable
# 3. Configuration File
#
# This will update the configuration{param}->{'value'} for use
# in the main program.
#
sub resolveConfiguration {
my $options = shift;
foreach my $param ( keys %$configuration ) {
if (
exists $options->{ $configuration->{$param}->{'command_line_override'} }
)
{
$configuration->{$param}->{'value'} =
$options->{ $configuration->{$param}->{'command_line_override'} };
}
elsif (
exists $ENV{ $configuration->{$param}->{'environment_override'} } )
{
$configuration->{$param}->{'value'} =
$ENV{ $configuration->{$param}->{'environment_override'} };
}
}
}
sub getDependencyVersion {
my $param = shift;
if ( !exists $configuration->{$param} ) {
die "Unknown parameter \"$param\"\n";
}
my $value = $configuration->{$param}->{'value'};
my $version = "";
my $tmpStr = "";
if ( $param eq "RSCOUT_DIR" ) {
# Simple case where the program reports it's version in it's usage details
#./RepeatScout -blah
#RepeatScout Version 1.0.6
#
#Usage:
#RepeatScout -sequence <seq> -output <out> -freq <freq> -l <l> [opts]
# -L # size of region to extend left or right (10000)
# -match # reward for a match (+1)
# -mismatch # penalty for a mismatch (-1)
#...
$tmpStr = `$value/RepeatScout -blah 2>&1`;
$tmpStr =~ /Version\s*(\d+\.\d+\.\d+)/;
$version = $1;
}elsif ( $param eq "RMBLAST_DIR" ) {
#./rmblastn -version
#rmblastn: 2.9.0+
# Package: blast 2.9.0, build Sep 9 2019 15:21:42
$tmpStr = `$value/rmblastn -version`;
$tmpStr =~ /rmblastn:\s+(\d+\.\d+\.\d+\+?)/;
$version = $1;
}elsif ( $param eq "RECON_DIR" ) {
# More complex. The version is only printed in a
# text file that may or may not have been installed by
# the user.
# 00README:
# Version 1.08 (Jan 2014)
if ( -e "$value/00README" ) {
open IN,"<$value/00README" or die;
while (<IN>){
if (/Version\s+(\d+\.\d+)/ )
{
$version = $1;
last;
}
}
close IN;
}else {
$tmpStr = `$value/eledef -v 2>&1`;
$tmpStr =~ /RECON version\s+(\d\S+)/;
$version = $1;
}
}elsif ( $param eq "TRF_DIR" ) {
# trf -V
# Tandem Repeats Finder, Version 4.09
# Copyright (C) Dr. Gary Benson 1999-2012. All rights reserved.
$tmpStr = `$value/trf -V 2>&1`;
$tmpStr =~ /Version\s+(\d+\.\d+)/;
$version = $1;
}elsif ( $param eq "UCSCTOOLS_DIR" ) {
# Currently Jim doesn't provide an option get a version. Need to
# sneakily pull it out of the binaries strings.
$tmpStr = `strings $value/twoBitInfo | grep "kent source version"`;
$version = "unknown";
$version = $1 if ( $tmpStr =~ /kent source version\s+(\d+)/ );
}elsif ( $param eq "CDHIT_DIR" ) {
#cd-hit -blah
# ====== CD-HIT version 4.8.1 (built on Mar 21 2019) ======
$tmpStr = `$value/cd-hit -blah 2>&1`;
$tmpStr =~ /CD-HIT version\s+(\d+\.\d+\.\d+)/;
$version = $1;
}elsif ( $param eq "GENOMETOOLS_DIR" ) {
#gt -version
#/home/rhubley/src/genometools-1.5.9/bin/gt (GenomeTools) 1.5.9
#Copyright (c) 2003-2016 G. Gremme, S. Steinbiss, S. Kurtz, and CONTRIBUTORS
#Copyright (c) 2003-2016 Center for Bioinformatics, University of Hamburg
#See LICENSE file or http://genometools.org/license.html for license details.
#
#Used compiler: cc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36.0.1)
#Compile flags: -g -Wall -Wunused-parameter -pipe -fPIC -Wpointer-arith -Wno-unknown-pragmas -O3 -Werror
$tmpStr = `$value/gt -version 2>&1`;
$tmpStr =~ /\(GenomeTools\)\s+(\d+\.\d+\.\d+)/;
$version = $1;
}elsif ( $param eq "LTR_RETRIEVER_DIR" ) {
# More complex. Older versions only printed the version in the
# output. This is fragile...but we are going to try and pull it
# out of the script:
open IN,"<$value/LTR_retriever" or die;
while (<IN>){
if (/^my\s+\$version\s*=\s*\"(\S+)\";/)
{
$version = $1;
last;
}
}
close IN;
}elsif ( $param eq "MAFFT_DIR" ) {
#mafft -blah
#------------------------------------------------------------------------------
# MAFFT v7.407 (2018/Jul/23)
# https://mafft.cbrc.jp/alignment/software/
# MBE 30:772-780 (2013), NAR 30:3059-3066 (2002)
#------------------------------------------------------------------------------
$tmpStr = `$value/mafft -blah 2>&1`;
$tmpStr =~ /MAFFT\s+v(\d+\.\d+)/;
$version = $1;
}elsif ( $param eq "NINJA_DIR" ) {
#Ninja -v
#Version 0.97-cluster_only
$tmpStr = `$value/Ninja -v 2>&1`;
$tmpStr =~ /Version\s+(\d+\.\d+\S+)/;
$version = $1;
}elsif ( $param eq "REPEATMASKER_DIR" ) {
#RepeatMasker -v
#RepeatMasker version 4.1.0
$tmpStr = `$value/RepeatMasker -v 2>&1`;
$tmpStr =~ /version\s+(\d+\.\d+\.\d+)/;
$version = $1;
}elsif ( $param eq "REPEATAFTERME_DIR" ) {
#ExtendAlign -h
#ExtendAlign Version 0.0.4 - build 436 date 20201118
$tmpStr = `$value/RAMExtend -h 2>&1`;
$tmpStr =~ /Version\s+(\d+\.\d+\.\d+)/;
$version = $1;
}
return $version;
}
}
1;