Coder Social home page Coder Social logo

bryanhanson / chemospec Goto Github PK

View Code? Open in Web Editor NEW
56.0 14.0 21.0 294.52 MB

R functions for the chemometric analysis of spectra

Home Page: https://bryanhanson.github.io/ChemoSpec/

R 93.93% TeX 6.07%
spectroscopy nmr infrared ultraviolet visible raman xrf

chemospec's Introduction

Project Status: Active - The project has reached a stable, usable state and is being actively developed.   Build & Check   Docs Current

CRAN status   metacran downloads   Downloads   status   Contributor Covenant

What is ChemoSpec?

ChemoSpec is a collection of functions for top-down exploratory data analysis of spectral data including nuclear magnetic resonance (NMR), infrared (IR), Raman, X-ray fluorescence (XRF) and other similar types of spectroscopy. Includes functions for plotting and inspecting spectra, peak alignment, hierarchical cluster analysis (HCA), principal components analysis (PCA) and model-based clustering. Robust methods appropriate for this type of high-dimensional data are available. ChemoSpec is designed for structured experiments, such as metabolomics investigations, where the samples fall into treatment and control groups. Graphical output is formatted consistently for publication quality plots. ChemoSpec is intended to be very user friendly and to help you get usable results quickly. A vignette covering typical operations is available.

Learn more about ChemoSpec

Installing ChemoSpec from CRAN:

chooseCRANmirror() # choose a CRAN mirror
install.packages("ChemoSpec")
library("ChemoSpec")

Installing ChemoSpec from Github:

install.packages("remotes")
library("remotes")
install_github(repo = "bryanhanson/ChemoSpec@main")
library("ChemoSpec")

If you use @some_other_branch you can download other branches that might be available. They may or may not pass CRAN checks and thus may not install automatically using the method above. Check the NEWS file to see what's up.

Also...

ChemoSpec requires ChemoSpecUtils to work. It should install automatically, but if not, you can use a command similar to the above to install it.

To view the Vignettes:

To access the vignettes, use the following, or visit here.

browseVignettes("ChemoSpec")

Code of Conduct

This project is released with a Contributor Code of Conduct. By contributing, you agree to abide by its terms.

Contributing

If you would like to contribute to the project, please see Contributing Guide.

License Information

ChemoSpec is distributed under the GPL-3 license, as stated in the DESCRIPTION file. For more info, see the GPL site.

Questions? [email protected]

chemospec's People

Contributors

bryanhanson avatar tejasvigupta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chemospec's Issues

problem with the removeFreq function in chemospec 5.3.2

Hello.
I process NMR spectra in Rstudio with the Chemospec package.
The data used are csv separated by a tab.
The problem is that after 10ppm, the data is no longer continuous and I can't remove the higher values with the remoFreq function.
The frequency scale runs from -2.01194 to 11.9976 no intensity unit provided
There are 57268 frequency values.
The frequency resolution is 0.000244 no intensity unit provided/point.

This data set is not continuous along the frequency axis.
Here are the data chunks:

beg.freq end.freq     size beg.indx end.indx

1 -2.01194 10.0001 12.01204 1 49103
2 10.00040 10.0006 0.00020 49104 49105
3 10.00090 10.0013 0.00040 49106 49108
4 10.00160 10.0018 0.00020 49109 49110
5 10.00210 10.0023 0.00020 49111 49112
6 10.00260 10.0028 0.00020 49113 49114
Do you have an idea of the problem?
thank you in advance

New ChemoSpec version 1.60-4

New version here on Github, and propagating through CRAN right now. Works with R 3.0.0 No new features really, but a lot of small tweaks to satisfy CRAN and fix documentation issues.

clupaSpectra not working

This may be more of an R issue, but the program will not allow me to install speaq because the MassSpecWavelet package is not available. This is the read out of the R code:

library(speaq)
Error: package ‘MassSpecWavelet’ required by ‘speaq’ could not be found

which will not allow you to do any spectral alignment within the R code even though this package is not required.

Rolling out plotly mode

To make plotly mode official (when we are ready), the following things need to be updated:

  • .onAttach Let's change the default to ggplot2!
  • Update GraphicsOptions.R to include plotly.
  • Update NEWS.md to include plotly.
  • chkGraphicsOpts needs to be checked, probably remove shiny.

Error in files2SpectraObject

Hello Bryan,
I am trying to use your package for analyzing some FTIR time course spectra. I exported the data from the proprietary format to .txt, converted them in .csv and formatted them as per the vignette.
However, when I try to create the spectral file I got an error.

files2SpectraObject(gr.crit = c("GEN1sp", "GEN2sp"), header = F, gr.cols = c("red3", "dodgerblue4"), out.file = "Test", debug = T)

The default behavior of this function has changed as of July 2016. See ?files2SpectraObject

files2SpectraObject is checking the first file

files2SpectraObject will now import your files
Importing file: GEN1sp0.csv
Error in [.data.frame(temp, , 2) : undefined columns selected

Do you have any clue of what :undefined columns selected refers to?

Best wishes,
Rosario

files2SpectraObject: Error message from R

Hi Bryan,

I'm trying to upload a large number of spectra (.dx format) using files2SpectraObject and about half way through processing I get:

"Error message from R: number of items to replace is not a multiple of replacement length"

I think it has something to do with the NPOINTS (number of data points) in that some differ slightly.

Any thoughts on this issue?

matrix2SpectraObject 'Error' Bringing in CSV

Hello,

I have lost much time trying to get the chemospec package to read my simple CSV file, which follows the requested profile.

Initially the error was as follows:
Error in matrix2SpectraObject(VIT_ctrl_A_Covid_B) :
You need to specify an input file

However, despite much effort specifying: gr.crit, gr.cols, in.file, etc...
I cannot get my file read into chemospec. Additionally, I seem to have all the tools and util., required.
Please help me through step 1 so I may begin working on the data.

Thank you!
S

Update Graphics Options

... with further information about modifying ggplot2 themes. Do this after issues around #56 are settled.

Not possible to create Spectra object from CSV file

Hello,

I have a single file "spectrum.xy" with the content as follows:

[ INIT OF FILE ]
freq,data
-244.378,3281.62
-241.835,-5469.72
-239.293,1090.93
-236.751,2729.67
and more pair of values...
[ END OF FILE ]

I am not able to load these data into an Spectra object. Either using file2SpectraObject nor matrix2SpectraObject,

However I can read easily this file with read.csv function (package readr)

Could you please show me an example of how do I have to call the function? Is the file format wrong??

spec <- matrix2SpectraObject(gr.crit = "spectrum", freq.unit = "no frequency unit provided",
int.unit = "no intensity unit provided", descrip = "test import", in.file="spectrum.xy")
Error in spectra$data[i, ] : subscript out of bounds
In addition: Warning message:
In groupNcolor(spectra, gr.crit, gr.cols) :
There was no match for gr.crit value spectrum among the file names.

Changing the extension to csv does not change anything.

Thanks in advance,
Tay

files2SpectraObject issues

Apologies if this query is ill informed, I'm relatively new to R so bare with me. I'm using Chemospec to analyse FT-IR spectra for my dissertation from 3 sample conditions (H = Heat, N = Nutrients, Bl = Blank) with readings taken following 5 exposure periods (A = 24hrs, B, = 48hrs etc).
Here is the most recent code I've tried (there have been various iterations but they all get the same error) :

HDPE_samples <- files2SpectraObject(
gr.crit = c("H(.)A","H(.)B","H(.)C","H(.)D","H(.)E",
"N(.
)A","N(.)B","N(.)C","N(.)D","N(.)E",
"Bl(.)A","Bl(.)B", "Bl(.)C", "Bl(.)D", "Bl(.*)E"),
gr.cols = c("coral","orangered", "firebrick 1", "red 2", "maroon",
"steelblue 1","steelblue 2","dodgerblue 2","dodgerblue 3","dodgerblue 4",
"tan 1","carrot","orange", "cadmiumorange","rawsienna"),
freq.unit = "cm−1",
int.unit = "absorbance (%)",
descrip = "Biodegradation of HDPE", fileExt = "/.CSV$",
out.file = "HDPE", header = TRUE, dec = ".",sep= ",")

Error message from R: cannot open the connection

There was a problem importing your files!

Are you importing csv or similar files?
Did you get a message such as 'undefined columns selected'?
You probably need to specify sep, header and dec values
Please read ?files2SpectraObject for details

For any trouble importing files set debug = TRUE

Warning message:
In file(file, "rt") : cannot open file 'NA': No such file or directory

I've looked through the package documentation, completed issues on github and anything I can find on stackoverflow & I'm still stumped, If you have any pointers on where I might be going wrong I would be so grateful to hear them!

warning when I install

Hi everybody,
I have an issu when i want to install this package:

Warning in install.packages :
download of package ‘ChemoSpec’ failed

I have R3.1.0 version of R software.

Thanks for your help.

Regards,

Maïna

importing csv/excel files

Everytime I try to import a matrix of batch of files using matrix2SpectraObject or files2SpectraObject I get the same error messages:
In groupNcolor(spectra, gr.crit, gr.cols) :
There was no match for gr.crit value wineA among the file names
In groupNcolor(spectra, gr.crit, gr.cols) :
There was no match for gr.crit value wineB among the file names
I have headers in my files that are wineA_1 to 17, etc. I have not yet been able to load any spectra using these commands.

Possible Simplification in ggplot2 graphics mode

During my code review, I saw a number of code blocks that we very nearly the same, suggesting that a helper function could be written to do this job and make the code simpler to read and maintain.

From reviewAllSpectra:

    x <- spectra$freq
    l.x <- length(x)
    df1 <- data.frame(x = NA_real_, y = NA_real_, spectra.name = NA_character_)
    for (i in 1:length(spectra$names)) {
      y <- spectra$data[i, ]
      spectra.name <- rep(spectra$names[i], l.x)
      df2 <- data.frame(x = x, y = y, spectra.name = spectra.name)
      df1 <- rbind(df1, df2)
    }
    df1 <- df1[-1, ]

From plotLoadings:

      names <- paste("PC", loads, "Loadings", sep = "")
      names <- c("RefSpectrum", names)
      x <- spectra$freq
      y <- spectra$data[ref, ]

      df <- data.frame(x, y)
      for (n in 1:length(loads)) {
        spec <- pca$rotation[, loads[n]]
        df <- cbind(df, spec)
      }

      names(df) <- c("Frequency", names)

There's more, I will look a bit more systematically later.

Problem with clupaSpectra

Hello,

If you perform an operation to remove frequencies and then try to use the clupaSpectra command it will give an error:

Error in mySpec [startR: endR]: only 0's may be mixed with negative subscripts

However, the function works correctly if you do not remove frequencies.

thank you

GSOC 2021: Phase 2 Plot Checklist

A checklist to help us keep track of progress.

Add plotly plot options to each plotting function.

1D Plotting Functions

  • plotSpectra
  • surveySpectra
  • surveySpectra2
  • reviewAllSpectra

2D Plotting Functions

  • plotScores
  • aovPCAscores
  • plot2Loadings
  • sPlotSpectra
  • plotScree
  • plotSpectraDist
  • pcaDiag

Create Spectra Object from DataFrame

This is a feature request. From the docs it seems that the only way to create a Spctra Object is to have data stored in files. If data is not originating form files, how can one create a Spectra Object? For example, if data is coming from a database. To generalize, having a way to create Spectra Objects from Data Frames might be useful.

GSOC 2021 Phase One Plots in ggplot2

A checklist to help us keep track of progress (some material transferred from #31).

Add ggplot2 plot options to each plotting function. Triggered by the user setting options(ChemoSpecGraphics = "ggplot2"). Work by branching off branch gsoc1. Use a new branch for each function as it is updated, e.g. gsoc1-plotSpectra. We'll merge each back into gsoc1 as we go.

To the greatest degree possible, we want to preserve the existing code that processes the data into a structure ready for plotting. Thus each function will have a broad structure like:

  • Check for the desired graphics option using chkGrafOpt.
  • Run the existing code to get the data ready for plotting
  • An if block for ggplot2 plotting.
  • And later: an if block for shiny plotting etc

1D Plotting Functions

  • plotSpectra
  • surveySpectra
  • surveySpectra2
  • loopThruSpectra -- My thoughts on adapting this function keep changing. In the base graphics version a single spectrum is plotted on the interactive graphics device, and the user must give the go ahead for the next plot. To keep things consistent, I think we should do exactly the same thing with ggplot2. I have a different idea for when we get to plotly (details later).
  • plotLoadings
  • aovPCAloadings

2D Plotting Functions

  • plotScores
  • aovPCAscores
  • plot2Loadings
  • sPlotSpectra
  • plotScree
  • plotSpectraDist
  • pcaDiag

normSpectra for body fluids

Hello. I hope this is the right way to ask you for help. If not, please tell me and I will do my best to solve it. Thank you.

The issue I'm having consists in Normalization of an IR Spectroscopy Spectra object of body fluids for forensic purposes. As I read in the manual for ChemoSpec, "Usually one normalizes data in which the sample preparation procedure may lead to differences in concentration, such as body fluids that might have been diluted during handling, or that vary due to the physiological state of the organism studied". Well, that's my case right now. Although there are three methods for doing this with the function "normSpectra" (Range, TotInt, and PQN), I haven't found them useful for my needs.

What I actually need is to get the intensities scaled between 0 and 1 (y unit is Log 1/R), so that the concentration of the fluid doesn't affect the intenstity of the whole spectra matrix. Is there any other way to get this done keeping the "Spectra" class of the object?

I am doing it this way as a kind of validation for other person's research. This person used The Unscrambler X 10.1 (Camo) software and normalized the spectra the way I mentioned. My point is getting to the same results with R software, so I need to do the most similar pre-treatment as possible.

I would appreciate any help. Thank you very much.

P.D. Thank you for the package, it is being highly useful, and I hope it becomes the ultimate tool for Spectra analysis.

chkGrafOpt needs unit tests

chkGrafOpt needs unit tests. ChemoSpec uses tinytest and the test files go into ChemoSpec/inst/tinytest.

Please do this work on a branch gsoc1-issue-X where X is the issue number, which will eventually merge into gsoc1.

Error in files2SpectraObject - S4 object?

Hi there,
I am new with ChemoSpec, and I am trying to analyse some FTIR data. I got an error from the begining with files2SpectraObject
files2SpectraObject(gr.crit = c("p", "m"), gr.cols = c("red", "blue"), freq.unit = "cm^-1", int.unit = "peak intensity", descrip = "Mixture DoE blanks and probiotics", out.file = "MixtrureIR", header = FALSE, sep=",", dec=".", debug="TRUE")

The files are imported, but I am getting this error:

Error message from R: trying to get slot "nir" from an object (class "Spectra") that is not an S4 object
There was a problem importing your files!
Are you importing csv or similar files?
Did you get a message such as 'undefined columns selected'?
You probably need to specify sep, header and dec values
Please read ?files2SpectraObject for details
For any trouble importing files set debug = TRUE

I am still beginer-ish with R, so I am not exactly sure what is a S4 object, and how to correct this error...

Thanks!

GSOC 2021 Community Bonding Period

This issue contains Community Bonding Tasks for Tejasvi.

Check these off as you complete them please.

  • Please register for the useR 2021 conference. I think your cost will be very little or zero, and I will reimburse you if there is any cost. Unfortunately the Shiny module talk is already full but I think we can watch it after it happens.
  • Look over both the ChemoSpec and ChemoSpecUtils code base so you know which package does the work for a particular plotting function.
  • Look at the workflows in .github/workflows for ChemoSpec. You don't need to be an expert on this but you should be familiar with the general process and what it is supposed to accomplish.
  • Read the ChemoSpec Contributing Guide.
  • Set up your work environment following the Contributing Guide. Make sure you can build and check successfully w/o making any changes (both ChemoSpec and ChemoSpecUtils).
  • Set up whatever you need for submitting weekly progress reports.
  • We're going to control the graphics output from ChemoSpec via R's option() function infrastructure. Write a function called chkGrafOpt that gets the value of getOption("ChemoSpecGraphics") and returns it, unless it is unset, in which case set the value to "base". Have it report if it changes the value. Give it an argument "silent = TRUE" to silence reporting. We will use this for each plotting function to check the value set by the user and call the appropriate graphics code. Take a look at .onAttach.R for how I set up the default value. So each function of interest will have all its existing code followed by a chkGrafOpt call, and then after that there will be graphics code for each possible value of getOption("ChemoSpecGraphics") as we add them.
  • Write a short help file that explains the graphics options, so users can access this information via the help system. Call it GraphicsOutput.R. You can model it after ChemoSpecUtils::colorSymbol.R but it will be much much shorter and for now, have no examples.
  • We'll need to define a custom theme for ggplot2 the details of which can be determined later. Just be sure that we include code to call this theme. It would also be nice if the user could specify their own theme, but that I think will be easy if we always return the ggplot2 object for users to modify.

7 June 2021: Transferring most of the rest of this to a new issue

Broadly, the work will be divided as follows:

At least this is the initial plan, we will change as needed! Based on Tejasvi's proposal mostly.

  1. Create the "options" setup needed so that users can choose between base and ggplot2 style graphics. Bryan did this already on the develop and gsoc1 branches. See onAttach.R.
  2. Add ggplot2 plot options to each plotting function. Triggered by the user setting options(ChemoSpecGraphics = "ggplot2"). Work by branching off branch gsoc1. Use a new branch for each function as it is updated, e.g. gsoc1-plotSpectra. We'll merge each back into gsoc1 as we go. As you do this you will of course be preserving the current (mostly/usually) base graphics option.
  3. Add plotly option for each plotting function. Triggered by the user setting options(ChemoSpecGraphics = "plotly"). Work on branch gsoc2. This should not take too long once the ggplot2 code is working.
    Goals 1 & 2 will likely be completed in Phase 1 of GSOC.
  4. Add shiny option for each plotting function. Triggered by the user setting options(ChemoSpecGraphics = "shiny"). Work on branch gsoc3.

Work on the Functions in this Order

  • plotSpectra
  • surveySpectra/surveySpectra2
  • plotLoadings
  • loopThruSpectra -- as data sets can be quite large, let's not have a ggplot2 version for this but instead go straight to plotly and have each spectrum in its own facet (so there is ggplot2 code to be added, it's just that users wouldn't likely want to plot it). That way the user can just scroll through the web page of all the spectra (the same thing in ggplot2 would not fit on a piece of paper which is why I doubt users will want to plot it).
  • And then the 2D plots listed in the GSOC proposal.

Some Resources that might be Helpful:

import files in Chemospec doesn't work

Hi! I try to import files in ChemoSpec, I have a collection of 15 samples (all have the A1... A15) for import....

glio <- files2SpectraObject(gr.crit=c("A"), gr.cols = c("auto"), freq.unit = "ppm", int.unit = "peak intensity",descrip = "glios", out.file = "glios",sep=",", dec = ".", debug = T, fileExt = ".csv")

and I have this error:

Error message from R: number of items to replace is not a multiple of replacement length

There was a problem importing your files!

Are you importing csv or similar files?
Did you get a message such as 'undefined columns selected'?
You probably need to specify sep, header and dec values
Please read ?files2SpectraObject for details

For any trouble importing files set debug = TRUE

I changed the format of CSV file, but I always have the same result.
somebody have a idea for fix it ?

Need to Look at argument tol

Need to look at all functions that use tol and see if it is handled consistently, and documented consistently. I suspect not.

ggplot2 theme modification

I ran some tests on modifying the ggplot2 theme with the latest versions. Here's some tests I ran:

# Theme Experiments
library("ChemoSpec")
library("ggplot2")

data(SrE.IR)

options(ChemoSpecGraphics = "ggplot2")

### plotSpectra tests
p1 <- plotSpectra(SrE.IR, which = 1:16, offset = 0.1, yrange = c(0, 1.75),
                  leg.loc = list(x = 0.8, y = 0.95)); p1

# theme_gray is the default for ggplot2
p2 <- p1 + theme_gray(); p2 # adds key but key is not by group, it's by sample

# theme_gray but override default legend
p3 <- p1 + theme_gray() + theme(legend.position = "none"); p3

# theme_light but override default legend
p4 <- p1 + theme_light() + theme(legend.position = "none"); p4

# theme_light, remove default legend, remove horizontal grid lines (fine tune appearance)
p5 <- p1 + theme_light() +
      theme(legend.position = "none") +
      theme(panel.grid.major.y = element_blank(), panel.grid.minor.y = element_blank()); p5

### plotScores tests
pca <- c_pcaSpectra(SrE.IR)

p1 <- plotScores(SrE.IR, pca); p1

# theme_gray is the default for ggplot2
p2 <- p1 + theme_gray(); p2 # does not add key

# theme_light
p4 <- p1 + theme_light(); p4

# theme_light, remove horizontal grid lines (fine tune appearance; silly test in this case)
p5 <- p1 + theme_light() +
      theme(panel.grid.major.y = element_blank(), panel.grid.minor.y = element_blank()); p5

### plotLoadings tests (using patchwork, so use & not + to modify)

p1 <- plotLoadings(SrE.IR, pca, loads = c(1, 2)); p1

p2 <- p1 & theme_gray(); p2

I think all of these look pretty good and behave as expected. I can update the documentation in the near future, but the essence of the instructions would be if you don't want our custom legend, then use leg.loc = "none", and use the usual methods of modifying ggplot2 objects to modify. It all works pretty good.

But in the course of these tests, I see that the default ggplot2 legend one gets for plotSpectra is a legend by sample name, not a legend by group. Also, plotScores doesn't have a legend after cancelling our custom legend and theme.

  • So, I wonder, can the data for plotSpectra be reshaped differently and/or the call to ggplot2 be modified so we can get a legend by group?
  • Can plotScores be modified (reshaping? change the call?) so we get a legend by group if we cancel our theme and custom legend?

Title Alignment in ggplot2 graphics mode

At least in the ChemoSpec-Plot-Combos internal vignette, the titles are left aligned with the left vertical axis. However, in plotScores they are left aligned with the y axis label.

  • See if this occurs in regular use (i.e. not the vignette)
  • Track it down either way.

makeEllipsoid: 95% Confidence ellipsoid of data instead of mean

Hi Bryan,
don't know if this is right place to ask - this is not really an issue, but since it's part of the package (and it is not mentioned until further down in the description) I figured I would ask anyway if this modification in your opinion returns the 95% confidence interval ellipsoid for the data itself, instead of the mean:

ell.95<-function (data, cl = 0.95) {

npoints <- 1000
mean <- colMeans(data)
p <- length(mean)
n <- nrow(data)

sphere <- matrix(rnorm(npoints * p), ncol = p)
cntr <- t(apply(sphere, 1, normVec))

cov <- var(data)
ev <- eigen(cov)
cntr <- cntr %% diag(sqrt(ev$values)) %% t(ev$vectors)
Fcrit <- qf(cl, p, n - p)

cntr <- cntr * Fcrit

colnames(cntr) <- colnames(data)
cntr + rep(mean, each = npoints)

Problem in importing csv files in Chemospec

When importing my csv files, I use the following arguments and I always get an error (even I have checked my csv files, they all have the same numbers of frequency)

ssp <- files2SpectraObject(gr.crit = c("E","F"),gr.cols = c("auto"),
freq.unit = "cm", int.unit = "abs", descrip = "SYD vs SYD_ACT",
out.file = "mydata", header= TRUE,
sep = ",", dec = ".", debug = TRUE, fileExt = ".csv")

Error message from R: unused arguments (gr.cols = c("auto"), out.file = "mydata")

There was a problem importing your files!

Are you importing csv or similar files?
Did you get a message such as 'undefined columns selected'?
You probably need to specify sep, header and dec values
Please read ?files2SpectraObject for details

For any trouble importing files set debug = TRUE

Determine the concentration

I want to determine the concentration of the substance into the matrix. How do I built a calibration curve to determine the concentration?

baselineSpectra: replacement has 3 rows, data has 2

When using baselineSpectra, changing the algorithm and the arguments in the Baseline correction window triggers errors. Here are the steps:

  1. Start interactive baseline correction:
    > data(SrE.IR)
    > baselineSpectra(SrE.IR)
  2. Update algorithm and parameters:
    • Select Asymmetric Least Squares (als):
      Error in unclass(x) : cannot unclass an external pointer`
    • Change Main smoothing (lambda2) from 8 to 6:
      Error in `$<-.data.frame`(`*tmp*`, "current", value = c(5, 6.3, 0.05)) : 
        replacement has 3 rows, data has 2
    • Click Update plot. The following plot is generated:
      err

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora 24 (Workstation Edition)

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] gWidgetsRGtk2_0.0-84 cairoDevice_2.24     gWidgets_0.0-54      RGtk2_2.20.33        ChemoSpec_4.4.85    

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.12       scidb_2.0.0        bit_1.1-12         munsell_0.4.3      colorspace_1.3-2   rlang_0.1.1        plyr_1.8.4         tools_3.4.1        js_1.1            
[10] grid_3.4.1         baseline_1.2-1     data.table_1.10.4  gtable_0.2.0       R.oo_1.21.0        openssl_0.9.6      bit64_0.9-7        lazyeval_0.2.0     digest_0.6.12     
[19] tibble_1.3.3       RColorBrewer_1.1-2 ggplot2_2.2.1      R.utils_2.5.0      curl_2.8.1         V8_1.5             compiler_3.4.1     scales_0.4.1       R.methodsS3_1.7.1 
[28] SparseM_1.77       jsonlite_1.5      

Support for converting data.frame to class Spectra

I have a bunch of data already in R in a tidy dataframe. I am interested in converting it to the Spectra class to use some of the cool methods/functions you have created. I have frequency, intensity and sample ID (group) columns. a function that reads a DF and makes spectra would be really useful I think.

ChemoSpec: as.Spectra.data.frame function doesn't work

as.Spectra.data.frame <- function(x, name, freq, intensity, group) {

# Helper function
isWholeNo <- function(x, tol = .Machine$double.eps^0.5) {abs(x - round(x)) < tol}	

# A few checks
if (length(units) != 2) stop("units should have length 2")

# Determine dimensions
no.pts <- length(unique(DF[,freq]))
no.spec <- length(DF[,freq])/no.pts
if (!isWholeNo(no.spec)) stop("no.spec was not an integer")

# Now build the Spectra object
Spectra <- vector("list", 9)
Spectra[[1]] <- unique(DF[,freq]) # frequency
Spectra[[2]] <- matrix(DF[,intensities], nrow = no.spec, byrow = TRUE)
Spectra[[3]] <- as.character(unique(DF[,names])) # names
Spectra[[4]] <- rep(NA_character_, no.spec) # groups
Spectra[[5]] <- rep("black", no.spec) # colors
Spectra[[6]] <- rep(1L, no.spec) # sym
Spectra[[7]] <- rep("a", no.spec) # alt.sym
Spectra[[8]] <- units # units
Spectra[[9]] <- desc # desc

# Update groups
for (i in 1:length(gr.crit)) {
	which <- grep(gr.crit[i], Spectra[[3]])
	if (length(which) == 0) warning("There was no match for gr.crit value ", gr.crit[i], " among the sample names.")
	Spectra[[4]][which] <- gr.crit[i]
	}
Spectra[[4]] <- as.factor(Spectra[[4]])

# Clean up and verify

class(Spectra) <- "Spectra"
names(Spectra) <- c("freq", "data", "names", "groups", "colors", "sym", "alt.sym", "units", "desc")
chkSpectra(Spectra)
return(Spectra)

}

#First simulate some data
set.seed(123)
bands=20
data <- data.frame(matrix(runif(60*bands),ncol=bands))
colnames(data) <- paste0(1:bands)
#Structure
str(data)
#Convert to Spectra object using the function
test<-as.Spectra.data.frame(data)

Doesn't work, please help me?
Thanks

Getting Ready for Release

No order to this checklist yet, just a series of reminders. Applies to both CS and CSU.

  • Undo any use of Remotes in DESCRIPTION Resolution: not necessary, CRAN doesn't use this field.
  • Undo any use of Remotes in workflows
  • Change any default branch settings at GH.
  • Update triggering branches in workflows.
  • Re-enable any disabled build configs in the workflows.
  • Remove and save plot combos vignette.
  • Review plot combos vignette.
  • Add new vignette.
  • How to update old vignette?
  • Run Bryan's usual checklist.
  • Examples assume base but ggplot2 is now the default, so change all where relevant.
  • Address this CSU issue
  • Check CSU, CS and CS2D together.
  • Likely will need to use the > version method on tests in CSU to get it onto CRAN to start.
  • Merge gsoc2 into devel
  • Check @importFrom for each file
  • Make sure @nord is used in the right places
  • Update ChemoSpec2D per bryanhanson/ChemoSpec2D#29.
  • Issue #83 on testing plotly

ggplot2 mode needs dedicated .ggAddLegend function

In the course of testing plots, I discovered that legends drawn by plotSpectra and .scorePlot don't accept the same inputs (in ggplot2 mode) for leg.loc.

Both functions uses npc type positioning and grobTree. But .scorePlot accepts strings like "topright", but it doesn't accept list(x = , y = ) like plotSpectra does.

So what we need is a dedicated function, let's call it .ggAddLegend, that accepts any input, e.g, "none", "topright", etc and list(x = , y = ). This requires removing the code from each function and blending it in the new function.

Also, the documentation is different, they need to be blended as well.

leg.loc also appears in hcaSpectra and hcaScores which are not on the GSOC 2021 plan, but they will get ggplot2 versions soon, so having .ggLegend will be used there too.

Possible bug in reading DX files

We are using some of the functions from ChemoSpec to load DX files in our package specmine.

Recently, when I updated the ChemoSpec package we suddenly became unable to read DX files, always returning the error:

"Problem understanding data block"

I was looking at the code and this seems to be related to some changes you added in version 4.3.30.
More specifically the following line of the function readJDX:
if (!length(spcstart) == 1L & length(spcend) == 1L) stop("Problem with delimiting data block")

seems incorrect. Maybe a ! is missing before length(spcend) ?
With this correction my files seem to load properly as before.

Miguel Rocha
[email protected]

Importing Data matrix2SpectraObject function

Hello,

I am using the ChemoSpec package to analyse NIR spectroscopy data. I have a file with column 1 being the wavelength, and the following columns as sample intensities. When applying the matrix2SpectraObject function I get the error message "line 1 did not have 17 elements". I understand this is an inputting error but was wondering whether you'd have any suggestions to resolve this?

Many thanks.

plotting scores

Hello, I´m new with ChemoSpec,
I tried to use plotScores function:
c_PCA <- c_pcaSpectra(dest,
choice = "noscale")
plotScores(dest, c_PCA, main = "PCA SCORES",
pcs = c(1,2),
ellipse = "rob",
tol = 0.01)
and the following error appeared:
Error in plot.window(...) : need finite 'xlim' values
How could I fix it? Thank you!

Un-split input for hypTestScores

data(metMUD2)
pca <- c_pcaSpectra(metMUD2)
hypTestScores(metMUD2, pca, fac = levels(metMUD2$groups))
hypTestScores(metMUD2, pca, fac = unique(metMUD2$groups))
hypTestScores(metMUD2, pca, fac = metMUD2$groups)

All of these do not work.

A Spectra object contains group information stored in its spectra$groups element, but you can also use splitSpectraGroups to generate additional groups/factors that might be more useful than the original.

I don't understand why passing the levels of the data doesn't work. Using split

Any advice welcome,

Craig

Question re plotScores and pcs parameter

In your typical example "plotScores" with parameter pcs=c(1,2) creates a display plot of PC2 scores versus PC1 scores. I assume that if pcs is changed to pcs=c(2,3) and the line executed that the new display plot would be PC3 scores versus PC2 scores. However, when I make this change and execute the line the displayed plot remains identical to the original example (e.g. , PC2 vs. PC1). Have I misunderstood the function of the pcs parameter? Any tips would be appreciated. Thanks.

New devel version of ChemoSpec with more import options

Just put up a new devel version of ChemoSpec which has a new, much more powerful function for importing files into ChemoSpec: files2SpectraObject. The file types that can be imported now are csv, csv2, dx (IR), and Bruker NMR txt files. In the case of the Bruker files, automatic alignment to the TMS peak is carried out.

sPlotSpectra error with SrE.IR data set

I tried the help page example for sPlotSpectra but used the SrE.IR data set rather than CuticleIR.

data(SrE.IR)
res <- classPCA(SrE.IR)
sPlotSpectra(SrE.IR, res)

This gives the plot and an error, which seems to come from the tolerance computation.

Error in quantile.default(py, probs = c(1 - tol, tol)) :
missing values and NaN's not allowed if 'na.rm' is FALSE

Related to this, the help page example has a wrong title.

Error while creating Spectra object : undefined columns selected

I am trying to create a spectral object with function files2SpectraObject. I have 1715 files (49 groups with 35 elements each). I named the files according to the vignette. Eah file is .csv and has just 2 columns. The first column contains the frequency and the second the intensity. When I run the function, the following error is returned:
files2SpectraObject is checking the first file

files2SpectraObject will now import your files
Importing file: GEN1_R1_1.csv
Error in [.data.frame(temp, , 2) : undefined columns selected

The function I run was:

files2SpectraObject(gr.crit = c("GEN1_R1_", "GEN2_R1_", "GEN3_R1_","GEN4_R1_","GEN5_R1_","GEN6_R1_","GEN7_R1_","GEN8_R1_","GEN9_R1_","GEN10_R1_","GEN11_R1_","GEN12_R1_","GEN13_R1_","GEN14_R1_","GEN15_R1_","GEN16_R1_","GEN17_R1_","GEN18_R1_","GEN19_R1_","GEN20_R1_","GEN21_R1_","GEN22_R1_","GEN23_R1_","GEN24_R1_","GEN25_R1_","GEN26_R1_","GEN27_R1_","GEN28_R1_","GEN29_R1_","GEN30_R1_","GEN31_R1_","GEN32_R1_","GEN33_R1_","GEN34_R1_","GEN35_R1_","GEN36_R1_","GEN37_R1_","GEN38_R1_","GEN39_R1_","GEN40_R1_","GEN41_R1_","GEN42_R1_","GEN43_R1_","GEN44_R1_","GEN45_R1_","GEN46_R1_","GEN47_R1_","GEN48_R1_","GEN49_R1_"), fileExt = "\.(csv)$", gr.cols = c("red3", "dodgerblue4"), freq.unit = "1/CM", int.unit = "abs", descrip = "Spectra of two genotypes of Miscanthus", out.file = "ABR33 Rep1 ", debug = T)

Any suggestion?

Thanks in advance,
Rosario

Update documentation about ... (applies only to base graphics)

This is a reminder... for all the functions getting ggplot2 options, update the documentation about the ... argument to note that it applies only to base graphics. Also, consider this a reminder to update all the documentation generally.

  • plotSpectra
  • surveySpectra
  • surveySpectra2
  • loopThruSpectra
  • plotLoadings
  • aovPCAloadings
  • plotScores
  • aovPCAscores
  • plot2Loadings
  • sPlotSpectra
  • plotScree
  • sampleDist
  • plotSpectraDist
  • pcaDiag

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.