Skip to content
Open
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
126 changes: 66 additions & 60 deletions src/main/java/org/reactome/release/qa/check/StableIdentifierCheck.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.reactome.release.qa.check;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;

import org.gk.model.GKInstance;
import org.gk.model.ReactomeJavaConstants;
Expand All @@ -23,64 +19,74 @@
public class StableIdentifierCheck extends AbstractQACheck {

public StableIdentifierCheck() {
}
}

@Override
public QAReport executeQACheck() throws Exception {
QAReport report = new QAReport();
report.setColumnHeaders("DBID", "DisplayName", "Issue", "LastAuthor");

Collection<GKInstance> stableIds = dba.fetchInstancesByClass(ReactomeJavaConstants.StableIdentifier);
dba.loadInstanceAttributeValues(stableIds, new String[] {ReactomeJavaConstants.identifier});
Map<String, Set<GKInstance>> idToInsts = new HashMap<>();
for (GKInstance stableId : stableIds) {
if (isEscaped(stableId)) {
continue;
}
String id = (String) stableId.getAttributeValue(ReactomeJavaConstants.identifier);
if (id == null) {
report.addLine(stableId.getDBID().toString(),
stableId.getDisplayName(),
"Missing identifier",
QACheckerHelper.getLastModificationAuthor(stableId));
continue;
}
idToInsts.compute(id, (key, set) -> {
if (set == null)
set = new HashSet<>();
set.add(stableId);
return set;
});
// Check if this stableId is used
Collection<GKInstance> referrers = stableId.getReferers(ReactomeJavaConstants.stableIdentifier);
if (referrers == null || referrers.size() == 0) {
report.addLine(stableId.getDBID().toString(),
stableId.getDisplayName(),
"Not used",
QACheckerHelper.getLastModificationAuthor(stableId));
}
else if (referrers.size() > 1) {
report.addLine(stableId.getDBID().toString(),
stableId.getDisplayName(),
"Referred more than once",
QACheckerHelper.getLastModificationAuthor(stableId));
}
}

for (Collection<GKInstance> instances: idToInsts.values()) {
if (instances.size() != 1) {
for (GKInstance stableId: instances) {
if (!isEscaped(stableId)) {
report.addLine(stableId.getDBID().toString(),
stableId.getDisplayName(),
"Duplicated identifier",
QACheckerHelper.getLastModificationAuthor(stableId));
}
}
}
}

return report;
QAReport report = new QAReport();
report.setColumnHeaders("DBID", "DisplayName", "Issue", "LastAuthor");

Collection<GKInstance> stableIds = dba.fetchInstancesByClass(ReactomeJavaConstants.StableIdentifier);
dba.loadInstanceAttributeValues(stableIds, new String[] {ReactomeJavaConstants.identifier});
Map<String, Set<GKInstance>> idToInsts = new HashMap<>();
for (GKInstance stableId : stableIds) {
if (isEscaped(stableId)) {
continue;
}
String id = (String) stableId.getAttributeValue(ReactomeJavaConstants.identifier);
if (id == null) {
report.addLine(stableId.getDBID().toString(),
stableId.getDisplayName(),
"Missing identifier",
QACheckerHelper.getLastModificationAuthor(stableId));
continue;
}
idToInsts.compute(id, (key, set) -> {
if (set == null)
set = new HashSet<>();
set.add(stableId);
return set;
});
// Check if this stableId is used by an existing instance or a deleted instance
Collection<GKInstance> instanceReferrers = stableId.getReferers(ReactomeJavaConstants.stableIdentifier);
Collection<GKInstance> deletedInstanceReferrers =
stableId.getReferers("deletedStableIdentifier");
Collection<GKInstance> referrers = new ArrayList<>();
if (instanceReferrers != null) {
referrers.addAll(instanceReferrers);
}
if (deletedInstanceReferrers != null) {
referrers.addAll(deletedInstanceReferrers);
}

if (referrers.size() == 0) {
report.addLine(stableId.getDBID().toString(),
stableId.getDisplayName(),
"Not used",
QACheckerHelper.getLastModificationAuthor(stableId));
}
else if (referrers.size() > 1) {
report.addLine(stableId.getDBID().toString(),
stableId.getDisplayName(),
"Referred more than once",
QACheckerHelper.getLastModificationAuthor(stableId));
}
}

for (Collection<GKInstance> instances: idToInsts.values()) {
if (instances.size() != 1) {
for (GKInstance stableId: instances) {
if (!isEscaped(stableId)) {
report.addLine(stableId.getDBID().toString(),
stableId.getDisplayName(),
"Duplicated identifier",
QACheckerHelper.getLastModificationAuthor(stableId));
}
}
}
}

return report;
}

}
Loading