欢迎光临散文网 会员登陆 & 注册

R检索Pubmed

2023-03-21 08:38 作者:Q日拱一卒  | 我要投稿

install.packages("easyPubMed")

library(easyPubMed)

library(dplyr)

library(parallel)

library(foreach)

library(doParallel)

get_pubmed <- function(query = my_query){

  # ncbi_key = '6c656032d3e950f2b15656d687fd4eeb8008'

  my_query <- get_pubmed_ids(my_query)

  my_query$Count

  # Fetch data

  my_abstracts_xml <- fetch_pubmed_data(my_query)  

  # Store Pubmed Records as elements of a list

  all_xml <- articles_to_list(my_abstracts_xml)

  # Windows systems may not support the following code.

  

  # Start a cluster with 3 cores

  cl <- makeCluster(4)

  registerDoParallel(cl)

  

  # Perform operation (use foreach)

  # The .combine argument guides result aggregation

  fullDF <- tryCatch(

    {foreach(x=1:length(all_xml), 

             .packages = 'easyPubMed',

             .combine = rbind) %dopar% article_to_df(pubmedArticle = all_xml[[x]], 

                                                     autofill = T, 

                                                     max_chars = -1, 

                                                     getKeywords = T, 

                                                     getAuthors = T)}, 

    error = function(e) {NULL},

    finally = {stopCluster(cl)})

  fullDF <- fullDF %>% 

    as_tibble()

  return(fullDF)

}



##根据期刊/关键词查找:

my_query<-"(Idiopathic pulmonary fibrosis[TIAB]) AND ((2022[Date - Publication] : 2022[Date - Publication]))"

qr1<-get_pubmed_ids(my_query)

##my_query<-"(Journal of Hepatology[Journal]) AND ((2022[Date - Publication] : 2022[Date - Publication]))"

##qr1<-get_pubmed_ids(my_query)

result<-fetch_pubmed_data(qr1,encoding = "ASCII")

result<-table_articles_byAuth(result,included_authors = "last",max_chars = 500)

write.csv(result,file="D:\\MDR database\\result.csv",row.names = F)


R检索Pubmed的评论 (共 条)

分享到微博请遵守国家法律