Repository navigation
Expand file tree
/
Copy pathpcServices.js
More file actions
71 lines (61 loc) · 1.91 KB
/
Copy pathpcServices.js
File metadata and controls
71 lines (61 loc) · 1.91 KB
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
let fetch = require('node-fetch');
const got = require('got');
//Traverse Options
const traverseOptions = {
method: 'GET',
headers: {
'Host' : 'www.pathwaycommons.org',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
};
//Traverse Options
const getOptions = {
method: 'GET',
headers: {
'Content-Type': 'text',
}
};
//Returns the request file from pathway commons
//Requires uri and format to be valid xml files
function getPC2(uri, format) {
//Construct query url
uri = encodeURIComponent(uri);
let url = 'https://www.pathwaycommons.org/pc2/get?format=' + format + '&uri=' + uri + '&user=pathwaycommons-js-lib%3Apathways-search';
return fetch(url, getOptions).then(response => response.text());
}
//Queries PC2 using traverse
//Returns metadata for the pathway
//Requires a valid query and uri
function traversePC2(uri, path) {
//Construct query url
uri = encodeURIComponent(uri);
path = encodeURIComponent(path);
let url = 'https://www.pathwaycommons.org/pc2/traverse?format=json&uri=' + uri + '&path=' + path + '&user=pathwaycommons-js-lib%3Apathways-search';
let retries = 10;
//Use Got instead of fetch due to known issue with fetch which causes socket hangups
return got(url, { json: true, retries: retries }).then(response => {
return response.body;
}).catch(error => {
console.log(error);
});
}
//Generate URL for getting data
function getURL(uri, format) {
uri = encodeURIComponent(uri);
let url = 'https://www.pathwaycommons.org/pc2/get?format=' + format + '&uri=' + uri + '&user=pathwaycommons-js-lib%3Apathways-search';
return url;
}
//Generate URL for a traverse query
function traverseURL(uri, path) {
uri = encodeURIComponent(uri);
let url = 'https://www.pathwaycommons.org/pc2/traverse?format=json&uri=' + uri + '&path=' + path;
return url;
}
//Export Functions
module.exports = {
getPC2,
traversePC2,
getURL,
traverseURL,
}