Commit b674c087 authored by Eric Coissac's avatar Eric Coissac

Add the detection of mutation between sequences

parent 579eda85
......@@ -23,15 +23,17 @@ RdMacros: Rdpack
Suggests: vegan,
roxygen2,
knitr,
rmarkdown
rmarkdown,
doParallel
Collate:
'ROBITools2.R'
'basic_plots.R'
'color.R'
'utils.R'
'robiobject.R'
'robidata.R'
'robiatomic.R'
'alignment.R'
'basic_plots.R'
'color.R'
'robidata.R'
'robitaxid.R'
'robitag.R'
'robiuniqueid.R'
......@@ -57,6 +59,7 @@ Collate:
'read_obitab.R'
'robimetabar_stat.R'
'robimetabar_xlsx.R'
'robimutation.R'
'robiseq_db.R'
'tagjump.R'
'tags_categories.R'
......
......@@ -15,6 +15,7 @@ S3method(as_robidata,robidata)
S3method(as_robilca,default)
S3method(as_robimotu,default)
S3method(as_robimotu,robimotu)
S3method(as_robimutation,default)
S3method(as_robiobject,default)
S3method(as_robiobject,robiobject)
S3method(as_robipath,default)
......@@ -44,6 +45,7 @@ S3method(dimnames,robimetabar)
S3method(ecofind,robitaxonomy)
S3method(ecotag_best_identity,robimetabar)
S3method(ecotag_best_identity,robimotu)
S3method(format,robimutation)
S3method(format,robitaxid)
S3method(forward_tags,default)
S3method(forward_tags,robimetabar)
......@@ -79,6 +81,7 @@ S3method(nmotus,robimetabar)
S3method(nodes,robitaxonomy)
S3method(nsamples,robimetabar)
S3method(pillar_shaft,robicategory)
S3method(pillar_shaft,robimutation)
S3method(pillar_shaft,robitag)
S3method(pillar_shaft,robitaxid)
S3method(pillar_shaft,robiuniqueid)
......@@ -140,11 +143,13 @@ S3method(type_sum,robitag_forward)
S3method(type_sum,robitag_reverse)
S3method(type_sum,robiuniqueid)
S3method(validate_object,default)
S3method(validate_object,robi4mer)
S3method(validate_object,robiatomic)
S3method(validate_object,robicategory)
S3method(validate_object,robidata)
S3method(validate_object,robimetabar)
S3method(validate_object,robimotu)
S3method(validate_object,robimutation)
S3method(validate_object,robisample)
S3method(validate_object,robitag)
S3method(validate_object,robitaxid)
......@@ -152,6 +157,7 @@ S3method(validate_object,robiuniqueid)
S3method(validate_robitaxonomy,robitaxonomy)
S3method(vec_cast.character,robicategory)
S3method(vec_cast.character,robilca)
S3method(vec_cast.character,robimutation)
S3method(vec_cast.character,robipath)
S3method(vec_cast.character,robitag)
S3method(vec_cast.character,robitag_forward)
......@@ -161,15 +167,18 @@ S3method(vec_cast.character,robitaxid_master)
S3method(vec_cast.character,robiuniqueid)
S3method(vec_cast.double,robicategory)
S3method(vec_cast.double,robilca)
S3method(vec_cast.double,robimutation)
S3method(vec_cast.double,robipath)
S3method(vec_cast.double,robitaxid)
S3method(vec_cast.double,robitaxid_master)
S3method(vec_cast.factor,robicategory)
S3method(vec_cast.integer,robicategory)
S3method(vec_cast.integer,robilca)
S3method(vec_cast.integer,robimutation)
S3method(vec_cast.integer,robipath)
S3method(vec_cast.integer,robitaxid)
S3method(vec_cast.integer,robitaxid_master)
S3method(vec_cast.logical,robimutation)
S3method(vec_cast.robicategory,character)
S3method(vec_cast.robicategory,default)
S3method(vec_cast.robicategory,factor)
......@@ -180,6 +189,10 @@ S3method(vec_cast.robilca,double)
S3method(vec_cast.robilca,integer)
S3method(vec_cast.robilca,robilca)
S3method(vec_cast.robilca,robitaxid)
S3method(vec_cast.robimutation,default)
S3method(vec_cast.robimutation,double)
S3method(vec_cast.robimutation,integer)
S3method(vec_cast.robimutation,robimutation)
S3method(vec_cast.robipath,character)
S3method(vec_cast.robipath,default)
S3method(vec_cast.robipath,double)
......@@ -223,12 +236,14 @@ S3method(vec_ptype2.character,robitag_reverse)
S3method(vec_ptype2.character,robiuniqueid)
S3method(vec_ptype2.double,robicategory)
S3method(vec_ptype2.double,robilca)
S3method(vec_ptype2.double,robimutation)
S3method(vec_ptype2.double,robipath)
S3method(vec_ptype2.double,robitaxid)
S3method(vec_ptype2.double,robitaxid_master)
S3method(vec_ptype2.factor,robicategory)
S3method(vec_ptype2.integer,robicategory)
S3method(vec_ptype2.integer,robilca)
S3method(vec_ptype2.integer,robimutation)
S3method(vec_ptype2.integer,robipath)
S3method(vec_ptype2.integer,robitaxid)
S3method(vec_ptype2.integer,robitaxid_master)
......@@ -243,6 +258,10 @@ S3method(vec_ptype2.robilca,double)
S3method(vec_ptype2.robilca,integer)
S3method(vec_ptype2.robilca,robilca)
S3method(vec_ptype2.robilca,robitaxid)
S3method(vec_ptype2.robimutation,default)
S3method(vec_ptype2.robimutation,double)
S3method(vec_ptype2.robimutation,integer)
S3method(vec_ptype2.robimutation,robimutation)
S3method(vec_ptype2.robipath,default)
S3method(vec_ptype2.robipath,double)
S3method(vec_ptype2.robipath,integer)
......@@ -278,6 +297,7 @@ S3method(vec_ptype2.robiuniqueid,default)
S3method(vec_ptype2.robiuniqueid,robiuniqueid)
S3method(vec_ptype_abbr,robicategory)
S3method(vec_ptype_abbr,robilca)
S3method(vec_ptype_abbr,robimutation)
S3method(vec_ptype_abbr,robipath)
S3method(vec_ptype_abbr,robitag)
S3method(vec_ptype_abbr,robitag_forward)
......@@ -285,8 +305,6 @@ S3method(vec_ptype_abbr,robitag_reverse)
S3method(vec_ptype_abbr,robitaxid)
S3method(vec_ptype_abbr,robitaxid_master)
S3method(vec_ptype_abbr,robiuniqueid)
S3method(write.xlsx,default)
S3method(write.xlsx,robimetabar)
export("levels <- .robicategory")
export("motus<-")
export("samples<-")
......@@ -295,12 +313,14 @@ export(H_q)
export(alternative_names)
export(alternative_taxids)
export(as.robimetabar.robiseq_db)
export(as_robi4mer)
export(as_robiatomic)
export(as_robicategory)
export(as_robidata)
export(as_robilca)
export(as_robimetabar)
export(as_robimotu)
export(as_robimutation)
export(as_robiobject)
export(as_robipath)
export(as_robisample)
......@@ -348,13 +368,16 @@ export(hist_tag_jumps)
export(ids)
export(ids_colname)
export(int2nuc)
export(is_dist_1_or_0)
export(is_full_taxonomy)
export(is_robi4mer)
export(is_robi_verbose)
export(is_robiatomic)
export(is_robicategory)
export(is_robidata)
export(is_robimetabar)
export(is_robimotu)
export(is_robimutation)
export(is_robiobject)
export(is_robisample)
export(is_robitag)
......@@ -377,12 +400,16 @@ export(motus_read_count)
export(motus_sample_count)
export(motus_sample_max)
export(motus_sample_min)
export(mutated_site)
export(mutation_position)
export(new_robi4mer)
export(new_robiatomic)
export(new_robicategory)
export(new_robidata)
export(new_robilca)
export(new_robimetabar)
export(new_robimotu)
export(new_robimutation)
export(new_robiobject)
export(new_robipath)
export(new_robisample)
......@@ -397,6 +424,7 @@ export(nmotus)
export(nodes)
export(nsamples)
export(nuc2int)
export(origin_site)
export(parent.robitaxonomy)
export(plot_read_x_hill)
export(plot_read_x_pcr_tags)
......@@ -418,6 +446,7 @@ export(reverse_tags_colname)
export(right_parse_sample_ids)
export(rkmer)
export(rnuc)
export(robi4mer)
export(robiassert)
export(robiassert_arg)
export(robiatomic)
......@@ -427,6 +456,7 @@ export(robidata)
export(robilca)
export(robimetabar)
export(robimotu)
export(robimutation)
export(robipath)
export(robisample)
export(robitag)
......@@ -453,6 +483,7 @@ export(set_sample.data.frame)
export(set_samples)
export(species)
export(spread_names.robitaxonomy)
export(substitution)
export(superkingdom)
export(tagjump)
export(tags)
......@@ -470,6 +501,7 @@ export(validate_object)
export(validate_robitaxonomy)
export(vec_cast.robicategory)
export(vec_cast.robilca)
export(vec_cast.robimutation)
export(vec_cast.robipath)
export(vec_cast.robitag)
export(vec_cast.robitag_forward)
......@@ -479,6 +511,7 @@ export(vec_cast.robitaxid_master)
export(vec_cast.robiuniqueid)
export(vec_ptype2.robicategory)
export(vec_ptype2.robilca)
export(vec_ptype2.robimutation)
export(vec_ptype2.robipath)
export(vec_ptype2.robitag)
export(vec_ptype2.robitag_forward)
......@@ -486,7 +519,6 @@ export(vec_ptype2.robitag_reverse)
export(vec_ptype2.robitaxid)
export(vec_ptype2.robitaxid_master)
export(vec_ptype2.robiuniqueid)
export(write.xlsx)
export(write_robitaxonomy)
import(R6)
import(doParallel)
......@@ -501,7 +533,6 @@ import(tidyr)
import(utils)
import(vctrs)
import(vegan)
import(xlsx)
importFrom(Rdpack,reprompt)
importFrom(glue,glue)
importFrom(pillar,pillar_shaft)
......
#' @import vctrs
#' @import rlang
#' @include robiatomic.R
#'
NULL
#' Test if an object belongs \code{robimutation} class
#'
#' @param object the object to test
#' @return a \code{logical} value
#'
#' @examples
#' x <- as_robimutation(256)
#' is_robimutation(x)
#' is_robimutation("toto")
#'
#' @author Eric Coissac <eric.coissac@metabarcoding.org>
#' @export
is_robimutation = function(object) {
inherits(object,'robimutation')
}
#' @rdname validate_object
#' @export
validate_object.robimutation <- function(object) {
if (any(!are_na(object) & object < 0)) {
bad = unique(object[!is.na(object) && object < 1])
stop(ngettext(length(bad),
sprintf("The mutation %d is negative or null",
bad[1]),
sprintf("The mutation (%s) are negative or null",
paste(bad,collapse = ","))))
}
object
}
#' Constructs a new \code{robimutation} instance.
#'
#' @param object an integer vector
#' @param ... Passed on to \code{\link[base]{structure}}()
#' @param class Subclasses to assign to the new object, default: none
#'
#' @examples
#' new_robimutation(1:10)
#'
#' @author Eric Coissac <eric.coissac@metabarcoding.org>
#' @export
new_robimutation <- function(object,
...,
verbose = is_robi_verbose(),
class = character()) {
object <- vec_cast(object,integer())
validate_object(
new_robiatomic(object,
...,
class = c(class, "robimutation")
)
)
}
#' Build a \code{robimutation} instance
#'
#' a \code{robimutation} is an integer vector that is for storing numerical taxonomic
#' identifiers. They are normally used to store NCBI taxids. They have to be positive
#' and not null.
#'
#' @param x an object coercible to an \code{integer}
#' @param verbose if `TRUE` warnings are emitted if the constructor takes
#' some decision because of missing values and estimates
#' default values these missing data.
#'
#' @return a \code{robimutation} instance
#'
#' @examples
#'
#' robimutation(1:10)
#'
#' @author Eric Coissac <eric.coissac@metabarcoding.org>
#' @export
robimutation <- function(x = 0) {
new_robimutation(rep(NA,x))
}
#' @export
vec_ptype2.robimutation <- function(x, y, ...) {
UseMethod("vec_ptype2.robimutation", y)
}
#' @method vec_ptype2.robimutation default
#' @export
vec_ptype2.robimutation.default <- function(x, y, ..., x_arg = "x", y_arg = "y") {
vec_default_ptype2(x, y, x_arg = x_arg, y_arg = y_arg)
}
#' @method vec_ptype2.robimutation robimutation
#' @export
vec_ptype2.robimutation.robimutation <- function(x, y, ...) robimutation()
#' @method vec_ptype2.robimutation integer
#' @export
vec_ptype2.robimutation.integer <- function(x, y, ...) integer()
#' @method vec_ptype2.integer robimutation
#' @export
vec_ptype2.integer.robimutation <- function(x, y, ...) integer()
#' @method vec_ptype2.robimutation double
#' @export
vec_ptype2.robimutation.double <- function(x, y, ...) double()
#' @method vec_ptype2.double robimutation
#' @export
vec_ptype2.double.robimutation <- function(x, y, ...) double()
#' @export
vec_cast.robimutation <- function(x, to, ...) UseMethod("vec_cast.robimutation")
#' @method vec_cast.robimutation default
#' @export
vec_cast.robimutation.default <- function(x, to, ...) vec_default_cast(x, to)
#' @method vec_cast.robimutation robimutation
#' @export
vec_cast.robimutation.robimutation <- function(x, to, ...) x
#' @method vec_cast.robimutation integer
#' @export
vec_cast.robimutation.integer <- function(x, to, ...)
new_robimutation(x)
#' @method vec_cast.integer robimutation
#' @export
vec_cast.integer.robimutation <- function(x, to, ...)
vec_data(x)
#' @method vec_cast.robimutation double
#' @export
vec_cast.robimutation.double <- function(x, to, ...)
new_robimutation(x)
#' @method vec_cast.double robimutation
#' @export
vec_cast.double.robimutation <- function(x, to, ...)
vec_cast(vec_data(x),double())
#' @method vec_cast.character robimutation
#' @export
vec_cast.character.robimutation <- function(x, to, ...)
.Call("ROBI_as_chararacter_mutation",vec_data(x))
#' @method vec_cast.logical robimutation
#' @export
vec_cast.logical.robimutation <- function(x, to, ...)
vec_cast(vec_data(x),logical())
#' Converts an object to a \code{robimutation} instance
#'
#' @param object the object to convert
#' @return a \code{robimutation} instance
#'
#' @examples
#' x <- robimutation(c(1,2,2759))
#' is_robimutation(x)
#'
#' @author Eric Coissac <eric.coissac@metabarcoding.org>
#' @export
as_robimutation = function(object) {
UseMethod("as_robimutation", object)
}
#' @rdname as_robimutation
#' @export
as_robimutation.default = function(object) {
vec_cast(object,robimutation())
}
#' @export
format.robimutation <- function(x, ...) {
out <- .Call("ROBI_as_chararacter_mutation",vec_data(x))
out[is.na(x)] <- NA
out
}
#' @export
vec_ptype_abbr.robimutation <- function(x, ...) {
"mutation"
}
#' @importFrom pillar pillar_shaft
#' @export
pillar_shaft.robimutation <- function(x, ...) {
out <- formatC(x)
out[is.na(x)] <- NA
pillar::new_pillar_shaft_simple(out, align = "left")
}
#' @export
is_dist_1_or_0 <- function(x,y,lx=nchar(x),ly=nchar(y)) {
data = tibble(x=x,y=y,lx=lx,ly=ly)
as_robimutation(.Call("ROBI_is_d0_or_d1",data$x,data$y,data$lx,data$ly))
}
#' @export
mutation_position <- function(x) {
robiassert_arg(is_robimutation(x),x,"x must be a robimutation instance")
.Call("ROBI_position_mutation",x)
}
#' @export
origin_site <- function(x) {
robiassert_arg(is_robimutation(x),x,"x must be a robimutation instance")
.Call("ROBI_origin_mutation",x)
}
#' @export
mutated_site <- function(x) {
robiassert_arg(is_robimutation(x),x,"x must be a robimutation instance")
.Call("ROBI_to_mutation",x)
}
#' @export
substitution <- function(x) {
robiassert_arg(is_robimutation(x),x,"x must be a robimutation instance")
.Call("ROBI_substitution_mutation",x)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/robimutation.R
\name{as_robimutation}
\alias{as_robimutation}
\alias{as_robimutation.default}
\title{Converts an object to a \code{robimutation} instance}
\usage{
as_robimutation(object)
\method{as_robimutation}{default}(object)
}
\arguments{
\item{object}{the object to convert}
}
\value{
a \code{robimutation} instance
}
\description{
Converts an object to a \code{robimutation} instance
}
\examples{
x <- robimutation(c(1,2,2759))
is_robimutation(x)
}
\author{
Eric Coissac <eric.coissac@metabarcoding.org>
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/robimutation.R
\name{is_robimutation}
\alias{is_robimutation}
\title{Test if an object belongs \code{robimutation} class}
\usage{
is_robimutation(object)
}
\arguments{
\item{object}{the object to test}
}
\value{
a \code{logical} value
}
\description{
Test if an object belongs \code{robimutation} class
}
\examples{
x <- as_robimutation(256)
is_robimutation(x)
is_robimutation("toto")
}
\author{
Eric Coissac <eric.coissac@metabarcoding.org>
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/robimutation.R
\name{new_robimutation}
\alias{new_robimutation}
\title{Constructs a new \code{robimutation} instance.}
\usage{
new_robimutation(object, ..., verbose = is_robi_verbose(), class = character())
}
\arguments{
\item{object}{an integer vector}
\item{...}{Passed on to \code{\link[base]{structure}}()}
\item{class}{Subclasses to assign to the new object, default: none}
}
\description{
Constructs a new \code{robimutation} instance.
}
\examples{
new_robimutation(1:10)
}
\author{
Eric Coissac <eric.coissac@metabarcoding.org>
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/alignment.R
\name{robi4mer}
\alias{robi4mer}
\alias{new_robi4mer}
\alias{is_robi4mer}
\alias{as_robi4mer}
\title{Vector of 4mers for multiplexing PCR.}
\usage{
robi4mer(length = 0)
new_robi4mer(
object,
adapte_length = TRUE,
...,
verbose = is_robi_verbose(),
class = character()
)
is_robi4mer(object)
as_robi4mer(object)
}
\arguments{
\item{length}{A non-negative integer specifying the desired length. Double
values will be coerced to integer: supplying an argument of length other
than one is an error.}
\item{object}{the object to convert.}
\item{adapte_length}{if \code{TRUE} longuest 4mers are shortened by trimming them
on the left side.}
\item{...}{Passed on to \code{\link[base:structure]{base::structure()}}. It allows for defining
attributes, specified in 4mer = value form, which will be attached to data
(see \code{\link{robiatomic}}).}
\item{verbose}{if \code{TRUE} warnings and messages are emitted when the
constructor takes some decision because of missing values and estimates
default values these missing data.}
\item{class}{Subclasses to assign to the new object, default: none}
\item{`object`}{the object to test.}
}
\value{
the \code{robi4mer()}and \code{new_robi4mer()} functions return a \code{robi4mer}
instance.
the \code{is_robi4mer()}, \code{is_robi4mer_forward()}, and \code{is_robi4mer_reverse()}
functions return a \code{\link{logical}} value.
the \code{as_robi4mer()} funtion returns a \code{robi4mer} value.
}
\description{
A \code{robi4mer} is character vector that is for storing short oligo nucleotides
used to 4mer sample. 4mers are always represented as uppercase letters and
contain only A, C, G, and T and every 4mer
}
\details{
The \code{robi4mer()} constructor builds a default \code{robi4mer} instance of
length defined by the \code{length} argument and composed of 4mers of length
zero.
The contructor \code{new_robi4mer} is the main function to create a
\code{robi4mer} instance. For simpler conversion to that class, it can be easier
to use the \code{as_robi4mer()} utility function.
\code{as_robi4mer} converts an object to a \code{robi4mer} instance.
}
\examples{
rt <- robi4mer(10)
rt <- new_robi4mer(c("ATC", "ATG", "CCC", "CTG"))
is_robi4mer(rt)
is_robi4mer("toto")
x <- c("AGT","GGT","CGT","GTA","CCC")
rt <- as_robi4mer(x)
}
\author{
Eric Coissac \href{mailto:eric.coissac@metabarcoding.org}{eric.coissac@metabarcoding.org}
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/robimutation.R
\name{robimutation}
\alias{robimutation}
\title{Build a \code{robimutation} instance}
\usage{
robimutation(x = 0)
}
\arguments{
\item{x}{an object coercible to an \code{integer}}
\item{verbose}{if `TRUE` warnings are emitted if the constructor takes
some decision because of missing values and estimates
default values these missing data.}
}
\value{
a \code{robimutation} instance
}
\description{
a \code{robimutation} is an integer vector that is for storing numerical taxonomic
identifiers. They are normally used to store NCBI taxids. They have to be positive
and not null.
}
\examples{
robimutation(1:10)
}
\author{
Eric Coissac <eric.coissac@metabarcoding.org>
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/robiobject.R, R/robiatomic.R, R/alignment.R,
% R/robidata.R, R/robitaxid.R, R/robitag.R, R/robiuniqueid.R, R/robimotu.R,
% R/robicategory.R, R/robisample.R, R/robimetabar.R
% R/robicategory.R, R/robisample.R, R/robimetabar.R, R/robimutation.R
\name{validate_object}
\alias{validate_object}
\alias{validate_object.default}
......@@ -15,6 +15,7 @@
\alias{validate_object.robicategory}
\alias{validate_object.robisample}
\alias{validate_object.robimetabar}
\alias{validate_object.robimutation}
\title{Validate a new object}
\usage{
validate_object(object, verbose = is_robi_verbose())
......@@ -40,6 +41,8 @@ validate_object(object, verbose = is_robi_verbose())
\method{validate_object}{robisample}(object, verbose = TRUE)
\method{validate_object}{robimetabar}(object, verbose = is_robi_verbose())
\method{validate_object}{robimutation}(object)
}
\arguments{
\item{object}{the object to validate}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/robimetabar_xlsx.R
\name{write.xlsx.robimetabar}
\alias{write.xlsx.robimetabar}
\title{Writes a `robimetabar` object as xlsx files.}
\usage{
\method{write.xlsx}{robimetabar}(
x,
file,
sheetName = NULL,
col.names = TRUE,
row.names = TRUE,
append = FALSE,
showNA = TRUE,
password = NULL
)
}
\arguments{
\item{data}{a metabarcoding.data object}
\item{filename}{a string indication in which file to save the
object. Please do no forget the `.xlsx` extension
at the end of the name if you want your computer
recognize the file as an excel file.}
}
\description{
Save metabacoding data in excel format.
}
\details{
If you encounter a memory bug run the following command
options(java.parameters = "- Xmx4096m")
As the first commande of your script before importing
any package
}
\author{
Eric Coissac
}
#include <R.h>
#include <Rinternals.h>
#include <Rdefines.h>
#include <stdint.h>
#define ABS(X) (((X) >= 0) ? (X):-(X))
#define MIN(X,Y) (((X) < (Y)) ? (X):(Y))
#define MAX(X,Y) (((X) > (Y)) ? (X):(Y))
/**
* Degenerated nucleotides are coded on four bits
*
* 8421
* ACGT
*
* Table for converting IUPAC symbol in DNA code
*
*/
static const char codeDNA[256] = { 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,