mgledi / DiffLogo

DiffLogo: Comparative visualisation of sequence motifs
http://difflogo.com
8 stars 6 forks source link

Columns of PWM must add up to 1.0 #30

Open laurapspector opened 3 months ago

laurapspector commented 3 months ago

I call getPwmFromFastaFile() to create a pwm from a FASTA file. The pwm has 8 columns. Then I call diffLogoFromPwm() and get the following error:

Error in preconditionPWM(pwm1) : Columns of PWM must add up to 1.0.

However, the sum of the columns is indeed 1 (see below).

> pwm1 <- getPwmFromFastaFile(<fasta_file1>, alphabet=FULL ALPHABET)
> pwm2 <- getPwmFromFastaFile(<fasta_file2>, alphabet=FULL ALPHABET)
> diffLogoFromPwm(pwm1 = pwm1, pwm2 = pwm2)
[1] "pwm must be of class matrix or data.frame. Trying to convert"
[1] "pwm must be of class matrix or data.frame. Trying to convert"
Error in preconditionPWM(pwm1) : Columns of PWM must add up to 1.0
> apply(pwm1, 2, sum)
1 2 3 4 5 6 7 8 
1 1 1 1 1 1 1 1 
> any(abs(1 - apply(pwm1, 2, sum)) > 0.01)
[1] FALSE
zhou-sumei commented 1 week ago

Hi, I encounted the same problem, but I find that conver the pwm to the dataFrame will resolve this problem. first_pwm <- as.data.frame(getPwmFromFastaFile("xxxx")) second_pwm <- as.data.frame(getPwmFromFastaFile("xxxx")) diffLogoFromPwm(first_pwm , second_pwm) it works on me, hope it could help you