forked from rintukutum/pRideMetadb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pRide-api.R
120 lines (117 loc) · 3.75 KB
/
pRide-api.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#-----------
# http://www.ebi.ac.uk/pride/ws/archive/#!/project/getProjectSummary
# Retrieve a detailed record of a specific project
getPrideProject <- function(pxd){
# pxd = "PXD004083"
# library('httr')
link <- paste0('http://www.ebi.ac.uk:80/pride/ws/archive/project/',pxd)
contentPRIDE <- GET(link)
queryContent <- connectionStatus(contentPRIDE)
return(queryContent)
}
getProjectList <- function(term = NULL, # string
resultsPerPage = 100, # integer
page = 0, # integer
sort = NULL, # string "score", "publication_date",
# id, project_title
order = TRUE, # string; sorting order asc (ascending) or desc(descending)
taxonID = NULL, # array[string]; NCBI taxon ID, 9606 for human
ptmsFilter = NULL, # array[string]; PTM annotation phosphorylation
tissueFilter = NULL, # array[string]; tissue annotation, brain
diseaseFilter = NULL, # array[string]; disease annotation
titleFilter = NULL, # array[string]; the title for keywords, "stress"
instrumentFilter = NULL, # array[string]; instrument names or keywords
experimentTypeFilter = NULL, # array[string]; experiment type, shotgun
quantificationFilter = NULL, # array[string]; quantification annotation, "label-free"
projectTagFilter = NULL # array[string]; project tags, "Biomedical"
){
# term
if(is.null(term)){
term <- ""
}
if(isTRUE(order)){
# descending order
order <- "desc"
}else{
# ascending order
order <- "asc"
}
if(resultsPerPage > 500){
stop(cat(paste0('******************************************************************\n',
'\tQuery of more than 500 results per page not allowed.\n',
'\tPlease proide less than or equal to 500 results.\n',
'******************************************************************\n')))
}
showResultsPerPage <- abs(as.integer(resultsPerPage))
# base url
# "http://www.ebi.ac.uk:80/pride/ws/archive/project/list?show=100&page=0&order=desc"
link <- "http://www.ebi.ac.uk:80/pride/ws/archive/project/list?"
queryLink <- paste0(link,
'show=', resultsPerPage,
'&',
'page=', page,
'&',
'order=', order)
projectList <- connectionStatus(GET(queryLink))[[1]]
return(projectList)
}
#------------
# Projects available at PRIDE database
getProjectCount <- function(query = NULL,
speciesFilter = NULL,
ptmsFilter = NULL,
tissueFilter = NULL,
diseaseFilter = NULL,
titleFilter = NULL,
instrumentFilter = NULL,
experimentTypeFilter = NULL,
quantificationFilter = NULL,
projectTagFilter = NULL){
# base url
# http://www.ebi.ac.uk:80/pride/ws/archive/project/count
baseURL <- "http://www.ebi.ac.uk:80/pride/ws/archive/project/count"
count <- connectionStatus(GET(baseURL))
cat(paste0(Sys.time(),'\n'))
cat(paste0('Number of PRIDE projects = ',count,'\n'))
return(count)
}
#------------
# Get all PRIDE projects with few informations
# This doesn't give complete information per
# project
#------------
getAllPrideProject <- function(resultsPerPage = 100){
count <- getProjectCount()
nIter <- seq(1, count, resultsPerPage)[-1]
#-----
# pages to traverse
nPages <- length(nIter)
projectPerPage <- list()
# page starts from 0
for(i in 0:nPages){
projectList <- getProjectList(resultsPerPage = resultsPerPage,
page = i)
cat(paste0('Page ', i, '\n'))
# as i = 0
# index should be 1 = i + 1
projectPerPage[[i+1]] <- projectList
cat(paste0('Number of results = ',length(projectList), '\n'))
#-----
# sleep for few seconds
Sys.sleep(0.2)
}
allProjects <- c()
for(i in 1:length(projectPerPage)){
allProjects <- append(allProjects, projectPerPage[[i]])
}
cat(paste0(Sys.time(),'\n'))
cat(paste0('Number of PRIDE projects downloaded = ',count,'\n'))
return(allProjects)
}
#-----------
# Need to add a checker
# for any new data is added to
# PRIDE database
checkNewPrideEntry <- function(){
count <- getProjectCount()
}