Skip to content

Commit

Permalink
Merge pull request #439 from EBISPOT/goci#166_split_and_index_bg_traits
Browse files Browse the repository at this point in the history
Goci#166 split and index bg traits
  • Loading branch information
ala-ebi authored Jul 26, 2021
2 parents e6b267d + 1d0190b commit fbcbfd9
Show file tree
Hide file tree
Showing 18 changed files with 202 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
################################################################################
Migration script to create table ASSOCIATION_BKG_EFO_TRAIT and its constraints
author: Ala Abid
date: 07 jun 2021
version: 2.7.0.002
################################################################################
*/

--------------------------------------------------------
-- CREATE TABLE, INDEX, FOREIGN KEY
--------------------------------------------------------

CREATE TABLE ASSOCIATION_BKG_EFO_TRAIT (ASSOCIATION_ID NUMBER(19,0), EFO_TRAIT_ID NUMBER(19,0));
ALTER TABLE ASSOCIATION_BKG_EFO_TRAIT MODIFY (EFO_TRAIT_ID NOT NULL);
ALTER TABLE ASSOCIATION_BKG_EFO_TRAIT MODIFY (ASSOCIATION_ID NOT NULL);
ALTER TABLE ASSOCIATION_BKG_EFO_TRAIT ADD CONSTRAINT ASSC_BKG_EFO_ASSC_ID_FK FOREIGN KEY (ASSOCIATION_ID) REFERENCES ASSOCIATION (ID);
ALTER TABLE ASSOCIATION_BKG_EFO_TRAIT ADD CONSTRAINT ASSC_BKG_EFO_TRAIT_ID_FK FOREIGN KEY (EFO_TRAIT_ID) REFERENCES EFO_TRAIT (ID);
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public class Association implements Trackable {
inverseJoinColumns = @JoinColumn(name = "EFO_TRAIT_ID"))
private Collection<EfoTrait> efoTraits = new ArrayList<>();

@ManyToMany
@JoinTable(name = "ASSOCIATION_BKG_EFO_TRAIT",
joinColumns = @JoinColumn(name = "ASSOCIATION_ID"),
inverseJoinColumns = @JoinColumn(name = "EFO_TRAIT_ID"))
private Collection<EfoTrait> bkgEfoTraits = new ArrayList<>();

@JsonIgnore
@OneToOne(mappedBy = "association", orphanRemoval = true)
private AssociationReport associationReport;
Expand Down Expand Up @@ -165,6 +171,7 @@ public Association(String riskFrequency,
Study study,
Collection<Locus> loci,
Collection<EfoTrait> efoTraits,
Collection<EfoTrait> bkgEfoTraits,
AssociationReport associationReport,
Collection<AssociationValidationReport> associationValidationReport,
Date lastMappingDate,
Expand Down Expand Up @@ -193,6 +200,7 @@ public Association(String riskFrequency,
this.study = study;
this.loci = loci;
this.efoTraits = efoTraits;
this.bkgEfoTraits = bkgEfoTraits;
this.associationReport = associationReport;
this.associationValidationReports = associationValidationReport;
this.lastMappingDate = lastMappingDate;
Expand Down Expand Up @@ -343,6 +351,18 @@ public void addEfoTrait(EfoTrait efoTrait) {
efoTraits.add(efoTrait);
}

public Collection<EfoTrait> getBkgEfoTraits() {
return bkgEfoTraits;
}

public void setBkgEfoTraits(Collection<EfoTrait> bkgEfoTraits) {
this.bkgEfoTraits = bkgEfoTraits;
}

public void addBkgEfoTrait(EfoTrait bkgEfoTrait) {
bkgEfoTraits.add(bkgEfoTrait);
}

public Boolean getSnpApproved() {
return snpApproved;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ public class EfoTrait {
@ManyToMany(mappedBy = "efoTraits")
private Collection<Study> studies;

@ManyToMany(mappedBy = "mappedBackgroundTraits")
private Collection<Study> studiesBkg;

@ManyToMany(mappedBy = "efoTraits")
private Collection<Association> associations;

@ManyToMany(mappedBy = "bkgEfoTraits")
private Collection<Association> associationsBkg;

// JPA no-args constructor
public EfoTrait() {
}
Expand Down Expand Up @@ -84,6 +90,14 @@ public void setStudies(Collection<Study> studies) {
this.studies = studies;
}

public Collection<Study> getStudiesBkg() {
return studiesBkg;
}

public void setStudiesBkg(Collection<Study> studiesBkg) {
this.studiesBkg = studiesBkg;
}

public Collection<Association> getAssociations() {
return associations;
}
Expand All @@ -92,6 +106,14 @@ public void setAssociations(Collection<Association> associations) {
this.associations = associations;
}

public Collection<Association> getAssociationsBkg() {
return associationsBkg;
}

public void setAssociationsBkg(Collection<Association> associationsBkg) {
this.associationsBkg = associationsBkg;
}

public String getShortForm() {
return shortForm;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class Study implements Trackable {
inverseJoinColumns = @JoinColumn(name = "DISEASE_TRAIT_ID"))
private DiseaseTrait backgroundTrait;

@ManyToMany()
@ManyToMany
@JoinTable(name = "STUDY_BACKGROUND_EFO_TRAIT",
joinColumns = @JoinColumn(name = "STUDY_ID"),
inverseJoinColumns = @JoinColumn(name = "EFO_TRAIT_ID"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public interface EfoTraitRepository extends JpaRepository<EfoTrait, Long> {
List<EfoTrait> findByStudiesIdAndStudiesHousekeepingCatalogPublishDateIsNotNullAndStudiesHousekeepingCatalogUnpublishDateIsNull(
Long studyId);

@RestResource(exported = false)
List<EfoTrait> findByStudiesBkgIdAndStudiesBkgHousekeepingCatalogPublishDateIsNotNullAndStudiesBkgHousekeepingCatalogUnpublishDateIsNull(
Long studyId);

@RestResource(exported = false)
List<EfoTrait> findByStudiesIdAndStudiesHousekeepingCatalogPublishDateIsNotNullAndStudiesHousekeepingCatalogUnpublishDateIsNull(
Sort sort,
Expand All @@ -51,6 +55,10 @@ Page<EfoTrait> findByStudiesIdAndStudiesHousekeepingCatalogPublishDateIsNotNullA
@Query("select e.trait from EfoTrait e join e.associations a where a.id = :associationId")
List<String> findTraitNamesByAssociationsId(Long associationId);

@RestResource(exported = false)
@Query("select e.trait from EfoTrait e join e.associationsBkg a where a.id = :associationId")
List<String> findBkgTraitNamesByAssociationsId(Long associationId);

@RestResource(exported = false)
List<EfoTrait> findByAssociationsId(Sort sort, Long associationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public Collection<EfoTrait> findMappedTraitByStudyId(Long studyId) {
studyId);
}

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

public Collection<EfoTrait> findMappedTraitByAssociationId(Long associationId) {
return efoTraitRepository.findByAssociationsId(associationId);
}
Expand All @@ -52,6 +57,10 @@ public Collection<String> findMappedTraitNamesByAssociationId(Long associationId
return efoTraitRepository.findTraitNamesByAssociationsId(associationId);
}

public Collection<String> findMappedBkgTraitNamesByAssociationId(Long associationId) {
return efoTraitRepository.findBkgTraitNamesByAssociationsId(associationId);
}

@Transactional(readOnly = true)
public List<EfoTrait> findAllEfoTraits() {
List<EfoTrait> allEfoTraits = efoTraitRepository.findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,7 @@ public String applyStudyEFOtraitToSnps(Model model, @PathVariable Long studyId,
associations.addAll(associationRepository.findByStudyId(studyId));
Study study = studyRepository.findOne((studyId));
Collection<EfoTrait> efoTraits = study.getEfoTraits();
Collection<EfoTrait> backgroundEfoTraits = study.getMappedBackgroundTraits();


if (associations.size() == 0 || efoTraits.size() == 0) {
Expand All @@ -1321,6 +1322,8 @@ public String applyStudyEFOtraitToSnps(Model model, @PathVariable Long studyId,
associationTraits.add(efoTrait);
}

Collection<EfoTrait> associationBackgroundTraits = new ArrayList<>(backgroundEfoTraits);

for (Association association : associations) {
if (association.getEfoTraits().size() != 0 && !overwrite) {
for (EfoTrait trait : associationTraits) {
Expand All @@ -1332,6 +1335,7 @@ public String applyStudyEFOtraitToSnps(Model model, @PathVariable Long studyId,
else {
association.setEfoTraits(associationTraits);
}
association.setBkgEfoTraits(associationBackgroundTraits);
association.setLastUpdateDate(new Date());
associationRepository.save(association);
}
Expand Down Expand Up @@ -1677,4 +1681,4 @@ public String getValidationResult(@PathVariable Long studyId, HttpSession sessio
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class SnpAssociationTableView {

private String efoTraits;

private String backgroundEfoTraits;

private Float orPerCopyNum;

private Float orPerCopyRecip;
Expand Down Expand Up @@ -93,6 +95,7 @@ public SnpAssociationTableView(Long associationId,
String betaUnit,
String description,
String efoTraits,
String backgroundEfoTraits,
String lastMappingDate,
String lastMappingPerformedBy,
String multiSnpHaplotype,
Expand Down Expand Up @@ -120,6 +123,7 @@ public SnpAssociationTableView(Long associationId,
this.betaUnit = betaUnit;
this.description = description;
this.efoTraits = efoTraits;
this.backgroundEfoTraits = backgroundEfoTraits;
this.lastMappingDate = lastMappingDate;
this.lastMappingPerformedBy = lastMappingPerformedBy;
this.multiSnpHaplotype = multiSnpHaplotype;
Expand Down Expand Up @@ -213,6 +217,14 @@ public void setEfoTraits(String efoTraits) {
this.efoTraits = efoTraits;
}

public String getBackgroundEfoTraits() {
return backgroundEfoTraits;
}

public void setBackgroundEfoTraits(String backgroundEfoTraits) {
this.backgroundEfoTraits = backgroundEfoTraits;
}

public String getLastMappingDate() {
return lastMappingDate;
}
Expand Down Expand Up @@ -376,4 +388,4 @@ public AssociationExtension getAssociationExtension() {
public void setAssociationExtension(AssociationExtension associationExtension) {
this.associationExtension = associationExtension;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ public SnpAssociationTableView createSnpAssociationTableView(Association associa
associationEfoTraits = String.join(", ", efoTraits);
snpAssociationTableView.setEfoTraits(associationEfoTraits);

Collection<String> backgroundEfoTraits = new ArrayList<>();
for (EfoTrait efoTrait: association.getBkgEfoTraits()) {
backgroundEfoTraits.add(efoTrait.getTrait());
}
String associationBackgroundEfoTraits = String.join(",", backgroundEfoTraits);
snpAssociationTableView.setBackgroundEfoTraits(associationBackgroundEfoTraits);

// Set OR values
snpAssociationTableView.setOrPerCopyNum(association.getOrPerCopyNum());
snpAssociationTableView.setOrPerCopyRecip(association.getOrPerCopyRecip());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
<th style="font-size: small">p-Value (mantissa x 10 exponent)</th>
<th style="font-size: small">p-Value Description</th>
<th style="font-size: small">EFO trait</th>
<th style="font-size: small">Background EFO trait</th>
<th style="font-size: small">OR</th>
<th style="font-size: small">OR reciprocal</th>
<th style="font-size: small">Beta</th>
Expand Down Expand Up @@ -485,6 +486,13 @@
th:text="'Warning: EFO trait not assigned'"></span>
</td>

<td>
<p th:text="${snpAssociationTableView.backgroundEfoTraits} ?: ''"></p>
<span style="font-style: italic; color:red; font-size: small"
th:if="*{#strings.isEmpty(snpAssociationTableView.backgroundEfoTraits)}"
th:text="'Warning: EFO trait not assigned'"></span>
</td>

<td th:text="${snpAssociationTableView.orPerCopyNum} ?: ''"></td>
<td>
<p th:text="${snpAssociationTableView.orPerCopyRecip} ?: ''"></p>
Expand Down Expand Up @@ -616,4 +624,4 @@
</script>

</body>
</html>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@
<field name="mappedLabel" type="text_general" indexed="true" stored="true" multiValued="true" />
<field name="mappedUri" type="text_general" indexed="true" stored="true" multiValued="true" />

<!-- background efotrait -->
<field name="mappedBkgLabel" type="text_general" indexed="true" stored="true" multiValued="true" />
<field name="mappedBkgUri" type="text_general" indexed="true" stored="true" multiValued="true" />

<!-- ontology expanded info -->
<field name="trait" type="text_general" indexed="true" stored="true" multiValued="true" />
<field name="traitUri" type="text_general" indexed="true" stored="true" multiValued="true" />
Expand Down Expand Up @@ -401,6 +405,8 @@
<copyField source="traitName" dest="text" />
<copyField source="mappedLabel" dest="text" />
<copyField source="mappedUri" dest="text" />
<copyField source="mappedBkgLabel" dest="text" />
<copyField source="mappedBkgUri" 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 @@ -174,6 +174,12 @@ public class AssociationDocument extends OntologyEnabledDocument<Association> {
@Field("mappedUri")
private Collection<String> mappedUris;

// embedded background EfoTrait info
@Field("mappedBkgLabel")
private Collection<String> mappedBkgLabels;
@Field("mappedBkgUri")
private Collection<String> mappedBkgUris;

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

this.mappedBkgLabels = new LinkedHashSet<>();
this.mappedBkgUris = new LinkedHashSet<>();

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

public void addMappedBkgUri(String mappedBkgUri) {
this.mappedBkgUris.add(mappedBkgUri);
}

public void addMappedBkgLabel(String mappedBkgLabel) {
this.mappedBkgLabels.add(mappedBkgLabel);
}

public void addStudyId(String studyId) {
this.studyIds.add(studyId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package uk.ac.ebi.spot.goci.model;

import org.apache.solr.client.solrj.beans.Field;

/**
* Javadocs go here!
*
* @author Ala Abid
* @date 26/05/21
*/
public class BackgroundEfoDocument extends OntologyEnabledDocument<EfoTrait> {
@Field private String mappedBkgLabel;
@Field private String mappedBkgUri;

public BackgroundEfoDocument(EfoTrait efoTrait) {
super(efoTrait);
this.mappedBkgLabel = efoTrait.getTrait();
this.mappedBkgUri = efoTrait.getUri();
// addTraitUri(mappedBkgUri);
}

public String getMappedBkgLabel() {
return mappedBkgLabel;
}

public String getMappedBkgUri() {
return mappedBkgUri;
}
}
Loading

0 comments on commit fbcbfd9

Please sign in to comment.