Đoạn mã cho phép bạn lấy dữ liệu từ thư viện y khoa Mỹ PubMed.
[/tomtat] [chitiet]
Chương trình R |
Thư viện y khoa Mỹ PubMed |
Đoạn mã cho phép lấy dữ liệu từ thư viện |
Từ khóa qua trọng trên PubMed |
Đoạn mã cho phép bạn lấy dữ liệu từ thư viện y khoa Mỹ PubMed. Với đoạn mã này cho phép bạn lấy 1000 chỉ mục trong thư viện.
Hướng dẫn sử dụng:
1. Cài phần mềm R từ trang https://www.r-project.org/
2. Tải file chứa đoạn mã https://github.com/quocdat/PharmStat/blob/master/pubmed_collection_data.R
Hoặc copy đoạn mã sau:
#install.packages("RISmed") # First, automagically install needed libraries: list.of.packages <- c("RISmed") new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])] if(length(new.packages)) install.packages(new.packages, repos='https://cran.rstudio.com/', dependencies = TRUE) library(RISmed) # setwd("Z:/BioMedSyn/R/project/PubMed and RISmed/") # search_topic <- 'copd' # Where do you save data search getwd() search_topic <- readline(prompt="Enter an key search: ") # for example Nexium #search_query <- EUtilsSummary(search_topic, retmax=1000, mindate=2012,maxdate=2012) search_query <- EUtilsSummary(search_topic) summary(search_query) # see the ids of our returned query QueryId(search_query) # get actual data from PubMed records<- EUtilsGet(search_query) class(records) # store it pubmed_data <- data.frame('Title'=ArticleTitle(records),'Abstract'=AbstractText(records)) head(pubmed_data,1) # Write txt in R write.table(pubmed_data, file='pubmed_collection_data.txt') # Write CSV in R write.csv(pubmed_data, file = "pubmed_collection_data.csv") # First, automagically install needed library xlsx for save file to xlsx: # list.of.packages <- c("rJava", "xlsx") # new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])] # if(length(new.packages)) install.packages(new.packages, repos='https://cran.rstudio.com/', dependencies = TRUE) # install.packages("xlsx", dependencies = TRUE) # library(xlsx) # write.xlsx(pubmed_data, "pubmed_data_nexium.xlsx") pubmed_data pubmed_data$Abstract <- as.character(pubmed_data$Abstract) pubmed_data$Abstract <- gsub(",", " ", pubmed_data$Abstract, fixed = TRUE) # see what we have str(pubmed_data) # Write txt in R write.table(pubmed_data, file='pubmed_collection_data_1.txt') # Write CSV in R write.csv(pubmed_data, file='pubmed_collection_data_1.csv')
Save lại thành file R
3. Save đoạn mã vào folder bạn muốn, ví dụ PubMed
4. Bạn có thể chạy file R từ file Batch sau:
Mã file batch:
Cho Windows 32bits
@echo off
mode con: cols=100 lines=20
Title "RUN R FILE"
color A1
@ echo on
RUN R FILE
@echo off
"C:\Program Files (x86)\R\R-3.5.0\bin\x64\Rscript.exe" "pubmed_collection_data.R"
[/video] [danhgia][/danhgia]
Không có nhận xét nào :
Đăng nhận xét