Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/main/java/org/reactome/DuplicateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public void findAndLogDuplicates() throws Exception {
referenceMolecule.getDisplayName()
);
}

this.duplicateReferenceMoleculeReporter.writeFooterIfInitialized();
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/reactome/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ private static void updateReferenceMolecules(List<GKInstance> referenceMolecules
processedCount += referenceMoleculeBatch.size();
logger.info("Finished processing " + processedCount + " reference molecules");
}

failedChEBILookupReporter.writeFooterIfInitialized();
referenceMoleculeChEBIIdentifierChangeReporter.writeFooterIfInitialized();
dbInteractor.closeReports();
}

private static void updateReferenceMoleculeBatch(List<GKInstance> referenceMoleculeBatch) throws Exception {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/reactome/database/DBInteractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.reactome.reports.ReferenceMoleculeNameChangeReporter;
import org.reactome.reports.SimpleEntityNameChangeReporter;

import java.io.IOException;
import java.sql.SQLException;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -177,6 +178,12 @@ public boolean updateModifiedInstanceEdits(GKInstance instance) throws Exception
return true;
}

public void closeReports() throws IOException {
this.referenceMoleculeNameChangeReporter.writeFooterIfInitialized();
this.referenceMoleculeFormulaChangeReporter.writeFooterIfInitialized();
this.simpleEntityNameChangeReporter.writeFooterIfInitialized();
}

GKInstance getInstanceEdit() throws Exception {
if (instanceEdit == null) {
instanceEdit = new GKInstance(getSchema().getClassByName(ReactomeJavaConstants.InstanceEdit));
Expand Down
74 changes: 74 additions & 0 deletions src/main/java/org/reactome/reports/AbstractReporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.reactome.reports;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public abstract class AbstractReporter {

private boolean initialized;

public abstract String getHeader();

public abstract String getFooter();

public abstract Path getFilePath();

public Path getReportDirectory() {
return Paths.get("reports");
}

public void report(String ...values) throws IOException {
initializeIfNeeded();

String reportLine = String.join("\t", values).concat(System.lineSeparator());
Files.write(
getFilePath(),
reportLine.getBytes(),
StandardOpenOption.APPEND
);
}

public void writeFooterIfInitialized() throws IOException {
if (!initialized) {
return;
}

String footerWithPrependedNewLines = ""
.concat(System.lineSeparator())
.concat(System.lineSeparator())
.concat(getFooter());

Files.write(
getFilePath(),
footerWithPrependedNewLines.getBytes(),
StandardOpenOption.APPEND
);
}

private void writeHeader() throws IOException {
Files.write(
getFilePath(),
getHeader().concat(System.lineSeparator()).getBytes(),
StandardOpenOption.CREATE, StandardOpenOption.APPEND
);
}

private void initializeIfNeeded() throws IOException {
if (initialized) {
return;
}

if (Files.notExists(getReportDirectory())) {
Files.createDirectories(getReportDirectory());
}

if (Files.notExists(getFilePath())) {
writeHeader();
}

initialized = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;

public class DuplicateReferenceMoleculeReporter implements Reportable {
public class DuplicateReferenceMoleculeReporter extends AbstractReporter {

@Override
public String getHeader() {
Expand All @@ -15,6 +15,12 @@ public String getHeader() {
);
}

@Override
public String getFooter() {
return "This report specifies Reference Molecule instances with duplicated ChEBI identifiers. " +
"Where possible, these should be merged and/or all but one removed from the curator database.";
}

@Override
public Path getFilePath() {
return getReportDirectory().resolve(Paths.get("duplicates.tsv"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;

public class FailedChEBILookupReporter implements Reportable {
public class FailedChEBILookupReporter extends AbstractReporter {

@Override
public String getHeader() {
Expand All @@ -14,6 +14,13 @@ public String getHeader() {
);
}

@Override
public String getFooter() {
return "This report specifies Reference Molecule instances whose ChEBI identifier couldn't be retrieved " +
"from the external ChEBI API. This may have been due to an intermittent service interruption or an " +
"invalid ChEBI identifier. The identifiers reported should be checked manually in ChEBI to verify them.";
}

@Override
public Path getFilePath() {
return getReportDirectory().resolve(Paths.get("failed-chebi-lookups.tsv"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;

public class ReferenceMoleculeChEBIIdentifierChangeReporter implements Reportable {
public class ReferenceMoleculeChEBIIdentifierChangeReporter extends AbstractReporter {

@Override
public String getHeader() {
Expand All @@ -13,12 +13,20 @@ public String getHeader() {
"Reference Molecule",
"Deprecated Identifier",
"Replacement Identifier",
"Affected referenceEntity DB_IDs",
"DB_ID of Molecule with Replacement Identifier",
"DB_IDs of referenceEntities of Molecule with Replacement Identifier"
"Affected Simple Entity DB_IDs",
"DB_ID of Reference Molecule with Replacement Identifier",
"DB_IDs of Simple Entities of Reference Molecule with Replacement Identifier"
);
}

@Override
public String getFooter() {
return "This reports specifies Reference Molecule instances whose ChEBI identifier has changed. " +
"For any instances reported, it is necessary to move the SimpleEntity referrers to the new " +
"Reference Molecule with the replacement identifier and remove the old Reference Molecule with " +
"deprecated identifier";
}

@Override
public Path getFilePath() {
return getReportDirectory().resolve(Paths.get("reference-molecule-chebi-identifier-changes.tsv"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;

public class ReferenceMoleculeFormulaChangeReporter implements Reportable {
public class ReferenceMoleculeFormulaChangeReporter extends AbstractReporter {
@Override
public String getHeader() {
return String.join("\t",
Expand All @@ -15,6 +15,13 @@ public String getHeader() {
);
}

@Override
public String getFooter() {
return "This report specifies when a Reference Molecule instance has a new chemical formula. " +
"This report is only informational as the changes have already been applied in the database - " +
" nothing need be done.";
}

@Override
public Path getFilePath() {
return getReportDirectory().resolve(Paths.get("reference-molecule-formula-changes.tsv"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;

public class ReferenceMoleculeNameChangeReporter implements Reportable {
public class ReferenceMoleculeNameChangeReporter extends AbstractReporter {
@Override
public String getHeader() {
return String.join("\t",
Expand All @@ -15,6 +15,13 @@ public String getHeader() {
);
}

@Override
public String getFooter() {
return "This report specifies when a Reference Molecule instance has a new name. " +
"This report is only informational as the changes have already been applied in the database - " +
" nothing need be done.";
}

@Override
public Path getFilePath() {
return getReportDirectory().resolve(Paths.get("reference-molecule-name-changes.tsv"));
Expand Down
43 changes: 0 additions & 43 deletions src/main/java/org/reactome/reports/Reportable.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;

public class SimpleEntityNameChangeReporter implements Reportable {
public class SimpleEntityNameChangeReporter extends AbstractReporter {

@Override
public String getHeader() {
Expand All @@ -18,6 +18,13 @@ public String getHeader() {
);
}

@Override
public String getFooter() {
return "This report specifies Simple Entities with updated names. If the update is applied automatically " +
"(true for the last column), nothing need be done. If the update is not applied automatically, it is " +
"a suggestion for curators to apply what is given in the 'Update Simple Entity Names' column.";
}

@Override
public Path getFilePath() {
return getReportDirectory().resolve(Paths.get("simple-entity-name-changes.tsv"));
Expand Down
Loading
Loading