Skip to content

Commit

Permalink
Merge pull request #9 from reactome/add-ci
Browse files Browse the repository at this point in the history
Add ci
  • Loading branch information
DerekTang04 authored Feb 21, 2024
2 parents 262575c + 6e98796 commit eb1b596
Show file tree
Hide file tree
Showing 19 changed files with 347 additions and 91 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
.github

.dockerignore
.gitignore
Dockerfile
README.md
89 changes: 89 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: analysis core ci


on:
workflow_dispatch:

pull_request:
types:
- opened
- synchronize

push:
branches:
- main


permissions:
id-token: write
contents: read


jobs:
lint:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
env:
REPO_DIR : /opt/analysis-core
steps:
- uses: actions/checkout@v4

- name: Run lint
run: |
docker build --build-arg REPO_DIR="$REPO_DIR" --target setup-env -t lint-image .
docker run --name lint-container lint-image
- name: Display lint errors
if: failure()
run: |
docker cp lint-container:"$REPO_DIR"/lint.log .
while IFS= read -r LINT_MSG; do echo "::warning::${LINT_MSG}"; done < lint.log
exit 1
docker-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: docker/setup-buildx-action@v3

- uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
tags: tmp-tag
outputs: type=docker,dest=/tmp/image.tar

- uses: actions/upload-artifact@v4
with:
name: image-artifact
path: /tmp/image.tar

docker-push:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
needs: docker-build
runs-on: ubuntu-latest
steps:
- env:
AWS_REGION : us-east-1
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.AWS_ROLE }}
aws-region: ${{ env.AWS_REGION }}

- id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- uses: actions/download-artifact@v4
with:
name: image-artifact
path: /tmp

- env:
AWS_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
AWS_REPO : analysis-core
IMG_TAG : latest
run: |
docker load --input /tmp/image.tar
docker image tag tmp-tag $AWS_REGISTRY/$AWS_REPO:$IMG_TAG
docker push $AWS_REGISTRY/$AWS_REPO:$IMG_TAG
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ARG REPO_DIR=/opt/analysis-core


# ===== stage 1 =====
FROM maven:3.9.6-eclipse-temurin-11-focal AS setup-env

ARG REPO_DIR

WORKDIR ${REPO_DIR}

COPY . .

SHELL ["/bin/bash", "-c"]

# run lint if container started
ENTRYPOINT []

CMD mvn -B -q checkstyle:check | \
grep -i --color=never '\.java\|failed to execute goal' > lint.log && \
exit 1 || \
exit 0


# ===== stage 2 =====
FROM setup-env AS build-jar

RUN mvn clean package


# ===== stage 3 =====
FROM eclipse-temurin:11-jre-focal

ARG REPO_DIR

ARG JAR_FILE=target/analysis-core-exec.jar

WORKDIR ${REPO_DIR}

COPY --from=build-jar ${REPO_DIR}/${JAR_FILE} ./target/
9 changes: 9 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="LineLength">
<property name="max" value="150"/>
</module>
<!-- Add more modules as needed -->
</module>
37 changes: 36 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<description>The Reactome analysis-core extracts data from the graph-database to create the intermediate data format
to be kept in memory and used for the analysis-service
</description>

<name>analysis-core</name>

<organization>
Expand All @@ -37,6 +38,7 @@
</parent>

<properties>
<java.version>11</java.version>
<start.class>org.reactome.server.analysis.core.Main</start.class>
</properties>

Expand Down Expand Up @@ -111,6 +113,7 @@
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand All @@ -119,24 +122,28 @@

<build>
<finalName>analysis-core</finalName>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven.resources.version}</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down Expand Up @@ -208,6 +215,34 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<!-- This dependency allows Checkstyle to understand Java 11 syntax -->
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.44</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>checkstyle-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<!-- Optional: Set encoding -->
<encoding>UTF-8</encoding>
</configuration>
</plugin>

</plugins>
</build>

Expand All @@ -224,6 +259,7 @@
<enabled>false</enabled>
</snapshots>
</repository>

<!-- EBI SNAPSHOT repo -->
<repository>
<id>nexus-ebi-snapshot-repo</id>
Expand All @@ -237,5 +273,4 @@
</snapshots>
</repository>
</repositories>

</project>
19 changes: 10 additions & 9 deletions src/main/java/org/reactome/server/analysis/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ public static void main(String[] args) throws JSAPException {

// Program Arguments -h, -p, -u, -k
SimpleJSAP jsap = new SimpleJSAP(Main.class.getName(), "Connect to Reactome Graph Database",
new Parameter[]{
new FlaggedOption("host", JSAP.STRING_PARSER, "bolt://localhost:7687", JSAP.NOT_REQUIRED, 'h', "host", "The neo4j host")
, new FlaggedOption("user", JSAP.STRING_PARSER, "neo4j", JSAP.NOT_REQUIRED, 'u', "user", "The neo4j user")
, new FlaggedOption("password", JSAP.STRING_PARSER, "neo4jj", JSAP.REQUIRED, 'k', "password", "The neo4j password")
, new FlaggedOption("output", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'o', "output", "The file where the results are written to")
, new QualifiedSwitch("test", JSAP.BOOLEAN_PARSER, null, JSAP.NOT_REQUIRED, 't', "test", "Test main species")
, new QualifiedSwitch("verbose", JSAP.BOOLEAN_PARSER, null, JSAP.NOT_REQUIRED, 'v', "verbose", "Requests verbose output")
}
new Parameter[]{
new FlaggedOption("host", JSAP.STRING_PARSER, "bolt://localhost:7687", JSAP.NOT_REQUIRED, 'h', "host", "The neo4j host")
, new FlaggedOption("user", JSAP.STRING_PARSER, "neo4j", JSAP.NOT_REQUIRED, 'u', "user", "The neo4j user")
, new FlaggedOption("password", JSAP.STRING_PARSER, "neo4jj", JSAP.REQUIRED, 'k', "password", "The neo4j password")
, new FlaggedOption("output", JSAP.STRING_PARSER, JSAP.NO_DEFAULT,
JSAP.REQUIRED, 'o', "output", "The file where the results are written to")
, new QualifiedSwitch("test", JSAP.BOOLEAN_PARSER, null, JSAP.NOT_REQUIRED, 't', "test", "Test main species")
, new QualifiedSwitch("verbose", JSAP.BOOLEAN_PARSER, null, JSAP.NOT_REQUIRED, 'v', "verbose", "Requests verbose output")
}
);

JSAPResult config = jsap.parse(args);
Expand Down Expand Up @@ -132,4 +133,4 @@ private static void calculateNumbersInHierarchyNodesForMainResources(HierarchyBu
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void initializeProducer(DataContainer data) {
if (producer == null) {
producer = new HierarchiesDataProducer(data);
} else {
logger.warn("Already initialized. Please ensure you do not use two data containers or you do not initialise this object with the same twice.");
logger.warn("Already initialized. Ensure you do not use two data containers or you do not initialise this object with the same twice.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,25 @@ public void build(Map<String, SpeciesNode> speciesMap) {
if (Main.VERBOSE) System.out.print(msgPrefix + speciesPrefix + " >> retrieving xrefs...");

//language=Cypher
query = "MATCH (:Species{taxId:$taxId})<-[:species]-(:Pathway)-[:hasEvent]->(rle:ReactionLikeEvent), " +
" (rle)-[:input|output|catalystActivity|physicalEntity|entityFunctionalStatus|diseaseEntity|regulatedBy|regulator|hasComponent|hasMember|hasCandidate|repeatedUnit|proteinMarker|RNAMarker*]->(pe:PhysicalEntity) " +
"WHERE (pe)-[:referenceEntity]->() " +
"WITH DISTINCT pe " +
"MATCH (pe)-[:referenceEntity]->(re:ReferenceEntity) " +
"OPTIONAL MATCH (re)-[:referenceGene]->(re2:ReferenceEntity)-[:referenceDatabase]->(rd:ReferenceDatabase) " +
"OPTIONAL MATCH (pe)-[:referenceEntity|crossReference*]->(dbi:DatabaseIdentifier) " +
"WITH DISTINCT re, " +
"COLLECT(DISTINCT rd.displayName + \":\" + re2.identifier) AS reIdentifiers, " +
"COLLECT(DISTINCT CASE dbi WHEN NULL THEN NULL ELSE {databaseName: dbi.databaseName, identifier: dbi.identifier} END) AS dbis, COUNT(DISTINCT dbi) AS n " +
"RETURN re.dbId AS referenceEntity, " +
" re.secondaryIdentifier AS secondaryIdentifiers, " +
" re.geneName AS geneNames, " +
" reIdentifiers + re.otherIdentifier AS otherIdentifiers, " +
" [{databaseName: re.databaseName, " +
" identifier: CASE WHEN re.variantIdentifier IS NOT NULL THEN re.variantIdentifier ELSE re.identifier END " +
query = "" +
"MATCH (:Species{taxId:$taxId})<-[:species]-(:Pathway)-[:hasEvent]->(rle:ReactionLikeEvent), " +
" (rle)-[:input|output|catalystActivity|physicalEntity|entityFunctionalStatus|" +
"diseaseEntity|regulatedBy|regulator|hasComponent|hasMember|hasCandidate|repeatedUnit|proteinMarker|RNAMarker*]->(pe:PhysicalEntity) " +
"WHERE (pe)-[:referenceEntity]->() " +
"WITH DISTINCT pe " +
"MATCH (pe)-[:referenceEntity]->(re:ReferenceEntity) " +
"OPTIONAL MATCH (re)-[:referenceGene]->(re2:ReferenceEntity)-[:referenceDatabase]->(rd:ReferenceDatabase) " +
"OPTIONAL MATCH (pe)-[:referenceEntity|crossReference*]->(dbi:DatabaseIdentifier) " +
"WITH DISTINCT re, " +
"COLLECT(DISTINCT rd.displayName + \":\" + re2.identifier) AS reIdentifiers, " +
"COLLECT(DISTINCT CASE dbi WHEN NULL THEN NULL ELSE {databaseName: dbi.databaseName, identifier: dbi.identifier} END) AS dbis, " +
"COUNT(DISTINCT dbi) AS n " +
"RETURN re.dbId AS referenceEntity, " +
" re.secondaryIdentifier AS secondaryIdentifiers, " +
" re.geneName AS geneNames, " +
" reIdentifiers + re.otherIdentifier AS otherIdentifiers, " +
" [{databaseName: re.databaseName, " +
" identifier: CASE WHEN re.variantIdentifier IS NOT NULL THEN re.variantIdentifier ELSE re.identifier END " +
" }] + CASE WHEN n = 0 THEN [] ELSE dbis END AS xrefs";

Map<Long, ReferenceEntityIdentifiers> xrefMap = new HashMap<>();
Expand All @@ -82,17 +85,21 @@ public void build(Map<String, SpeciesNode> speciesMap) {
if (Main.VERBOSE) System.out.print(msgPrefix + speciesPrefix + " >> retrieving participants...");

//language=Cypher
query = "MATCH (:Species{taxId:$taxId})<-[:species]-(p:Pathway)-[:hasEvent]->(rle:ReactionLikeEvent), " +
" (rle)-[:input|output|catalystActivity|physicalEntity|entityFunctionalStatus|diseaseEntity|regulatedBy|regulator|hasComponent|hasMember|hasCandidate|repeatedUnit|proteinMarker|RNAMarker*]->(pe:PhysicalEntity)-[:referenceEntity]->(re:ReferenceEntity) " +
"WITH DISTINCT p, pe, re, COLLECT(DISTINCT {dbId: rle.dbId, stId: rle.stId}) AS rles " +
"OPTIONAL MATCH (pe)-[:hasModifiedResidue]->(tm:TranslationalModification)-[:psiMod]->(mod:PsiMod) " +
"WITH DISTINCT p, pe, re, rles, COLLECT(DISTINCT {coordinate: tm.coordinate, mod: mod.identifier}) AS tmods, COUNT(DISTINCT mod) AS n " +
"RETURN p.dbId AS pathway, " +
" pe.dbId AS physicalEntity, " +
" pe.speciesName AS speciesName, " +
" re.dbId as referenceEntity, " +
" rles AS reactions, " +
" CASE WHEN n = 0 THEN [] ELSE tmods END AS mods";
query = "" +
"MATCH (:Species{taxId:$taxId})<-[:species]-(p:Pathway)-[:hasEvent]->(rle:ReactionLikeEvent), " +
" (rle)-[:input|output|catalystActivity|physicalEntity|entityFunctionalStatus|diseaseEntity|" +
"regulatedBy|regulator|hasComponent|hasMember|hasCandidate|repeatedUnit|proteinMarker|RNAMarker*]" +
"->(pe:PhysicalEntity)-[:referenceEntity]->(re:ReferenceEntity) " +
"WITH DISTINCT p, pe, re, COLLECT(DISTINCT {dbId: rle.dbId, stId: rle.stId}) AS rles " +
"OPTIONAL MATCH (pe)-[:hasModifiedResidue]->(tm:TranslationalModification)-[:psiMod]->(mod:PsiMod) " +
"WITH DISTINCT p, pe, re, rles, " +
" COLLECT(DISTINCT {coordinate: tm.coordinate, mod: mod.identifier}) AS tmods, COUNT(DISTINCT mod) AS n " +
"RETURN p.dbId AS pathway, " +
" pe.dbId AS physicalEntity, " +
" pe.speciesName AS speciesName, " +
" re.dbId as referenceEntity, " +
" rles AS reactions, " +
" CASE WHEN n = 0 THEN [] ELSE tmods END AS mods";

Collection<EntitiesQueryResult> result;
try {
Expand Down Expand Up @@ -157,8 +164,12 @@ public void setOrthologous() {
if (Main.VERBOSE) System.out.print(msgPrefix + " retrieving relationships...");

String query = "" +
"MATCH (re1:ReferenceEntity)<-[:referenceEntity]-(:PhysicalEntity)-[:inferredTo]->(:PhysicalEntity)-[:referenceEntity]->(re2:ReferenceEntity) " +
"RETURN DISTINCT re1.databaseName AS originDatabaseName, re1.identifier AS originIdentifier, re2.databaseName AS inferredToDatabaseName, re2.identifier AS inferredToIdentifier";
"MATCH (re1:ReferenceEntity)<-[:referenceEntity]-(:PhysicalEntity)" +
"-[:inferredTo]->(:PhysicalEntity)-[:referenceEntity]->(re2:ReferenceEntity) " +
"RETURN DISTINCT re1.databaseName AS originDatabaseName, " +
"re1.identifier AS originIdentifier, " +
"re2.databaseName AS inferredToDatabaseName, "+
"re2.identifier AS inferredToIdentifier";
Map<String, Object> paramsMap = new HashMap<>();

Collection<OrthologyResult> orthologyResults;
Expand Down Expand Up @@ -201,4 +212,4 @@ public EntitiesContainer getEntitiesContainer() {
public IdentifiersMap<EntityNode> getEntitiesMap() {
return entitiesMap;
}
}
}
Loading

0 comments on commit eb1b596

Please sign in to comment.