-
Notifications
You must be signed in to change notification settings - Fork 9
/
fun_processing.R
142 lines (131 loc) · 5.84 KB
/
fun_processing.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
read_fun <- function(){
fun2fun<-read.csv("data/funToTheFun.csv")
fun2fun <- tidyr::spread(fun2fun,key = trait_name,value = value,convert = TRUE)
return(fun2fun)
}
fun_to_counts<- function(fun2fun) {
#get rid of variables not used
fun2fun <- fun2fun[,-which(names(fun2fun) %in% c("obj_id","species","studyName","Genus","culture_media","studyName","source_funguild_fg","notes_fg","longitude","latitude","higher_clade"))]
#change charater columns to all be "1"
fun2fun[which(names(fun2fun)!="speciesMatched")][!is.na(fun2fun[which(names(fun2fun)!="speciesMatched")])] <- 1
#change charater columns to integers
fun2fun %>%
group_by(speciesMatched) %>%
mutate_if(is.character,as.numeric)->fun2fun
#collapse to species
fun2fun %>%
group_by(speciesMatched) %>%
summarise_all(sum)->fun2fun
#make categories by trait type (i.e. physio, morpho, enzyme, omics)
fun2fun %>%
#rowwise will make sure the sum operation will occur on each row
rowwise() %>%
#then a simple sum(..., na.rm=TRUE) is enough to result in what you need
mutate(morpho = sum(spore_width,
spore_length,
spore_size,
ascoma_development,
ascus_dehiscence,
ascoma_type,
fruiting_body_size, na.rm=TRUE)) -> fun2fun
fun2fun %>%
#rowwise will make sure the sum operation will occur on each row
rowwise() %>%
#then a simple sum(..., na.rm=TRUE) is enough to result in what you need
mutate(enzymatic = sum(cellobiohydrolase,
beta_glucosidase,
alpha_glucosidase,
n_acetyl_glucosaminidase,
beta_xylosidase,
acid_phosphatase,
beta_glucuronidase,
leucine_aminopeptidase,
phenol_oxidase,
peroxidase,
Cohens_d_Glucose,
Cohens_d_Cellulose, na.rm=TRUE)) -> fun2fun
fun2fun %>%
#rowwise will make sure the sum operation will occur on each row
rowwise() %>%
#then a simple sum(..., na.rm=TRUE) is enough to result in what you need
mutate(stochio = sum(tissue_cn,
tissue_cp,
tissue_np,
sporocarp_N,
sporocarp_protein,
sporocarp_chitin,
melanin_content,
Cohens_d_Xylan,
Cohens_d_Lignin,
Cohens_d_Tannin,na.rm=TRUE)) -> fun2fun
fun2fun %>%
#rowwise will make sure the sum operation will occur on each row
rowwise() %>%
#then a simple sum(..., na.rm=TRUE) is enough to result in what you need
mutate(physio = sum(sporocarp_resp,na.rm=TRUE)) -> fun2fun
fun2fun %>%
#rowwise will make sure the sum operation will occur on each row
rowwise() %>%
#then a simple sum(..., na.rm=TRUE) is enough to result in what you need
mutate(gene = sum(dsDNA,
aminoAcidPermease_count,
ammoniumTransporter_count,
auxinResponsivePromoter_count,
betaGlucanSynthase_count,
chitinase_count,
coldShockProtein_count,
fungalLigninPeroxidase_count,
betaGlucosidase1_count,
endoglucanase12_count,
alphaGlucosidase15_count,
alphaGlucosidase31_count,
invertase32_count,
betaXylosidase43_count,
cellobiohydrolase6_count,
crystalineCellulaseAA9_count,
cellobiohydrolase7_count,
alphaMannanase76_count,
chitosanase8_count,
glucosidase81_count,
glycopeptidase85_count,
amylase88_count,
endoglucanase9_count,
glycoproteinSynthesis92_count,
heatShockProtein_count,
melanin_count,
nitrateTransporter_count,
acidPhosphatase_count,
phosphateTransporter_count,
RNAHelicase_count,
total_genes,
trehalase_count,
RNApolymerase_count,na.rm=TRUE)) -> fun2fun
fun2fun %>%
#rowwise will make sure the sum operation will occur on each row
rowwise() %>%
#then a simple sum(..., na.rm=TRUE) is enough to result in what you need
mutate(life_his = sum(extension_rate,
em_expl,
em_text,
growth_form_fg,
guild_fg,
trophic_mode_fg,na.rm=TRUE)) -> fun2fun
fun2fun_spp_count <- fun2fun[,which(names(fun2fun) %in% c("gene","physio","life_his","morpho","enzymatic","stochio","speciesMatched"))]
return(fun2fun_spp_count)
}
fun_to_binary <- function(fun2fun_spp_count){
fun2fun<-fun2fun_spp_count
fun2fun[fun2fun == 0] <- NA
fun2fun<- as.data.frame(fun2fun)
rownames(fun2fun)<-fun2fun$speciesMatched
fun2fun <- fun2fun[-which(names(fun2fun)=="speciesMatched")]
fun2fun[which(names(fun2fun)!="speciesMatched")][!is.na(fun2fun[which(names(fun2fun)!="speciesMatched")])] <- 1
fun2fun$morpho[fun2fun$morpho==1]="morpho"
fun2fun$enzymatic[fun2fun$enzymatic==1]="enz"
fun2fun$stochio[fun2fun$stochio==1]="stochio"
fun2fun$physio[fun2fun$physio==1]="phys"
fun2fun$life_his[fun2fun$life_his==1]="life_his"
fun2fun$gene[fun2fun$gene==1]="gene"
fun2fun_binary<-fun2fun
return(fun2fun_binary)
}