Skip to content

Commit 6915b12

Browse files
authored
Merge pull request #1385 from PathwayCommons/iss1373_genphysentmap-fetch
Fetch the generic physical entity map directly
2 parents cbb6128 + 5a380b2 commit 6915b12

File tree

6 files changed

+35
-92
lines changed

6 files changed

+35
-92
lines changed

.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# this is for Docker Compose only, to resolve ${...} parameters/expressions
22
# inside a YAML config file; these values won't automatically override replace
33
# ARG or ENV values in Dockerfile or containers, unless specified to do so.
4-
PC_VERSION=v12
54
PC_URL=http://beta.pathwaycommons.org/
65
NODE_ENV=production
76
PORT=9090

Dockerfile

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
# Node.js base image (based on Alpine Linux)
66
FROM node:8
77

8-
# install some tools
9-
RUN apt-get update && apt-get install curl unzip jq
10-
118
# Create an unprivileged user w/ home directory
129
RUN groupadd appuser && useradd --gid appuser --shell /bin/bash --create-home appuser
1310

@@ -37,12 +34,5 @@ EXPOSE 3000
3734
RUN chown appuser:appuser -R /home/appuser/app
3835
USER appuser
3936

40-
# required PC_VERSION (e.g. 'v12') arg for updating the generic entities map (json) - converting
41-
# the physical_entities.json.gz from the corresponding subdirectory of www.pathwaycommons.org/archives/PC2/
42-
ARG PC_VERSION
43-
ENV PC_VERSION=${PC_VERSION}
44-
# update the generic physical entities metadata (PC_VERSION is required by the script)
45-
RUN cd /home/appuser/app/src/scripts/generic-entity-mapping && sh update.sh
46-
4737
# Start the application
4838
CMD npm start

README.md

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,6 @@ The following environment variables can be used to configure the server (also do
3838
- `NCBI_API_KEY`: NCBI E-Utilities API key ([read more](https://ncbiinsights.ncbi.nlm.nih.gov/2017/11/02/new-api-keys-for-the-e-utilities/))
3939
- `FACTOID_URL`: the Factoid app URL (default: 'http://unstable.factoid.baderlab.org/')
4040
41-
### Switching Pathway Commons Versions (release/other)
42-
43-
If you're not using Docker, and Pathway Commons have been updated since this app's last built,
44-
or you want to connect to a different PC web service instance (at ${PC_URL}/pc2/),
45-
then `src/server/routes/pathways/generate-pathway-json/biopax-metadata/generic-physical-entity-map.json`
46-
needs to be updated as follows:
47-
```sh
48-
cd src/scripts/generic-entity-mapping/
49-
PC_VERSION=v12 sh update.sh
50-
```
51-
to auto-refresh `physical_entities.json.gz` from the path `www.pathwaycommons.org/archives/PC2/${PC_VERSION}/` in Pathway Commons.
52-
5341
## Run targets
5442
5543
- `npm start` : start the server
@@ -68,12 +56,12 @@ to auto-refresh `physical_entities.json.gz` from the path `www.pathwaycommons.or
6856
6957
### Build image and run locally
7058
71-
Build the image ("production" web app to consume PC2 v12 web service at the default URL).
59+
Build the image.
7260
Here, `app-ui` is used as the image name.
7361
7462
```
7563
cd app-ui
76-
docker build --build-arg NODE_ENV=production --build-arg PC_VERSION=v12 -t app-ui .
64+
docker build --build-arg NODE_ENV=production -t app-ui .
7765
```
7866
7967
Run the container:
@@ -96,12 +84,11 @@ Notes:
9684
9785
### Run the image from Docker Hub using Docker Compose
9886
99-
NOTE: existing images and containers must be updated shortly after every new official PC release; otherwise,
100-
the web app will be still using some old metadata while getting new pathway data from the web service at http://www.pathwaycommons.org/
87+
NOTE: existing images and containers must be restarted shortly after every new official PC release; otherwise, the web app will be still using some old cached data while getting new pathway data from the web service at http://www.pathwaycommons.org/
10188
102-
Pathway Commons maintains a stable [Docker Hub](https://hub.docker.com/) image for
103-
[app-ui](https://hub.docker.com/r/pathwaycommons/app-ui/) that is automatically built each time a commit is pushed
104-
to the master branch on GitHub (other versions can be also built automatically or on-demand and pushed to that
89+
Pathway Commons maintains a stable [Docker Hub](https://hub.docker.com/) image for
90+
[app-ui](https://hub.docker.com/r/pathwaycommons/app-ui/) that is automatically built each time a commit is pushed
91+
to the master branch on GitHub (other versions can be also built automatically or on-demand and pushed to that
10592
PC repository on Docker Hub).
10693
10794
To run the app using the pathwaycommons/app-ui:master image, execute:
@@ -118,7 +105,7 @@ Notes:
118105

119106
### Custom build/rebuild/run with Docker Compose
120107

121-
Create .env file in this directory and define there yours: PC_VERSION, NODE_ENV, PC_URL, FACTOID_URL, PORT options;
108+
Create .env file in this directory and define there yours: NODE_ENV, PC_URL, FACTOID_URL, PORT options;
122109
execute:
123110

124111
```sh
@@ -129,7 +116,7 @@ docker-compose -f dev-compose.yml up -d
129116

130117
## Testing
131118

132-
All files `/test` will be run by [Mocha](https://mochajs.org/). You can `npm test` to run all tests, or you
119+
All files `/test` will be run by [Mocha](https://mochajs.org/). You can `npm test` to run all tests, or you
133120
can run `npm run test ./test/path/to/test` to run specific tests.
134121

135122
[Chai](http://chaijs.com/) is included to make the tests easier to read and write.
@@ -140,7 +127,7 @@ can run `npm run test ./test/path/to/test` to run specific tests.
140127
Students who work on the repo should follow these instructions for each feature that they work on:
141128

142129
1. Initial preparation (only needed once)
143-
1. [Make a fork on Github](https://github.com/PathwayCommons/app-ui#fork-destination-box) (if you haven't already)
130+
1. [Make a fork on Github](https://github.com/PathwayCommons/app-ui#fork-destination-box) (if you haven't already)
144131
under your personal account
145132
1. Check out the fork repo: `git clone https://github.com/myusername/app-ui.git`
146133
1. Change the directory to the project: `cd app-ui`
@@ -156,15 +143,15 @@ Students who work on the repo should follow these instructions for each feature
156143
1. Select `Merge into Current Branch`
157144
1. Make a feature branch for the new feature or change you are working on. Make sure to give your branch a clear, meaningful name.
158145
1. Using the console: `git checkout -b name-of-feature`
159-
1. Using GitUp: Right click the `HEAD` commit (which should be the top commit of your local `development` branch),
146+
1. Using GitUp: Right click the `HEAD` commit (which should be the top commit of your local `development` branch),
160147
then select `Create Branch...`
161148
1. Make commits as you're working on your feature:
162149
1. Using the console: `git commit -am "My descriptive commit message"`
163150
1. Using GitUp: Use the `Select View` tab (`View > Commit`)
164151
1. Stage the files
165152
1. Add a descriptive commit message
166153
1. Press the `Commit` button
167-
1. Periodically (at least once just before making a pull request) make sure your feature branch takes into account
154+
1. Periodically (at least once just before making a pull request) make sure your feature branch takes into account
168155
the latest changes other people have made:
169156
1. Make sure your `development` branch is up-to-date:
170157
1. Using the console: `git checkout development && git merge pc/development`
@@ -174,11 +161,11 @@ the latest changes other people have made:
174161
1. Make sure your feature branch is up-to-date:
175162
1. Using the console: `git checkout name-of-feature`, `git merge development`
176163
1. Using GitUp:
177-
1. Make sure your `HEAD` is the newest commit of your feature branch: Right-click the latest commit
164+
1. Make sure your `HEAD` is the newest commit of your feature branch: Right-click the latest commit
178165
on `name-of-feature` branch and select `Checkout "name-of-feature" Branch`
179166
1. Right-click the latest commit of the `development` branch and select `Merge into Current Branch`
180167
1. Push your commits to GitHub:
181-
1. Note: You can push as often as you'd like so that your code is backed up on GitHub. You *must* push everything
168+
1. Note: You can push as often as you'd like so that your code is backed up on GitHub. You *must* push everything
182169
before you make a pull request.
183170
1. Using the console: `git push`
184171
1. Using GitUp: `Remotes > Push Current Branch`
@@ -194,7 +181,7 @@ the latest changes other people have made:
194181
1. Merge the latest dev into the release branch.
195182
1. Make sure the tests are passing: `npm test`
196183
1. Make sure the linting is passing: `npm run lint`
197-
1. Bump the version number with `npm version`, in accordance with [semver](http://semver.org/). The `version` command
184+
1. Bump the version number with `npm version`, in accordance with [semver](http://semver.org/). The `version` command
198185
in `npm` updates both `package.json` and git tags, but note that it uses a `v` prefix on the tags (e.g. `v1.2.3`).
199186
1. For a bug fix / patch release, run `npm version patch`.
200187
1. For a new feature release, run `npm version minor`.

src/scripts/generic-entity-mapping/update.sh

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/server/routes/pathways/generate-pathway-json/biopax-metadata/generic-physical-entity-map.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/server/routes/pathways/generate-pathway-json/biopax-metadata/index.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
const fs = require('fs');
21
const _ = require('lodash');
2+
3+
const { fetch } = require('../../../../../util');
34
const { xref2Uri } = require('../../../../external-services/pathway-commons');
5+
const { PC_URL } = require('../../../../../config');
6+
const GENERIC_PHYSICAL_ENTITY_URL = PC_URL + 'downloads/generic-physical-entity-map.json';
47

58
let extractBiopaxMetadata = ( biopaxJsonEntry, physicalEntityData ) => {
69
let xrefLinks = _.get(biopaxJsonEntry, 'xrefLinks', {});
@@ -116,7 +119,7 @@ let fillInBiopaxMetadata = async ( cyJsonEles, biopaxJsonText ) => {
116119
let nodes = cyJsonEles.nodes;
117120

118121
let bm = await biopaxText2ElementMap( biopaxJsonText, xref2Uri );
119-
let physicalEntityData = getGenericPhyiscalEntityData( nodes );
122+
let physicalEntityData = await getGenericPhyiscalEntityData( nodes );
120123

121124
nodes.forEach( node => {
122125
let nodeId = node.data.id;
@@ -136,14 +139,24 @@ let fillInBiopaxMetadata = async ( cyJsonEles, biopaxJsonText ) => {
136139
return cyJsonEles;
137140
};
138141

142+
let genericPhysicalEntityMapCache = null;
143+
const toJSON = res => res.json();
144+
const asMap = json => new Map( _.toPairs( json ) );
145+
const updateGenericPhysicalEntityMapCache = async () => {
146+
return fetch( GENERIC_PHYSICAL_ENTITY_URL )
147+
.then( toJSON )
148+
.then( asMap )
149+
.then( m => genericPhysicalEntityMapCache = m );
150+
};
139151

140-
let getGenericPhysicalEntityMap = _.memoize(() => JSON.parse(
141-
fs.readFileSync(__dirname + '/generic-physical-entity-map.json', 'utf-8')
142-
));
152+
const getGenericPhysicalEntityMap = async () => {
153+
if ( _.isNull( genericPhysicalEntityMapCache ) ) await updateGenericPhysicalEntityMapCache();
154+
return genericPhysicalEntityMapCache;
155+
};
143156

144-
let getGenericPhyiscalEntityData = nodes => {
157+
let getGenericPhyiscalEntityData = async nodes => {
145158
let nodeGeneSynonyms = {};
146-
let genericPhysicalEntityMap = getGenericPhysicalEntityMap();
159+
let genericPhysicalEntityMap = await getGenericPhysicalEntityMap();
147160

148161
nodes.forEach(node => {
149162
let genericPE = genericPhysicalEntityMap[node.data.id];
@@ -156,4 +169,4 @@ let getGenericPhyiscalEntityData = nodes => {
156169
};
157170

158171

159-
module.exports = { fillInBiopaxMetadata, getGenericPhyiscalEntityData, biopaxText2ElementMap, extractBiopaxMetadata };
172+
module.exports = { fillInBiopaxMetadata, biopaxText2ElementMap, extractBiopaxMetadata };

0 commit comments

Comments
 (0)