use of uk.ac.ebi.spot.goci.model.EfoTrait in project goci by EBISPOT.
the class TraitEnrichmentService method doEnrichment.
@Override
public void doEnrichment(DiseaseTraitDocument document) {
long id = Long.valueOf(document.getId().split(":")[1]);
studyService.findByDiseaseTraitId(id).forEach(study -> {
document.embed(new StudyDocument(study));
Set<EfoTrait> efoTraits = new HashSet<>();
traitService.findMappedTraitByStudyId(study.getId()).forEach(efoTraits::add);
efoTraits.forEach(trait -> {
document.embed(new EfoDocument(trait));
associationService.findPublishedAssociationsByEfoTraitId(trait.getId()).forEach(association -> document.embed(new AssociationDocument(association)));
});
});
}
use of uk.ac.ebi.spot.goci.model.EfoTrait in project goci by EBISPOT.
the class AssociationAttributeService method getEfoTraitsFromRepository.
public Collection<EfoTrait> getEfoTraitsFromRepository(Collection<String> efoUris) {
Collection<EfoTrait> efoTraits = new ArrayList<>();
for (String uri : efoUris) {
String fullUri;
if (uri.contains("EFO")) {
fullUri = "http://www.ebi.ac.uk/efo/".concat(uri);
} else if (uri.contains("Orphanet")) {
fullUri = "http://www.orpha.net/ORDO/".concat(uri);
} else {
fullUri = "http://purl.obolibrary.org/obo/".concat(uri);
}
Collection<EfoTrait> traits = efoTraitRepository.findByUri(fullUri);
for (EfoTrait trait : traits) {
efoTraits.add(trait);
}
}
return efoTraits;
}
use of uk.ac.ebi.spot.goci.model.EfoTrait in project goci by EBISPOT.
the class DefaultGWASOWLConverter method convertAssociation.
protected void convertAssociation(Association association, OWLOntology ontology, Set<String> issuedWarnings) {
// get the trait association class
OWLClass taClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.TRAIT_ASSOCIATION_CLASS_IRI));
IRI taIndIRI = getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, association);
// create a new trait association instance
OWLNamedIndividual taIndiv = getDataFactory().getOWLNamedIndividual(taIndIRI);
// assert class membership
OWLClassAssertionAxiom classAssertion = getDataFactory().getOWLClassAssertionAxiom(taClass, taIndiv);
getManager().addAxiom(ontology, classAssertion);
// get datatype relations
OWLDataProperty has_p_value = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_P_VALUE_PROPERTY_IRI));
// get annotation relations
OWLAnnotationProperty rdfsLabel = getDataFactory().getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
//pvalue but says it was less then 10-6. So if we have no pvalue we just don't add it.
if (association.getPvalueMantissa() != null && association.getPvalueExponent() != null) {
double pval = association.getPvalueMantissa() * Math.pow(10, association.getPvalueExponent());
OWLLiteral pValue = getDataFactory().getOWLLiteral(pval);
// OWLLiteral pValue = getDataFactory().getOWLLiteral(association.getPvalueMantissa()+"e"+association.getPvalueExponent());
OWLDataPropertyAssertionAxiom p_value_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_p_value, taIndiv, pValue);
AddAxiom add_p_value = new AddAxiom(ontology, p_value_relation);
getManager().applyChange(add_p_value);
}
// get the snp instance for this association
OWLNamedIndividual snpIndiv;
String rsId = null;
for (Locus locus : association.getLoci()) {
for (RiskAllele riskAllele : locus.getStrongestRiskAlleles()) {
SingleNucleotidePolymorphism snp = riskAllele.getSnp();
rsId = snp.getRsId();
snpIndiv = getDataFactory().getOWLNamedIndividual(getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, snp));
if (snpIndiv == null) {
String warning = "A new SNP with the given RSID only will be created";
if (!issuedWarnings.contains(warning)) {
getLog().warn(warning);
issuedWarnings.add(warning);
}
snpIndiv = getDataFactory().getOWLNamedIndividual(getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, "SingleNucleotidePolymorphism", snp.getRsId(), true));
// assert class membership
OWLClass snpClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.SNP_CLASS_IRI));
OWLClassAssertionAxiom snpClassAssertion = getDataFactory().getOWLClassAssertionAxiom(snpClass, snpIndiv);
getManager().addAxiom(ontology, snpClassAssertion);
// assert rsid relation
OWLDataProperty has_snp_rsid = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_SNP_REFERENCE_ID_PROPERTY_IRI));
OWLLiteral rsid = getDataFactory().getOWLLiteral(snp.getRsId());
OWLDataPropertyAssertionAxiom rsid_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_snp_rsid, snpIndiv, rsid);
AddAxiom add_rsid = new AddAxiom(ontology, rsid_relation);
getManager().applyChange(add_rsid);
// assert label
OWLAnnotationAssertionAxiom snp_label_annotation = getDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, snpIndiv.getIRI(), rsid);
AddAxiom add_snp_label = new AddAxiom(ontology, snp_label_annotation);
getManager().applyChange(add_snp_label);
}
// get object properties
OWLObjectProperty has_subject = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.HAS_SUBJECT_IRI));
OWLObjectProperty is_subject_of = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.IS_SUBJECT_OF_IRI));
// assert relations
OWLObjectPropertyAssertionAxiom has_subject_snp_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(has_subject, taIndiv, snpIndiv);
AddAxiom add_has_subject_snp = new AddAxiom(ontology, has_subject_snp_relation);
getManager().applyChange(add_has_subject_snp);
OWLObjectPropertyAssertionAxiom is_subject_of_snp_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(is_subject_of, snpIndiv, taIndiv);
AddAxiom add_is_subject_of_snp = new AddAxiom(ontology, is_subject_of_snp_relation);
getManager().applyChange(add_is_subject_of_snp);
}
// get the EFO class for the trait
for (EfoTrait efoTrait : association.getEfoTraits()) {
OWLClass traitClass;
traitClass = getDataFactory().getOWLClass(IRI.create(efoTrait.getUri()));
if (traitClass == null) {
String warning = "This trait will be mapped to Experimental Factor";
if (!issuedWarnings.contains(warning)) {
getLog().warn(warning);
issuedWarnings.add(warning);
}
traitClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.EXPERIMENTAL_FACTOR_CLASS_IRI));
}
// create a new trait instance (puns the class)
IRI traitIRI = traitClass.getIRI();
OWLNamedIndividual traitIndiv = getDataFactory().getOWLNamedIndividual(traitIRI);
if (ontology.containsIndividualInSignature(traitIRI)) {
getLog().trace("Trait individual '" + traitIRI.toString() + "' (type: " + traitClass + ") already exists");
} else {
getLog().trace("Creating trait individual '" + traitIRI.toString() + "' (type: " + traitClass + ")");
}
// and also add the gwas label to the individual so we don't lose curated data
OWLDataProperty has_gwas_trait_name = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_GWAS_TRAIT_NAME_PROPERTY_IRI));
OWLLiteral gwasTrait = getDataFactory().getOWLLiteral(association.getStudy().getDiseaseTrait().getTrait());
OWLDataPropertyAssertionAxiom gwas_trait_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_gwas_trait_name, taIndiv, gwasTrait);
AddAxiom add_gwas_trait_name = new AddAxiom(ontology, gwas_trait_relation);
getManager().applyChange(add_gwas_trait_name);
// assert class membership
OWLClassAssertionAxiom traitClassAssertion = getDataFactory().getOWLClassAssertionAxiom(traitClass, traitIndiv);
getManager().addAxiom(ontology, traitClassAssertion);
// get object properties
OWLObjectProperty has_object = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.HAS_OBJECT_IRI));
OWLObjectProperty is_object_of = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.IS_OBJECT_OF_IRI));
// assert relations
OWLObjectPropertyAssertionAxiom has_object_trait_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(has_object, taIndiv, traitIndiv);
AddAxiom add_has_object_trait = new AddAxiom(ontology, has_object_trait_relation);
getManager().applyChange(add_has_object_trait);
OWLObjectPropertyAssertionAxiom is_object_of_trait_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(is_object_of, traitIndiv, taIndiv);
AddAxiom add_is_object_of_trait = new AddAxiom(ontology, is_object_of_trait_relation);
getManager().applyChange(add_is_object_of_trait);
}
// finally, assert label for this association
OWLLiteral label = getDataFactory().getOWLLiteral("Association between " + rsId + " and " + association.getStudy().getDiseaseTrait().getTrait());
OWLAnnotationAssertionAxiom label_annotation = getDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, taIndiv.getIRI(), label);
AddAxiom add_band_label = new AddAxiom(ontology, label_annotation);
getManager().applyChange(add_band_label);
}
}
use of uk.ac.ebi.spot.goci.model.EfoTrait in project goci by EBISPOT.
the class DefaultGWASOWLPublisher method validateGWASData.
/**
* Validates the data obtained from the GWAS catalog (prior to converting to OWL)
*
* @param studies the set of studies to validate
*/
protected void validateGWASData(Collection<Study> studies) {
// now check a random assortment of 5 studies for trait associations, abandoning broken ones
int count = 0;
int noAssocCount = 0;
int termMismatches = 0;
for (Study study : studies) {
// try {
Collection<Association> associations = study.getAssociations();
getLog().debug("Study (PubMed ID '" + study.getPubmedId() + "') had " + associations.size() + " associations");
if (associations.size() > 0) {
for (Association association : associations) {
String efoTraitsDashSepList = "";
for (EfoTrait efoTrait : association.getEfoTraits()) {
if ("".equals(efoTraitsDashSepList)) {
efoTraitsDashSepList.concat(efoTrait.getTrait());
} else {
efoTraitsDashSepList.concat(", " + efoTrait.getTrait());
}
}
for (Locus locus : association.getLoci()) {
for (RiskAllele riskAllele : locus.getStrongestRiskAlleles()) {
getLog().debug(// " Association: SNP '" + association.getAssociatedSNP().getRSID() +
" Association: SNP '" + riskAllele.getSnp().getRsId() + "' <-> Trait '" + efoTraitsDashSepList.toString() + "'");
}
}
}
count++;
} else {
noAssocCount++;
}
}
int eligCount = studies.size() - noAssocCount;
int correctCount = count + termMismatches;
getLog().info("\n\nREPORT:\n" + eligCount + "/" + studies.size() + " declared associations and therefore could usefully be mapped.\n" + (eligCount - count - termMismatches) + "/" + eligCount + " failed due to data integrity concerns.\n" + count + "/" + correctCount + " studies could be completely mapped after passing all checks.\n" + termMismatches + "/" + correctCount + " failed due to missing or duplicated terms in EFO");
}
use of uk.ac.ebi.spot.goci.model.EfoTrait in project goci by EBISPOT.
the class SnpAssociationTableViewService method createSnpAssociationTableView.
/**
* Create object, from Association, that will be returned to view
*
* @param association Association object
*/
public SnpAssociationTableView createSnpAssociationTableView(Association association) {
SnpAssociationTableView snpAssociationTableView = new SnpAssociationTableView();
// For SNP interaction studies snp, proxy snps, risk alleles etc
// should be separated by an 'x'
String delimiter = "; ";
if (association.getSnpInteraction()) {
delimiter = " x ";
}
snpAssociationTableView.setAssociationId(association.getId());
// For each locus relevant attributes
Collection<Locus> loci = association.getLoci();
Collection<String> allLociGenes = new ArrayList<>();
Collection<String> allLociRiskAlleles = new ArrayList<String>();
Collection<String> allLociSnps = new ArrayList<String>();
Collection<String> allLociProxySnps = new ArrayList<String>();
Collection<String> allLociRiskAlleleFrequencies = new ArrayList<String>();
Collection<String> allLociSnpStatuses = new ArrayList<String>();
// By looking at each locus in turn we can keep order in view
for (Locus locus : loci) {
// Store gene names, a locus can have a number of genes attached.
// Per locus create a comma separated list and add to an array.
// Further processing will then delimit this list
// either by ; or 'x' depending on association type
Collection<String> currentlocusGenes = new ArrayList<>();
String commaSeparatedGenes = "";
for (Gene gene : locus.getAuthorReportedGenes()) {
currentlocusGenes.add(gene.getGeneName());
}
if (!currentlocusGenes.isEmpty()) {
commaSeparatedGenes = String.join(", ", currentlocusGenes);
allLociGenes.add(commaSeparatedGenes);
} else {
allLociGenes.add("NR");
}
//This sort ensures that haplotype SNPs are displayed in the correct order
Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
for (RiskAllele riskAllele : ra) {
allLociRiskAlleles.add(riskAllele.getRiskAlleleName());
// Based on assumption we only have one locus with a single risk allele attached
if (!association.getMultiSnpHaplotype() && !association.getSnpInteraction()) {
if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
allLociRiskAlleleFrequencies.add(riskAllele.getRiskFrequency());
}
}
// SNPs attached to risk allele
SingleNucleotidePolymorphism snp = riskAllele.getSnp();
allLociSnps.add(snp.getRsId());
// Set proxies if present
Collection<String> currentLocusProxies = new ArrayList<>();
String commaSeparatedProxies = "";
if (riskAllele.getProxySnps() != null) {
for (SingleNucleotidePolymorphism proxySnp : riskAllele.getProxySnps()) {
currentLocusProxies.add(proxySnp.getRsId());
}
}
// Comma separate proxies in view
if (!currentLocusProxies.isEmpty()) {
commaSeparatedProxies = String.join(", ", currentLocusProxies);
allLociProxySnps.add(commaSeparatedProxies);
} else {
allLociProxySnps.add("NR");
}
// Only required for SNP interaction studies
if (association.getSnpInteraction() != null) {
if (association.getSnpInteraction()) {
// Genome wide Vs Limited List
Collection<String> snpStatus = new ArrayList<>();
String commaSeparatedSnpStatus = "";
if (riskAllele.getLimitedList() != null) {
if (riskAllele.getLimitedList()) {
snpStatus.add("LL");
}
}
if (riskAllele.getGenomeWide() != null) {
if (riskAllele.getGenomeWide()) {
snpStatus.add("GW");
}
}
if (!snpStatus.isEmpty()) {
commaSeparatedSnpStatus = String.join(", ", snpStatus);
allLociSnpStatuses.add(commaSeparatedSnpStatus);
} else {
allLociSnpStatuses.add("NR");
}
// Allele risk frequency
if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
allLociRiskAlleleFrequencies.add(riskAllele.getRiskFrequency());
} else {
allLociRiskAlleleFrequencies.add("NR");
}
}
}
}
}
// Create delimited strings for view
String authorReportedGenes = null;
if (allLociGenes.size() > 1) {
authorReportedGenes = String.join(delimiter, allLociGenes);
} else {
authorReportedGenes = String.join("", allLociGenes);
}
snpAssociationTableView.setAuthorReportedGenes(authorReportedGenes);
String strongestRiskAlleles = null;
if (allLociRiskAlleles.size() > 1) {
strongestRiskAlleles = String.join(delimiter, allLociRiskAlleles);
} else {
strongestRiskAlleles = String.join("", allLociRiskAlleles);
}
snpAssociationTableView.setStrongestRiskAlleles(strongestRiskAlleles);
String associationSnps = null;
if (allLociSnps.size() > 1) {
associationSnps = String.join(delimiter, allLociSnps);
} else {
associationSnps = String.join("", allLociSnps);
}
snpAssociationTableView.setSnps(associationSnps);
String associationProxies = null;
if (allLociProxySnps.size() > 1) {
associationProxies = String.join(delimiter, allLociProxySnps);
} else {
associationProxies = String.join("", allLociProxySnps);
}
snpAssociationTableView.setProxySnps(associationProxies);
// Set both risk frequencies
String associationRiskAlleleFrequencies = null;
if (allLociRiskAlleleFrequencies.size() > 1) {
associationRiskAlleleFrequencies = String.join(delimiter, allLociRiskAlleleFrequencies);
} else {
associationRiskAlleleFrequencies = String.join("", allLociRiskAlleleFrequencies);
}
snpAssociationTableView.setRiskAlleleFrequencies(associationRiskAlleleFrequencies);
snpAssociationTableView.setAssociationRiskFrequency(association.getRiskFrequency());
String associationSnpStatuses = null;
if (allLociSnpStatuses.size() > 1) {
associationSnpStatuses = String.join(delimiter, allLociSnpStatuses);
} else {
associationSnpStatuses = String.join("", allLociSnpStatuses);
}
snpAssociationTableView.setSnpStatuses(associationSnpStatuses);
snpAssociationTableView.setPvalueMantissa(association.getPvalueMantissa());
snpAssociationTableView.setPvalueExponent(association.getPvalueExponent());
snpAssociationTableView.setPvalueDescription(association.getPvalueDescription());
Collection<String> efoTraits = new ArrayList<>();
for (EfoTrait efoTrait : association.getEfoTraits()) {
efoTraits.add(efoTrait.getTrait());
}
String associationEfoTraits = null;
associationEfoTraits = String.join(", ", efoTraits);
snpAssociationTableView.setEfoTraits(associationEfoTraits);
// Set OR values
snpAssociationTableView.setOrPerCopyNum(association.getOrPerCopyNum());
snpAssociationTableView.setOrPerCopyRecip(association.getOrPerCopyRecip());
snpAssociationTableView.setOrPerCopyRecipRange(association.getOrPerCopyRecipRange());
// Set beta values
snpAssociationTableView.setBetaNum(association.getBetaNum());
snpAssociationTableView.setBetaDirection(association.getBetaDirection());
snpAssociationTableView.setBetaUnit(association.getBetaUnit());
snpAssociationTableView.setRange(association.getRange());
snpAssociationTableView.setDescription(association.getDescription());
snpAssociationTableView.setStandardError(association.getStandardError());
snpAssociationTableView.setAssociationType(association.getSnpType());
if (association.getMultiSnpHaplotype() != null) {
if (association.getMultiSnpHaplotype()) {
snpAssociationTableView.setMultiSnpHaplotype("Yes");
}
if (!association.getMultiSnpHaplotype()) {
snpAssociationTableView.setMultiSnpHaplotype("No");
}
}
if (association.getSnpInteraction() != null) {
if (association.getSnpInteraction()) {
snpAssociationTableView.setSnpInteraction("Yes");
}
if (!association.getSnpInteraction()) {
snpAssociationTableView.setSnpInteraction("No");
}
}
if (association.getSnpApproved() != null) {
if (association.getSnpApproved()) {
snpAssociationTableView.setSnpApproved("Yes");
}
if (!association.getSnpApproved()) {
snpAssociationTableView.setSnpApproved("No");
}
}
// Get validation warnings
snpAssociationTableView.setValidationWarnings(associationValidationReportService.getWarningSet(association.getId()));
// Get mapping details
if (association.getLastMappingPerformedBy() != null) {
snpAssociationTableView.setLastMappingPerformedBy(association.getLastMappingPerformedBy());
}
snpAssociationTableView.setMappingStatus("false");
if (association.getLastMappingDate() != null) {
snpAssociationTableView.setMappingStatus("true");
}
if (association.getLastMappingDate() != null) {
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
String dateOfLastMapping = df.format(association.getLastMappingDate());
snpAssociationTableView.setLastMappingDate(dateOfLastMapping);
}
return snpAssociationTableView;
}
Aggregations