Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add background traits to solr #81

Open
wants to merge 1 commit into
base: 2.x-stable
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ Page<DiseaseTrait> findByStudiesPublicationIdPubmedId(
"group by dt.id order by count(dt.id) desc")
List<Map.Entry> getDiseaseTraitCounts();

//findByStudiesIdAndStudiesHousekeepingCatalogPublishDateIsNotNullAndStudiesHousekeepingCatalogUnpublishDateIsNull
@RestResource(exported = false)
@Query("select t from DiseaseTrait t join t.studies s join s.housekeeping h where h.catalogPublishDate is null " +
"and h.catalogUnpublishDate is not null and s.id = :studyId")
List<DiseaseTrait> findBackgroundTraitByStudyId(
Long studyId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,11 @@ Page<EfoTrait> findByStudiesIdAndStudiesHousekeepingCatalogPublishDateIsNotNullA
@RestResource(exported = false)
Page<EfoTrait> findByStudiesPublicationIdPubmedId(String pumbedId, Pageable pageable);

//findByStudiesIdAndStudiesHousekeepingCatalogPublishDateIsNotNullAndStudiesHousekeepingCatalogUnpublishDateIsNull
@RestResource(exported = false)
@Query("select t from EfoTrait t join t.studies s join s.housekeeping h where h.catalogPublishDate is null " +
"and h.catalogUnpublishDate is not null and s.id = :studyId")
List<EfoTrait> findMappedBackgroundTraitByStudyId(
Long studyId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public void loadAssociatedData(Association association) {
int traitCount = association.getEfoTraits().size();
//Study study = studyService.fetchOne(association.getStudy());
Study study = association.getStudy();
study.getBackgroundTrait().getTrait();
study.getMappedBackgroundTraits().size();
AtomicInteger reportedGeneCount = new AtomicInteger();
Collection<SingleNucleotidePolymorphism> snps = new HashSet<>();
Collection<SingleNucleotidePolymorphism> proxySnps = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ public void loadAssociatedData(Study study) {
int efoTraitCount = study.getEfoTraits().size();
int associationCount = study.getAssociations().size();
int ancestryCount = study.getAncestries().size();
if(study.getBackgroundTrait() != null) {
study.getBackgroundTrait().getTrait();
}
if(study.getMappedBackgroundTraits() != null) {
study.getMappedBackgroundTraits().size();
}

study.getAncestries().forEach(
ancestry -> {
Expand Down Expand Up @@ -272,6 +278,8 @@ public void deepLoadAssociatedData(Study study) {
int associationCount = study.getAssociations().size();
// int snpCount = study.getSingleNucleotidePolymorphisms().size();
int platformCount = study.getPlatforms().size();
study.getMappedBackgroundTraits().size();
study.getBackgroundTrait().getTrait();

int ancestryCount = study.getAncestries().size();

Expand Down Expand Up @@ -329,6 +337,8 @@ public void deepLoadAssociatedData(Study study) {
for (Association association : study.getAssociations()) {
int lociCount = association.getLoci().size();
int associationEfoTraitCount = association.getEfoTraits().size();
study.getBackgroundTrait().getTrait();
study.getMappedBackgroundTraits().size();
getLog().trace("Association '" + association.getId() + "' is linked to " + lociCount + " loci and " +
associationEfoTraitCount + "efo traits.");
for (Locus locus : association.getLoci()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,20 @@ public Collection<DiseaseTrait> findReportedTraitByStudyId(Long studyId) {
studyId);
}

public Collection<DiseaseTrait> findBackgroundTraitByStudyId(Long studyId) {
return diseaseTraitRepository.findBackgroundTraitByStudyId(
studyId);
}

public Collection<DiseaseTrait> findReportedTraitByAssociationId(Long associationId) {
return diseaseTraitRepository.findByStudiesAssociationsIdAndStudiesHousekeepingCatalogPublishDateIsNotNullAndStudiesHousekeepingCatalogUnpublishDateIsNull(
associationId);
}

public Collection<EfoTrait> findMappedBackgroundTraitByStudyId(Long studyId) {
return efoTraitRepository.findMappedBackgroundTraitByStudyId(studyId);
}

public Collection<EfoTrait> findMappedTraitByStudyId(Long studyId) {
return efoTraitRepository.findByStudiesIdAndStudiesHousekeepingCatalogPublishDateIsNotNullAndStudiesHousekeepingCatalogUnpublishDateIsNull(
studyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,13 @@

<!-- diseasetrait -->
<field name="traitName" type="text_general" indexed="true" stored="true" multiValued="true" />
<field name="backgroundTraitName" type="text_general" indexed="true" stored="true" multiValued="true" />

<!-- efotrait -->
<field name="mappedLabel" type="text_general" indexed="true" stored="true" multiValued="true" />
<field name="mappedUri" type="text_general" indexed="true" stored="true" multiValued="true" />
<field name="backgroundEfoLabel" type="text_general" indexed="true" stored="true" multiValued="true" />
<field name="backgroundEfoUri" type="text_general" indexed="true" stored="true" multiValued="true" />

<!-- ontology expanded info -->
<field name="trait" type="text_general" indexed="true" stored="true" multiValued="true" />
Expand Down Expand Up @@ -397,8 +400,11 @@
<copyField source="study_additionalAncestryDescription" dest="text" />
<copyField source="study_accessionId" dest="text" />
<copyField source="traitName" dest="text" />
<copyField source="backgroundTraitName" dest="text" />
<copyField source="mappedLabel" dest="text" />
<copyField source="mappedUri" dest="text" />
<copyField source="backgroundEfoLabel" dest="text" />
<copyField source="backgroundEfoUri" dest="text" />
<copyField source="trait" dest="text" />
<copyField source="traitUri" dest="text" />
<copyField source="shortForm" dest="text" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ public class AssociationDocument extends OntologyEnabledDocument<Association> {
@Field("mappedLabel") private Collection<String> mappedLabels;
@Field("mappedUri") private Collection<String> mappedUris;

// embedded DiseaseTrait info
@Field("backgroundTraitName") private Collection<String> backgroundTraitNames;

// embedded EfoTrait info
@Field("backgroundEfoLabel") private Collection<String> backgroundEfoLabels;
@Field("backgroundEfoUri") private Collection<String> backgroundEfoUris;

public AssociationDocument(Association association) {
super(association);
this.riskFrequency = association.getRiskFrequency();
Expand Down Expand Up @@ -152,6 +159,11 @@ public AssociationDocument(Association association) {
this.mappedLabels = new LinkedHashSet<>();
this.mappedUris = new LinkedHashSet<>();

this.backgroundTraitNames = new LinkedHashSet<>();

this.backgroundEfoLabels = new LinkedHashSet<>();
this.backgroundEfoUris = new LinkedHashSet<>();

this.ancestralGroups = new LinkedHashSet<>();
this.countriesOfOrigin = new LinkedHashSet<>();
this.countriesOfRecruitment = new LinkedHashSet<>();
Expand Down Expand Up @@ -351,6 +363,18 @@ public void addMappedUri(String mappedUri) {
this.mappedUris.add(mappedUri);
}

public void addBackgroundTraitName(String traitName) {
this.backgroundTraitNames.add(traitName);
}

public void addBackgroundEfoLabel(String mappedLabel) {
this.backgroundEfoLabels.add(mappedLabel);
}

public void addBackgroundEfoUri(String mappedUri) {
this.backgroundEfoUris.add(mappedUri);
}

public void addStudyId(String studyId) {
this.studyIds.add(studyId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public class StudyDocument extends OntologyEnabledDocument<Study> {
@Field("mappedLabel") private Collection<String> mappedLabels;
@Field("mappedUri") private Collection<String> mappedUris;

// embedded DiseaseTrait info
@Field("backgroundTraitName") private Collection<String> backgroundTraitNames;

// embedded EfoTrait info
@Field("backgroundEfoLabel") private Collection<String> backgroundEfoLabels;
@Field("backgroundEfoUri") private Collection<String> backgroundEfoUris;

public StudyDocument(Study study) {
super(study);
this.pubmedId = study.getPublicationId().getPubmedId();
Expand Down Expand Up @@ -146,6 +153,11 @@ public StudyDocument(Study study) {

this.mappedLabels = new LinkedHashSet<>();
this.mappedUris = new LinkedHashSet<>();

this.backgroundTraitNames = new LinkedHashSet<>();

this.backgroundEfoLabels = new LinkedHashSet<>();
this.backgroundEfoUris = new LinkedHashSet<>();
}

public String getPubmedId() {
Expand Down Expand Up @@ -273,6 +285,18 @@ public void addMappedUri(String mappedUri) {
this.mappedUris.add(mappedUri);
}

public void addBackgroundTraitName(String traitName) {
this.backgroundTraitNames.add(traitName);
}

public void addBackgroundEfoLabel(String mappedLabel) {
this.backgroundEfoLabels.add(mappedLabel);
}

public void addBackgroundEfoUri(String mappedUri) {
this.backgroundEfoUris.add(mappedUri);
}

public Collection<String> getAncestralGroups() {
return ancestralGroups;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.ac.ebi.spot.goci.model.AssociationDocument;
import uk.ac.ebi.spot.goci.model.DiseaseTraitDocument;
import uk.ac.ebi.spot.goci.model.EfoDocument;
import uk.ac.ebi.spot.goci.model.StudyDocument;
import uk.ac.ebi.spot.goci.model.*;

/**
* Javadocs go here!
Expand All @@ -14,7 +11,7 @@
* @date 13/02/15
*/
@Service
public class AssociationEnrichmentService implements DocumentEnrichmentService<AssociationDocument> {
public class AssociationEnrichmentService implements DocumentEnrichmentService<AssociationDocument, Association> {
private final DiseaseTraitDocumentCache diseaseTraitCache;
private final StudyDocumentCache studyCache;
private StudyService studyService;
Expand All @@ -36,7 +33,7 @@ public AssociationEnrichmentService(StudyService studyService, TraitService trai
return 2;
}

@Override public void doEnrichment(AssociationDocument document) {
@Override public void doEnrichment(AssociationDocument document, Association association) {
long id = Long.valueOf(document.getId().split(":")[1]);

studyService.findByAssociationId(id).forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Tony Burdett
* @date 19/01/15
*/
public interface DocumentEnrichmentService<D extends Document> {
public interface DocumentEnrichmentService<D extends Document, T> {
/**
* The priority of a document enrichment service indicates the order in which enrichments will be run, lowest value
* first. This enables enrichment chaining.
Expand All @@ -18,5 +18,5 @@ public interface DocumentEnrichmentService<D extends Document> {
*/
int getPriority();

void doEnrichment(D document);
void doEnrichment(D document, T dbObject);
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public <O, D extends Document<O>> D convert(O object, Class<D> documentType) {
return des1.getPriority() - des2.getPriority();
}
})
.forEach(documentEnrichmentService -> documentEnrichmentService.doEnrichment(document));
.forEach(documentEnrichmentService -> documentEnrichmentService.doEnrichment(document, object));

// and return
return document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.ac.ebi.spot.goci.model.DiseaseTrait;
import uk.ac.ebi.spot.goci.model.OntologyEnabledDocument;
import uk.ac.ebi.spot.goci.ontology.owl.OntologyLoader;

Expand All @@ -18,7 +19,7 @@
* @date 19/01/15
*/
@Service
public class OntologyExpansionService implements DocumentEnrichmentService<OntologyEnabledDocument<?>> {
public class OntologyExpansionService implements DocumentEnrichmentService<OntologyEnabledDocument<?>, Object> {
private OntologyLoader ontologyLoader;

private final Logger log = LoggerFactory.getLogger(getClass());
Expand All @@ -36,7 +37,7 @@ public OntologyExpansionService(OntologyLoader ontologyLoader) {
return 4;
}

@Override public void doEnrichment(OntologyEnabledDocument<?> document) {
@Override public void doEnrichment(OntologyEnabledDocument<?> document, Object o) {
// improve trait document with parent and child terms etc here
for (String traitUriString : document.getTraitUris()) {
traitUriString = traitUriString.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.ac.ebi.spot.goci.model.Association;
import uk.ac.ebi.spot.goci.model.AssociationDocument;
import uk.ac.ebi.spot.goci.model.DiseaseTraitDocument;
import uk.ac.ebi.spot.goci.model.EfoDocument;
import uk.ac.ebi.spot.goci.model.StudyDocument;
import uk.ac.ebi.spot.goci.model.*;

import java.util.Collection;

Expand All @@ -17,7 +13,7 @@
* @date 13/02/15
*/
@Service
public class StudyEnrichmentService implements DocumentEnrichmentService<StudyDocument> {
public class StudyEnrichmentService implements DocumentEnrichmentService<StudyDocument, Study> {
private final EfoDocumentCache efoCache;
private final DiseaseTraitDocumentCache diseaseTraitCache;
private final StudyDocumentCache studyDocumentCache;
Expand All @@ -39,19 +35,24 @@ public StudyEnrichmentService(AssociationService associationService,
return 1;
}

@Override public void doEnrichment(StudyDocument document) {
@Override public void doEnrichment(StudyDocument document, Study study) {
long id = Long.valueOf(document.getId().split(":")[1]);
if(!studyDocumentCache.hasDocument(id)){
studyDocumentCache.addDocument(id, document);
}
// if(!studyDocumentCache.hasDocument(id)){
// studyDocumentCache.addDocument(id, document);
// }

Collection<Association> associations = associationService.findPublishedAssociationsByStudyId(id);
Collection<Association> associations = study.getAssociations();
document.setAssociationCount(associations.size());
associations.forEach(association -> document.embed(new AssociationDocument(association)));

traitService.findReportedTraitByStudyId(id).forEach(
trait -> document.embed(diseaseTraitCache.getDocument(trait.getTrait())));
traitService.findMappedTraitByStudyId(id).forEach(
document.embed(diseaseTraitCache.getDocument(study.getDiseaseTrait().getTrait()));
study.getEfoTraits().forEach(
trait -> document.embed(efoCache.getDocument(trait.getTrait())));
document.addBackgroundTraitName(study.getBackgroundTrait().getTrait());
study.getMappedBackgroundTraits().forEach(efoTrait -> {
document.addBackgroundEfoLabel(efoTrait.getTrait());
document.addBackgroundEfoUri(efoTrait.getUri());
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.ac.ebi.spot.goci.model.AssociationDocument;
import uk.ac.ebi.spot.goci.model.DiseaseTraitDocument;
import uk.ac.ebi.spot.goci.model.EfoDocument;
import uk.ac.ebi.spot.goci.model.EfoTrait;
import uk.ac.ebi.spot.goci.model.StudyDocument;
import uk.ac.ebi.spot.goci.model.*;

import java.util.HashSet;
import java.util.Set;
Expand All @@ -18,7 +14,7 @@
* @date 13/02/15
*/
@Service
public class TraitEnrichmentService implements DocumentEnrichmentService<DiseaseTraitDocument> {
public class TraitEnrichmentService implements DocumentEnrichmentService<DiseaseTraitDocument, DiseaseTrait> {
private final EfoDocumentCache efoCache;
private StudyService studyService;
private AssociationService associationService;
Expand All @@ -38,7 +34,7 @@ public TraitEnrichmentService(StudyService studyService,
return 3;
}

@Override public void doEnrichment(DiseaseTraitDocument document) {
@Override public void doEnrichment(DiseaseTraitDocument document, DiseaseTrait diseaseTrait) {
long id = Long.valueOf(document.getId().split(":")[1]);
// Comment this part if you want to exclude the DiseaseTrait Doc Enrichment
studyService.findByDiseaseTraitId(id).forEach(
Expand Down