Skip to content

Commit

Permalink
Merge pull request #1805 from alliance-genome/SCRUM-4754
Browse files Browse the repository at this point in the history
SCRUM-4754 Fix GAF loads
  • Loading branch information
markquintontulloch authored Jan 15, 2025
2 parents e0f101f + e3dd6c1 commit 0870f18
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.alliancegenome.curation_api.dao;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.persistence.Query;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.alliancegenome.curation_api.dao.base.BaseSQLDAO;
import org.alliancegenome.curation_api.model.entities.GeneOntologyAnnotation;
import org.alliancegenome.curation_api.model.entities.Organization;
import org.alliancegenome.curation_api.model.ingest.dto.GeneOntologyAnnotationDTO;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.base.Objects;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.persistence.Query;

@ApplicationScoped
public class GeneOntologyAnnotationDAO extends BaseSQLDAO<GeneOntologyAnnotation> {
Expand All @@ -34,17 +36,24 @@ insert into GeneOntologyAnnotation (id, singlegene_id,goterm_id)
return gaf;
}

public Map<Long, GeneOntologyAnnotationDTO> getAllGafIdsPerProvider(Organization sourceOrganization) {
public Map<Long, GeneOntologyAnnotationDTO> getAllGafIdsPerProvider(String speciesAbbreviation) {
String speciesNameClause = " and spec.displayname = :speciesName";
if (Objects.equal(speciesAbbreviation, "XB")) {
speciesNameClause = " and spec.displayname in ('XBXL', 'XBXT')";
}

Query query = entityManager.createNativeQuery("""
select gga.id, be.primaryexternalid, ot.curie
from GeneOntologyAnnotation as gga , BiologicalEntity as be, ontologyterm as ot,
species as spec
where gga.singlegene_id = be.id
and be.taxon_id = spec.taxon_id
and spec.displayname = :speciesName
and gga.goterm_id = ot.id
""");
query.setParameter("speciesName", sourceOrganization.getAbbreviation());
select gga.id, be.primaryexternalid, ot.curie
from GeneOntologyAnnotation as gga , BiologicalEntity as be, ontologyterm as ot,
species as spec
where gga.singlegene_id = be.id
and be.taxon_id = spec.taxon_id
and gga.goterm_id = ot.id
""" + speciesNameClause);
if (!Objects.equal(speciesAbbreviation, "XB")) {
query.setParameter("speciesName", speciesAbbreviation);
}

List<Object[]> result = query.getResultList();
Map<Long, GeneOntologyAnnotationDTO> map = new HashMap<>();
result.forEach(object -> {
Expand All @@ -53,6 +62,7 @@ public Map<Long, GeneOntologyAnnotationDTO> getAllGafIdsPerProvider(Organization
dto.setGoTermCurie((String) object[2]);
map.put((Long) object[0], dto);
});

return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@

import org.alliancegenome.curation_api.exceptions.ObjectUpdateException;
import org.alliancegenome.curation_api.model.entities.GeneOntologyAnnotation;
import org.alliancegenome.curation_api.model.entities.Organization;
import org.alliancegenome.curation_api.model.entities.bulkloads.BulkFMSLoad;
import org.alliancegenome.curation_api.model.entities.bulkloads.BulkLoadFileHistory;
import org.alliancegenome.curation_api.model.ingest.dto.GeneOntologyAnnotationDTO;
import org.alliancegenome.curation_api.services.GeneOntologyAnnotationService;
import org.alliancegenome.curation_api.services.OrganizationService;
import org.alliancegenome.curation_api.util.ProcessDisplayHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang.StringUtils;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import lombok.extern.jbosslog.JBossLog;

@JBossLog
@ApplicationScoped
public class GeneOntologyAnnotationExecutor extends LoadFileExecutor {

Expand All @@ -42,7 +39,6 @@ public class GeneOntologyAnnotationExecutor extends LoadFileExecutor {
public void execLoad(BulkLoadFileHistory bulkLoadFileHistory) throws IOException {

String abbr = ((BulkFMSLoad) bulkLoadFileHistory.getBulkLoad()).getFmsDataSubType();
Organization organization = organizationService.getByAbbr(abbr).getEntity();

// curie, List<GO curie>
Map<String, List<String>> uiMap = new HashMap<>();
Expand All @@ -56,7 +52,7 @@ public void execLoad(BulkLoadFileHistory bulkLoadFileHistory) throws IOException
String orgID = token[0];
String modID = token[1];
String goID = token[4];
if (abbr.equalsIgnoreCase(orgID) || orgID.equalsIgnoreCase("Xenbase") || abbr.equals("HUMAN") && orgID.equals("RGD")) {
if (abbr.equalsIgnoreCase(orgID) || abbr.equals("XB") && orgID.equalsIgnoreCase("Xenbase") || abbr.equals("HUMAN") && orgID.equals("RGD")) {
List<String> goIDs = uiMap.computeIfAbsent(modID, list -> new ArrayList<>());
goIDs.add(goID);
}
Expand All @@ -68,7 +64,7 @@ public void execLoad(BulkLoadFileHistory bulkLoadFileHistory) throws IOException

String name = bulkLoadFileHistory.getBulkLoad().getName();

Map<Long, GeneOntologyAnnotationDTO> gafMap = service.getGafMap(organization);
Map<Long, GeneOntologyAnnotationDTO> gafMap = service.getGafMap(abbr);
List<Long> gafIdsBefore = new ArrayList<>(gafMap.keySet().stream().toList());
gafIdsBefore.removeIf(Objects::isNull);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ private Species getSingleSpecies(String orgAbbreviation) {
}


public Map<Long, GeneOntologyAnnotationDTO> getGafMap(Organization organization) {
public Map<Long, GeneOntologyAnnotationDTO> getGafMap(String dataSubtype) {
if (gafMap.size() > 0) {
return gafMap;
}
gafMap = gafDAO.getAllGafIdsPerProvider(organization);
gafMap = gafDAO.getAllGafIdsPerProvider(dataSubtype);
return gafMap;
}

Expand Down

0 comments on commit 0870f18

Please sign in to comment.