2 cat("\014") # clear console
\r
3 setwd("D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela")
\r
4 rm(list=ls(all=T)) # remove r objects
\r
7 update.packages("ona")
\r
9 banana = onaDownload("BCMT_NM2017","seedtracker","megy","megy")
\r
22 flowerID = select(banana, "X_submission_time","X_submitted_by",contains("floweringID")) %>%
\r
23 gather(flowering, flowerID, ends_with("floweringID"), na.rm = T)
\r
24 flowerID$flowering <- NULL
\r
25 flower <- as.data.frame(flowerID$flowerID)
\r
26 flowerName = select(banana, ends_with("flowerName")) %>%
\r
27 gather(flower, accession_name, ends_with("flowerName"), na.rm=T)
\r
28 flowerName$flower <- NULL
\r
29 datetime = as.data.frame(str_split_fixed(flowerID$X_submission_time, "T", 2))
\r
30 flowerIDs = as.data.frame(c(datetime, flowerID, flower, flowerName))
\r
31 flowerIDs$X_submission_time <- NULL
\r
32 colnames(flowerIDs) = c("submit_date","submit_time","submitted_by","flowerID","flower","accession_name")
\r
33 pSex <- select(banana, ends_with("plantSex")) %>%
\r
34 gather(psex, sex, ends_with("plantSex"), na.rm = T)
\r
36 floweringDate <- select(banana, ends_with("flowering_date")) %>%
\r
37 gather(date, flowering_date, ends_with("flowering_date"), na.rm = T)
\r
38 floweringDate$date <- NULL
\r
39 flowered <- as.data.frame(c(flowerIDs, floweringDate, pSex))
\r
40 fDate = as.Date(flowered$flowering_date)
\r
41 fdateLimit = Sys.Date() - 7
\r
42 floweringd = filter(flowered, fDate>=fdateLimit)
\r
43 flowering <- floweringd[order(floweringd$flowering_date),]
\r
44 floweringDF <- write.csv(flowering, file = "flowering.csv", row.names = F)
\r
45 all.flowering <- write.csv(flowered, file = "all_flowering.csv", row.names = F)
\r
48 FPOLLN = select(banana, "X_submission_time","X_submitted_by",ends_with("_gps_latitude"),ends_with("_gps_longitude"), contains("FirstPollination"))
\r
49 parent <- select(FPOLLN,"X_submission_time","X_submitted_by",ends_with("_gps_latitude"),ends_with("_gps_longitude"), ends_with("parent")) %>%
\r
50 gather(parents, parentName, ends_with("parent"), na.rm = T)
\r
51 parent$parents <- NULL
\r
52 First.datetime = as.data.frame(str_split_fixed(parent$X_submission_time, "T", 2))
\r
53 parentID = as.data.frame(str_split_fixed(parent$parentName, "/", 2))
\r
54 colnames(parentID) <- c("mother", "father")
\r
55 femaleID <- as.data.frame(parentID$mother)
\r
56 female.acc.name = select(FPOLLN, ends_with("femaleName"))%>%
\r
57 gather(female, mother.acc.name, ends_with("femaleName"), na.rm=T)
\r
58 female.acc.name$female <- NULL
\r
59 male.acc.name = select(FPOLLN, ends_with("maleAccName"))%>%
\r
60 gather(male, father.acc.name, ends_with("maleAccName"), na.rm=T)
\r
61 male.acc.name$male <- NULL
\r
63 parents = as.data.frame(c(First.datetime, parent, femaleID, parentID, female.acc.name, male.acc.name))
\r
64 parents$X_submission_time <- NULL
\r
65 firstDate <- select(FPOLLN, ends_with("firstpollination_date")) %>%
\r
66 gather(date, firstpollination_date, ends_with("firstpollination_date"), na.rm = T)
\r
67 firstDate$date <- NULL
\r
68 cross <- select(FPOLLN, ends_with("crossID")) %>%
\r
69 gather(cross, crossnumber, ends_with("crossID"), na.rm = T)
\r
71 crossID <- as.data.frame(cross$crossnumber)
\r
72 first_pollination <- as.data.frame(c(parents, cross, firstDate, crossID))
\r
74 colnames(first_pollination) <- c("submission_date","submission_time","submitted_by","latitude","longitude","parentNames","femaleID",
\r
75 "mother","father","mother_accessionName","father_accessionName","crossnumber","firstpollination_date","crossID")
\r
76 firstpollination = as.data.frame(first_pollination[c(1:8,10,9,11:14)])
\r
77 first <- write.csv(firstpollination, file = "firstpollination.csv", row.names = F)
\r
80 # Repeat pollination
\r
81 rpt = select(banana, "X_submission_time","X_submitted_by",contains("repeatpollination"))
\r
83 getCrossID = select(rpt, "X_submission_time","X_submitted_by", ends_with("getCrossID")) %>%
\r
84 gather(cross, crossnumber, ends_with("getCrossID"), na.rm = T)
\r
85 rptMaleID = select(rpt, ends_with("rptMaleID")) %>%
\r
86 gather(rptMale, Male_plotNumber, ends_with("rptMaleID"), na.rm = T)
\r
87 rptMale_AccName = select(rpt, ends_with("getMaleAccName")) %>%
\r
88 gather(rptMale, Male_accessionName, ends_with("getMaleAccName"), na.rm = T)
\r
89 rptPollnDate = select(rpt, ends_with("rptpollination_date")) %>%
\r
90 gather(date, repeatPollinationDate, ends_with("rptpollination_date"), na.rm = T)
\r
92 repeatData <- as.data.frame(c(getCrossID,rptMaleID,rptMale_AccName, rptPollnDate))
\r
93 repeatdf = select(repeatData,"X_submission_time","X_submitted_by","crossnumber","Male_plotNumber","Male_accessionName","repeatPollinationDate")
\r
94 repeat.df = select(repeatData,"crossnumber","Male_plotNumber","Male_accessionName","repeatPollinationDate")
\r
95 repeatdt = data.table(repeat.df)
\r
96 repeatDT = as.data.frame(repeatdt[,number := 1:.N, by = crossnumber])
\r
97 repeatDTwide = reshape(repeatDT,direction = "wide", idvar = "crossnumber", timevar = "number")
\r
98 repeatID = data.frame(repeatDTwide$crossnumber)
\r
99 colnames(repeatID) <- "repeatpollinationID"
\r
100 repeatDT.wide <- data.frame(c(repeatID, repeatDTwide))
\r
101 repeatpollnData <- write.csv(repeatDT.wide, file = "repeatpollination.csv", row.names = F)
\r
104 harVEST = select(banana, "X_submission_time","X_submitted_by",contains("harvesting"))
\r
105 harvestedID = select(harVEST, "X_submission_time","X_submitted_by",ends_with("harvestID")) %>%
\r
106 gather(id, crossnumber, ends_with("harvestID"),na.rm = T)
\r
107 harvestID <- data.frame(harvestedID$crossnumber)
\r
108 harvestdate = select(harVEST, ends_with("harvesting_date")) %>%
\r
109 gather(date, harvesting_date, na.rm = T) %>% select(harvesting_date)
\r
110 hDate = str_replace(harvestdate$harvesting_date, "-", "/")
\r
111 harvestDATE = str_replace(hDate, "-", "/")
\r
112 pollinated_date = select(harVEST, ends_with("pollinated_date")) %>%
\r
113 gather(date, pollinated_date, na.rm=T) %>% select(pollinated_date)
\r
114 pDate = str_replace(pollinated_date$pollinated_date, "-", "/")
\r
115 pollinationDATE = str_replace(pDate, "-", "/")
\r
116 pollination2Harvest = data.frame(pollinationDATE, harvestDATE)
\r
117 pollination2Harvest$days2Maturity <- as.Date(as.character(pollination2Harvest$harvestDATE), format="%Y/%m/%d")-
\r
118 as.Date(as.character(pollination2Harvest$pollinationDATE), format="%Y/%m/%d")
\r
119 ripeningshed = select(banana, ends_with("taken_ripening_shed")) %>%
\r
120 gather(shed, to_ripeningshed, ends_with("taken_ripening_shed"), na.rm = T)
\r
121 harvest.datetime = as.data.frame(str_split_fixed(harvestedID$X_submission_time, "T", 2))
\r
123 harvested = as.data.frame(c(harvest.datetime,harvestedID, harvestID,harvestdate, pollination2Harvest, ripeningshed))
\r
124 harvested$pollinationDATE <- NULL
\r
125 harvested$harvestDATE <- NULL
\r
126 harvested$X_submission_time <- NULL
\r
127 harvestingdf = select(harvested,V1,V2,X_submitted_by, crossnumber,harvestedID.crossnumber, harvesting_date, days2Maturity,to_ripeningshed)
\r
128 colnames(harvestingdf) = c("submission_date","submission_time","submitted_by","crossnumber", "harvestID", "harvesting_date","days_to_maturity","to_ripening_shed")
\r
129 harvest = write.csv(harvestingdf, file = "harvesting.csv", row.names = F)
\r
132 RIPE = select(banana, "X_submission_time","X_submitted_by",contains("ripening"))
\r
133 ripenid = select(RIPE, "X_submission_time","X_submitted_by",ends_with("ripenedID")) %>%
\r
134 gather(ids, crossnumber, ends_with("ripenedID"), na.rm = T)
\r
135 ripenID <- data.frame(ripenid$crossnumber)
\r
136 getHarDate = select(RIPE, ends_with("Harvest_date")) %>%
\r
137 gather(date, dateHarvested, ends_with("Harvest_date"), na.rm = T)
\r
138 dateHarv = str_replace(getHarDate$dateHarvested, "-", "/")
\r
139 dateHarvest = str_replace(dateHarv, "-", "/")
\r
141 ripendate = select(RIPE, ends_with("ripening_date")) %>%
\r
142 gather(date, ripen_date, ends_with("ripening_date"), na.rm = T)
\r
143 dateRipe = str_replace(ripendate$ripen_date, "-", "/")
\r
144 dateRipened = str_replace(dateRipe, "-", "/")
\r
145 Harvest2Ripening = data.frame(dateHarvest, dateRipened)
\r
146 Harvest2Ripening$days_harvest_ripening <- as.Date(as.character(Harvest2Ripening$dateRipened), format="%Y/%m/%d")-
\r
147 as.Date(as.character(Harvest2Ripening$dateHarvest), format="%Y/%m/%d")
\r
148 Harvest2Ripening$dateRipened <- NULL
\r
149 Harvest2Ripening$dateHarvest <- NULL
\r
150 ripen.datetime = as.data.frame(str_split_fixed(ripenid$X_submission_time, "T", 2))
\r
151 ripened = as.data.frame(c(ripen.datetime, ripenid, ripenID,ripendate, Harvest2Ripening))
\r
152 ripened$X_submission_time <- NULL
\r
153 ripeningdf = select(ripened, V1,V2,X_submitted_by,crossnumber, ripenid.crossnumber, ripen_date, days_harvest_ripening)
\r
154 colnames(ripeningdf) = c("submission_date","submission_time","submitted_by","crossnumber", "ripenID","ripen_date","days_harvest_ripening")
\r
156 ripening = write.csv(ripeningdf, file = "ripening.csv", row.names = F)
\r
159 EXTRACTION = select(banana, "X_submission_time", "X_submitted_by", contains("seedExtraction"))
\r
160 extractid = select(EXTRACTION, "X_submission_time", "X_submitted_by", ends_with("extractionID")) %>%
\r
161 gather(extract, crossnumber,ends_with("extractionID"), na.rm = T)
\r
162 extractID <- data.frame(extractid$crossnumber)
\r
163 total = select(banana, ends_with("totalSeedsExtracted")) %>%
\r
164 gather(total, number_seeds, ends_with("totalSeedsExtracted"), na.rm = T)
\r
165 extractdate = select(EXTRACTION, ends_with("extraction_date")) %>%
\r
166 gather(date, seed_extraction_date, ends_with("extraction_date"),na.rm = T)
\r
167 dateExtract = str_replace(extractdate$seed_extraction_date, "-", "/")
\r
168 dateExtrd = str_replace(dateExtract, "-", "/")
\r
170 DateRipen = select(EXTRACTION, ends_with("ripened_date"))%>%
\r
171 gather(date, DateRipen, ends_with("ripened_date"), na.rm=T)
\r
172 dateRip = str_replace(DateRipen$DateRipen, "-", "/")
\r
173 dateRip = str_replace(dateRip, "-", "/")
\r
174 ripen2Extract = data.frame(dateExtrd, dateRip)
\r
175 ripen2Extract$days_ripening_extraction <- as.Date(as.character(ripen2Extract$dateExtrd), format="%Y/%m/%d")-
\r
176 as.Date(as.character(ripen2Extract$dateRip), format="%Y/%m/%d")
\r
177 ripen2Extract$dateExtrd <- NULL
\r
178 ripen2Extract$dateRip <- NULL
\r
179 extr.datetime = as.data.frame(str_split_fixed(extractid$X_submission_time, "T", 2))
\r
180 extracted = as.data.frame(c(extr.datetime,extractid, extractID,extractdate, total, ripen2Extract))
\r
181 extracted$X_submission_time <- NULL
\r
182 extractiondf = select(extracted, V1, V2,X_submitted_by,crossnumber,extractid.crossnumber, seed_extraction_date, number_seeds, days_ripening_extraction)
\r
183 colnames(extractiondf) = c("submission_date","submission_time","submitted_by", "crossnumber", "extractID","seed_extraction_date", "number_seeds",
\r
184 "days_ripening_extraction")
\r
185 extractd = write.csv(extractiondf, file = "extraction.csv", row.names = F)
\r
190 statuses = select(banana, "X_submission_time","X_submitted_by",contains("plantstatus"))
\r
191 stolen.type = select(statuses, ends_with("plant_status")) %>%
\r
192 gather(type, status, ends_with("plant_status"), na.rm = T) %>%
\r
193 filter(status=="bunch_stolen")
\r
194 mother.stolenID = select(statuses, "X_submission_time","X_submitted_by",ends_with("stolen_statusID"))%>%
\r
195 gather(mother.status, motherID, ends_with("stolen_statusID"), na.rm = T)
\r
196 mother.stolen.ID <- data.frame(mother.stolenID$motherID)
\r
197 stolendate = select(statuses, ends_with("stolen_date")) %>%
\r
198 gather(date, stolen_date, ends_with("stolen_date"), na.rm = T)
\r
200 stolen.status.datetime = as.data.frame(str_split_fixed(mother.stolenID$X_submission_time, "T", 2))
\r
201 mother.stolen.status = as.data.frame(c(stolen.status.datetime, mother.stolenID, mother.stolen.ID, stolendate, stolen.type))
\r
202 mother.stolen.status$X_submission_time <- NULL
\r
203 mother.stolendf = select(mother.stolen.status, V1,V2,X_submitted_by, motherID, mother.stolenID.motherID, stolen_date, status)
\r
204 colnames(mother.stolendf) = c("submission_date","submission_time","submitted_by","ID", "statusID","date", "status")
\r
207 cross.stolenID = select(statuses, "X_submission_time","X_submitted_by",ends_with("stolenBunch_statusID"))%>%
\r
208 gather(cross.status, crossID, ends_with("stolenBunch_statusID"), na.rm = T)
\r
209 cross.stolen.ID <- data.frame(cross.stolenID$crossID)
\r
210 if(dim(mother.stolendf)[1]>0 & dim(cross.stolenID)[1]>0){
\r
211 cross.status.datetime = as.data.frame(str_split_fixed(cross.stolenID$X_submission_time, "T", 2))
\r
212 cross.stolen.status = as.data.frame(c(cross.status.datetime, cross.stolenID, cross.stolen.ID, stolendate, stolen.type))
\r
213 cross.stolen.status$X_submission_time <- NULL
\r
214 cross.stolendf = select(cross.stolen.status, V1,V2,X_submitted_by, crossID, cross.stolenID.crossID, stolen_date, status)
\r
215 colnames(cross.stolendf) = c("submission_date","submission_time","submitted_by","ID", "statusID","date", "status")
\r
216 stolendf = rbind(mother.stolendf, cross.stolendf)
\r
218 stolendf = mother.stolendf
\r
221 ########################################################
\r
224 fallen.type = select(statuses, ends_with("plant_status")) %>%
\r
225 gather(type, status, ends_with("plant_status"), na.rm = T) %>%
\r
226 filter(status=="fallen")
\r
227 mother.fallenID = select(statuses, "X_submission_time","X_submitted_by",ends_with("fallen_statusID"))%>%
\r
228 gather(mother.status, motherID, ends_with("fallen_statusID"), na.rm = T)
\r
229 mother.fallen.ID <- data.frame(mother.fallenID$motherID)
\r
230 fallendate = select(statuses, ends_with("fallen_date")) %>%
\r
231 gather(date, fallen_date, ends_with("fallen_date"), na.rm = T)
\r
233 fallen.status.datetime = as.data.frame(str_split_fixed(mother.fallenID$X_submission_time, "T", 2))
\r
234 mother.fallen.status = as.data.frame(c(fallen.status.datetime, mother.fallenID, mother.fallen.ID, fallendate, fallen.type))
\r
235 mother.fallen.status$X_submission_time <- NULL
\r
236 mother.fallendf = select(mother.fallen.status, V1,V2,X_submitted_by, motherID, mother.fallenID.motherID, fallen_date, status)
\r
237 colnames(mother.fallendf) = c("submission_date","submission_time","submitted_by","ID", "statusID","date", "status")
\r
240 cross.fallenID = select(statuses, "X_submission_time","X_submitted_by",ends_with("fallenBunch_statusID"))%>%
\r
241 gather(cross.status, crossID, ends_with("fallenBunch_statusID"), na.rm = T)
\r
242 cross.fallen.ID <- data.frame(cross.fallenID$crossID)
\r
243 if(dim(mother.fallendf)[1]>0 & dim(cross.fallenID)[1]>0){
\r
244 cross.status.datetime = as.data.frame(str_split_fixed(cross.fallenID$X_submission_time, "T", 2))
\r
245 cross.fallen.status = as.data.frame(c(cross.status.datetime, cross.fallenID, cross.fallen.ID, fallendate, fallen.type))
\r
246 cross.fallen.status$X_submission_time <- NULL
\r
247 cross.fallendf = select(cross.fallen.status, V1,V2,X_submitted_by, crossID, cross.fallenID.crossID, fallen_date, status)
\r
248 colnames(cross.fallendf) = c("submission_date","submission_time","submitted_by","ID", "statusID","date", "status")
\r
249 fallendf = rbind(mother.fallendf, cross.fallendf)
\r
251 fallendf = mother.fallendf
\r
255 target = c("has_disease","died","unusual","okay")
\r
256 othertype = select(statuses, ends_with("plant_status")) %>%
\r
257 gather(type, status, ends_with("plant_status"), na.rm = T) %>%
\r
258 filter(status %in% target)
\r
259 otherID = select(statuses, "X_submission_time","X_submitted_by",ends_with("plant_statusID"))%>%
\r
260 gather(status, ID, ends_with("plant_statusID"), na.rm = T)
\r
261 other.ID <- data.frame(otherID$ID)
\r
262 other.date = select(statuses, ends_with("status_Date")) %>%
\r
263 gather(sdate, date, ends_with("status_Date"), na.rm = T)
\r
265 otherstatus.datetime = as.data.frame(str_split_fixed(otherID$X_submission_time, "T", 2))
\r
266 otherstatus = as.data.frame(c(otherstatus.datetime, other.date, otherID, other.ID, other.date, othertype))
\r
267 otherstatus$X_submission_time <- NULL
\r
268 otherdf = select(otherstatus, V1,V2,X_submitted_by, ID, otherID.ID, date, status.1)
\r
269 colnames(otherdf) = c("submission_date","submission_time","submitted_by","ID", "statusID","date", "status")
\r
271 statusDF = rbind(stolendf, fallendf, otherdf)
\r
275 good = select(banana, ends_with("goodSeeds")) %>%
\r
276 gather(good, good_seeds,ends_with("goodSeeds"), na.rm = T)
\r
277 bad = select(banana, ends_with("badSeeds")) %>%
\r
278 gather(bad, bad_seeds, ends_with("badSeeds"),na.rm = T)
\r
279 RESCUED = select(banana, "X_submission_time","X_submitted_by",contains("embryoRescue"))
\r
280 rescueid = select(RESCUED, "X_submission_time","X_submitted_by",ends_with("embryorescueID"))%>%
\r
281 gather(id, crossnumber,ends_with("embryorescueID"), na.rm = T)
\r
282 rescueID <- data.frame(rescueid$crossnumber)
\r
283 rescueseeds = select(RESCUED, ends_with("embryorescue_seeds")) %>%
\r
284 gather(seeds, number_rescued, ends_with("embryorescue_seeds"),na.rm = T)
\r
285 rescuedate = select(RESCUED, ends_with("embryorescue_date"))%>%
\r
286 gather(id, rescue_date,ends_with("embryorescue_date"), na.rm = T)
\r
287 date_Resc = str_replace(rescuedate$rescue_date, "-", "/")
\r
288 dateResc = str_replace(date_Resc, "-", "/")
\r
290 dateEXTRD = select(RESCUED, ends_with("extracted_date")) %>%
\r
291 gather(date, extract_date, ends_with("extracted_date"), na.rm = T)
\r
292 date_EXTRD = str_replace(dateEXTRD$extract_date, "-", "/")
\r
293 dateEXTRD = str_replace(date_EXTRD, "-", "/")
\r
294 Extract2Rescue = data.frame(dateEXTRD, dateResc)
\r
295 Extract2Rescue$days_extraction_rescue <- as.Date(as.character(Extract2Rescue$dateResc), format="%Y/%m/%d")-
\r
296 as.Date(as.character(Extract2Rescue$dateEXTRD), format="%Y/%m/%d")
\r
297 Extract2Rescue$dateEXTRD <- NULL
\r
298 Extract2Rescue$dateResc <-NULL
\r
299 resc.datetime = as.data.frame(str_split_fixed(rescueid$X_submission_time, "T", 2))
\r
300 rescued = as.data.frame(c(resc.datetime,rescueid,rescueID,good, bad, rescuedate, rescueseeds, Extract2Rescue))
\r
301 rescued$X_submission_time <- NULL
\r
302 rescuingdf = select(rescued, V1, V2,X_submitted_by,crossnumber, rescueid.crossnumber, good_seeds, bad_seeds, number_rescued, rescue_date, days_extraction_rescue)
\r
303 colnames(rescuingdf) = c("submission_date","submission_time","submitted_by","crossnumber", "rescueID","good_seeds","badseeds","number_rescued", "rescue_date", "days_extraction_rescue")
\r
304 rescueed = write.csv(rescuingdf, file = "rescued.csv", row.names = F)
\r
306 # 2 WEEKS GERMINATION
\r
307 week2Germination = select(banana,"X_submission_time","X_submitted_by", contains("embryo_germinatn_after_2wks") )
\r
308 twowksID = select(week2Germination, "X_submission_time","X_submitted_by",ends_with("germinating_2wksID")) %>%
\r
309 gather(germinating, crossnumber, ends_with("germinating_2wksID"), na.rm = T)
\r
310 week2ID <- data.frame(twowksID$crossnumber)
\r
311 active2wks = select(week2Germination, ends_with("actively_2wks")) %>%
\r
312 gather(active, actively_germination_after_two_weeks, ends_with("actively_2wks"),na.rm = T)
\r
313 twowksDate = select(week2Germination, ends_with("2wks_date")) %>%
\r
314 gather(date, germination_after_2weeks_date, ends_with("2wks_date"),na.rm = T)
\r
315 date2wk = str_replace(twowksDate$germination_after_2weeks_date, "-", "/")
\r
316 date2wks = str_replace(date2wk, "-", "/")
\r
317 rescDate = select(week2Germination, ends_with("rescued_date")) %>%
\r
318 gather(date, rescuedDate, ends_with("rescued_date"), na.rm = T)
\r
319 dateERescue = str_replace(rescDate$rescuedDate, "-", "/")
\r
320 dateERescued = str_replace(dateERescue, "-", "/")
\r
322 Rescue_2wks = data.frame(date2wks, dateERescued)
\r
323 Rescue_2wks$days_rescue_2wksGermination <- as.Date(as.character(Rescue_2wks$date2wks), format="%Y/%m/%d")-
\r
324 as.Date(as.character(Rescue_2wks$dateERescued), format="%Y/%m/%d")
\r
325 Rescue_2wks$date2wks <- NULL
\r
326 Rescue_2wks$dateERescued <- NULL
\r
327 two.datetime = as.data.frame(str_split_fixed(twowksID$X_submission_time, "T", 2))
\r
328 germination2weeks = as.data.frame(c(two.datetime,twowksID, week2ID, twowksDate, active2wks, Rescue_2wks))
\r
329 germination2weeks$X_submission_time <- NULL
\r
330 germination2weeksdf = select(germination2weeks, V1,V2,X_submitted_by,crossnumber,twowksID.crossnumber, germination_after_2weeks_date, actively_germination_after_two_weeks, days_rescue_2wksGermination)
\r
331 colnames(germination2weeksdf) = c("submission_date","submission_time","submitted_by","crossnumber", "week2ID","germination_after_2weeks_date",
\r
332 "actively_germination_after_two_weeks","days_rescue_2weeksGermination")
\r
333 germ2wks = write.csv(germination2weeksdf, file = "germinating2weeks.csv", row.names = F)
\r
335 # 6 weeks GERMINATION
\r
336 week6 = select(banana,"X_submission_time","X_submitted_by",contains("embryo_germinatn_after_6weeks"))
\r
337 week6ID = select(week6, "X_submission_time","X_submitted_by", ends_with("germinating_6weeksID"))%>%
\r
338 gather(germinating, crossnumber, ends_with("germinating_6weeksID"),na.rm = T)
\r
339 week6.ID <- data.frame(week6ID$crossnumber)
\r
340 active6weeks = select(week6, ends_with("actively_6weeks")) %>%
\r
341 gather(active, actively_germination_after_6weeks, ends_with("actively_6weeks"),na.rm = T)
\r
343 week6Date = select(week6, ends_with("germinating_6weeks_date")) %>%
\r
344 gather(date, germination_after_6weeks_date, ends_with("germinating_6weeks_date"),na.rm = T)
\r
345 date6weeks = str_replace(week6Date$germination_after_6weeks_date, "-", "/")
\r
346 date.6weeks = str_replace(date6weeks, "-", "/")
\r
347 germ2wks_date = select(week6, ends_with("germinated_2wksdate")) %>%
\r
348 gather(date, germ2wksdate, ends_with("germinated_2wksdate"), na.rm = T)
\r
349 germ2wkDate = str_replace(germ2wks_date$germ2wksdate, "-","/")
\r
350 germinated2wksDate = str_replace(germ2wkDate,"-","/")
\r
351 Germination_2wks_6weeks = data.frame(germinated2wksDate, date.6weeks)
\r
352 Germination_2wks_6weeks$days_2weeks_6weeks_Germination <- as.Date(as.character(Germination_2wks_6weeks$date.6weeks), format="%Y/%m/%d")-
\r
353 as.Date(as.character(Germination_2wks_6weeks$germinated2wksDate), format="%Y/%m/%d")
\r
354 Germination_2wks_6weeks$germinated2wksDate <- NULL
\r
355 Germination_2wks_6weeks$dateOneM <- NULL
\r
356 week6.datetime = as.data.frame(str_split_fixed(week6ID$X_submission_time, "T", 2))
\r
357 germination6weeks = as.data.frame(c(week6.datetime,week6ID, week6.ID, week6Date, active6weeks, Germination_2wks_6weeks))
\r
358 germination6weeks$X_submission_time <- NULL
\r
359 germination6weeksdf = select(germination6weeks,V1, V2,X_submitted_by,crossnumber,week6ID.crossnumber, germination_after_6weeks_date, actively_germination_after_6weeks, days_2weeks_6weeks_Germination)
\r
360 colnames(germination6weeksdf) = c("submission_date","submission_time","submitted_by","crossnumber", "week6ID","germination_after_6weeks_date",
\r
361 "actively_germination_after_6weeks", "days_2weeksGermination_6weeksGermination")
\r
362 germ6weeks = write.csv(germination6weeksdf, file = "germinating6weeks.csv", row.names = F)
\r
365 SUBCT = select(banana, "X_submission_time","X_submitted_by", contains("subculturing"))
\r
366 subcultureid = select(SUBCT, "X_submission_time","X_submitted_by", ends_with("subcultureID"))%>%
\r
367 gather(ids, crossnumber, ends_with("subcultureID"), na.rm = T)
\r
368 subcultureID <- data.frame(subcultureid$crossnumber)
\r
369 subcdate = select(SUBCT, ends_with("subculture_date")) %>%
\r
370 gather(date, subculture_date, ends_with("subculture_date"),na.rm = T)
\r
371 subDate = str_replace(subcdate$subculture_date, "-","/")
\r
372 subdDate = str_replace(subDate,"-","/")
\r
373 week6Gdate = select(SUBCT, ends_with("germinated_6weeksdate")) %>%
\r
374 gather(date, week6germDate, ends_with("germinated_6weeksdate"), na.rm = T)
\r
375 week6Date = str_replace(week6Gdate$week6germDate, "-","/")
\r
376 week6.Date = str_replace(week6Date,"-","/")
\r
377 week6Germ_subculture = data.frame(subdDate, week6.Date)
\r
378 week6Germ_subculture$days_6weeks_Germination_subculture <- as.Date(as.character(week6Germ_subculture$subdDate), format="%Y/%m/%d")-
\r
379 as.Date(as.character(week6Germ_subculture$week6.Date), format="%Y/%m/%d")
\r
380 week6Germ_subculture$subdDate <- NULL
\r
381 week6Germ_subculture$monthDate <- NULL
\r
382 subcultures = select(SUBCT, ends_with("multiplicationNumber")) %>%
\r
383 gather(date, subcultures,ends_with("multiplicationNumber"), na.rm = T)
\r
384 sub.datetime = as.data.frame(str_split_fixed(subcultureid$X_submission_time, "T", 2))
\r
385 subculturin = as.data.frame(c(sub.datetime, subcultureid, subcultureID, subcdate, subcultures, week6Germ_subculture))
\r
386 subculturin$X_submission_time <- NULL
\r
387 subculturingdf = select(subculturin, V1, V2, X_submitted_by,crossnumber, subcultureid.crossnumber, subculture_date, subcultures, days_6weeks_Germination_subculture)
\r
388 colnames(subculturingdf) = c("submision_date","submission_time","submitted_by","crossnumber","subcultureID", "subculture_date","subcultures", "days_6weeks_Germination_subculture")
\r
389 #multiplication = select(subculture, ends_with("multiplicationID"))
\r
390 subdata = write.csv(subculturingdf, file = "subculture.csv", row.names = F)
\r
393 if (is.na(SUBCT$Laboratory.subculturing.subcultureID)){
\r
397 subculture_date = NA
\r
398 subIDs = cbind(crossnumber,plantletID, subculture, subculture_date)
\r
399 colnames(subIDs) = c("crossnumber","plantletID", "subculture","subculture_date")
\r
401 subplants = select(SUBCT,ends_with("subculture_date"), ends_with("multiplicationID"))%>%
\r
402 gather(plantlets, subplants, ends_with("multiplicationID"), na.rm=T)
\r
403 subplants$plantlets <- NULL
\r
404 subplants$Laboratory.subculturing.subculture_date <- NULL
\r
405 subID = data.frame(str_sub(subplants$subplants, 1, str_length(subplants$subplants)-4))
\r
406 subIDplants = data.frame(c(subID, subplants))
\r
407 subIDp = subIDplants[,c(1,2,5)]
\r
408 colnames(subIDp) = c("crossnumber","subculture_date", "subculture")
\r
409 subIDp$plantletID <- subIDp$subculture
\r
410 subIDs= subIDp[,c(1,4,3,2)]
\r
412 subplants = write.csv(subIDs, file = "subplants.csv", row.names = F)
\r
415 ROOT = select(banana,"X_submission_time","X_submitted_by",contains("rooting"))
\r
416 rootid = select(ROOT, "X_submission_time","X_submitted_by", ends_with("rootingID")) %>%
\r
417 gather(id, plantletID, ends_with("rootingID"),na.rm = T)
\r
418 rootID <- data.frame(rootid$plantletID)
\r
419 root.datetime = as.data.frame(str_split_fixed(rootid$X_submission_time, "T", 2))
\r
421 rootdate = select(ROOT, ends_with("rooting_date")) %>%
\r
422 gather(date, date_rooting, ends_with("rooting_date"),na.rm = T)
\r
423 rootDate = str_replace(rootdate$date_rooting, "-","/")
\r
424 rDate = str_replace(rootDate,"-","/")
\r
426 sub_date = select(ROOT, ends_with("getSubDate"))%>%
\r
427 gather(date, date_subcultured, ends_with("getSubDate"), na.rm = T)
\r
428 subDate = str_replace(sub_date$date_subcultured, "-","/")
\r
429 sub.date = str_replace(subDate,"-","/")
\r
431 subculture_rooting = data.frame(rDate, sub.date)
\r
432 subculture_rooting$days_subculture_rooting <- as.Date(as.character(subculture_rooting$rDate), format="%Y/%m/%d")-
\r
433 as.Date(as.character(subculture_rooting$sub.date), format="%Y/%m/%d")
\r
434 subculture_rooting$rDate <- NULL
\r
435 subculture_rooting$sub.date <- NULL
\r
437 rootin = as.data.frame(c(root.datetime,rootid, rootID, rootdate, subculture_rooting))
\r
438 rootin$X_submission_time <- NULL
\r
439 rootingdf = select(rootin, V1, V2,X_submitted_by,plantletID, rootid.plantletID, date_rooting, days_subculture_rooting )
\r
440 colnames(rootingdf) = c("submission_date","submission_time","submitted_by","plantletID","rootID", "date_rooting", "days_subculture_rooting")
\r
441 rooted = write.csv(rootingdf, file = "rooting.csv", row.names = F)
\r
445 HOUSE = select(banana, "X_submission_time","X_submitted_by", contains("screenhouse"))
\r
446 transferscrnhseid = select(HOUSE,"X_submission_time","X_submitted_by", ends_with("screenhseID")) %>%
\r
447 gather(id, plantletID,ends_with("screenhseID"), na.rm = T)
\r
448 transferscrnhseID <- data.frame(transferscrnhseid$plantletID)
\r
449 transferdate = select(HOUSE, ends_with("screenhse_transfer_date")) %>%
\r
450 gather(date, date_of_transfer_to_screenhse,ends_with("screenhse_transfer_date"), na.rm = T)
\r
452 dateHSE = str_replace(transferdate$date_of_transfer_to_screenhse, "-", "/")
\r
453 dateHSED = str_replace(dateHSE, "-", "/")
\r
454 rootedDate = select(HOUSE, ends_with("rooted_date")) %>%
\r
455 gather(date, rootdate, ends_with("rooted_date"), na.rm = T)
\r
456 dateRTD = str_replace(rootedDate$rootdate, "-", "/")
\r
457 dateROOTED = str_replace(dateRTD, "-", "/")
\r
458 rooting2Screenhse = data.frame(dateROOTED, dateHSED)
\r
459 rooting2Screenhse$days_rooting_screenhse <- as.Date(as.character(rooting2Screenhse$dateHSED), format="%Y/%m/%d")-
\r
460 as.Date(as.character(rooting2Screenhse$dateROOTED), format="%Y/%m/%d")
\r
461 rooting2Screenhse$dateROOTED <- NULL
\r
462 rooting2Screenhse$dateHSED <- NULL
\r
463 trans.datetime = as.data.frame(str_split_fixed(transferscrnhseid$X_submission_time, "T", 2))
\r
464 transferscreenhse = as.data.frame(c(trans.datetime,transferscrnhseid, transferscrnhseID, transferdate, rooting2Screenhse))
\r
465 transferscreenhse$X_submission_time <- NULL
\r
466 screenhsedf = select(transferscreenhse, V1, V2,X_submitted_by,plantletID,transferscrnhseid.plantletID, date_of_transfer_to_screenhse,days_rooting_screenhse) #transfer to screenhsedf
\r
467 colnames(screenhsedf) = c("submission_date","submission_time","submitted_by","plantletID", "transferscrnhseID","screenhse_transfer_date","days_rooting_screenhse")
\r
468 screenhse = write.csv(screenhsedf, file = "screenhouse.csv", row.names = F)
\r
471 HARD = select(banana, "X_submission_time","X_submitted_by", contains("hardening"))
\r
472 hardenedid = select(HARD,"X_submission_time","X_submitted_by", ends_with("hardeningID")) %>%
\r
473 gather(id, plantletID, ends_with("hardeningID"),na.rm = T)
\r
474 hardenID <- data.frame(hardenedid$plantletID)
\r
475 hardeneddate = select(HARD, ends_with("hardening_date")) %>%
\r
476 gather(date, hardening_date,ends_with("hardening_date"), na.rm = T)
\r
477 dateHARD = str_replace(hardeneddate$hardening_date, "-", "/")
\r
478 dateHARDENED = str_replace(dateHARD, "-", "/")
\r
480 screenhseDATE = select(HARD, ends_with("screenhsed_date")) %>%
\r
481 gather(date, screendate, ends_with("screenhsed_date"), na.rm = T)
\r
482 dateSHSE = str_replace(screenhseDATE$screendate, "-", "/")
\r
483 dateSHSED = str_replace(dateSHSE, "-", "/")
\r
484 screenhse2Hardening = data.frame(dateHARDENED, dateSHSED)
\r
485 screenhse2Hardening$days_scrnhse_hardening <- as.Date(as.character(screenhse2Hardening$dateHARDENED), format="%Y/%m/%d")-
\r
486 as.Date(as.character(screenhse2Hardening$dateSHSED), format="%Y/%m/%d")
\r
487 screenhse2Hardening$dateHARDENED <- NULL
\r
488 screenhse2Hardening$dateSHSED <- NULL
\r
489 harden.datetime = as.data.frame(str_split_fixed(hardenedid$X_submission_time, "T", 2))
\r
490 hardening = as.data.frame(c(harden.datetime,hardenedid,hardenID, hardeneddate, screenhse2Hardening))
\r
491 hardening$X_submission_time <- NULL
\r
492 hardeningdf = select(hardening, V1, V2, X_submitted_by, plantletID, hardenedid.plantletID,hardening_date, days_scrnhse_hardening) ## hardening
\r
493 colnames(hardeningdf) = c("submission_date","submission_time","submitted_by","plantletID","hardenID", "hardening_date", "days_scrnhse_hardening")
\r
494 hardenned = write.csv(hardeningdf, file = "hardening.csv", row.names = F)
\r
497 OPEN = select(banana,"X_submission_time","X_submitted_by", contains("transplant_openfield"))
\r
498 openfield_ID = select(OPEN, "X_submission_time","X_submitted_by",ends_with("openfieldID")) %>%
\r
499 gather(id, plantletID,ends_with("openfieldID"), na.rm = T)
\r
500 openfieldID <- data.frame(openfield_ID$plantletID)
\r
501 opendate = select(OPEN, ends_with("transplanting_date")) %>%
\r
502 gather(date, date_of_transfer_to_openfield, ends_with("transplanting_date"),na.rm = T)
\r
503 dateOPEN = str_replace(opendate$date_of_transfer_to_openfield, "-", "/")
\r
504 dateOPENFD = str_replace(dateOPEN, "-", "/")
\r
506 dateHardd = select(OPEN, ends_with("hardened_date"))%>%
\r
507 gather(date, hard_date, ends_with("hardened_date"), na.rm = T)
\r
508 dateHarder = str_replace(dateHardd$hard_date, "-","/")
\r
509 dateHD = str_replace(dateHarder, "-","/")
\r
510 harden2OField = data.frame(dateOPENFD, dateHD)
\r
511 harden2OField$days_hardening_openfield <- as.Date(as.character(harden2OField$dateOPENFD), format="%Y/%m/%d")-
\r
512 as.Date(as.character(harden2OField$dateHD), format="%Y/%m/%d")
\r
513 harden2OField$dateOPENFD <- NULL
\r
514 harden2OField$dateHD <- NULL
\r
515 open.datetime = as.data.frame(str_split_fixed(openfield_ID$X_submission_time, "T", 2))
\r
516 openfieldtransfer = as.data.frame(c(open.datetime,openfield_ID,openfieldID, opendate, harden2OField))
\r
517 openfieldtransfer$X_submission_time <- NULL
\r
518 openfieldtransferdf = select(openfieldtransfer,V1, V2, X_submitted_by, plantletID,openfield_ID.plantletID,date_of_transfer_to_openfield, days_hardening_openfield) #to open field
\r
519 colnames(openfieldtransferdf) = c("submission_date","submission_time","submitted_by","plantletID", "openfieldID","date_of_transfer_to_openfield",
\r
520 "days_hardening_openfield")
\r
521 openfd = write.csv(openfieldtransferdf, file = "openfield.csv", row.names = F)
\r
523 # Screenhouse status
\r
524 sstatus = select(banana, "X_submission_time","X_submitted_by", contains("screenhse_status"))
\r
525 sstatusDate = select(sstatus, ends_with("scrnhsestatus_Date"))%>%
\r
526 gather(sdate,date, ends_with("scrnhsestatus_Date"), na.rm = T)
\r
527 sstatusDate$sdate <-NULL
\r
528 sstatusID = select(sstatus, "X_submission_time","X_submitted_by", ends_with("scrnhse_statusID"))%>%
\r
529 gather(ssID, statusID, ends_with("scrnhse_statusID"), na.rm = T)
\r
530 sstatusID$ssID <- NULL
\r
531 sstatusID$sstatus_datetime = as.data.frame(str_split_fixed(sstatusID$X_submission_time, "T", 2))
\r
532 sstatusID$X_submission_time <- NULL
\r
533 s.status = select(sstatus, ends_with("scrnhseStatus"))%>%
\r
534 gather(sstatus, status, ends_with("scrnhseStatus"), na.rm = T)
\r
535 s.status$sstatus <- NULL
\r
536 scrnhse.status = data.frame(c(sstatusID, sstatusDate, s.status))
\r
537 scrnhse.status$ID = scrnhse.status$statusID
\r
538 colnames(scrnhse.status) = c("submitted_by", "statusID", "submission_date","submission_time","date","status","ID")
\r
539 select(scrnhse.status, "submission_date","submission_time","submitted_by","ID","statusID","date","status")
\r
541 merged_status = rbind(statusDF, scrnhse.status)
\r
542 merged.status = write.csv(merged_status, file = "status.csv", row.names = F)
\r
545 ContaminID <- select(banana, "X_submission_time","X_submitted_by",ends_with("econtaminationID")) %>%
\r
546 gather(contamination, crossnumber, ends_with("econtaminationID"), na.rm = T)
\r
547 contaminationID <- data.frame(ContaminID$crossnumber)
\r
548 ContaminDate <- select(banana, ends_with("contamination_date")) %>%
\r
549 gather(date, contamination_date, ends_with("contamination_date"), na.rm = T)
\r
550 contam.datetime = as.data.frame(str_split_fixed(ContaminID$X_submission_time, "T", 2))
\r
551 contaminated = select(banana, ends_with("contaminated")) %>%
\r
552 gather(contamination, contaminated, ends_with("contaminated"), na.rm=T)
\r
554 contamination <- as.data.frame(c(contam.datetime,ContaminID, contaminationID, ContaminDate, contaminated)) %>%
\r
555 select(V1,V2,"X_submitted_by", crossnumber,ContaminID.crossnumber, contamination_date, contaminated)
\r
556 colnames(contamination) <- c("submission_date","submission_time","submitted_by","crossnumber","contaminationID","contamination_date","contamination")
\r
557 contamination$time <- NULL
\r
558 contamin <- write.csv(contamination, file = "contamination.csv", row.names = F)
\r
561 allbanana = list(firstpollination, repeatDT.wide, harvestingdf[,4:8], ripeningdf[,4:7], extractiondf[,4:8], rescuingdf[,4:10], germination2weeksdf[,4:8],
\r
562 germination6weeksdf[,4:8], subculturingdf[,4:8])
\r
563 bananadat = Reduce(function(x,y) merge(x,y, all = T, by= "crossnumber"), allbanana)
\r
564 bananadf = select(bananadat, crossnumber, everything())
\r
565 bananadata = bananadf
\r
566 bananadata1 = write.csv(bananadata, file = "bananadata.csv", row.names = F)
\r
569 allplantlets = list(subIDs, rootingdf[,4:7], screenhsedf[,4:7], hardeningdf[,4:7], openfieldtransferdf[,4:7])
\r
570 merge_plantlets = Reduce(function(x,y) merge(x,y, all=T, by = "plantletID"), allplantlets)
\r
571 plantsDF = select(merge_plantlets, crossnumber, plantletID, everything())
\r
572 plantletsdf = write.csv(plantsDF, file = "plantlets.csv", row.names = F)
\r
574 ## EMAIL NOTIFICATIONS
\r
576 # 1. status reported today
\r
578 filter.status = filter(pStatus, status!='okay')
\r
579 sdate = as.Date(filter.status$date)
\r
580 filter.status.date = filter(filter.status, sdate==today)
\r
582 if (dim(filter.status.date)[1]!=0){
\r
583 write.csv(filter.status.date, file = "statusReport.csv", row.names = F)
\r
585 to("karanjamargaret@gmail.com") %>%
\r
586 from("megykah@gmail.com") %>%
\r
587 text_body("Please see the list of accession that have been reported to have a problem today. Bests, Margaret") -> first_part
\r
590 subject("Banana pipeline today status report") %>%
\r
591 attach_file("D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\statusReport.csv") -> file_attachment
\r
593 send_message(file_attachment)
\r
597 dataset <- c(bananadata, firstpollination, harvestingdf, ripeningdf, extractiondf, rescuingdf, germination2weeksdf,
\r
598 germination6weeksdf, subculturingdf, rootingdf, screenhsedf, hardeningdf, openfieldtransferdf)
\r
600 ## POST MEDIA FILES TO ONA
\r
602 raw.result <- GET("https://api.ona.io/api/v1/user.json", authenticate(user = "seedtracker",password = "Seedtracking101"))
\r
603 raw.result.char<-rawToChar(raw.result$content)
\r
604 raw.result.json<-fromJSON(raw.result.char)
\r
605 TOKEN_KEY <- raw.result.json$temp_token
\r
609 meta_flowerid <- readChar("D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\metadata_flowerid.txt", 10)
\r
610 hdr=c(Authorization=paste("Temptoken ",TOKEN_KEY))
\r
611 DELETE(paste("https://api.ona.io/api/v1/metadata/",meta_flowerid),add_headers(Authorization=paste("Temptoken ",TOKEN_KEY)))
\r
614 meta_bananaid <- readChar("D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\metadata_bananaid.txt", 10)
\r
615 hdr=c(Authorization=paste("Temptoken ",TOKEN_KEY))
\r
616 DELETE(paste("https://api.ona.io/api/v1/metadata/",meta_bananaid),add_headers(Authorization=paste("Temptoken ",TOKEN_KEY)))
\r
619 meta_statusID <- readChar("D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\metadata_statusID.txt", 10)
\r
620 hdr=c(Authorization=paste("Temptoken ",TOKEN_KEY))
\r
621 DELETE(paste("https://api.ona.io/api/v1/metadata/",meta_statusID),add_headers(Authorization=paste("Temptoken ",TOKEN_KEY)))
\r
624 meta_contaminationID <- readChar("D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\metadata_contaminationID.txt", 10)
\r
625 hdr=c(Authorization=paste("Temptoken ",TOKEN_KEY))
\r
626 DELETE(paste("https://api.ona.io/api/v1/metadata/",meta_contaminationID),add_headers(Authorization=paste("Temptoken ",TOKEN_KEY)))
\r
629 meta_plantletsID = readChar("D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\metadata_plantletsID.txt", 10)
\r
630 hdr=c(Authorization=paste("Temptoken ",TOKEN_KEY))
\r
631 DELETE(paste("https://api.ona.io/api/v1/metadata/",meta_plantletsID),add_headers(Authorization=paste("Temptoken ",TOKEN_KEY)))
\r
633 ## UPLOAD FLOWERING DATA
\r
634 header=c(Authorization=paste("Temptoken ", TOKEN_KEY), `Content-Type` = 'multipart/form-data')
\r
635 post.flower.results <- postForm("https://api.ona.io/api/v1/metadata.json",
\r
636 data_value='flowering.csv',data_type='media',xform=237289,
\r
637 data_file=fileUpload(filename = "D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\flowering.csv",contentType = 'text/csv'),
\r
638 .opts=list(httpheader=header), verbose = TRUE)
\r
639 # upload bananadata
\r
640 header=c(Authorization=paste("Temptoken ", TOKEN_KEY), `Content-Type` = 'multipart/form-data')
\r
641 post.banana.results <- postForm("https://api.ona.io/api/v1/metadata.json",
\r
642 data_value='bananadata.csv',data_type='media',xform=237289,
\r
643 data_file=fileUpload(filename = "D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\bananadata.csv",contentType = 'text/csv'),
\r
644 .opts=list(httpheader=header), verbose = TRUE)
\r
646 header=c(Authorization=paste("Temptoken ", TOKEN_KEY), `Content-Type` = 'multipart/form-data')
\r
647 post.status.results <- postForm("https://api.ona.io/api/v1/metadata.json",
\r
648 data_value='status.csv',data_type='media',xform=237289,
\r
649 data_file=fileUpload(filename = "D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\status.csv",contentType = 'text/csv'),
\r
650 .opts=list(httpheader=header), verbose = TRUE)
\r
652 # contamination upload
\r
653 header=c(Authorization=paste("Temptoken ", TOKEN_KEY), `Content-Type` = 'multipart/form-data')
\r
654 post.contamination.results <- postForm("https://api.ona.io/api/v1/metadata.json",
\r
655 data_value='contamination.csv',data_type='media',xform=237289,
\r
656 data_file=fileUpload(filename = "D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\contamination.csv",contentType = 'text/csv'),
\r
657 .opts=list(httpheader=header), verbose = TRUE)
\r
660 header=c(Authorization=paste("Temptoken ", TOKEN_KEY), `Content-Type` = 'multipart/form-data')
\r
661 post.plantlets.results <- postForm("https://api.ona.io/api/v1/metadata.json",
\r
662 data_value='plantlets.csv',data_type='media',xform=237289,
\r
663 data_file=fileUpload(filename = "D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\plantlets.csv",contentType = 'text/csv'),
\r
664 .opts=list(httpheader=header), verbose = TRUE)
\r
665 D:\github\ODK_bananaCrossingTool\Nelson Mandela
\r
669 flower.raw.result.json<-fromJSON(post.flower.results)
\r
670 metadata_flowerid <- flower.raw.result.json$id
\r
671 meta_flower <- cat(metadata_flowerid, file = "D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\metadata_flowerid.txt")
\r
674 banana.raw.result.json<-fromJSON(post.banana.results)
\r
675 metadata_bananaid <- banana.raw.result.json$id
\r
676 meta_flower <- cat(metadata_bananaid, file = "D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\metadata_bananaid.txt")
\r
679 status.raw.result.json<-fromJSON(post.status.results)
\r
680 metadata_statusid <- status.raw.result.json$id
\r
681 meta_status <- cat(metadata_statusid, file = "D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\metadata_statusID.txt")
\r
683 # get contamination ID
\r
684 contamination.raw.result.json<-fromJSON(post.contamination.results)
\r
685 metadata_contaminationid <- contamination.raw.result.json$id
\r
686 meta_contamination <- cat(metadata_contaminationid, file = "D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\metadata_contaminationID.txt")
\r
688 # get subplantlets ID
\r
689 plantlets.raw.result.json<-fromJSON(post.plantlets.results)
\r
690 metadata_plantletsid <- plantlets.raw.result.json$id
\r
691 meta_plantlets <- cat(metadata_plantletsid, file = "D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\metadata_plantletsID.txt")
\r
694 # organize shiny app data
\r
697 nFlower = strrep(c("Arusha","flowering"),1)
\r
698 if (dim(flowered)[1]!=0){
\r
699 flower = data.frame(c(nFlower, flowered))
\r
700 flowered <- select(flower, "X.Arusha.","X.flowering.","accession_name", "submit_date", "submitted_by")
\r
701 colnames(flowered) <- c("location","activity","accession","date","contributor")
\r
703 flowered <- data.frame(0)
\r
707 nFirst = strrep(c("Arusha","firstpollination"), 1)
\r
708 if(dim(firstpollination)[1]!=0) {
\r
709 first = data.frame(c(nFirst, firstpollination))
\r
710 first_pollinationed = select(first,"X.Arusha.","X.firstpollination.", "crossnumber", "submission_date", "submitted_by")
\r
711 colnames(first_pollinationed) = c("location","activity","accession","date","contributor")
\r
713 first_pollinationed <- data.frame(0)
\r
717 nRepeat = strrep(c("Arusha","repeatpollination"), 1)
\r
718 if(dim(repeatdf)[1]!=0) {
\r
719 repeatP = data.frame(c(nRepeat, repeatdf))
\r
720 repeat_pollinationed = select(repeatP,"X.Arusha.","X.repeatpollination.", "crossnumber", "repeatPollinationDate","X_submitted_by")
\r
721 colnames(repeat_pollinationed) = c("location","activity","accession","date","contributor")
\r
723 repeat_pollinationed <- data.frame(0)
\r
727 nHarvest = strrep(c("Arusha","harvested"), 1)
\r
728 if(dim(harvestingdf)[1]!=0){
\r
729 Harvest = data.frame(c(nHarvest,harvestingdf))
\r
730 harvestdf = select(Harvest,"X.Arusha.", "X.harvested.", "crossnumber", "harvesting_date", "submitted_by")
\r
731 colnames(harvestdf) = c("location","activity","accession","date","contributor")
\r
733 harvestdf <- data.frame(0)
\r
737 nRipen = strrep(c("Arusha","ripened"), 1)
\r
738 if(dim(ripeningdf)[1]!=0){
\r
739 ripenD = data.frame(c(nRipen,ripeningdf))
\r
740 ripendf = select(ripenD,"X.Arusha.", "X.ripened.", "crossnumber", "ripen_date", "submitted_by")
\r
741 colnames(ripendf) = c("location","activity","accession","date","contributor")
\r
743 ripendf <- data.frame(0)
\r
747 nExtr = strrep(c("Arusha","extracted"), 1)
\r
748 if(dim(extractiondf)[1]!=0){
\r
749 Extr = as.data.frame(c(nExtr,extractiondf))
\r
750 extracted <- select(Extr,"X.Arusha.", "X.extracted.", "crossnumber", "seed_extraction_date", "submitted_by")
\r
751 colnames(extracted) <- c("location","activity","accession","date","contributor")
\r
753 extracted <- data.frame(0)
\r
756 nRescue = strrep(c("Arusha","embryrescued"), 1)
\r
757 if(dim(rescuingdf)[1]!=0){
\r
758 Rescue = as.data.frame(c(nRescue,rescuingdf))
\r
759 rescued <- select(Rescue,"X.Arusha.", "X.embryrescued.", "crossnumber", "rescue_date", "submitted_by")
\r
760 colnames(rescued) <- c("location","activity","accession","date","contributor")
\r
762 rescued <- data.frame(0)
\r
764 # Germinated after 2wks
\r
765 n2Wks = strrep(c("Arusha","germinated after 2 weeks"), 1)
\r
766 if(dim(germination2weeksdf)[1]!=0){
\r
767 G2wk = as.data.frame(c(n2Wks,germination2weeksdf))
\r
768 germinated_2weeks <- select(G2wk, "X.Arusha.","X.germinated.after.2.weeks.", "crossnumber", "germination_after_2weeks_date", "submitted_by")
\r
769 colnames(germinated_2weeks) <- c("location","activity","accession","date","contributor")
\r
771 germinated_2weeks <- data.frame(0)
\r
774 # Germinated after 6weeks
\r
775 n6weeks = strrep(c("Arusha","germinated after 6 weeks"), 1)
\r
776 if(dim(germination6weeksdf)[1]!=0){
\r
777 G6weeks = as.data.frame(c(n6weeks,germination6weeksdf))
\r
778 germinated_6weeks <- select(G6weeks,"X.Arusha.", "X.germinated.after.6.weeks.", "crossnumber", "germination_after_6weeks_date", "submitted_by")
\r
779 colnames(germinated_6weeks) <- c("location","activity","accession","date","contributor")
\r
781 germinated_6weeks <- data.frame(0)
\r
784 nSub = strrep(c("Arusha","subcultured"), 1)
\r
785 if(dim(subculturingdf)[1]!=0){
\r
786 Sub = as.data.frame(c(nSub,subculturingdf))
\r
787 subculturing <- select(Sub, "X.Arusha.","X.subcultured.", "crossnumber", "subculture_date", "submitted_by")
\r
788 colnames(subculturing) <- c("location","activity","accession","date","contributor")
\r
790 subculturing <- data.frame(0)
\r
793 nRoot = strrep(c("Arusha","rooted"), 1)
\r
794 if(dim(rootingdf)[1]!=0){
\r
795 Root = as.data.frame(c(nRoot,rootingdf))
\r
796 rooted <- select(Root, "X.Arusha.","X.rooted.", "plantletID", "date_rooting", "submitted_by")
\r
797 colnames(rooted) <- c("location","activity","accession","date","contributor")
\r
799 rooted <- data.frame(0)
\r
802 n.Shse = strrep(c("Arusha","screenhouse"), 1)
\r
803 if(dim(screenhsedf)[1]!=0){
\r
804 S.hse = as.data.frame(c(n.Shse,screenhsedf))
\r
805 screen_housed <- select(S.hse,"X.Arusha.", "X.screenhouse.", "plantletID", "screenhse_transfer_date", "submitted_by")
\r
806 colnames(screen_housed) <- c("location","activity","accession","date","contributor")
\r
808 screen_housed <- data.frame(0)
\r
811 nHard = strrep(c("Arusha","hardened"), 1)
\r
812 if(dim(hardeningdf)[1]!=0){
\r
813 Hard = as.data.frame(c(nHard,hardeningdf))
\r
814 hardened <- select(Hard,"X.Arusha.", "X.hardened.", "plantletID", "hardening_date", "submitted_by")
\r
815 colnames(hardened) <- c("location","activity","accession","date","contributor")
\r
817 hardened <- data.frame(0)
\r
821 nOpn = strrep(c("Arusha","openfield"), 1)
\r
822 if(dim(openfieldtransferdf)[1]!=0){
\r
823 opn = as.data.frame(c(nOpn,openfieldtransferdf))
\r
824 open_field <- select(opn, "X.Arusha.","X.openfield.", "plantletID", "date_of_transfer_to_openfield", "submitted_by")
\r
825 colnames(open_field) <- c("location","activity","accession","date","contributor")
\r
827 open_field <- data.frame(0)
\r
830 nStatus = strrep(c("Arusha","status"), 1)
\r
831 if(dim(statusDF)[1]!=0){
\r
832 sta = as.data.frame(c(nStatus,statusDF))
\r
833 statusD <- select(sta, "X.Arusha.","X.status.", "statusID", "date", "submitted_by")
\r
834 colnames(statusD) <- c("location","activity","accession","date","contributor")
\r
836 statusD <- data.frame(0)
\r
839 mylist <- list(flowered,first_pollinationed,repeat_pollinationed, harvestdf,ripendf, extracted,rescued,germinated_2weeks,germinated_6weeks,
\r
840 subculturing,rooted,screen_housed,hardened,open_field, statusD)
\r
842 for (i in 2:length(mylist)) {
\r
843 r <- merge(r, mylist[[i]], all=TRUE)
\r
846 cleanTable = write.csv(r, file = "D:\\github\\ODK_bananaCrossingTool\\Nelson Mandela\\cleantable.csv", row.names = F)
\r
848 # NUMBER OF ACCESSION IN DIFFERENT STAGES OF PROJECT
\r
849 all_crosses <- bananadata %>% select("crossnumber","repeatPollinationDate.1","harvesting_date", "ripen_date","seed_extraction_date","rescue_date","germination_after_2weeks_date",
\r
850 "germination_after_6weeks_date","subculture_date")
\r
851 nrows<-dim(all_crosses)[1]
\r
853 repeatpollination=0
\r
858 germinatingafter2weeks=0
\r
859 germinatingafter1month=0
\r
863 if (is.na(all_crosses$repeatPollinationDate.1[i])){
\r
864 firstpollination<-firstpollination+1
\r
867 if(is.na(all_crosses$harvesting_date[i]) & all_crosses$repeatPollinationDate.1[i]!="NULL") {
\r
868 repeatpollination<-repeatpollination+1
\r
871 if(is.na(all_crosses$ripen_date[i]) & all_crosses$harvesting_date[i]!="NULL"){
\r
872 harvested <- harvested+1
\r
875 if(is.na(all_crosses$seed_extraction_date[i]) & all_crosses$ripen_date[i]!="NULL"){
\r
876 ripening <- ripening+1
\r
879 if(is.na(all_crosses$rescue_date[i]) & all_crosses$seed_extraction_date[i]!="NULL"){
\r
880 seedextraction = seedextraction+1
\r
883 if(is.na(all_crosses$germination_after_2weeks_date[i]) & all_crosses$rescue_date[i]!="NULL"){
\r
884 embryorescue = embryorescue+1
\r
887 if(is.na(all_crosses$germination_after_6weeks_date[i]) & all_crosses$germination_after_2weeks_date[i]!="NULL"){
\r
888 germinatingafter2weeks = germinatingafter2weeks+1
\r
891 if(is.na(all_crosses$subculture_date[i]) & all_crosses$germination_after_6weeks_date[i]!="NULL"){
\r
892 germinatingafter1month = germinatingafter1month+1
\r
903 all_plantlets = plantsDF %>% select("crossnumber","plantletID","subculture_date","date_rooting","screenhse_transfer_date",
\r
904 "hardening_date","date_of_transfer_to_openfield")
\r
905 nplants = dim(all_plantlets)[1]
\r
913 for(i in 1:nplants){
\r
914 if (is.na(all_plantlets$date_rooting[i])){
\r
915 subcultures=subcultures+1
\r
918 if(is.na(all_plantlets$screenhse_transfer_date[i]) & all_plantlets$date_rooting[i]!="NULL") {
\r
922 if(is.na(all_plantlets$hardening_date[i]) & all_plantlets$screenhse_transfer_date[i]!="NULL"){
\r
923 screenhouse=screenhouse+1
\r
926 if(is.na(all_plantlets$date_of_transfer_to_openfield[i]) & all_plantlets$hardening_date[i]!="NULL"){
\r
927 hardening = hardening+1
\r
930 if(all_plantlets$date_of_transfer_to_openfield[i]!="NULL"){
\r
931 openfield = openfield+1
\r
941 in_activity = c("firstpollination","repeatpollination","harvested","ripening","seedextraction","embryorescue",
\r
942 "germinatingafter2weeks","germinatingafter1month","subculture","rooting","screenhouse","hardening","openfield")
\r
943 number = c(firstpollination,repeatpollination,harvested,ripening,seedextraction,embryorescue,
\r
944 germinatingafter2weeks,germinatingafter1month,subculture,rooting,screenhouse,hardening,openfield)
\r
945 nTable = as.data.frame(cbind(in_activity, number))
\r
946 n.Table = write.csv(nTable, file="nTable.csv", row.names = F)
\r