Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ ContributorsCheck/contributors-check/src/main/resources/auth.properties
.project
.settings
*/target/*
target/
.recommenders
NullCheck/src/main/resources/auth.properties
auth.properties

# ItelliJ Files
.idea/
release-qa.iml
21 changes: 17 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<properties>
<bundle.symbolicName>reactome-release-qa</bundle.symbolicName>
<bundle.namespace>org.reactome</bundle.namespace>
<!-- Prevent Using platform encoding (UTF-8 actually) to copy filtered
<!-- Prevent Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! See: https://maven.apache.org/general.html -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<opencsv.version>4.2</opencsv.version>
Expand Down Expand Up @@ -159,6 +159,19 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.18.3</version>
<scope>test</scope>
</dependency>

<!-- The CSV parser. -->
<dependency>
<groupId>com.opencsv</groupId>
Expand All @@ -182,7 +195,7 @@
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<!-- Log4j2-to-Log4j1.x bridge - just in case something in reactome-base
<!-- Log4j2-to-Log4j1.x bridge - just in case something in reactome-base
depends on log4j 1.x code. -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand All @@ -200,8 +213,8 @@
<groupId>org.reactome.base</groupId>
<artifactId>reactome-base</artifactId>
<version>${reactome.base.version}</version>
<!-- exclude old log4j 1.x libraries - log4j 1.x has not been
supported for a while ( See: https://blogs.apache.org/foundation/entry/apache_logging_services_project_announces
<!-- exclude old log4j 1.x libraries - log4j 1.x has not been
supported for a while ( See: https://blogs.apache.org/foundation/entry/apache_logging_services_project_announces
) -->
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@
import org.gk.persistence.MySQLAdaptor;
import org.reactome.release.qa.annotations.ReleaseQACheck;
import org.reactome.release.qa.common.AbstractQACheck;
import org.reactome.release.qa.common.QACheckerHelper;
import org.reactome.release.qa.common.QAReport;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
Expand All @@ -26,7 +19,12 @@
@ReleaseQACheck
public class EHLDSubpathwayChangeCheck extends AbstractQACheck implements ChecksTwoDatabases
{
final private String NOT_AVAILABLE = "N/A";
private final String NOT_AVAILABLE = "N/A";
// Need to create the following value in org/gk/model/ReactomeJavaConstants.java in the Curator Tool project
// source code
public static final String HAS_EHLD = "hasEHLD";


private MySQLAdaptor olderDatabase;

@Override
Expand All @@ -42,7 +40,7 @@ public QAReport executeQACheck() throws Exception
"Subpathway Names removed in " + this.dba.getDBName()
);

List<Long> pathwayIds = new ArrayList<>(getPathwayIDsWithEHLD());
List<Long> pathwayIds = new ArrayList<>(getPathwayIDsWithEHLD(this.dba));
List<EHLDPathway> oldPathways = getEHLDPathways(pathwayIds, getOtherDBAdaptor());
List<EHLDPathway> newPathways = getEHLDPathways(pathwayIds, this.dba);

Expand Down Expand Up @@ -73,54 +71,28 @@ public QAReport executeQACheck() throws Exception
}

@Override
public void setOtherDBAdaptor(MySQLAdaptor olderDatabase) { this.olderDatabase = olderDatabase; }

public MySQLAdaptor getOtherDBAdaptor() { return this.olderDatabase; };

private List<Long> getPathwayIDsWithEHLD() throws EHLDPathwayIDRetrievalException {
final String reactomeEHLDURL = "https://reactome.org/download/current/ehld/";
List<Long> pathwayIds = new ArrayList<>();
try {
BufferedReader ehldWebSource = new BufferedReader(
new InputStreamReader(new URL(reactomeEHLDURL).openStream())
);

pathwayIds.addAll(parsePathwayIds(ehldWebSource));
pathwayIds.sort(Comparator.comparing(Long::longValue));

ehldWebSource.close();
} catch (IOException e) {
e.printStackTrace();
}

if (pathwayIds.isEmpty()) {
throw new EHLDPathwayIDRetrievalException("Unable to retrieve pathway ids from " + reactomeEHLDURL);
}

return pathwayIds;
public void setOtherDBAdaptor(MySQLAdaptor olderDatabase) {
this.olderDatabase = olderDatabase;
}

private List<Long> parsePathwayIds(BufferedReader ehldWebSource) throws IOException {
List<Long> pathwayIds = new ArrayList<>();

Pattern svgFileName = getSVGFileNamePattern();
String sourceLine;
while ((sourceLine = ehldWebSource.readLine()) != null) {
Matcher svgMatcher = svgFileName.matcher(sourceLine);
if (svgMatcher.find()) {
Long pathwayId = Long.parseLong(svgMatcher.group(1));
pathwayIds.add(pathwayId);
}
}

return pathwayIds;
public MySQLAdaptor getOtherDBAdaptor() {
return this.olderDatabase;
}

private Pattern getSVGFileNamePattern() {
return Pattern.compile("\"(\\d+)\\.svg\"");
List<Long> getPathwayIDsWithEHLD(MySQLAdaptor newerDatabase) throws EHLDPathwayIDRetrievalException {
try {
return asGKInstanceCollection(
newerDatabase.fetchInstanceByAttribute(ReactomeJavaConstants.Pathway, HAS_EHLD, "=", true)
)
.stream()
.map(GKInstance::getDBID)
.collect(Collectors.toList());
} catch (Exception e) {
throw new EHLDPathwayIDRetrievalException("Unable to retrieve pathway ids from " + newerDatabase, e);
}
}

private List<EHLDPathway> getEHLDPathways(Collection<Long> dbIds, MySQLAdaptor database) {
List<EHLDPathway> getEHLDPathways(Collection<Long> dbIds, MySQLAdaptor database) {
List<EHLDPathway> ehldPathways = new ArrayList<>();
try {
ehldPathways.addAll(
Expand Down Expand Up @@ -178,13 +150,13 @@ private boolean isPathway(GKInstance instance) {
return instance.getSchemClass().isa(ReactomeJavaConstants.Pathway);
}

private class EHLDPathwayIDRetrievalException extends Exception {
public EHLDPathwayIDRetrievalException(String retrievalError) {
super(retrievalError);
private static class EHLDPathwayIDRetrievalException extends Exception {
public EHLDPathwayIDRetrievalException(String retrievalError, Throwable cause) {
super(retrievalError, cause);
}
}

private class EHLDPathway {
class EHLDPathway {
final private GKInstance pathway;
final private List<GKInstance> subPathways;
final private Integer reactomeVersion;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.reactome.release.qa.check;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.reactome.release.qa.check.EHLDSubpathwayChangeCheck.HAS_EHLD;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.gk.model.GKInstance;
import org.gk.model.ReactomeJavaConstants;
import org.gk.persistence.MySQLAdaptor;
import org.gk.schema.SchemaClass;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.reactome.release.qa.check.EHLDSubpathwayChangeCheck.EHLDPathway;

public class EHLDSubpathwayChangeCheckTest {
@Mock
MySQLAdaptor adaptor;

@Mock
SchemaClass pathwaySchemaClass;

@Mock
GKInstance firstPathway;

@Mock
GKInstance secondPathway;

private static final long FIRST_PATHWAY_DB_ID = 1L;
private static final long SECOND_PATHWAY_DB_ID = 2L;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}

@Test
public void testGetEHLDPathwayIDs() throws Exception {
setUpMockPathways();

EHLDSubpathwayChangeCheck ehldSubpathwayChangeCheck = new EHLDSubpathwayChangeCheck();
List<Long> pathwayIDs = ehldSubpathwayChangeCheck.getPathwayIDsWithEHLD(adaptor);

assertThat(pathwayIDs, contains(firstPathway.getDBID())); // Contains firstPathway id only
}

@Test
public void testGetEHLDSubPathways() throws Exception {
setUpMockPathways();
Mockito.when(adaptor.fetchInstance((Collection<Long>) Collections.singletonList(FIRST_PATHWAY_DB_ID)))
.thenReturn(Collections.singletonList(firstPathway));
Mockito.when(firstPathway.getAttributeValuesList(ReactomeJavaConstants.hasEvent))
.thenReturn(Collections.singletonList(secondPathway));

EHLDSubpathwayChangeCheck ehldSubpathwayChangeCheck = new EHLDSubpathwayChangeCheck();
EHLDPathway firstEHLDPathway = ehldSubpathwayChangeCheck.getEHLDPathways(
Collections.singletonList(FIRST_PATHWAY_DB_ID), adaptor
).get(0);

assertThat(firstEHLDPathway.getPathway(), equalTo(firstPathway));
assertThat(firstEHLDPathway.getSubPathways(), contains(secondPathway));
}

private void setUpMockPathways() throws Exception {
setUpMockPathway(firstPathway, FIRST_PATHWAY_DB_ID, true);
setUpMockPathway(secondPathway, SECOND_PATHWAY_DB_ID, false);
Collection<GKInstance> ehldPathways = Arrays.asList(firstPathway);

Mockito.when(adaptor.fetchInstanceByAttribute(ReactomeJavaConstants.Pathway, HAS_EHLD, "=", true))
.thenReturn(ehldPathways);
}

private void setUpMockPathway(GKInstance pathway, long dbId, boolean hasEHLD) throws Exception {
Mockito.when(pathway.getSchemClass()).thenReturn(pathwaySchemaClass);
Mockito.when(pathwaySchemaClass.isa(ReactomeJavaConstants.Pathway)).thenReturn(true);
Mockito.when(pathway.getDBID()).thenReturn(dbId);
}
}