Skip to content

Commit

Permalink
Merge branch 'master' into devel
Browse files Browse the repository at this point in the history
* master: (24 commits)
  temporarily disable updateObject test - see issue #166
  torture test script
  Fix class version problem for Spectrum1 and Spectrum2
  new lines cleanup
  set version in initialise for Spectum only
  Use getClassVersion function to get class versions.
  Add class version to C-constructors
  set Spectrum class in initialize
  revert to previous NAnnotatedDataFrame
  fix new error quantifying msnexp with empty phenodata
  set class version in NAnnotatedDataFrame initialize
  fix iPQF unit test to take into account new class versions
  fix MSnProcess and MIAPE initialize to set class version earlier
  set class version in MIAPE initialize
  new rcpp attribs
  class version helper functions
  MSnProcess has class set in initialize and validity checks for version
  Initiating removal or new() class version construction inside prototype.
  Tix removeReporters,OnDiskMSnExp
  Reverting to old initialize,Spectrum (see issue #163)
  ...

From: Laurent <lg390@cam.ac.uk>

git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/MSnbase@122190 bc3139a8-67e5-0310-9ffc-ced21a209358
  • Loading branch information
l.gatto committed Oct 11, 2016
1 parent 1cfc8fd commit a1cb083
Show file tree
Hide file tree
Showing 26 changed files with 654 additions and 746 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: MSnbase
Title: Base Functions and Classes for MS-based Proteomics
Version: 1.99.5
Version: 1.99.6
Description: Basic plotting, data manipulation and processing
of MS-based Proteomics data.
Authors@R: c(person(given = "Laurent", family = "Gatto",
Expand Down
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
CHANGES IN VERSION 1.99.6
-------------------------
o Reverting to old initialize,Spectrum (see issue #163)
<2016-10-07 Fri>
o Setting Spectrum class versions outside of prototype (see issue
#163). For this, there is now a vector of class version in
.MSnbaseEnv <2016-10-10 Mon>

CHANGES IN VERSION 1.99.5
-------------------------
o Add removeReporters,OnDiskMSnExp (see issue #161 for details)
Expand Down
106 changes: 60 additions & 46 deletions R/DataClasses.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
## Returns of class version as documented in .MSnBaseEnd$ClassVersions
## as and instance of class Versions.
getClassVersion <- function(x) {
if (!is.character(x))
x <- class(x)[1]
## This get class versions from parent classes (if any)
ver <- classVersion(x)
## Adds (or overwrites) x's class version to the list of class
## versions
ver[x] <- getClassVersionString(x)
ver
}
## Utility to just extract the version string from the environment.
getClassVersionString <- function(x) {
if (!is.character(x))
x <- class(x)[1]
return(.MSnbaseEnv$ClassVersions[x])
}

######################################################################
## MSnProcess: Container for MSnExp and MSnSet processing information
## See online documentation for more information.
setClass("MSnProcess",
representation = representation(
files="character",
processing="character",
merged="logical",
cleaned="logical",
removedPeaks="character",
smoothed="logical",
trimmed="numeric",
normalised="logical",
MSnbaseVersion="character"),
contains=c("Versioned"),
prototype = prototype(
new("Versioned", versions=c(MSnProcess="0.1.3")),
processing=character(),
files=character(),
trimmed=numeric(),
removedPeaks=character(),
MSnbaseVersion=character()) ## set in initialize()
)
files = "character",
processing = "character",
merged = "logical",
cleaned = "logical",
removedPeaks = "character",
smoothed = "logical",
trimmed = "numeric",
normalised = "logical",
MSnbaseVersion = "character"),
contains = c("Versioned"),
prototype = prototype(
new("Versioned", versions = c(MSnProcess = "0.1.3")),
processing = character(),
files = character(),
trimmed = numeric(),
removedPeaks = character(),
MSnbaseVersion = character())) ## set in initialize()

#################################################################
## The 'Minimum Information About a Proteomics Experiment' Class
Expand All @@ -36,7 +54,7 @@ setClass("MIAPE",
samples = "list",
preprocessing = "list",
other = "list",
##########################
## ########################
## Based on MIAPE-MS 2.24
## will be updated with MIAPE-MSI and MIAPE-Quant
## 1. General features - (a) Global descriptors
Expand Down Expand Up @@ -79,7 +97,8 @@ setClass("MIAPE",
),
contains = c("MIAxE"),
prototype = prototype(
new("Versioned", versions=c(classVersion("MIAxE"), MIAPE="0.2.2")),
new("Versioned",
versions = c(classVersion("MIAxE"), MIAPE = "0.2.2")),
name = "",
lab = "",
contact = "",
Expand All @@ -90,8 +109,7 @@ setClass("MIAPE",
email = "",
samples = list(),
preprocessing = list(),
other = list())
)
other = list()))

############################################################################
## NAnnotatedDataFrame: As Biobase's AnnotatedDataFrame, it is composed of
Expand All @@ -105,7 +123,7 @@ setClass("NAnnotatedDataFrame",
multiLabels = "character"),
contains = c("AnnotatedDataFrame"),
prototype = prototype(
new("Versioned", versions=list(NAnnotatedDataFrame="0.0.3")),
new("Versioned", versions = list(NAnnotatedDataFrame="0.0.3")),
multiplex = 1,
multiLabels = "Single run"),
validity = function(object) {
Expand Down Expand Up @@ -149,7 +167,7 @@ setClass("pSet",
"VIRTUAL"),
contains = "Versioned",
prototype = prototype(
new("Versioned", versions=c(pSet="0.1.1")),
new("Versioned", versions = c(pSet = "0.1.1")),
assayData = new.env(parent=emptyenv()),
experimentData = new("MIAPE"),
phenoData = new("NAnnotatedDataFrame",
Expand Down Expand Up @@ -193,7 +211,6 @@ setClass("Spectrum",
"VIRTUAL"),
contains=c("Versioned"),
prototype = prototype(
new("Versioned", versions=c(Spectrum="0.4.0")),
rt = numeric(),
polarity = NA_integer_,
acquisitionNum = NA_integer_,
Expand Down Expand Up @@ -235,8 +252,6 @@ setClass("Spectrum2",
collisionEnergy = "numeric"),
contains=c("Spectrum"),
prototype = prototype(
new("Versioned",
versions=c(classVersion("Spectrum"), Spectrum2="0.2.0")),
merged = 1,
acquisitionNum = integer(),
precScanNum = integer(),
Expand All @@ -262,7 +277,6 @@ setClass("Spectrum2",
setClass("Spectrum1",
contains=c("Spectrum"),
prototype = prototype(
new("Versioned", versions=c(classVersion("Spectrum"), Spectrum1="0.2.0")),
polarity=integer(),
msLevel = as.integer(1)),
validity = function(object) {
Expand All @@ -280,27 +294,27 @@ setClass("Spectrum1",
## See online documentation for more information.
setClass("ReporterIons",
representation = representation(
name="character",
reporterNames="character",
description="character",
mz="numeric",
col="character",
width="numeric"),
contains=c("Versioned"),
prototype = prototype(
new("Versioned", versions=c(ReporterIons="0.1.0")),
name=character(),
reporterNames=character(),
description=character(),
mz=numeric(),
col=character(),
width=numeric()),
name = "character",
reporterNames = "character",
description = "character",
mz = "numeric",
col = "character",
width = "numeric"),
contains = c("Versioned"),
prototype = prototype(
new("Versioned", versions = c(ReporterIons = "0.1.0")),
name = character(),
reporterNames = character(),
description = character(),
mz = numeric(),
col = character(),
width = numeric()),
validity = function(object) {
msg <- validMsg(NULL, NULL)
if (length(object@mz)==0) {
msg <- validMsg(msg,"No reporter ions defined.")
if (length(object@mz) == 0) {
msg <- validMsg(msg, "No reporter ions defined.")
} else {
if (length(object@col)!=length(object@mz))
if (length(object@col) != length(object@mz))
warning("Missing color(s) for the reporter ions.")
}
if (is.null(msg)) TRUE
Expand Down
2 changes: 1 addition & 1 deletion R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file was generated by Rcpp::compileAttributes
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

imp_neighbour_avg <- function(x, k) {
Expand Down
16 changes: 15 additions & 1 deletion R/environment.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
.MSnbaseEnv <- new.env(parent=emptyenv(), hash=TRUE)
.MSnbaseEnv <- new.env(parent = emptyenv(), hash = TRUE)

## As discussed in issue #163 for details, the random errors we see
## (see issue #138) seem to come (partially at least) from using new
## in the prototype. As a result, these will be setn (and tested in
## validity methods) outside of the prototype. The vector below stores
## the respective class versions. When a class doesn't have one, the
## version should be defined as NA_character_.

ClassVersions <- c(
Spectrum = "0.4.0",
Spectrum1 = "0.2.0",
Spectrum2 = "0.2.0")

assign("ClassVersions", ClassVersions, envir = .MSnbaseEnv)

assign("amino.acids",
data.frame(AA = c("peg","A","R","N","D","C","E",
Expand Down
116 changes: 27 additions & 89 deletions R/functions-Spectrum1.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ show_Spectrum1 <- function(spectrum) {

############################################################
## Constructor function for Spectrum1 objects. This one uses C-code and
## is faster than a call to "new"
## is faster than a call to "new".
## It calls the "versioned" constructor in C that adds also the class version(s)
## (see issue #163).
Spectrum1 <- function(peaksCount = length(mz), rt = numeric(),
acquisitionNum = NA_integer_, scanIndex = integer(),
tic = 0, mz = numeric(), intensity = numeric(),
Expand All @@ -28,16 +30,29 @@ Spectrum1 <- function(peaksCount = length(mz), rt = numeric(),
if (!is.logical(centroided)) centroided <- as.logical(centroided)
if (!is.logical(smoothed)) smoothed <- as.logical(smoothed)
if (!is.integer(polarity)) polarity <- as.integer(polarity)
## Define the class versions.
versions <- list(Spectrum = getClassVersionString("Spectrum"),
Spectrum1 = getClassVersionString("Spectrum1"))
res <- .Call("Spectrum1_constructor",
1L, peaksCount, rt, acquisitionNum, scanIndex, tic, mz,
intensity, fromFile, centroided, smoothed, polarity, TRUE,
PACKAGE = "MSnbase")
lapply(versions, .versionToNum), PACKAGE = "MSnbase")
return(res)
}

############################################################
## .versionToNum
## Simple helper function to convert a character version string into an
## integer vector.
.versionToNum <- function(z) {
return(as.integer(unlist(strsplit(z, split = ".", fixed = TRUE))))
}

############################################################
## Constructor for Spectrum1 that ensures ordering of M/Z-intensity
## pairs by M/Z value (increasing).
## It calls the "versioned" constructor in C that adds also the class version(s)
## (see issue #163).
Spectrum1_mz_sorted <- function(peaksCount = length(mz), rt = numeric(),
acquisitionNum = NA_integer_,
scanIndex = integer(), tic = 0,
Expand All @@ -56,103 +71,22 @@ Spectrum1_mz_sorted <- function(peaksCount = length(mz), rt = numeric(),
if (!is.logical(centroided)) centroided <- as.logical(centroided)
if (!is.logical(smoothed)) smoothed <- as.logical(smoothed)
if (!is.integer(polarity)) polarity <- as.integer(polarity)
## Define the class versions.
versions <- list(Spectrum = getClassVersionString("Spectrum"),
Spectrum1 = getClassVersionString("Spectrum1"))
res <- .Call("Spectrum1_constructor_mz_sorted",
1L, peaksCount, rt, acquisitionNum, scanIndex, tic, mz,
intensity, fromFile, centroided, smoothed, polarity, TRUE,
PACKAGE="MSnbase")
lapply(versions, .versionToNum), PACKAGE="MSnbase")
return(res)
}

############################################################
## This one does not ensure M/Z ordering is correct!
Spectra1 <- function(peaksCount = NULL, rt = numeric(),
acquisitionNum = NA_integer_,
scanIndex = integer(), tic = 0, mz = numeric(),
intensity = numeric(), fromFile = integer(),
centroided = NA, smoothed = NA,
polarity = NA_integer_, nvalues = integer()) {
if (length(mz) == 0 | length(intensity) == 0 | length(nvalues) == 0){
stop("Arguments 'mz', 'intensity' and 'nvalues' are required!")
} else {
if (length(mz) != length(intensity))
stop("Lengths of 'mz' and 'intensity' do not match!")
}
nvals <- length(nvalues)
## Now match all of the lengths to the length of nvalues.
if (length(peaksCount) == 0)
peaksCount <- nvalues
## rt
if (length(rt) == 0){
rt <- rep(NA_integer_, nvals)
} else {
if (length(rt) != nvals)
stop("Length of 'rt' has to match the length of 'nvalues'!")
}
## acquisitionNum
if (length(acquisitionNum) == 1) {
acquisitionNum <- rep(acquisitionNum, nvals)
} else {
if (length(acquisitionNum) != nvals)
stop("Length of 'acquisitionNum' has to match the length of 'nvalues'!")
}
## scanIndex
if (length(scanIndex) == 0){
scanIndex <- rep(NA_integer_, nvals)
} else {
if (length(scanIndex) != nvals)
stop("Length of 'scanIndex' has to match the length of 'nvalues'!")
}
## tic
if (length(tic) == 1){
tic <- rep(tic, nvals)
} else {
if (length(tic) != nvals)
stop("Length of 'tic' has to match the length of 'nvalues'!")
}
## fromFile
if (length(fromFile) == 0){
fromFile <- rep(NA_integer_, nvals)
} else {
if (length(fromFile) != nvals)
stop("Length of 'fromFile' has to match the length of 'nvalues'!")
}
## polarity
if (length(polarity) == 1){
polarity <- rep(polarity, nvals)
} else {
if (length(polarity) != nvals)
stop("Length of 'polarity' has to match the length of 'nvalues'!")
}
## Ensure the arguments are in correct format
if (!is.integer(peaksCount)) peaksCount <- as.integer(peaksCount)
if (!is.double(rt)) rt <- as.double(rt)
if (!is.integer(acquisitionNum)) acquisitionNum <- as.integer(acquisitionNum)
if (!is.integer(scanIndex)) scanIndex <- as.integer(scanIndex)
if (!is.double(tic)) tic <- as.double(tic)
if (!is.double(mz)) mz <- as.double(mz)
if (!is.double(intensity)) intensity <- as.double(intensity)
if (!is.integer(fromFile)) fromFile <- as.integer(fromFile)
if (!is.logical(centroided)) centroided <- as.logical(centroided)
if (!is.logical(smoothed)) smoothed <- as.logical(smoothed)
if (!is.integer(polarity)) polarity <- as.integer(polarity)
## OK, now let's call C.
res <- .Call("Multi_Spectrum1_constructor", 1L, as.integer(peaksCount),
rt,
acquisitionNum,
scanIndex,
tic, mz, intensity,
fromFile,
centroided,
smoothed,
polarity,
as.integer(nvalues), TRUE,
PACKAGE = "MSnbase")
return(res)
}

############################################################
## Constructor to create multiple Spectrum1 objects ensuring that
## M/Z-intensity pairs are ordered by M/Z.
## It calls the "versioned" constructor in C that adds also the class version(s)
## (see issue #163).
Spectra1_mz_sorted <- function(peaksCount = NULL, rt = numeric(),
acquisitionNum = NA_integer_,
scanIndex = integer(), tic = 0, mz = numeric(),
Expand Down Expand Up @@ -236,6 +170,9 @@ Spectra1_mz_sorted <- function(peaksCount = NULL, rt = numeric(),
if (!is.logical(centroided)) centroided <- as.logical(centroided)
if (!is.logical(smoothed)) smoothed <- as.logical(smoothed)
if (!is.integer(polarity)) polarity <- as.integer(polarity)
## Define the class versions.
versions <- list(Spectrum = getClassVersionString("Spectrum"),
Spectrum1 = getClassVersionString("Spectrum1"))
## OK, now let's call C.
res <- .Call("Multi_Spectrum1_constructor_mz_sorted",
1L,
Expand All @@ -249,6 +186,7 @@ Spectra1_mz_sorted <- function(peaksCount = NULL, rt = numeric(),
smoothed,
polarity,
as.integer(nvalues), TRUE,
lapply(versions, .versionToNum),
PACKAGE = "MSnbase")
return(res)
}
Loading

0 comments on commit a1cb083

Please sign in to comment.