I am trying to work on TEclass from https://academic.oup.com/bioinformatics/article/25/10/1329/269651
When I'm using the TEclassBuild.pl I get an Illegal division by zero error at line 179 message.
Looking at the subroutine that handles that;
#-------------------------------------------------------------------------------
# Purpose : Builds a feature-vector for each sequence. The features are
# oligomer frequencies.
# Usage : process_sequence($string, $number, *filehandle)
# Arguments : sequence (string), prefix (number), output (filehandle)
# Returns : Nothing, prints.
# Globals : Uses the global variables of the build_tetramer_hash (or pentamer)
# subroutines
#*******************
sub process_sequence {
my $sequence = uc($_[0]);
my $prefix = $_[1]; # The the SVM "classifier"
my $OUT = $_[2]; # Filehandle
# The vector of SVM features. Initially every element is zero
my @features;
foreach my $x (0..$oligos) {
$features[$x] = 0;
}
my $iterations = length($sequence)-$mer-1;
# Counts the number of occurences of each x-mer in the sequence
foreach my $x (0..$iterations) {
if ( exists( $x_mers{substr($sequence, $x, $mer)} ) ) {
$features[$x_mers{substr($sequence, $x, $mer)}]++;
$features[$oligos+1]++;
}
}
# Calculates and prints the frequencies for each oligomer
print $OUT $prefix, "\t";
foreach my $x (0..$oligos) {
$features[$x] /= $features[$oligos+1];
print $OUT "", ($x+1), ':', $features[$x], "\t";
}
print $OUT "\n";
}
Line 179 is
176: # Calculates and prints the frequencies for each oligomer
177: print $OUT $prefix, "\t";
178: foreach my $x (0..$oligos) {
179: $features[$x] /= $features[$oligos+1];
180: print $OUT "", ($x+1), ':', $features[$x], "\t";
181:}
Line 179 shows that they add a +1 to the denominator. Wouldn't that mean that I am not dividing the $features[$x] with 0? Any suggestions? I ran it a couple of times with different parameters but still I receive the same error message.
They add +1 to the index of features.
It seems the if statement some 8 lines back is never true.
Thanks for the suggestion. I tried the suggestion below first but if that doesn't work, I'll take a look further into this. Thanks!
Debug the values of the array at different stages of the script. Check that the array is initialized to non-zero values, or that a pseudocount is applied correctly.
Still not sure what's happening. I tried changing
to
Thanks for the tip. The job is now running a bit further. Hopefully this works properly. Thanks
That's not a good idea.
does have a special meaning (summing all occurances). You should find out why it is zero, not replace it with something else.
I tried redoing this and ensuring that @features does not contain any zero values. It still gives me an illegal division by zero error message.