writeIntensity.Rd
This function writes an intensity matrix as generated by intensityMatrix
into a file in the R, csv, NEXUS or FASTA formats. For NEXUS format it allows to specify weights for peaks.
writeIntensity(x, filename = "intMatrix", format = c("R", "csv", "NEXUS", "FASTA"),
binary = FALSE, labels = NULL, weights=NULL, ...)
Intensity matrix as obtained from intensityMatrix
.
A character string specifying a name for the destination file (filename extension not required).
One of R (default .RData
file), text (comma-separated .csv
file), NEXUS (.nex
file) or FASTA (.fas
file).
Logical value. If TRUE
, a binary version (1: peak presence, 0: peak absence) of x
is saved (default FALSE
).
Optional vector of ID labels for the samples.
Optional numeric vector of peak weights (NEXUS format).
Additional arguments.
This is a wrapper function to simplify the writing of an intensity matrix in different formats while adding some extra features. It includes the common NEXUS and FASTA formats as an extension of functions in the ape
package to handle peak intensity data. It also allows for taxa/sample pre-computed peak weights to be included in the NEXUS file. It checks whether the names meet NEXUS name conventions and gives them adequate format if not. A binary intensity matrix is always internally generated (binary = TRUE
) when either the NEXUS or FASTA format is chosen. If any, NA
values in x
are assumed to denote zero intensity/peak absence and are then converted into zeros.
No return value, file in selected format created on destination folder.
# Load example data
data(spectra) # list of MassSpectra class objects
# Some pre-processing
spectra <- screenSpectra(spectra)$fspectra
spectra <- transformIntensity(spectra, method = "sqrt")
spectra <- wavSmoothing(spectra)
spectra <- removeBaseline(spectra)
peaks <- detectPeaks(spectra)
peaks <- alignPeaks(peaks, minFreq = 0.8)
# Intensity matrix
int <- intensityMatrix(peaks)
# Save as R file (saved to a temporary location as an example)
# \donttest{
writeIntensity(int, file = file.path(tempdir(), "int"))
# }
# Save as binary NEXUS file (saved to a temporary location as an example)
# \donttest{
writeIntensity(int, file = file.path(tempdir(),"int.binary"),
format = "NEXUS", interleaved = FALSE)
# }