Search in sources :

Example 21 with RiskAllele

use of uk.ac.ebi.spot.goci.model.RiskAllele in project goci by EBISPOT.

the class SnpInteractionAssociationService method createAssociation.

public Association createAssociation(SnpAssociationInteractionForm form) {
    // Set simple string, boolean and float association attributes
    Association association = setCommonAssociationElements(form);
    // Set multi-snp and snp interaction checkboxes
    association.setMultiSnpHaplotype(false);
    association.setSnpInteraction(true);
    // For each column create a loci
    Collection<Locus> loci = new ArrayList<>();
    for (SnpFormColumn col : form.getSnpFormColumns()) {
        Locus locus = new Locus();
        locus.setDescription("SNP x SNP interaction");
        // Set locus genes
        Collection<String> authorReportedGenes = col.getAuthorReportedGenes();
        Collection<Gene> locusGenes = lociAttributesService.createGene(authorReportedGenes);
        locus.setAuthorReportedGenes(locusGenes);
        // Create SNP
        String curatorEnteredSNP = col.getSnp();
        SingleNucleotidePolymorphism snp = lociAttributesService.createSnp(curatorEnteredSNP);
        // One risk allele per locus
        String curatorEnteredRiskAllele = col.getStrongestRiskAllele();
        RiskAllele riskAllele = lociAttributesService.createRiskAllele(curatorEnteredRiskAllele, snp);
        Collection<RiskAllele> locusRiskAlleles = new ArrayList<>();
        // Set risk allele attributes
        riskAllele.setGenomeWide(col.getGenomeWide());
        riskAllele.setLimitedList(col.getLimitedList());
        riskAllele.setRiskFrequency(col.getRiskFrequency());
        // Check for a proxy and if we have one create a proxy snp
        Collection<String> curatorEnteredProxySnps = col.getProxySnps();
        if (curatorEnteredProxySnps != null && !curatorEnteredProxySnps.isEmpty()) {
            Collection<SingleNucleotidePolymorphism> riskAlleleProxySnps = new ArrayList<>();
            for (String curatorEnteredProxySnp : curatorEnteredProxySnps) {
                SingleNucleotidePolymorphism proxySnp = lociAttributesService.createSnp(curatorEnteredProxySnp);
                riskAlleleProxySnps.add(proxySnp);
            }
            riskAllele.setProxySnps(riskAlleleProxySnps);
        }
        // Link risk allele to locus
        locusRiskAlleles.add(riskAllele);
        locus.setStrongestRiskAlleles(locusRiskAlleles);
        // Add locus to collection and link to our association
        loci.add(locus);
    }
    association.setLoci(loci);
    return association;
}
Also used : RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) Association(uk.ac.ebi.spot.goci.model.Association) Gene(uk.ac.ebi.spot.goci.model.Gene) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Locus(uk.ac.ebi.spot.goci.model.Locus) SnpFormColumn(uk.ac.ebi.spot.goci.curation.model.SnpFormColumn)

Example 22 with RiskAllele

use of uk.ac.ebi.spot.goci.model.RiskAllele in project goci by EBISPOT.

the class AssociationDownloadService method extractGeneticData.

private void extractGeneticData(Association association, StringBuilder line) {
    final StringBuilder strongestAllele = new StringBuilder();
    final StringBuilder reportedGenes = new StringBuilder();
    final StringBuilder rsId = new StringBuilder();
    final StringBuilder proxySnpsRsIds = new StringBuilder();
    final StringBuilder riskAlleleFrequency = new StringBuilder();
    // Set our delimiter for download spreadsheet
    final String delimiter;
    if (association.getSnpInteraction() != null && association.getSnpInteraction()) {
        delimiter = " x ";
    } else {
        delimiter = "; ";
    }
    // Interaction specific values
    if (association.getSnpInteraction() != null && association.getSnpInteraction()) {
        association.getLoci().forEach(locus -> {
            Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
            ra.forEach(riskAllele -> {
                if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
                    String frequency = riskAllele.getRiskFrequency();
                    setOrAppend(riskAlleleFrequency, frequency, delimiter);
                } else {
                    setOrAppend(riskAlleleFrequency, "NR", delimiter);
                }
            });
            Collection<String> currentLocusGenes = new ArrayList<>();
            String commaSeparatedGenes = "";
            locus.getAuthorReportedGenes().forEach(gene -> {
                currentLocusGenes.add(gene.getGeneName().trim());
            });
            if (!currentLocusGenes.isEmpty()) {
                commaSeparatedGenes = String.join(", ", currentLocusGenes);
                setOrAppend(reportedGenes, commaSeparatedGenes, delimiter);
            } else {
                setOrAppend(reportedGenes, "NR", delimiter);
            }
        });
    } else {
        // Single study or a haplotype
        association.getLoci().forEach(locus -> {
            Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
            ra.forEach(riskAllele -> {
                setOrAppend(riskAlleleFrequency, "", "");
            });
            locus.getAuthorReportedGenes().forEach(gene -> {
                setOrAppend(reportedGenes, gene.getGeneName().trim(), ", ");
            });
        });
    }
    // Set attributes common to all associations
    association.getLoci().forEach(locus -> {
        Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
        ra.forEach(riskAllele -> {
            setOrAppend(strongestAllele, riskAllele.getRiskAlleleName(), delimiter);
            SingleNucleotidePolymorphism snp = riskAllele.getSnp();
            setOrAppend(rsId, snp.getRsId(), delimiter);
            Collection<String> currentLocusProxies = new ArrayList<>();
            String colonSeparatedProxies = "";
            if (riskAllele.getProxySnps() != null) {
                for (SingleNucleotidePolymorphism proxySnp : riskAllele.getProxySnps()) {
                    currentLocusProxies.add(proxySnp.getRsId());
                }
            }
            if (!currentLocusProxies.isEmpty()) {
                colonSeparatedProxies = String.join(", ", currentLocusProxies);
                setOrAppend(proxySnpsRsIds, colonSeparatedProxies, delimiter);
            } else {
                setOrAppend(proxySnpsRsIds, "NR", delimiter);
            }
        });
    });
    line.append(reportedGenes.toString());
    line.append("\t");
    line.append(strongestAllele.toString());
    line.append("\t");
    line.append(rsId.toString());
    line.append("\t");
    line.append(proxySnpsRsIds.toString());
    line.append("\t");
    line.append(riskAlleleFrequency.toString());
    line.append("\t");
}
Also used : RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) OutputStream(java.io.OutputStream) Service(org.springframework.stereotype.Service) EfoTrait(uk.ac.ebi.spot.goci.model.EfoTrait) Association(uk.ac.ebi.spot.goci.model.Association) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)

Aggregations

RiskAllele (uk.ac.ebi.spot.goci.model.RiskAllele)22 ArrayList (java.util.ArrayList)16 Locus (uk.ac.ebi.spot.goci.model.Locus)12 SingleNucleotidePolymorphism (uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)12 Gene (uk.ac.ebi.spot.goci.model.Gene)11 Association (uk.ac.ebi.spot.goci.model.Association)9 Test (org.junit.Test)4 EfoTrait (uk.ac.ebi.spot.goci.model.EfoTrait)4 Location (uk.ac.ebi.spot.goci.model.Location)3 Study (uk.ac.ebi.spot.goci.model.Study)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Collectors (java.util.stream.Collectors)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 SnpFormColumn (uk.ac.ebi.spot.goci.curation.model.SnpFormColumn)2 SnpFormRow (uk.ac.ebi.spot.goci.curation.model.SnpFormRow)2 SnpMappingForm (uk.ac.ebi.spot.goci.curation.model.SnpMappingForm)2 GenomicContext (uk.ac.ebi.spot.goci.model.GenomicContext)2 IOException (java.io.IOException)1