Remove duplicated patient samples (samples from the same patient/column ID)
Source:R/curatedBreastData_process.R
removeDuplicatedPatients.RdFunction to keep only 1 sample per patient (column ID) in the data matrix. Keeps the sample that has the overall highest variance.
Usage
removeDuplicatedPatients(
exprMatrix,
outputFile = "duplicatedPatientsOutput.txt",
varMetric = c("everything", "all.obs", "complete.obs", "na.or.complete",
"pairwise.complete.obs")
)Arguments
- exprMatrix
Expression matrix, with features in the rows and samples in the columns.
- outputFile
Output file for messages that print status of removing duplicated samples. Include full directory if file should not be printed to current working directory.
- varMetric
Standard options taken from the base var() function. May be important if you have NA values in your data matrix; otherwise, "everything" is usually fine.
Note
Suggestions are welcome for further ways to pick the best sample from samples from the same patient. No curatedBreastData matrices currently have samples that share the same patient ID, but this function is especially useful for say TCGA data, where this is often the case.
It is suggseted one imputes missing values using the filterAndImpute function before running this function to avoid -Inf and NA values in the variance calculations.
Examples
#No curatedBreastData has duplicated samples,
#but we can still run this function on one of the datasets:
#load up our datasets
curatedBreastDataExprSetList <- getCuratedBreastDataExprSetList(test=TRUE)
#This dataset does not have NA values, which makes for a good example without
#extra pre-processing.
outputMatrix <- removeDuplicatedPatients(exprMatrix=
exprs(curatedBreastDataExprSetList[[1]]),
outputFile = tempfile(), varMetric = c("everything"))
#>
#> Starting with 30patients.
#> found no multiple samples from the same patient(s)
#final dimensions - unchanged in this case with
#no samples sharing the same patient ID.
dim(outputMatrix)
#> [1] 500 30