Skip to content

Commit 20dcdd9

Browse files
Merge pull request #6 from stephenturner/dev
support medrxiv
2 parents 64d927a + 75534f6 commit 20dcdd9

21 files changed

Lines changed: 320 additions & 171 deletions

‎DESCRIPTION‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Package: biorecap
2-
Title: Retrieve and summarize bioRxiv preprints with a local LLM using ollama
3-
Version: 0.1.1
2+
Title: Retrieve and summarize bioRxiv and medRxiv preprints with a local LLM using ollama
3+
Version: 0.2.0
44
Authors@R:
55
person("Stephen", "Turner", , "vustephen@gmail.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0001-9140-9028"))
7-
Description: Retrieve and summarize bioRxiv preprints with a local LLM using ollama.
7+
Description: Retrieve and summarize bioRxiv and medRxiv preprints with a local LLM using ollama.
88
License: MIT + file LICENSE
99
URL: https://stephenturner.github.io/biorecap/
1010
BugReports: https://github.com/stephenturner/biorecap/issues

‎NEWS.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# biorecap 0.2.0
2+
3+
- Added medRxiv support. The `get_preprints()` function will now pull from either the bioRxiv or medRxiv RSS feed depending on the subject passed to it. All downstream functions and reporting updated to reflect this change (fixes #5).
4+
- Changed default model to llama 3.2 3B.
5+
- Added new source column for the returned preprints indicating whether the preprint came from bioRxiv or medRxiv.
6+
- Updated tests.
7+
18
# biorecap 0.1.1
29

310
- Fix bug in `add_summary()` caused by upstream changes in ollamar (fixes #1).

‎R/biorecap.R‎

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ build_prompt_subject <- function(subject,
4444
title,
4545
summary,
4646
nsentences=5L,
47-
instructions=c("I am giving you information about preprints published in bioRxiv recently.",
47+
instructions=c("I am giving you information about recent bioRxiv/medRxiv preprints.",
4848
"I'll give you the subject, preprint titles, and short summary of each paper.",
4949
"Please provide a general summary new advances in this subject/field in general.",
5050
"Provide this summary of the field in as many sentences as I instruct.",
@@ -57,31 +57,52 @@ build_prompt_subject <- function(subject,
5757
return(prompt)
5858
}
5959

60-
#' Get bioRxiv preprints
60+
#' Get bioRxiv/medRxiv preprints
6161
#'
62-
#' @param subject A character vector of valid biorxiv subjects. See [subjects].
63-
#' @param baseurl The base URL for the biorxiv RSS feed. Default is `https://connect.biorxiv.org/biorxiv_xml.php?subject=`. Do not change unless you know what you are doing.
62+
#' @param subject A character vector of valid bioRxiv and/or medRxiv subjects. See [subjects].
6463
#' @param clean Logical; try to strip out graphical abstract information? If TRUE, this strips away any text between `O_FIG` and `C_FIG`, and the words `graphical abstract` from the abstract text in the RSS feed.
6564
#'
66-
#' @return A data frame of bioRxiv preprints.
65+
#' @return A data frame of preprints from bioRxiv and/or medRxiv.
6766
#' @export
6867
#'
6968
#' @examples
70-
#' preprints <- get_preprints(subject=c("bioinformatics", "genomics"))
69+
#' preprints <- get_preprints(subject=c("bioinformatics", "Public_and_Global_Health"))
7170
#' preprints
7271
#'
73-
get_preprints <- function(subject="all", baseurl="https://connect.biorxiv.org/biorxiv_xml.php?subject=", clean=TRUE) {
72+
get_preprints <- function(subject="all", clean=TRUE) {
7473

74+
subject <- tolower(subject)
7575
stopifnot(is.character(subject))
76-
if (any(!subject %in% biorecap::subjects)) stop("Invalid subject. See ?subjects for valid choices.")
76+
if (any(!subject %in% as.vector(unlist(biorecap::subjects)))) stop("Invalid subject. See ?subjects for valid choices.")
7777

78-
preprints <-
79-
lapply(subject, \(x) suppressMessages(preprints <- tidyRSS::tidyfeed(paste0(baseurl, x)))) |>
80-
stats::setNames(subject) |>
81-
dplyr::bind_rows(.id="subject") |>
82-
dplyr::select("subject", title="item_title", url="item_link", abstract="item_description") |>
83-
dplyr::mutate(dplyr::across(dplyr::everything(), trimws))
84-
if (nrow(preprints)<1L) stop("Something went wrong. No papers found for subject ", subject) #nocov
78+
preprints <- list()
79+
80+
subject_bio <- subject[subject %in% biorecap::subjects$biorxiv]
81+
if (length(subject_bio)>0) {
82+
preprints$bio <-
83+
lapply(subject_bio, \(x) suppressMessages(preprints <- tidyRSS::tidyfeed(paste0("https://connect.biorxiv.org/biorxiv_xml.php?subject=", x)))) |>
84+
stats::setNames(subject_bio) |>
85+
dplyr::bind_rows(.id="subject") |>
86+
dplyr::select("subject", title="item_title", url="item_link", abstract="item_description") |>
87+
dplyr::mutate(dplyr::across(dplyr::everything(), trimws)) |>
88+
dplyr::mutate("source"="bioRxiv", .before=1)
89+
if (nrow(preprints$bio)<1L) stop("Something went wrong. No papers found for subject ", subject) #nocov
90+
}
91+
92+
93+
subject_med <- subject[subject %in% biorecap::subjects$medrxiv]
94+
if (length(subject_med)>0) {
95+
preprints$med <-
96+
lapply(subject_med, \(x) suppressMessages(preprints <- tidyRSS::tidyfeed(paste0("https://connect.medrxiv.org/medrxiv_xml.php?subject=", x)))) |>
97+
stats::setNames(subject_med) |>
98+
dplyr::bind_rows(.id="subject") |>
99+
dplyr::select("subject", title="item_title", url="item_link", abstract="item_description") |>
100+
dplyr::mutate(dplyr::across(dplyr::everything(), trimws)) |>
101+
dplyr::mutate("source"="medRxiv", .before=1)
102+
if (nrow(preprints$med)<1L) stop("Something went wrong. No papers found for subject ", subject) #nocov
103+
}
104+
105+
preprints <- dplyr::bind_rows(preprints)
85106

86107
if (clean) {
87108
preprints <-
@@ -101,7 +122,7 @@ get_preprints <- function(subject="all", baseurl="https://connect.biorxiv.org/bi
101122
#'
102123
#' @seealso [build_prompt_preprint()]
103124
#'
104-
#' @return A data frame of bioRxiv preprints with a prompt added.
125+
#' @return A data frame of preprints with a prompt added.
105126
#' @export
106127
#'
107128
#' @examples
@@ -144,7 +165,7 @@ add_prompt <- function(preprints, ...) {
144165
#' preprints
145166
#' }
146167
#'
147-
add_summary <- function(preprints, model="llama3.1") {
168+
add_summary <- function(preprints, model="llama3.2") {
148169

149170
if (!inherits(preprints, "preprints_prompt")) warning("Expecting a tibble of class 'preprints_prompt' returned from get_preprints() |> add_prompt().")
150171
if (!inherits(preprints, "data.frame")) stop("Expecting a data frame.")
@@ -222,13 +243,13 @@ tt_preprints <- function(preprints, cols=c("title", "summary"), width=c(1,3)) {
222243
}
223244

224245

225-
#' Create a report from bioRxiv preprints
246+
#' Create a report from bioRxiv/medRxiv preprints
226247
#'
227248
#' @param output_dir Directory to save the report.
228249
#' @param subject Character vector of subjects to include in the report.
229250
#' @param nsentences Number of sentences to summarize each paper in.
230251
#' @param model The model to use for generating summaries. See [ollamar::list_models()].
231-
#' @param use_example_preprints Use the example preprints data included with the package instead of fetching new data from bioRxiv. For diagnostic/testing purposes only.
252+
#' @param use_example_preprints Use the example preprints data included with the package instead of fetching new data from bioRxiv/medRxiv. For diagnostic/testing purposes only.
232253
#' @param ... Other arguments passed to [rmarkdown::render()].
233254
#'
234255
#' @return Nothing; called for its side effects to produce a report.

‎R/data.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#'
55
#' @references <https://www.biorxiv.org/alertsrss>
66
#'
7-
#' @format A character vector
7+
#' @format A list of character vectors of subjects, one for bioRxiv, one for medRxiv.
88
#'
99
#' @examples
1010
#' subjects

‎README.Rmd‎

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ knitr::opts_chunk$set(
2828
[![biorecap-r-universe](https://stephenturner.r-universe.dev/badges/biorecap)](https://stephenturner.r-universe.dev/biorecap)
2929
<!-- badges: end -->
3030

31-
Retrieve and summarize [bioRxiv](https://www.biorxiv.org/) preprints using a local LLM with [Ollama](https://ollama.com/) via [ollamar](https://cran.r-project.org/package=ollamar).
31+
Retrieve and summarize [bioRxiv](https://www.biorxiv.org/) and [medRxiv](https://www.medrxiv.org/) preprints using a local LLM with [Ollama](https://ollama.com/) via [ollamar](https://cran.r-project.org/package=ollamar).
3232

3333
Turner, S. D. (2024). biorecap: an R package for summarizing bioRxiv preprints with a local LLM. _arXiv_, 2408.11707. https://doi.org/10.48550/arXiv.2408.11707.
3434

@@ -73,43 +73,44 @@ list_models()
7373
```
7474

7575
```
76-
#> # A tibble: 3 × 4
77-
#> name model parameter_size quantization_level
78-
#> <chr> <chr> <chr> <chr>
79-
#> 1 gemma2:latest gemma2:latest 9.2B Q4_0
80-
#> 2 llama3.1:latest llama3.1:latest 8.0B Q4_0
81-
#> 3 llama3.1:70b llama3.1:70b 70.6B Q4_0
76+
name size parameter_size quantization_level modified
77+
1 gemma2:latest 5.4 GB 9.2B Q4_0 2024-08-07T07:35:15
78+
3 llama3.1:70b 40 GB 70.6B Q4_0 2024-07-24T10:57:08
79+
4 llama3.1:latest 4.7 GB 8.0B Q4_0 2024-07-31T09:38:38
80+
5 llama3.2:latest 2 GB 3.2B Q4_K_M 2024-09-25T14:54:23
81+
6 phi3:latest 2.2 GB 3.8B Q4_0 2024-08-28T04:37:58
8282
```
8383

84-
Write an HTML report containing summaries of recent preprints in select subject areas to the current working directory.
84+
Write an HTML report containing summaries of recent preprints in select subject areas to the current working directory. You can include both bioRxiv and medRxiv subjects, and biorecap will know which RSS feed to use.
8585

8686
```{r, eval=FALSE}
8787
biorecap_report(output_dir=".",
88-
subject=c("bioinformatics", "genomics", "synthetic_biology"),
88+
subject=c("bioinformatics", "infectious_diseases"),
8989
model="llama3.1")
9090
```
9191

92-
Example HTML report generated from the bioRxiv RSS feed on August 6, 2024:
92+
Example HTML report generated from bioRxiv (bioinformatics) and infectious diseases (medRxiv) subjects on September 25, 2024:
9393

9494
```{r, echo=FALSE}
95-
knitr::include_graphics(here::here("man/figures/report_screenshot.png"))
95+
knitr::include_graphics(here::here("man/figures/report_screenshot.jpg"))
9696
```
9797

9898

9999
### Details
100100

101-
The `get_preprints()` function retrieves preprints from bioRxiv's RSS feeds. You pass one or more subjects to the `subject` argument.
101+
The `get_preprints()` function retrieves preprints from the RSS feed of either bioRxiv or medRxiv, based on the subject you provided. You pass one or more subjects to the `subject` argument.
102102

103103
```{r, eval=FALSE}
104104
pp <- get_preprints(subject=c("bioinformatics",
105-
"genomics",
106-
"synthetic_biology"))
107-
pp
105+
"infectious_diseases"))
106+
head(pp)
107+
tail(pp)
108108
```
109109

110110
```{r, echo=FALSE}
111111
pp <- example_preprints
112-
pp |> dplyr::select(-prompt, -summary)
112+
pp |> dplyr::select(-prompt, -summary) |> head()
113+
pp |> dplyr::select(-prompt, -summary) |> tail()
113114
```
114115

115116
The `add_prompt()` function adds a prompt to each preprint that will be used to prompt the model.
@@ -137,9 +138,9 @@ The `add_summary()` function uses a locally running LLM available through Ollama
137138

138139
```{r, eval=FALSE}
139140
pp <-
140-
get_preprints(subject=c("bioinformatics", "genomics", "synthetic_biology")) |>
141+
get_preprints(subject=c("bioinformatics", "infectious_diseases")) |>
141142
add_prompt() |>
142-
add_summary(model="llama3.1")
143+
add_summary(model="llama3.2")
143144
```
144145

145146
Let's take a look at the results:
@@ -156,20 +157,21 @@ The `biorecap_report()` function runs this code in an RMarkdown template, writin
156157

157158
```{r, eval=FALSE}
158159
biorecap_report(output_dir=".",
159-
subject=c("bioinformatics", "genomics", "synthetic_biology"),
160-
model="llama3.1")
160+
subject=c("bioinformatics", "infectious_diseases"),
161+
model="llama3.2")
161162
```
162163

163-
The built-in `subjects` vector contains all the available bioRxiv subjects.
164+
The built-in `subjects` is a list with vectors containing all the available bioRxiv and medRxiv subjects.
164165

165166
```{r}
166-
subjects
167+
subjects$biorxiv
168+
subjects$medrxiv
167169
```
168170

169171
You could create a report for _all_ subjects like this (note, this could take some time):
170172

171173
```{r, eval=FALSE}
172174
biorecap_report(output_dir=".",
173175
subject=subjects,
174-
model="llama3.1")
176+
model="llama3.2")
175177
```

0 commit comments

Comments
 (0)