-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMariana_larval_counts_BCODMO.R
55 lines (43 loc) · 2.19 KB
/
Mariana_larval_counts_BCODMO.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
# Mariana 2010 pumps matched to World Register of Marine Species for submitting data to BCO-DMO
# Stace Beaulieu
# 2022-02-22
#
# Input files:
# Mariana_2010_pumps_WORKING-COPY_20220221.xlsx downloaded from Google sheet
# Mariana_providedname_20220212_matched.txt output from WoRMS Taxon Match GUI
# Output file:
# Mariana_larval_counts_BCODMO.csv
###Import libraries
library(readxl)
library(dplyr) # for select and join
library(magrittr) # for pipe
library(readr) # for write_csv
###Import data
# input files in working directory
larval_counts_input <- read_excel("Mariana_2010_pumps_WORKING-COPY_20220221.xlsx", sheet = "larval_counts", skip=8)
# Skip specifies the number of rows to be skipped before reading
WoRMS_input <- read.delim("Mariana_providedname_20220212_matched.txt")
# using base R
WoRMS_input <- WoRMS_input %>% mutate_all(na_if,"")
# change blanks to NAs
###Exclude some columns before joining
larval_counts <- select(larval_counts_input,-"Size Fraction",-"...9",-"...10",-"Total...29", -"Total...30", -"Total...31", -"Total...32", -"Total...33", -"Total...34")
WoRMS <- WoRMS_input %>% select("ScientificName","LSID","Kingdom","Phylum","Class","Order","Family","Genus","Species")
# providedname is what I provided to the WoRMS Taxon Match tool, and
# ScientificName is what was output from that tool matched to LSID
# all providedname were exact matches to ScientificName
###Inspect tables
summary(larval_counts) # class character due to taxa with presence absence
summary(WoRMS)
###Join tables
larval_counts_WoRMS <- cbind(larval_counts, WoRMS)
# can't use join per se due to repeated rows in the WoRMS table
# retain WoRMS ScientifcName to be able to test exact match
larval_counts_WoRMS$boolean <- with(larval_counts_WoRMS, scientificName == ScientificName)
###Inspect the boolean for equivalence
###Move a column, exclude a column
# the data product for BCODMO will use the camel case Darwin Core term scientificName
Mariana_larval_counts_BCODMO <- larval_counts_WoRMS %>% select(-ScientificName,-boolean) %>%
relocate(LSID, .before = taxonRank)
###Output file
write_csv(Mariana_larval_counts_BCODMO, "c:/Users/sbeaulieu/Desktop/Mariana_larval_counts_BCODMO.csv") # give this a date when generated