Bioconductor / Biostrings

Efficient manipulation of biological strings
https://bioconductor.org/packages/Biostrings
57 stars 16 forks source link

Biostrings::score ? #109

Closed urniaz closed 4 months ago

urniaz commented 4 months ago

Hi,

I am updating my old package and have an error from Biostrings as "Error: object ‘score’ is not exported by 'namespace:Biostrings'".

We used to apply Biostrings::score() function although it is not available now. Could you please advice how to fix it?

Thanks!

Best wishes, Rafal.

vjcitn commented 4 months ago

please provide sessionInnfo() result after error message is produced

urniaz commented 4 months ago

R version 4.4.0 (2024-04-24) Platform: x86_64-apple-darwin20 Running under: macOS Sonoma 14.5

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Warsaw tzcode source: internal

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] compiler_4.4.0 tools_4.4.0

vjcitn commented 4 months ago

report sessionInfo after the error in the same session so we see your version of Biostrings

hpages commented 4 months ago

Short answer:

score() is an S4 generic defined in the BiocGenerics package:

library(Biostrings)
score
# standardGeneric for "score" defined from package "BiocGenerics"
# 
# function (x, ...) 
# standardGeneric("score")
# <bytecode: 0x556d3c6c3240>
# <environment: 0x556d3c6bdbc8>
# Methods may be defined for arguments: x
# Use  showMethods(score)  for currently available ones.

so use BiocGenerics::score() instead of Biostrings::score().

Detailed answer:

There used to be a couple of score() methods defined in Biostrings (prior to 2.72.0), one for PairwiseAlignments objects and one for PairwiseAlignmentsSingleSubjectSummary objects. In the latest version of Biostrings these methods are now defined in the pwalign package.

Many things have moved from Biostrings to pwalign, and, for most of them, there's a redirect mechanism with a warning that lets you know about this move. For example:

library(Biostrings)
pairwiseAlignment("aaXXXXbb", "aaXXyXXbb")
# Global PairwiseAlignmentsSingleSubject (1 of 1)
# pattern: aaXX-XXbb
# subject: aaXXyXXbb
# score: 1.854049 
# Warning message:
# In .call_fun_in_pwalign("pairwiseAlignment", ...) :
#   pairwiseAlignment() has moved to the pwalign package. Please call
#   pwalign::pairwiseAlignment() to get rid of this warning.

The redirect mechanism is easy to implement and works nicely here because pairwiseAlignment() is a regular function. However, for S4 methods these redirects are a little bit more tricky to put in place.

Anyways, note that one should not try to call a specific method directly but should always call the generic function instead. So the right thing to do in your case would be to call BiocGenerics::score() ( (the score() S4 generic is defined in the BiocGenerics package). The generic function will take care of dispatching to the appropriate method.

In the meantime I'll look into implementing a redirect mechanism for the old score() methods in Biostrings to the new ones in pwalign.

urniaz commented 4 months ago

Dear hpages, your solution works fine! Thank you so much ! Best wishes, Rafal.