#!/usr/bin/env Rscript args = commandArgs(trailingOnly=TRUE) if (!require("europepmc", character.only=T, quietly=T)) { install.packages("europepmc") library("europepmc", character.only=T) } if (!require("reshape2", character.only=T, quietly=T)) { install.packages("reshape2") library("reshape2", character.only=T) } if (!require("dplyr", character.only=T, quietly=T)) { install.packages("dplyr") library("dplyr", character.only=T) } annotate_doi_list_europmc=function(doi_list){ annotated_doi_df=c() for(i in 1:length(doi_list)){ # print(i) print(doi_list[i]) annotated_dois_df_load=tryCatch(epmc_search(paste("DOI:",doi_list[i],sep="")),error = function(e) NULL) if(is.null(annotated_dois_df_load)){annotated_dois_df_load=tryCatch(epmc_search(doi_list[i]),error = function(e) NULL)} if(is.null(annotated_dois_df_load)){next} if(dim(annotated_dois_df_load)[1]==1){ annotated_dois_df_load=tryCatch(dplyr::select(annotated_dois_df_load,id,source,pmid,pmcid,doi,title, authorString,journalTitle,pubYear,pubType,isOpenAccess,citedByCount, firstPublicationDate),error = function(e) NULL) if(is.null(annotated_dois_df_load)){next} annotated_doi_df=rbind(annotated_doi_df,annotated_dois_df_load) } } return(data.frame(annotated_doi_df)) } data=read.table(args[1],sep="\t",header=T) anno=annotate_doi_list_europmc(as.character(data[,1])) write.table(anno,paste("annotated_EPMC",args[1],sep="_"),sep="\t",quote = F,row.names = F)