-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateVARNAcolormap.pl
executable file
·246 lines (199 loc) · 7.47 KB
/
createVARNAcolormap.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
#!/usr/bin/env perl
#===============================================================================
#
# FILE: createVARNAcolormap.pl
#
# USAGE: ./createVARNAcolormap.pl
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Christoph Kaempf (CK), kaempf@bioinf.uni-leipzig.de
# ORGANIZATION:
# VERSION: 1.0
# CREATED: 05.08.2012 15:29:50
# REVISION: ---
#===============================================================================
use strict;
use warnings;
use utf8;
use feature "switch";
use Data::Dumper;
use File::Basename;
use Getopt::Long;
use List::Util qw(first max maxstr min minstr reduce shuffle sum);
use Log::Log4perl qw(get_logger :levels);
use Math::BigFloat;
use Pod::Usage;
use Path::Class;
my $module_dir = dirname(__FILE__);
push(@INC, $module_dir);
###############################################################################
#
# Options section
#
################################################################################
my $help = 0;
my $man = 0;
my $off_file = "";
my $rdat_file = "";
my $verbose = 0;
GetOptions(
"help|h" => \$help,
"man|m" => \$man,
"off=s" => \$off_file, # mandatory
"rdat=s" => \$rdat_file, # mandatory
"verbose|v+" => \$verbose # optional
);
if ( $help ) {
pod2usage( -verbose => 1 ) && exit;
} elsif ( $man ) {
pod2usage( -verbose => 2 ) && exit;
} elsif ( $off_file eq "" || $rdat_file eq "" ){
pod2usage( { -verbose => 1,
-message => "Use this script like this:\n"});
}
###############################################################################
#
# Logger initiation
#
###############################################################################
my $log4perl_conf = file(dirname(__FILE__), "RNAprobing.log.conf");
# Apply configuration to the logger
Log::Log4perl->init("$log4perl_conf");
# Get the logger
my $logger_name = "RNAprobing";
my $logger = &configureLogger($verbose, $logger_name);
$logger->info("++++ ".__FILE__." has been started. ++++");
# require RNAprobing classes just after logger initialization
require RNAprobing::RDATFile;
require RNAprobing::OFFFile;
################################################################################
#
# Files to objects
#
################################################################################
# check if input files exist
$rdat_file = &checkFiles($rdat_file);
$off_file = &checkFiles($off_file);
# creation of RDAT file object and information extraction
my $rdat_object = RNAprobing::RDATFile->new();
$rdat_object->read_file($rdat_file);
my $rdat_filename = fileparse($rdat_object->filename());
my $rdat_seq_startpos = $rdat_object->seq_startpos();
#my $rdat_reactivity = $rdat_object->data()->reactivity();
#my $rdat_seqpos_reactivity = $rdat_object->seqpos_reactivity_map();
my @rdat_seq = split(//, $rdat_object->sequence());
my @rdat_seqpos = @{$rdat_object->seqpos()};
# creation of OFF file object and information extraction
my $off_object = RNAprobing::OFFFile->new();
$off_object->read_file($off_file);
###############################################################################
#
# Map the sequences according to the BLAT/BLAST output
#
###############################################################################
my $off_sequence = $off_object->sequence();
my $rdat_sequence = $rdat_object->sequence();
my $rdat_offset = $rdat_object->offset();
my ($start_position, $end_position); # position where both sequences start to be equal
if ($rdat_sequence =~ /$off_sequence/) {
$start_position = $-[0];
$end_position = $start_position + length($off_sequence);
} else {
$logger->error("Can't match sequence in ".$off_object->filename().
" to sequence in ".$rdat_object->filename());
exit(1);
}
foreach my $rdat_index ( @{$rdat_object->data()->indices()} ) {
my $color_map_filename = $rdat_filename."_".$rdat_index.".color_map";
$color_map_filename =~ s/\.rdat//g;
$logger->info("Write Color Map to $color_map_filename.");
open(my $color_map, ">", $color_map_filename) or die "Couldn't open file $color_map_filename. Error: $!";
for (my $i = $start_position; $i <= $end_position; $i++){
print($color_map $rdat_object->data()->seqpos_reactivity_map($rdat_index)->{1+$rdat_offset+$i}."\n");
}
}
###############################################################################
##
## Subroutine section
##
###############################################################################
###############################################################
##
## &configureLogger($verbosityLevel)
## - Configures and initialzes the Logger
## - $verbosityLevel = scalar value that sets log level
## -- 0 => $ERROR
## -- 1 => $WARN
## -- 2 => $INFO
## -- >2 => $DEBUG
##
###############################################################
sub configureLogger{
## Configure the logger ##
my $verbose = shift;
my $logger_name = shift;
my $logger = get_logger($logger_name);
$logger->info("Verbosity level: $verbose");
SELECT:{
if ($verbose == 0){$logger->level($ERROR); $logger->debug("Log level is ERROR") ; last SELECT; }
if ($verbose == 1){ $logger->level($WARN) ; $logger->debug("Log level is WARN") ; last SELECT; }
if ($verbose == 2){ $logger->level($INFO) ; $logger->debug("Log level is INFO") ; last SELECT; }
else { $logger->level($DEBUG); $logger->debug("Log level is DEBUG") ; last SELECT; }
}
return $logger;
}
###############################################################################
##
## &checkFiles(@filesToBeChecked)
## - Performs file checks and returns an array with all succesfully checked files
## - @filesToBeChecked = array of files to be checked
##
###############################################################################
sub checkFiles {
# Check if files are readable
my $testfile = shift;
my $checkedfile = ();
my $logger = get_logger("RNAprobing");
$logger->info("Perform file checks for file $testfile");
if ( -f $testfile){
$logger->info("$testfile is a plain file");
if ( -r $testfile) {
my $abs_path = File::Spec->rel2abs( $testfile );
$logger->info("$testfile can be accessed");
$checkedfile= $abs_path;
$logger->debug("Absolute path: $abs_path");
} else {
$logger->error("Can not access $testfile");
}
} else {
$logger->error("$testfile is not a plain file");
$logger->error("$testfile is a directory") if ( -d $testfile);
}
return $checkedfile;
}
__END__
=head1 NAME
createVARNAcolormap.pl - Creates a file which can be used as a color map for the VARNA RNA visulalization tool.
=head1 SYNOPSIS
createVARNAcolormap.pl --off </path/to/off-file> --rdat </path/to/rdat-file>
=head1 DESCRIPTION
Creates a file which can be used as a color map for the VARNA RNA visulalization tool.
=head1 OPTIONS
=over 8
=item B<-h, --help>
Display help message
=item B<-m, --man>
Display whole man page
=item B<--off>
DBN or OFF file containing the sequence and structure information of a RNA (normally extracted from NDB RNAML files); mandatory
=item B<--rdat>
RDAT file containing the probing information for a RNA (normally downloaded from the RMDB); mandatory
=item B<-v, --verbose>
Increases the verbosity level. Can be used multiple times (verbosest if used 3 or more times)
=back
=cut