Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small edits in fig + rename #5

Merged
merged 2 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ write.csv(table, file="concept_mapping_coverage.csv", row.names = FALSE)

# Coverage plot like fig 6 in EHDEN DoA
# note: coverage is percentage NOT failing to map
coverage_results %>%
fig <- coverage_results %>%
# To keep things simple, we only look at the six main domains and units
filter(domainField %in% c("VISIT", "PROCEDURE", "DRUG", "CONDITION", "MEASUREMENT",
"OBSERVATION", "MEAS-UNIT", "OBS-UNIT")
Expand All @@ -69,20 +69,19 @@ coverage_results %>%
geom_col() +
geom_text(aes(label=scales::percent(coveragePct, accuracy = 0.01)),
position=position_stack(vjust=0.5),
size=3, colour="white", fontface="bold") +
size=3, colour="gray10", fontface="bold") +
theme_minimal() +
theme(
axis.text.y=element_text(size=10),
strip.placement="outside",
strip.text.y=element_text(angle=90, hjust=0.5, face="bold", size=6,
margin=margin(r=0))
strip.text.y=element_text(angle=0, hjust=0.5, face="bold", size=6)
) +
coord_flip() +
facet_grid(domainField ~ ., scales="free_y", space="free_y", switch="y") +
scale_y_continuous(labels = scales::percent) +
guides(fill=FALSE) +
ylab("Percentage Coverage (%)") +
xlab("") +
scale_fill_manual(values=c("darkblue", "skyblue"))
scale_fill_manual(values=c("cornflowerblue", "skyblue"))

ggsave('concept_mapping_coverage.png', height = 5, width = 5 * 1.61803)
ggsave('concept_mapping_coverage.png', height = 8, width = 8 * 1.61803)

Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ get_threshold_location <- function(df, row){
filter(
checkName == row$checkName &
cdmTableName == row$cdmTableName)

# for Field+Concept Level only
if(tolower(row$Level) %in% c("field", "concept")){
df3<-df3%>%filter(cdmFieldName == row$cdmFieldName)
}

# 'additional' auxiliary columns
if(row$checkName=="isForeignKey"){
df3<-df3%>%filter(fkTableName==row$fkTableName)}
Expand All @@ -94,7 +94,7 @@ get_threshold_location <- function(df, row){
if(tolower(row$Level) == "concept" &
row$checkName%in%c("plausibleValueLow", "plausibleValueHigh")){
df3 <- df3%>%filter(conceptId==row$conceptId &
unitConceptId==row$unitConceptId)}
unitConceptId==row$unitConceptId)}
return(df3$index)
}

Expand All @@ -111,37 +111,37 @@ edit_threshold <- function(df, index, row){
notes_old <- stringr::str_replace_all(notes_old, "[|][|]", "")
notes_new <- paste(notes_old, row$Notes, sep="|")
df[index, 'Notes'] = notes_new

return(df)

}

main_function <- function(file, file_new, thresholds){
# 1) get longer table
df <- read.csv(file, colClasses = "character", stringsAsFactors = FALSE)
df_long <- pivot_longer_func(df)
# 2) Edit thresholds
for(i in c(1:nrow(thresholds))){
row = thresholds[i,]
index <- get_threshold_location(df_long, row)
df_long <- edit_threshold(df_long, index, row)
}
# 3) get originally wide table
df_new <- pivot_wider_func(df=df_long)
df_new <- df_new[colnames(df)]
# 4) save it!
write.csv(df_new, file_new, row.names = FALSE)
# 5) (optional) final check
df.old <- read.csv(file, colClasses = "character", stringsAsFactors = FALSE)
df.new <- read.csv(file_new, colClasses = "character", stringsAsFactors = FALSE)
end <- base::all.equal(df.old, df.new)
end <- stringr::str_replace(end, "string mismatch", "difference")
end <- stringr::str_replace(end, "TRUE", "No differences")
print(end)
# 1) get longer table
df <- read.csv(file, colClasses = "character", stringsAsFactors = FALSE)
df_long <- pivot_longer_func(df)

# 2) Edit thresholds
for(i in c(1:nrow(thresholds))){
row = thresholds[i,]
index <- get_threshold_location(df_long, row)
df_long <- edit_threshold(df_long, index, row)
}

# 3) get originally wide table
df_new <- pivot_wider_func(df=df_long)
df_new <- df_new[colnames(df)]

# 4) save it!
write.csv(df_new, file_new, row.names = FALSE)

# 5) (optional) final check
df.old <- read.csv(file, colClasses = "character", stringsAsFactors = FALSE)
df.new <- read.csv(file_new, colClasses = "character", stringsAsFactors = FALSE)
end <- base::all.equal(df.old, df.new)
end <- stringr::str_replace(end, "string mismatch", "difference")
end <- stringr::str_replace(end, "TRUE", "No differences")
print(end)
}

# Main function
Expand Down