-
Notifications
You must be signed in to change notification settings - Fork 0
/
StandardizeLabels.r
57 lines (50 loc) · 3.03 KB
/
StandardizeLabels.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Helper function to standardize sample and treatment labels (so don't have to recode in each script)
library(phyloseq)
# Takes a phyloseq object and standardizes sample.type and treatment columns of the metadata (sample_data)
standardize_labels = function(mydata, type=c('extraction','amplification')){
metadata = sample_data(mydata)
if(is.null(type)){
stop("No type given for standardizing labels")
}else if(type=='extraction'){
metadata$sample.type = sapply(as.character(metadata$sample.type), switch,
"Leaf-Arabidopsis"="Arabidopsis Leaf",
"Leaf-Corn"="Maize Leaf",
"Leaf-Soybean"="Soybean Leaf",
"Soil-Soil SS1"="Soil",
NA) # NA catches anything that didn't match
metadata$sample.type = factor(metadata$sample.type, levels=c("Arabidopsis Leaf", "Maize Leaf", "Soybean Leaf", "Soil"))
metadata$treatment = sapply(as.character(metadata$treatment), switch,
ExtracNAmp="ExtractNAmp",
MoBioPowerSoil="PowerSoil",
QiagenDNeasyPlant="DNeasyPlant",
ZymoEasyDna = "EasyDNA",
KazuBuffer = "KazuBuffer",
NA) # NA catches anything that didn't match
metadata$treatment = factor(metadata$treatment)
}
else if(type=='amplification'){
metadata$sample.type = sapply(as.character(metadata$sample.type), switch,
"leaf-maize"="Maize Leaf",
"leaf-soybean"="Soybean Leaf",
"defined-community"="Defined Community",
"soil-clay"="Soil 1",
"soil-flowerbed"="Soil 2",
"blank"="blank",
"water"="water",
NA) # NA catches anything that didn't match
metadata$sample.type = factor(metadata$sample.type)
metadata$treatment = sapply(as.character(metadata$treatment), switch,
BlockingOligos_v3v4="BO_3/4",
BlockingOligos_v5v7="BO_5/7",
BlockingOligos_v5v7_noLinkers="BO_5/7",
Discriminating = "Discriminating",
PNAs= "PNA",
Universal="Universal",
NA) # NA catches anything that didn't match
metadata$treatment = factor(metadata$treatment)
}else{
stop("Illegal sample type provided to standardize_labels")
}
sample_data(mydata) = metadata
return(mydata)
}