forked from mattmattmattmatt/DeepSNVMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure_deepseq.pl
executable file
·145 lines (107 loc) · 3.3 KB
/
configure_deepseq.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
#! /usr/bin/perl -w
use strict;
use FindBin;
use lib "$FindBin::Bin";
use modules::Deepseq;
use modules::Exception;
use modules::SystemCall;
use Data::Dumper;
use File::Basename;
use Cwd 'abs_path';
use Pod::Usage;
use Getopt::Long;
use vars qw(%OPT);
GetOptions(\%OPT,
"help|h",
"man|m",
"conf_file=s",
"test",
"force"
);
pod2usage(-verbose => 2) if $OPT{man};
pod2usage(1) if ($OPT{help});
=pod
=head1 SYNOPSIS
configure_deepseq.pl -test generate_test_conf -conf_file generate_specific conf_file -force force_overwrite_conf
Required flags: NONE
=head1 OPTIONS
-help brief help message
-man full documentation
=head1 NAME
configure_deepseq.pl -> Wrapper script for configure deepseq run
=head1 DESCRIPTION
date
a script that creates deepseq.conf containing path info
=head1 AUTHOR
Matthew Field
=head1 EXAMPLE
sample -f file
=cut
my (undef,$base) = fileparse(abs_path($0));
my $conf_file;
if ($OPT{test}) {
$conf_file = defined $OPT{conf_file}?$OPT{conf_file}:$base.'/deepseq_test.conf';
} else {
$conf_file = defined $OPT{conf_file}?$OPT{conf_file}:$base.'/deepseq.conf';
}
if (-e $conf_file && !$OPT{force}) {
modules::Exception->throw("Conf file $conf_file already exists, please remove this file or run with the flag '-force'");
}
#Set the path variable and generate a conf file
print "What is the path to samtools [default=/usr/bin/samtools]?";
my $samtools = <STDIN>;
chomp $samtools;
if ( !-e $samtools && -e '/usr/bin/samtools' ) {
print "Using system samtools: /usr/bin/samtools\n";
$samtools = '/usr/bin/samtools';
} elsif (!-e $samtools) {
modules::Exception->throw("Samtools $samtools doesn't exist");
}
print "What is the path to bwa [default=/usr/bin/bwa]?";
my $bwa = <STDIN>;
chomp $bwa;
if ( !-e $bwa && -e '/usr/bin/bwa' ) {
print "Using system bwa: /usr/bin/bwa\n";
$bwa = '/usr/bin/bwa';
} elsif (!-e $bwa) {
modules::Exception->throw("Bwa $bwa doesn't exist");
}
my $sys_call = modules::SystemCall->new();
my $ref_fasta_abs;
if ($OPT{test}) {
$ref_fasta_abs = abs_path('./sample/ref.fa');
} else {
print "What is the path to single reference fasta file?";
my $ref_fasta = <STDIN>;
chomp $ref_fasta;
if ( !-e $ref_fasta ) {
modules::Exception->throw("Ref fasta file $ref_fasta doesn't exist");
}
$ref_fasta_abs = abs_path($ref_fasta);
}
#Check the bwa index is present....
my $bwa_index_file = $ref_fasta_abs . '.sa';
if (!-e $bwa_index_file) {
#Sometimes it ref.fa.sa but sometimes it's ref.sa so check both
print "Can't find the index file $bwa_index_file\n" unless $OPT{test};
($bwa_index_file = $ref_fasta_abs) =~ s/\.fa$/\.sa/;
if (!-e $bwa_index_file) {
print "Can't find index file $bwa_index_file\n" unless $OPT{test};
print "Can't find any bwa index files, so we will create it. This may take a while..." unless $OPT{test};
my $bwa_index_command = join(" ",
$bwa,
'index -a bwtsw',
$ref_fasta_abs
);
$sys_call->run($bwa_index_command);
$bwa_index_file = $ref_fasta_abs;
}
}
#bwa only requires the file prefix name
$bwa_index_file =~ s/\.sa$//;
open(CONF,">$conf_file") || modules::Exception->throw("Can't open xml file $conf_file for writing\n");
print CONF "bwa=$bwa\n";
print CONF "samtools=$samtools\n";
print CONF "ref_fasta=$ref_fasta_abs\n";
print CONF "bwa_index=$bwa_index_file\n";
close CONF;