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
2 changes: 1 addition & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="LineLength">
<property name="max" value="150"/>
<property name="max" value="250"/>
</module>
<!-- Add more modules as needed -->
</module>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>org.reactome.base</groupId>
<artifactId>reactome-base</artifactId>
<version>2.2.4-SNAPSHOT</version>
<version>2.0.0</version>
</dependency>
<!-- Test dependencies -->
<dependency>
Expand Down
147 changes: 106 additions & 41 deletions src/main/java/org/reactome/orthoinference/EWASInferrer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import static org.gk.model.ReactomeJavaConstants.*;

import org.gk.model.InstanceDisplayNameGenerator;
import org.gk.model.ReactomeJavaConstants;
import org.gk.persistence.MySQLAdaptor;
import org.gk.schema.GKSchemaClass;
import org.gk.schema.InvalidAttributeException;
import org.gk.schema.SchemaClass;
import org.gk.schema.*;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

public class EWASInferrer {

Expand Down Expand Up @@ -98,7 +99,11 @@ public static List<GKInstance> inferEWAS(GKInstance ewasInst) throws InvalidAttr
for (int endCoord : (Collection<Integer>) ewasInst.getAttributeValuesList(endCoordinate)) {
infEWASInst.addAttributeValue(endCoordinate, endCoord);
}
if (infEWASInst.getAttributeValue(startCoordinate) != null && (int) infEWASInst.getAttributeValue(startCoordinate) > 1 || infEWASInst.getAttributeValue(endCoordinate) != null && (int) infEWASInst.getAttributeValue(endCoordinate) > 1) {
if (infEWASInst.getAttributeValue(startCoordinate) != null &&
(int) infEWASInst.getAttributeValue(startCoordinate) > 1 ||
infEWASInst.getAttributeValue(endCoordinate) != null &&
(int) infEWASInst.getAttributeValue(endCoordinate) > 1) {

List<String> infEWASInstNames = (ArrayList<String>) (ewasInst).getAttributeValuesList(name);
infEWASInst.addAttributeValue(name, infEWASInstNames.get(0));
infEWASInst.addAttributeValue(name, homologueId);
Expand Down Expand Up @@ -339,53 +344,41 @@ public static void readENSGMappingFile(String toSpecies, String pathToOrthopairs

// Fetches Uniprot DB instance
@SuppressWarnings("unchecked")
public static void fetchAndSetUniprotDbInstance() throws Exception
{
public static void fetchAndSetUniprotDbInstance() throws Exception {
Collection<GKInstance> uniprotDbInstances = (Collection<GKInstance>) dba.fetchInstanceByAttribute(ReferenceDatabase, name, "=", "UniProt");
uniprotDbInst = uniprotDbInstances.iterator().next();
}

// Creates instance pertaining to the species Ensembl Protein DB
public static void createEnsemblProteinDbInstance(String toSpeciesLong, String toSpeciesReferenceDbUrl, String toSpeciesEnspAccessUrl) throws Exception
{
String enspSpeciesDb = "ENSEMBL_" + toSpeciesLong + "_PROTEIN";
enspDbInst = new GKInstance(dba.getSchema().getClassByName(ReferenceDatabase));
enspDbInst.setDbAdaptor(dba);
enspDbInst.addAttributeValue(created, instanceEditInst);
enspDbInst.addAttributeValue(name, "Ensembl");
enspDbInst.addAttributeValue(name, enspSpeciesDb);
enspDbInst.addAttributeValue(url, toSpeciesReferenceDbUrl);
enspDbInst.addAttributeValue(accessUrl, toSpeciesEnspAccessUrl);
enspDbInst.setAttributeValue(_displayName, "Ensembl");
dba.storeInstance(enspDbInst);
}
public static void fetchAndSetEnsemblDbInstance(String ensemblDatabaseType, String pathToRefDbConfig)
throws Exception {

// Creates instance pertaining to the species Ensembl Gene DB
public static void createEnsemblGeneDBInstance(String toSpeciesLong, String toSpeciesReferenceDbUrl, String toSpeciesEnsgAccessUrl) throws Exception
{
String ensgSpeciesDb = "ENSEMBL_" + toSpeciesLong + "_GENE";
ensgDbInst = new GKInstance(dba.getSchema().getClassByName(ReferenceDatabase));
ensgDbInst.setDbAdaptor(dba);
ensgDbInst.addAttributeValue(created, instanceEditInst);
ensgDbInst.addAttributeValue(name, "ENSEMBL");
ensgDbInst.addAttributeValue(name, ensgSpeciesDb);
ensgDbInst.addAttributeValue(url, toSpeciesReferenceDbUrl);
ensgDbInst.addAttributeValue(accessUrl, toSpeciesEnsgAccessUrl);
ensgDbInst.setAttributeValue(_displayName, "ENSEMBL");
dba.storeInstance(ensgDbInst);
GKInstance ensemblDbInst = fetchOrCreateEnsemblDbInstance(ensemblDatabaseType, pathToRefDbConfig);
if (ensemblDbInst == null) {
throw new IllegalStateException(
"Unable to fetch EnsEMBL Reference Database for type: " + ensemblDatabaseType
);
}

ensgDbInst = ensemblDbInst;
enspDbInst = ensemblDbInst;
}

// Create instance pertaining to any alternative reference DB for the species
public static void createAlternateReferenceDBInstance(JSONObject altRefDbJSON) throws Exception
{
alternateDbInst = new GKInstance(dba.getSchema().getClassByName(ReferenceDatabase));
alternateDbInst.setDbAdaptor(dba);
alternateDbInst.addAttributeValue(created, instanceEditInst);
alternateDbInst.addAttributeValue(name, ((JSONArray) altRefDbJSON.get("dbname")).get(0));
alternateDbInst.addAttributeValue(url, altRefDbJSON.get("url"));
alternateDbInst.addAttributeValue(accessUrl, altRefDbJSON.get("access"));
alternateDbInst.setAttributeValue(_displayName, ((JSONArray) altRefDbJSON.get("dbname")).get(0));
alternateDbInst = InstanceUtilities.checkForIdenticalInstances(alternateDbInst, null);
String altRefDbDisplayName = (String) ((JSONArray) altRefDbJSON.get("dbname")).get(0);
if (refDbExistsInDb(altRefDbDisplayName)) {
alternateDbInst = getRefDbFromDb(altRefDbDisplayName);
} else {
alternateDbInst = new GKInstance(dba.getSchema().getClassByName(ReferenceDatabase));
alternateDbInst.setDbAdaptor(dba);
alternateDbInst.addAttributeValue(created, instanceEditInst);
alternateDbInst.addAttributeValue(name, altRefDbDisplayName);
alternateDbInst.addAttributeValue(url, altRefDbJSON.get("url"));
alternateDbInst.addAttributeValue(accessUrl, altRefDbJSON.get("access"));
alternateDbInst.setAttributeValue(_displayName, altRefDbDisplayName);
alternateDbInst = InstanceUtilities.checkForIdenticalInstances(alternateDbInst, null);
}
if (altRefDbJSON.get("alt_id") != null)
{
altRefDbId = (String) altRefDbJSON.get("alt_id");
Expand All @@ -412,4 +405,76 @@ public static void setWormbaseMappings(Map<String, List<String>> wormbaseMapping
public static void setGeneNameMappingFile(Map<String, String> geneNameMappingsCopy) {
geneNameMappings = geneNameMappingsCopy;
}

private static boolean refDbExistsInDb(String refDbDisplayName) throws Exception {
Collection<GKInstance> refDbInstances =
dba.fetchInstanceByAttribute(ReferenceDatabase, _displayName, "=", refDbDisplayName);
return refDbInstances != null && !refDbInstances.isEmpty();
}

private static GKInstance getRefDbFromDb(String refDbDisplayName) throws Exception {
return (GKInstance) dba.fetchInstanceByAttribute(
ReferenceDatabase, _displayName, "=", refDbDisplayName
).iterator().next();
}

private static GKInstance fetchOrCreateEnsemblDbInstance(String ensemblDatabaseType, String pathToRefDbConfig)
throws Exception {

String ensemblRefDBDisplayName;
if (ensemblDatabaseType.equals("main")) {
ensemblRefDBDisplayName = "ENSEMBL";
} else if (ensemblDatabaseType.equals("fungi")) {
ensemblRefDBDisplayName = "ENSEMBL Fungi";
} else if (ensemblDatabaseType.equals("protist")) {
ensemblRefDBDisplayName = "ENSEMBL Protist";
} else {
throw new IllegalStateException(ensemblDatabaseType + " is not a valid EnsEMBL database type");
}

return refDbExistsInDb(ensemblRefDBDisplayName) ?
getRefDbFromDb(ensemblRefDBDisplayName) :
createRefDb(ensemblRefDBDisplayName, pathToRefDbConfig);
}

private static GKInstance createRefDb(String refDbDisplayName, String pathToRefDbConfig)
throws Exception {

JSONObject refDbJsonObject = getRefDBJSONObject(refDbDisplayName, pathToRefDbConfig);

GKInstance refDbInstance = new GKInstance(fetchSchema().getClassByName(ReferenceDatabase));
refDbInstance.setDbAdaptor(dba);
refDbInstance.setAttributeValue(ReactomeJavaConstants.created, instanceEditInst);
refDbInstance.setAttributeValue(ReactomeJavaConstants.accessUrl, refDbJsonObject.get("accessUrl"));
refDbInstance.setAttributeValue("identifiersPrefix", refDbJsonObject.get("identifiersPrefix"));
refDbInstance.setAttributeValue(ReactomeJavaConstants.resourceIdentifier,
refDbJsonObject.get("resourceIdentifier"));
refDbInstance.setAttributeValue(ReactomeJavaConstants.url, refDbJsonObject.get("url"));
refDbInstance.setAttributeValue(ReactomeJavaConstants.name, Collections.singletonList(refDbDisplayName));
InstanceDisplayNameGenerator.setDisplayName(refDbInstance);

return refDbInstance;
}

private static JSONObject getRefDBJSONObject(String refDbDisplayName, String pathToRefDbConfig) {
JSONParser parser = new JSONParser();
JSONObject refDbsJsonObject;
try {
refDbsJsonObject = (JSONObject) parser.parse(new FileReader(pathToRefDbConfig));
} catch (IOException | ParseException e) {
throw new RuntimeException("Unable to read/parse JSON from " + pathToRefDbConfig, e);
}
return (JSONObject) refDbsJsonObject.get(refDbDisplayName);
}

private static Schema fetchSchema() {
if (dba.getSchema() == null) {
try {
return dba.fetchSchema();
} catch (Exception e) {
throw new RuntimeException("Unable to fetch schema from " + dba, e);
}
}
return dba.getSchema();
}
}
17 changes: 11 additions & 6 deletions src/main/java/org/reactome/orthoinference/EventsInferrer.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static void inferEvents(Properties props, String species) throws Exceptio
releaseVersion = props.getProperty("releaseNumber");
String pathToOrthopairs = props.getProperty("pathToOrthopairs", "orthopairs");
String pathToSpeciesConfig = props.getProperty("pathToSpeciesConfig", "src/main/resources/Species.json");
String pathToRefDbConfig = props.getProperty("pathToRefDbConfig", "src/main/resources/refdb.json");
String dateOfRelease = props.getProperty("dateOfRelease");
int personId = Integer.valueOf(props.getProperty("personId"));
setReleaseDates(dateOfRelease);
Expand All @@ -95,9 +96,7 @@ public static void inferEvents(Properties props, String species) throws Exceptio
logger.info("Beginning orthoinference of " + speciesName);

JSONObject refDb = (JSONObject) speciesObject.get("refdb");
String refDbUrl = (String) refDb.get("url");
String refDbProteinUrl = (String) refDb.get("access");
String refDbGeneUrl = (String) refDb.get("ensg_access");
String ensemblDatabaseType = (String) refDb.get("use_gk_central_ensembl_ref_db");

// Creates two files that a) list reactions that are eligible for inference and b) those that are successfully inferred
String eligibleFilename = "eligible_" + species + "_75.txt";
Expand All @@ -120,8 +119,7 @@ public static void inferEvents(Properties props, String species) throws Exceptio
}
EWASInferrer.readENSGMappingFile(species, pathToOrthopairs);
EWASInferrer.fetchAndSetUniprotDbInstance();
EWASInferrer.createEnsemblProteinDbInstance(speciesName, refDbUrl, refDbProteinUrl);
EWASInferrer.createEnsemblGeneDBInstance(speciesName, refDbUrl, refDbGeneUrl);
EWASInferrer.fetchAndSetEnsemblDbInstance(ensemblDatabaseType, pathToRefDbConfig);

JSONObject altRefDbJSON = (JSONObject) speciesObject.get("alt_refdb");
if (altRefDbJSON != null)
Expand Down Expand Up @@ -348,7 +346,14 @@ private static void setSummationInstance() throws Exception
GKInstance summationInst = new GKInstance(dbAdaptor.getSchema().getClassByName(Summation));
summationInst.setDbAdaptor(dbAdaptor);
summationInst.addAttributeValue(created, instanceEditInst);
String summationText = "This event has been computationally inferred from an event that has been demonstrated in another species.<p>The inference is based on the homology mapping from PANTHER. Briefly, reactions for which all involved PhysicalEntities (in input, output and catalyst) have a mapped orthologue/paralogue (for complexes at least 75% of components must have a mapping) are inferred to the other species. High level events are also inferred for these events to allow for easier navigation.<p><a href='/electronic_inference_compara.html' target = 'NEW'>More details and caveats of the event inference in Reactome.</a> For details on PANTHER see also: <a href='http://www.pantherdb.org/about.jsp' target='NEW'>http://www.pantherdb.org/about.jsp</a>";
String summationText = "This event has been computationally inferred from an event that has been " +
"demonstrated in another species.<p>The inference is based on the homology mapping from PANTHER. " +
"Briefly, reactions for which all involved PhysicalEntities (in input, output and catalyst) have a " +
"mapped orthologue/paralogue (for complexes at least 75% of components must have a mapping) are " +
"inferred to the other species. High level events are also inferred for these events to allow for " +
"easier navigation.<p><a href='/electronic_inference_compara.html' target = 'NEW'>More details and " +
"caveats of the event inference in Reactome.</a> For details on PANTHER see also: " +
"<a href='http://www.pantherdb.org/about.jsp' target='NEW'>http://www.pantherdb.org/about.jsp</a>";
summationInst.addAttributeValue(text, summationText);
summationInst.addAttributeValue(_displayName, summationText);
summationInst = InstanceUtilities.checkForIdenticalInstances(summationInst, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ private static GKInstance createInfEntitySet(GKInstance entitySetInst, boolean o
for (GKInstance candidateInst : candidateInstances)
{
GKInstance infCandidateInst = createOrthoEntity(candidateInst, false);
if (infCandidateInst != null && !existingMemberInstances.contains(infCandidateInst.getAttributeValue(name).toString()) && !existingCandidateInstances.contains(infCandidateInst.getAttributeValue(name).toString()))
if (infCandidateInst != null &&
!existingMemberInstances.contains(infCandidateInst.getAttributeValue(name).toString()) &&
!existingCandidateInstances.contains(infCandidateInst.getAttributeValue(name).toString()))
{
existingCandidateInstances.add(infCandidateInst.getAttributeValue(name).toString());
infCandidatesList.add(infCandidateInst);
Expand Down
Loading
Loading