-
Notifications
You must be signed in to change notification settings - Fork 0
/
urbmigmalavi_02 trait merge_C_noLeuco.R
173 lines (136 loc) · 4.44 KB
/
urbmigmalavi_02 trait merge_C_noLeuco.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
## MalAvi, urbanization, migration
## 02_trait merge
## last updated 4/4/2023
## clean environment & plots
rm(list=ls())
graphics.off()
gc()
## libraries
library(readxl)
library(reshape2)
## read in edgelist
setwd("~/Documents/Github/urbmigmalavi/flat files")
edge=read.csv("MalAvi edgelist.csv")
data=edge
#trim off Leuco
subsetted_data <- data[data$parasiteGenus != "Leucocytozoon", ]
data=subsetted_data
#export edgelist with no Leuco
write.csv(data,"MalAvi edgelist_noLeuco.csv")
## alternative lineage to NA
data$Alt_Lineage_Name=as.character(data$Alt_Lineage_Name)
data$Alt_Lineage_Name=ifelse(data$Alt_Lineage_Name=="",NA,data$Alt_Lineage_Name)
## collapse into host data
lset=list()
for(i in 1:length(unique(data$tip))){
## subset
set=data[data$tip%in%unique(data$tip)[i],]
## collapse lineage
nset=data.frame(tip=unique(data$tip)[i],
lineages=paste(set$Lineage_Name,collapse=", "),
alt_lineages=paste(set$Alt_Lineage_Name[!is.na(set$Alt_Lineage_Name)],collapse=", "))
lset[[i]]=nset
}
## collapse
data=do.call(rbind.data.frame,lset)
rm(lset,nset,set,i)
## load AVONET
#setwd("/Users/danielbecker/OneDrive - University of Oklahoma/Becker Lab/Datasets/AVONET")
setwd("/Users/taylorverrett/Documents/GitHub/urbmigmalavi/AVONET")
avonet=read_excel("AVONET Supplementary dataset 1.xlsx",4)
## check name
mis=setdiff(data$tip,avonet$Species3)
## fix label
avonet$tip=avonet$Species3
## merge
data=merge(data,avonet,by="tip",all.x=T)
## load BirdTree taxonomy
#setwd("~/OneDrive - University of Oklahoma/Becker Lab/Datasets/BirdTree")
setwd("/Users/taylorverrett/Documents/GitHub/urbmigmalavi/BirdTree")
pnames=read.csv("BLIOCPhyloMasterTax.csv")
## check mismatch
mis=setdiff(data$tip,pnames$Scientific)
## merge
pnames$tip=pnames$Scientific
data=merge(data,pnames,by="tip",all.x=T)
rm(mis,pnames)
## Merge in Gonzalez-Lagos et al. 2022 (urban traits)
setwd("/Users/taylorverrett/Documents/GitHub/urbmigmalavi/Gonzalez-Lagos et al 2021 Ecography")
gdata=read.csv("DataS1.csv")
## fix
gdata$tip=gsub("_"," ",gdata$animal)
## check name
mis=setdiff(data$tip,gdata$tip)
## fix synonyms
rownames(gdata)=gdata$tip
## Acrocephalus baeticatus/Acrocephalus scirpaceus
new=gdata["Acrocephalus scirpaceus",]
new$tip="Acrocephalus baeticatus"
rownames(new)=new$tip
gdata=rbind.data.frame(gdata,new)
## Otus lempiji/Otus bakkamoena
new=gdata["Otus bakkamoena",]
new$tip="Otus lempiji"
rownames(new)=new$tip
gdata=rbind.data.frame(gdata,new)
## Otus lettia/Otus bakkamoena
new=gdata["Otus bakkamoena",]
new$tip="Otus lettia"
rownames(new)=new$tip
gdata=rbind.data.frame(gdata,new)
## Parus caeruleus/Parus teneriffae
new=gdata["Parus caeruleus",]
new$tip="Parus teneriffae"
rownames(new)=new$tip
gdata=rbind.data.frame(gdata,new)
## Turdus nigriceps/Turdus subalaris
new=gdata["Turdus nigriceps",]
new$tip="Turdus subalaris"
rownames(new)=new$tip
gdata=rbind.data.frame(gdata,new)
## Poospiza nigrorufa/Poospiza whitii
new=gdata["Poospiza nigrorufa",]
new$tip="Poospiza whitii"
rownames(new)=new$tip
gdata=rbind.data.frame(gdata,new)
## Momotus aequatorialis/Momotus momota
new=gdata["Momotus momota",]
new$tip="Momotus aequatorialis"
rownames(new)=new$tip
gdata=rbind.data.frame(gdata,new)
## Nectarinia ludovicensis/Cinnyris ludovicensis
new=gdata["Cinnyris ludovicensis",]
new$tip="Nectarinia ludovicensis"
rownames(new)=new$tip
gdata=rbind.data.frame(gdata,new)
## Phylloscopus nitidus/Phylloscopus trochiloides
new=gdata["Phylloscopus trochiloides",]
new$tip="Phylloscopus nitidus"
rownames(new)=new$tip
gdata=rbind.data.frame(gdata,new)
## check name
mis=setdiff(data$tip,gdata$tip)
rm(mis,new)
## clean trait data
gdata=gdata[c("tip","urban","humanDisturbed", "UTI", "tolerance")]
## merge
data=merge(data,gdata,by="tip",all.x=T)
rm(gdata,avonet)
## as factor
data$urban=factor(data$urban)
data$humanDisturbed=factor(data$humanDisturbed)
data$Migration=factor(data$Migration)
data$tolerance=factor(data$tolerance)
## export cleaned data
#setwd("~/Desktop/urbmigmalavi/flat files")
setwd("/Users/taylorverrett/Documents/GitHub/urbmigmalavi/flat files")
write.csv(data,"MalAvi hosts with traits_cleaned_C_noLeuco.csv")
## pull lineages
ldata=edge
ldata=ldata[!duplicated(ldata$Lineage_Name),]
ldata=ldata[c("Lineage_Name","Alt_Lineage_Name","parasiteGenus")]
## export
#setwd("~/Desktop/urbmigmalavi/flat files")
setwd("/Users/taylorverrett/Documents/GitHub/urbmigmalavi/flat files")
write.csv(ldata,"MalAvi lineages cleaned_C_noLeuco.csv")