%% PLSR models for starch, protein and TAG quantification
% Yuehui HE
% 2017-7-26

%% I.PLSR model for starch quantification 
%% Step 1. datasets imported
Xtrain_SCRS_32M % train dataset: mean Raman spectra from two of the triplicates at each time point
Ytrain_Starch % train dataset: starch content of corresponding samples 
Xtest_SCRS_16M % test dataset: mean Raman spectra from the other one of the triplicates at each time point
Xtest_SCRS_960cells % dataset of single cell Raman spectra of 960 cells
%% Step 2. PCs selection for PLSR modeling
c=cvpartition(32,'leaveout');
[XL,YL,XS,YS,BETA,PCTVAR,MSE,stats]=plsregress(Xtrain_SCRS_32M,Ytrain_Starch,10,'cv',c);
plot(1:10,cumsum(100*PCTVAR(2,:)),'-bo');
%% Step 3. Establishment of PLSR model for starch quantification
[XL,YL,XS,YS,BETA,PCTVAR,MSE,stats]=plsregress(Xtrain_SCRS_32M,Ytrain_Starch,6,'cv',c);% 6 PCs were selected for PLSR modeling
Yfit_Starch_32M = [ones(size(Xtrain_SCRS_32M,1),1) Xtrain_SCRS_32M]*BETA;% Starch content quantification of 32 samples (Calibration of PLSR model) 
Yfit_Starch_16M = [ones(size(Xtest_SCRS_16M,1),1) Xtest_SCRS_16M]*BETA;% Starch content quantification of 16 samples (Validation of PLSR model)
Yfit_Starch_960Cells = [ones(size(Xtest_SCRS_960cells,1),1) Xtest_SCRS_960cells]*BETA;% Starch content quantification of 960 individual cells
%% Step 4. Starch quantification of C. reinhardtii cells based on the SCRS (e.g.Xtest_SCRS_XXX )
Yfit_Starch_XXX = [ones(size(Xtest_SCRS_XXX,1),1) Xtest_SCRS_XXX]*BETA;

%% II.PLSR model for protein quantification 
%% Step 1. datasets imported
Xtrain_SCRS_32M % train dataset: mean Raman spectra from two of the triplicates at each time point
Ytrain_Protein % train dataset: protein content of corresponding samples 
Xtest_SCRS_16M % test dataset: mean Raman spectra from the other one of the triplicates at each time point
Xtest_SCRS_960cells % dataset of single cell Raman spectra of 960 cells
%% Step 2. PCs selection for PLSR modeling
c=cvpartition(32,'leaveout');
[XL,YL,XS,YS,BETA,PCTVAR,MSE,stats]=plsregress(Xtrain_SCRS_32M,Ytrain_Protein,10,'cv',c);
plot(1:10,cumsum(100*PCTVAR(2,:)),'-bo');
%% Step 3. Establishment of PLSR model for protein quantification
[XL,YL,XS,YS,BETA,PCTVAR,MSE,stats]=plsregress(Xtrain_SCRS_32M,Ytrain_Protein,6,'cv',c);% 6 PCs were selected for PLSR modeling
Yfit_Protein_32M = [ones(size(Xtrain_SCRS_32M,1),1) Xtrain_SCRS_32M]*BETA;% Protein content quantification of 32 samples (Calibration of PLSR model) 
Yfit_Protein_16M = [ones(size(Xtest_SCRS_16M,1),1) Xtest_SCRS_16M]*BETA;% Protein content quantification of 16 samples (Validation of PLSR model)
Yfit_Protein_960Cells = [ones(size(Xtest_SCRS_960cells,1),1) Xtest_SCRS_960cells]*BETA;% Protein content quantification of 960 individual cells
%% Step 4. Protein quantification of C. reinhardtii cells based on the SCRS (e.g.Xtest_SCRS_XXX )
Yfit_Protein_XXX = [ones(size(Xtest_SCRS_XXX,1),1) Xtest_SCRS_XXX]*BETA;

%% III.PLSR model for TAG quantification 
%% Step 1. datasets imported
Xtrain_SCRS_21M % train dataset: mean Raman spectra from two of the triplicates at each time point (1 from 0h)
Ytrain_TAG % train dataset: TAG content of corresponding samples 
Xtest_SCRS_10M % test dataset: mean Raman spectra from the other one of the triplicates at each time point (except 0h)
Xtest_SCRS_960cells % dataset of single cell Raman spectra of 960 cells
%% Step 2. PCs selection for PLSR modeling
c=cvpartition(21,'leaveout');
[XL,YL,XS,YS,BETA,PCTVAR,MSE,stats]=plsregress(Xtrain_SCRS_21M,Ytrain_TAG,10,'cv',c);
plot(1:10,cumsum(100*PCTVAR(2,:)),'-bo');
%% Step 3. Establishment of PLSR model for TAG quantification
[XL,YL,XS,YS,BETA,PCTVAR,MSE,stats]=plsregress(Xtrain_SCRS_21M,Ytrain_TAG,7,'cv',c);% 7 PCs were selected for PLSR modeling
Yfit_TAG_21M = [ones(size(Xtrain_SCRS_21M,1),1) Xtrain_SCRS_21M]*BETA;% TAG content quantification of 21 samples (Calibration of PLSR model) 
Yfit_TAG_10M = [ones(size(Xtest_SCRS_10M,1),1) Xtest_SCRS_10M]*BETA;% TAG content quantification of 10 samples (Validation of PLSR model)
Yfit_TAG_960Cells = [ones(size(Xtest_SCRS_960cells,1),1) Xtest_SCRS_960cells]*BETA;% TAG content quantification of 960 individual cells
%% Step 4. TAG quantification of C. reinhardtii cells based on the SCRS (e.g.Xtest_SCRS_XXX )
Yfit_TAG_XXX = [ones(size(Xtest_SCRS_XXX,1),1) Xtest_SCRS_XXX]*BETA;
