Last active
February 7, 2019 23:09
-
-
Save laderast/52daadf0492cae4e78b96028f0678214 to your computer and use it in GitHub Desktop.
Ways to manipulate Expression Sets for HW3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Some useful ways to manipulate expressionSets | |
# Please cite me if you use this code | |
library(Hiiragi2013) | |
# load data | |
data(x) | |
# Show sample Information | |
pData(phenoData(x)) | |
# Show names of columns in sample Information | |
varLabels(x) | |
# We want to subset based on genotype | |
x$genotype | |
#grab indices where genotype == "WT" | |
WT <- grep("WT", x$genotype) | |
WT | |
#This also works | |
WTL <- x$genotype == "WT" | |
WTL | |
#grab only the WT data | |
#these are identical | |
WTdata <- x[,WTL] | |
WTdata2 <- x[,WT] | |
#extract the expression matrix | |
exp_matrix <- Biobase::exprs(x[,WTL]) | |
#recode the data as classes | |
E325classes <- ifelse(WTdata$sampleGroup =="E3.25", 1, 0) | |
#show that we coded them correctly | |
data.frame(WTdata$sampleGroup, E325classes) | |
#add these labels back to the expressionSet | |
WTdata$E325classes <- E325classes | |
#Show we added them back | |
pData(phenoData(WTdata)) | |
#Sample Random columns | |
numSamples <- ncol(WTdata) | |
randomSample <- sample.int(n=numSamples, size=10, replace = FALSE) | |
#confirm that we sampled correctly | |
randomSample | |
#make a new sampled set from the WTdata | |
sampledWT <- WTdata[,randomSample] | |
sampleNames(sampledWT) | |
#Confirm that the classes are correct | |
sampledWT$E325classes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment