Skip to content

Commit

Permalink
annotate pubmed table
Browse files Browse the repository at this point in the history
  • Loading branch information
pcastellanoescuder committed Dec 15, 2023
1 parent 28dc478 commit db120d5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ddh
Type: Package
Title: Utility Functions and Data Sets for Data-driven Hypothesis
Version: 0.3.19
Version: 0.3.20
Authors@R: c(
person(given = "Matthew",
family = "Hirschey",
Expand Down Expand Up @@ -58,6 +58,7 @@ Imports:
rayvertex,
remotes,
rlang,
rvest,
scales,
stringr,
tibble,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export(make_tissue)
export(make_top_table)
export(make_umap_plot)
export(plot_size_finder)
export(pubmed_title)
export(scale_color_ddh_c)
export(scale_color_ddh_d)
export(scale_fill_ddh_c)
Expand Down
18 changes: 18 additions & 0 deletions R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -889,3 +889,21 @@ good_file_namer <- function(input = list){
}
return(good_file_name)
}

#' Extract PubMed Title from PubMed ID
#'
#' @param pmid PubMed ID
#'
#' @export
pubmed_title <- function(pmid) {
paper_url <- glue::glue("https://pubmed.ncbi.nlm.nih.gov/{pmid}/")

paper_title <- rvest::read_html(paper_url) %>%
rvest::html_nodes("title") %>%
rvest::html_text()

paper_title <- gsub(" - PubMed", "", paper_title[1])

return(paper_title)
}

15 changes: 13 additions & 2 deletions R/tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,30 @@ make_compound_table <- function(input = list(),
#' @export
#' @examples
#' make_pubmed_table(input = list(type = 'gene', content = 'ROCK1'))
#' make_pubmed_table(input = list(type = 'gene', content = 'ROCK1'), title = TRUE)
#' \dontrun{
#' make_pubmed_table(input = list(type = 'gene', content = 'ROCK1'))
#' }
make_pubmed_table <- function(input = list()) {
make_pubmed_table <- function(input = list(), n_papers = 10, title = FALSE) {
make_pubmed_table_raw <- function() {
pubmed_table <-
get_data_object(object_name = input$content,
dataset_name = "universal_pubmed",
pivotwider = TRUE) %>%
dplyr::mutate(year = as.numeric(year),
pmid = as.numeric(pmid)) %>%
dplyr::arrange(as.numeric(pmid)) %>%
dplyr::arrange(dplyr::desc(year)) %>%
dplyr::slice(1:n_papers) %>%
dplyr::select(id, pmid, year, pmcid)

if (title) {
pubmed_table <- pubmed_table %>%
dplyr::rowwise() %>%
dplyr::mutate(Title = pubmed_title(pmid)) %>%
dplyr::ungroup() %>%
dplyr::relocate(Title, .after = pmid)
}

return(pubmed_table)
}
#error handling
Expand Down
3 changes: 2 additions & 1 deletion man/make_pubmed_table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/pubmed_title.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db120d5

Please sign in to comment.