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
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+
99111compatible_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 ))
0 commit comments