Create Auto.PCA.R

USAGE INSTRUCTIONS:
source the package by saving this code as an .R file in your directory where the peak-picked data is held and paste the following command into your R console adding in the address of your study directory:
> source('your_working_directory_address/Auto.PCA.R')
Package dependencies:- requires the "pcaMethods" package
Paste 
>install.packages("pcaMethods")
into R console to automatically install this package to your library. 
This software function performs automated PCA analysis. The first stage is to remove features below the QC RSD threshold set in the previous function (PreProc.QC.LSC) thereby removing data which is not found to be reproducible in the pooled sample.  This function takes the QC corrected output .csv file ("QC_corrected.csv") and calculates the first 3 principal components then automatically identifies and removes outliers based on the Hotellings T2 distribution. The outliers are removed based on an acceptable tolerance representing a proportional expansion of the ellipse which is user defined. eg. 1.1.
If outliers are detected they will be removed and saved in a table in the working directory including the distance to model (DModX) value and the name of the samples and relative positions, a further PCA model will then be calculated. It will perform a maximum of 3 seperate calculations of PCA models with a potential 3 rounds of outlier removal. The Hotellings statistics are also saved summarising each model in a seperate table "Hotellings_statistics.csv".
The function automatically generates and saves figures as both .pdf and .png files for each PCA models with the QC samples labelled in red.
The function also removes data of outlying samples from the experiments Y data. A .csv file containing the Y variable data with sample names as rows and names of each Y variable along the columns must be placed in the directory with the data.
The function finally saves two .csv files "PCA.outliers.removed.csv" for the X matrix and "Y.outliers.removed.csv" for the Y variables.

X - QC corrected output data  (default = "QC_Corrected.csv")
Yvar - Y variable matrix (default = "Y.csv")
QCInt - QC samples interval for your experiment (default = 5 ie. every 4th sample)
SGroups - number of study groups or subdirectories of your study (defaults = 3 suggested arrangement is QCs, samples and blanks)
scaling - scaling method for PCA calculation (default = "pareto", other options include "none", "vector" and "uv")
tol - outlier removal tolerance based on an proportional expansion of the Hotellings T2 ellipse beyond which to remove outliers ( defaults =1.1)
wd - the address of your working directory in the format "D:\\R_data\\"