Skip to content

Commit 8bd40a5

Browse files
committed
Biostrings 2.79.3: Repair compatible_seqtypes/get_seqtype_conversion_lookup
Repair low-level utilities Biostrings:::compatible_seqtypes() and get_seqtype_conversion_lookup() when at least one of the supplied sequence type is "ModDNA" or "ModRNA". This regression was introduced in previous commit (commit b15bffb, Biostrings 2.79.2) and was breaking the Modstrings package. See #132
1 parent b15bffb commit 8bd40a5

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ biocViews: SequenceMatching, Alignment, Sequencing, Genetics,
77
DataImport, DataRepresentation, Infrastructure
88
URL: https://bioconductor.org/packages/Biostrings
99
BugReports: https://github.com/Bioconductor/Biostrings/issues
10-
Version: 2.79.2
10+
Version: 2.79.3
1111
License: Artistic-2.0
1212
Encoding: UTF-8
1313
Authors@R: c(

R/seqtype.R

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
### -------------------------------------------------------------------------
44
###
55
### Most sequence containers in Biostrings have a "sequence type" that
6-
### indicates the nature of the sequence(s) that the container can store:
6+
### reflects the type of sequences that it represents as well as the
7+
### encoding that is used to store the sequence internally:
78
###
89
### sequence | | |
910
### type | description | alphabet | encoded
@@ -13,8 +14,14 @@
1314
### "RNA" | RNA sequence(s) | RNA_ALPHABET | yes
1415
### "AA" | amino acid sequence(s) | AA_ALPHABET | yes
1516
###
16-
### seqtype() returns that sequence type. For example 'seqtype(AAString())'
17-
### returns "AA".
17+
### The seqtype() function returns the sequence type. For
18+
### example 'seqtype(AAString())' returns "AA".
19+
###
20+
### The ModString package by Felix Ernst introduces two additional sequence
21+
### types, "ModDNA" and "ModRNA", that are treated as sequence type "B" by
22+
### compatible_seqtypes(), get_seqtype_conversion_lookup(), and
23+
### get_seqtype_switches_before_binary_op() below.
24+
###
1825
### Unless specified otherwise, things in this file are not exported.
1926

2027

@@ -96,10 +103,18 @@ xs_dec_lkup <- function(x)
96103
### determine those restrictions.
97104
###
98105

106+
### Note that sequence types "ModDNA" and "ModRNA" are treated as sequence
107+
### type "B" by compatible_seqtypes(), get_seqtype_conversion_lookup(), and
108+
### get_seqtype_switches_before_binary_op() below.
109+
.SUPPORTED_SEQTYPES <- c("B", "DNA", "RNA", "AA", "ModDNA", "ModRNA")
110+
99111
compatible_seqtypes <- function(seqtype1, seqtype2)
100112
{
101-
stopifnot(isSingleString(seqtype1), isSingleString(seqtype2))
102-
if (seqtype1 == seqtype2 || seqtype1 == "B" || seqtype2 == "B")
113+
stopifnot(isSingleString(seqtype1), seqtype1 %in% .SUPPORTED_SEQTYPES,
114+
isSingleString(seqtype2), seqtype2 %in% .SUPPORTED_SEQTYPES)
115+
if (seqtype1 == seqtype2 ||
116+
seqtype1 %in% c("B", "ModDNA", "ModRNA") ||
117+
seqtype2 %in% c("B", "ModDNA", "ModRNA"))
103118
return(TRUE)
104119
is_nucleo1 <- seqtype1 %in% c("DNA", "RNA")
105120
is_nucleo2 <- seqtype2 %in% c("DNA", "RNA")
@@ -112,6 +127,10 @@ get_seqtype_conversion_lookup <- function(from_seqtype, to_seqtype)
112127
if (!compatible_seqtypes(from_seqtype, to_seqtype))
113128
stop("incompatible sequence types \"",
114129
from_seqtype, "\" and \"", to_seqtype, "\"")
130+
if (from_seqtype %in% c("ModDNA", "ModRNA"))
131+
from_seqtype <- "B"
132+
if (to_seqtype %in% c("ModDNA", "ModRNA"))
133+
to_seqtype <- "B"
115134
if (from_seqtype == to_seqtype)
116135
return(NULL)
117136
from_is_nucleo <- from_seqtype %in% c("DNA", "RNA")
@@ -130,7 +149,7 @@ get_seqtype_conversion_lookup <- function(from_seqtype, to_seqtype)
130149
return(AA_STRING_CODEC@enc_lkup)
131150
if (from_seqtype == "AA")
132151
return(AA_STRING_CODEC@dec_lkup)
133-
stop("Biostrings internal error, please report") # should never happen
152+
stop("Biostrings internal error, please report") # should never happen
134153
}
135154

136155
### Returns a character vector of length 2 indicating the 2 target seqtypes
@@ -140,6 +159,10 @@ get_seqtype_conversion_lookup <- function(from_seqtype, to_seqtype)
140159
what_op, class1, class2)
141160
{
142161
stopifnot(isSingleString(seqtype1), isSingleString(seqtype2))
162+
if (seqtype1 %in% c("ModDNA", "ModRNA"))
163+
seqtype1 <- "B"
164+
if (seqtype2 %in% c("ModDNA", "ModRNA"))
165+
seqtype2 <- "B"
143166
if (seqtype1 == seqtype2)
144167
return(c(seqtype1, seqtype2))
145168
if (!compatible_seqtypes(seqtype1, seqtype2))

tests/testthat/test-seqtype.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
test_that("compatible_seqtypes()", {
3+
compatible_seqtypes <- Biostrings:::compatible_seqtypes
4+
SUPPORTED_SEQTYPES <- Biostrings:::.SUPPORTED_SEQTYPES
5+
target <- matrix(TRUE,
6+
nrow=length(SUPPORTED_SEQTYPES),
7+
ncol=length(SUPPORTED_SEQTYPES),
8+
dimnames=list(SUPPORTED_SEQTYPES, SUPPORTED_SEQTYPES))
9+
target[c("DNA", "RNA"), "AA"] <- target["AA", c("DNA", "RNA")] <- FALSE
10+
current <- sapply(SUPPORTED_SEQTYPES,
11+
function(seqtype1) sapply(SUPPORTED_SEQTYPES,
12+
function(seqtype2) compatible_seqtypes(seqtype1, seqtype2))
13+
)
14+
expect_identical(current, target)
15+
})
16+

0 commit comments

Comments
 (0)