Search in sources :

Example 11 with RiskAllele

use of uk.ac.ebi.spot.goci.model.RiskAllele 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;
}
Also used : RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleDateFormat(java.text.SimpleDateFormat) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Locus(uk.ac.ebi.spot.goci.model.Locus) Gene(uk.ac.ebi.spot.goci.model.Gene) Service(org.springframework.stereotype.Service) EfoTrait(uk.ac.ebi.spot.goci.model.EfoTrait) Association(uk.ac.ebi.spot.goci.model.Association) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) DateFormat(java.text.DateFormat) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) EfoTrait(uk.ac.ebi.spot.goci.model.EfoTrait) Gene(uk.ac.ebi.spot.goci.model.Gene) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Locus(uk.ac.ebi.spot.goci.model.Locus) SimpleDateFormat(java.text.SimpleDateFormat) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView)

Example 12 with RiskAllele

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

the class SnpInteractionAssociationService method createForm.

// Create a form to return to view from Association model object
@Override
public SnpAssociationForm createForm(Association association) {
    // Create form
    SnpAssociationInteractionForm form = new SnpAssociationInteractionForm();
    // Set simple string and boolean values
    form.setAssociationId(association.getId());
    form.setPvalueDescription(association.getPvalueDescription());
    form.setSnpType(association.getSnpType());
    form.setSnpApproved(association.getSnpApproved());
    form.setPvalueMantissa(association.getPvalueMantissa());
    form.setPvalueExponent(association.getPvalueExponent());
    form.setStandardError(association.getStandardError());
    form.setRange(association.getRange());
    form.setDescription(association.getDescription());
    form.setRiskFrequency(association.getRiskFrequency());
    // Set OR/Beta values
    form.setOrPerCopyNum(association.getOrPerCopyNum());
    form.setOrPerCopyRecip(association.getOrPerCopyRecip());
    form.setOrPerCopyRecipRange(association.getOrPerCopyRecipRange());
    form.setBetaNum(association.getBetaNum());
    form.setBetaUnit(association.getBetaUnit());
    form.setBetaDirection(association.getBetaDirection());
    // Add collection of Efo traits
    form.setEfoTraits(association.getEfoTraits());
    // Create form columns
    List<SnpFormColumn> snpFormColumns = new ArrayList<>();
    // For each locus get genes and risk alleles
    Collection<Locus> loci = association.getLoci();
    Collection<GenomicContext> snpGenomicContexts = new ArrayList<GenomicContext>();
    Collection<SingleNucleotidePolymorphism> snps = new ArrayList<SingleNucleotidePolymorphism>();
    List<SnpMappingForm> snpMappingForms = new ArrayList<SnpMappingForm>();
    // Create a column per locus
    if (loci != null && !loci.isEmpty()) {
        for (Locus locus : loci) {
            SnpFormColumn snpFormColumn = new SnpFormColumn();
            // Set genes
            Collection<String> authorReportedGenes = new ArrayList<>();
            for (Gene gene : locus.getAuthorReportedGenes()) {
                authorReportedGenes.add(gene.getGeneName());
            }
            snpFormColumn.setAuthorReportedGenes(authorReportedGenes);
            // Set risk allele
            Collection<RiskAllele> locusRiskAlleles = locus.getStrongestRiskAlleles();
            String strongestRiskAllele = null;
            String snp = null;
            Collection<String> proxySnps = new ArrayList<>();
            Boolean genomeWide = false;
            Boolean limitedList = false;
            String riskFrequency = null;
            // For snp x snp interaction studies should only have one risk allele per locus
            if (locusRiskAlleles != null && locusRiskAlleles.size() == 1) {
                for (RiskAllele riskAllele : locusRiskAlleles) {
                    strongestRiskAllele = riskAllele.getRiskAlleleName();
                    snp = riskAllele.getSnp().getRsId();
                    SingleNucleotidePolymorphism snp_obj = riskAllele.getSnp();
                    snps.add(snp_obj);
                    Collection<Location> locations = snp_obj.getLocations();
                    for (Location location : locations) {
                        SnpMappingForm snpMappingForm = new SnpMappingForm(snp, location);
                        snpMappingForms.add(snpMappingForm);
                    }
                    snpGenomicContexts.addAll(genomicContextRepository.findBySnpId(snp_obj.getId()));
                    // Set proxy
                    if (riskAllele.getProxySnps() != null) {
                        for (SingleNucleotidePolymorphism riskAlleleProxySnp : riskAllele.getProxySnps()) {
                            proxySnps.add(riskAlleleProxySnp.getRsId());
                        }
                    }
                    if (riskAllele.getGenomeWide() != null && riskAllele.getGenomeWide()) {
                        genomeWide = true;
                    }
                    if (riskAllele.getLimitedList() != null && riskAllele.getLimitedList()) {
                        limitedList = true;
                    }
                    riskFrequency = riskAllele.getRiskFrequency();
                }
            } else {
                throw new RuntimeException("More than one risk allele found for locus " + locus.getId() + ", this is not supported yet for SNP interaction associations");
            }
            // Set column attributes
            snpFormColumn.setStrongestRiskAllele(strongestRiskAllele);
            snpFormColumn.setSnp(snp);
            snpFormColumn.setProxySnps(proxySnps);
            snpFormColumn.setGenomeWide(genomeWide);
            snpFormColumn.setLimitedList(limitedList);
            snpFormColumn.setRiskFrequency(riskFrequency);
            snpFormColumns.add(snpFormColumn);
        }
    }
    form.setSnpMappingForms(snpMappingForms);
    form.setGenomicContexts(snpGenomicContexts);
    form.setSnps(snps);
    form.setSnpFormColumns(snpFormColumns);
    form.setNumOfInteractions(snpFormColumns.size());
    return form;
}
Also used : SnpAssociationInteractionForm(uk.ac.ebi.spot.goci.curation.model.SnpAssociationInteractionForm) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) GenomicContext(uk.ac.ebi.spot.goci.model.GenomicContext) SnpMappingForm(uk.ac.ebi.spot.goci.curation.model.SnpMappingForm) 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) Location(uk.ac.ebi.spot.goci.model.Location)

Example 13 with RiskAllele

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

the class LociAttributesServiceTest method saveRiskAllele.

@Test
public void saveRiskAllele() throws Exception {
    RiskAllele NEW_RISK_ALLELE = new RiskAlleleBuilder().setSnp(SNP_01).setRiskAlleleName("rs579459-?").setProxySnps(Arrays.asList(PROXY_SNP_01, PROXY_SNP_02)).build();
    // Stubbing
    when(singleNucleotidePolymorphismRepository.findByRsIdIgnoreCase(NEW_RISK_ALLELE.getSnp().getRsId())).thenReturn(null);
    when(singleNucleotidePolymorphismRepository.findByRsIdIgnoreCase(PROXY_SNP_01.getRsId())).thenReturn(null);
    when(singleNucleotidePolymorphismRepository.findByRsIdIgnoreCase(PROXY_SNP_02.getRsId())).thenReturn(null);
    when(singleNucleotidePolymorphismRepository.save(NEW_RISK_ALLELE.getSnp())).thenReturn(SNP_01);
    when(singleNucleotidePolymorphismRepository.save(PROXY_SNP_01)).thenReturn(PROXY_SNP_01);
    when(singleNucleotidePolymorphismRepository.save(PROXY_SNP_02)).thenReturn(PROXY_SNP_02);
    lociAttributesService.saveRiskAlleles(Collections.singletonList(NEW_RISK_ALLELE));
    verify(singleNucleotidePolymorphismRepository, times(1)).findByRsIdIgnoreCase(NEW_RISK_ALLELE.getSnp().getRsId());
    verify(singleNucleotidePolymorphismRepository, times(1)).save(NEW_RISK_ALLELE.getSnp());
    verify(singleNucleotidePolymorphismRepository, times(1)).findByRsIdIgnoreCase(PROXY_SNP_01.getRsId());
    verify(singleNucleotidePolymorphismRepository, times(1)).save(PROXY_SNP_01);
    verify(singleNucleotidePolymorphismRepository, times(1)).findByRsIdIgnoreCase(PROXY_SNP_02.getRsId());
    verify(singleNucleotidePolymorphismRepository, times(1)).save(PROXY_SNP_02);
    verify(riskAlleleRepository, times(1)).save(NEW_RISK_ALLELE);
}
Also used : RiskAlleleBuilder(uk.ac.ebi.spot.goci.builder.RiskAlleleBuilder) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) Test(org.junit.Test)

Example 14 with RiskAllele

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

the class AssociationRowProcessorTest method testCreateAssociationFromUploadRow.

@Test
public void testCreateAssociationFromUploadRow() throws Exception {
    // Stubbing mock object behaviour
    when(associationAttributeService.createLocusGenes(STANDARD_ROW.getAuthorReportedGene(), ",")).thenReturn(Arrays.asList(GENE_01, GENE_02));
    when(associationAttributeService.createSnp(STANDARD_ROW.getSnp())).thenReturn(SNP_01);
    when(associationAttributeService.createRiskAllele(STANDARD_ROW.getStrongestAllele(), SNP_01)).thenReturn(RA_01);
    when(associationAttributeService.createSnp(STANDARD_ROW.getProxy())).thenReturn(PROXY);
    Association association = associationRowProcessor.createAssociationFromUploadRow(STANDARD_ROW);
    verify(associationCalculationService, never()).reverseCI(STANDARD_ROW.getRange());
    verify(associationCalculationService, never()).setRange(STANDARD_ROW.getStandardError(), STANDARD_ROW.getOrPerCopyNum());
    verify(associationAttributeService, never()).getEfoTraitsFromRepository(Collections.EMPTY_LIST);
    verify(associationAttributeService, times(1)).createLocusGenes(STANDARD_ROW.getAuthorReportedGene(), ",");
    verify(associationAttributeService, times(1)).createSnp(STANDARD_ROW.getSnp());
    verify(associationAttributeService, times(1)).createSnp(STANDARD_ROW.getProxy());
    verify(associationAttributeService, times(1)).createRiskAllele(STANDARD_ROW.getStrongestAllele(), SNP_01);
    assertThat(association).extracting("id", "riskFrequency", "pvalueDescription", "pvalueMantissa", "pvalueExponent", "multiSnpHaplotype", "snpInteraction", "snpApproved", "snpType", "standardError", "range", "description", "orPerCopyNum", "orPerCopyRecip", "orPerCopyRecipRange", "betaNum", "betaUnit", "betaDirection", "study", "associationReport", "lastMappingDate", "lastMappingPerformedBy", "lastUpdateDate").containsExactly(null, "0.52", "(some pvalue description)", 2, -7, false, false, false, null, (float) 0.6, "[0.82-0.92]", null, (float) 1.22, null, null, null, null, null, null, null, null, null, null);
    assertThat(association.getEfoTraits()).isEmpty();
    assertThat(association.getEvents()).isEmpty();
    assertThat(association.getStudy()).isNull();
    assertThat(association.getLoci()).hasSize(1);
    // Check locus attributes
    Collection<Gene> locusGenes = new ArrayList<>();
    association.getLoci().stream().forEach(locus -> {
        locusGenes.addAll(locus.getAuthorReportedGenes());
    });
    Collection<RiskAllele> locusRiskAlleles = new ArrayList<>();
    association.getLoci().stream().forEach(locus -> {
        locusRiskAlleles.addAll(locus.getStrongestRiskAlleles());
    });
    Collection<SingleNucleotidePolymorphism> proxies = new ArrayList<>();
    locusRiskAlleles.stream().forEach(riskAllele -> {
        proxies.addAll(riskAllele.getProxySnps());
    });
    assertThat(association.getLoci()).extracting(Locus::getDescription).containsOnly("Single variant");
    assertThat(locusGenes).hasSize(2).contains(GENE_01, GENE_02);
    assertThat(locusRiskAlleles).hasSize(1).contains(RA_01);
    assertThat(locusRiskAlleles).extracting("riskAlleleName", "riskFrequency", "snp.rsId").contains(tuple("rs123-?", "0.52", "rs123"));
    assertThat(locusRiskAlleles).extracting(RiskAllele::getSnp).contains(SNP_01);
    assertThat(proxies).contains(PROXY);
    assertThat(proxies).extracting(SingleNucleotidePolymorphism::getRsId).containsExactly("rs99");
}
Also used : Association(uk.ac.ebi.spot.goci.model.Association) Gene(uk.ac.ebi.spot.goci.model.Gene) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Test(org.junit.Test)

Example 15 with RiskAllele

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

the class AssociationRowProcessor method createLocusRiskAlleles.

private Collection<RiskAllele> createLocusRiskAlleles(String strongestAllele, String snp, String proxy, String riskFrequency, String snpStatus, String delimiter) {
    Collection<RiskAllele> locusRiskAlleles = new ArrayList<>();
    // For our list of snps, proxies and risk alleles separate by delimiter
    List<String> snps = new ArrayList<>();
    String[] separatedSnps = snp.split(delimiter);
    for (String separatedSnp : separatedSnps) {
        //            if(separatedSnp != null & separatedSnp.trim().equals("")) {
        snps.add(separatedSnp.trim());
    //            }
    }
    List<String> riskAlleles = new ArrayList<>();
    String[] separatedRiskAlleles = strongestAllele.split(delimiter);
    for (String separatedRiskAllele : separatedRiskAlleles) {
        //            if(separatedRiskAllele != null & separatedRiskAllele.trim().equals("")) {
        riskAlleles.add(separatedRiskAllele.trim());
    //            }
    }
    List<String> proxies = new ArrayList<>();
    if (proxy != null) {
        String[] separatedProxies = proxy.split(delimiter);
        for (String separatedProxy : separatedProxies) {
            //                if(separatedProxy != null & separatedProxy.trim().equals("")) {
            proxies.add(separatedProxy.trim());
        //                }
        }
    }
    // Value is only recorded for SNP interaction associations
    List<String> riskFrequencies = new ArrayList<>();
    Iterator<String> riskFrequencyIterator = null;
    if (riskFrequency != null) {
        String[] separatedRiskFrequencies = riskFrequency.split(delimiter);
        for (String separatedRiskFrequency : separatedRiskFrequencies) {
            riskFrequencies.add(separatedRiskFrequency.trim());
        }
        riskFrequencyIterator = riskFrequencies.iterator();
    }
    // Snp status
    List<String> snpStatuses = new ArrayList<>();
    Iterator<String> snpStatusIterator = null;
    if (snpStatus != null) {
        String[] separatedSnpStatuses = snpStatus.split(delimiter);
        for (String separatedSnpStatus : separatedSnpStatuses) {
            snpStatuses.add(separatedSnpStatus.trim());
        }
        snpStatusIterator = snpStatuses.iterator();
    }
    Iterator<String> riskAlleleIterator = riskAlleles.iterator();
    Iterator<String> snpIterator = snps.iterator();
    Iterator<String> proxyIterator = proxies.iterator();
    // Loop through our risk alleles
    if (riskAlleles.size() == snps.size()) {
        while (riskAlleleIterator.hasNext()) {
            String snpValue = snpIterator.next().trim();
            String riskAlleleValue = riskAlleleIterator.next().trim();
            SingleNucleotidePolymorphism newSnp = associationAttributeService.createSnp(snpValue);
            // Create a new risk allele and assign newly created snp
            RiskAllele newRiskAllele = associationAttributeService.createRiskAllele(riskAlleleValue, newSnp);
            // Check for proxies and if we have one create a proxy snp
            if (proxies.size() != 0) {
                if (proxies.size() == snps.size()) {
                    String proxyValue = proxyIterator.next().trim();
                    Collection<SingleNucleotidePolymorphism> newRiskAlleleProxies = new ArrayList<>();
                    //                        else
                    if (proxyValue.contains(",")) {
                        String[] splitProxyValues = proxyValue.split(",");
                        for (String splitProxyValue : splitProxyValues) {
                            SingleNucleotidePolymorphism proxySnp = associationAttributeService.createSnp(splitProxyValue.trim());
                            newRiskAlleleProxies.add(proxySnp);
                        }
                    } else {
                        SingleNucleotidePolymorphism proxySnp = associationAttributeService.createSnp(proxyValue);
                        newRiskAlleleProxies.add(proxySnp);
                    }
                    newRiskAllele.setProxySnps(newRiskAlleleProxies);
                } else {
                    getLog().error("Proxy SNP number and SNP number do not match");
                }
            }
            // If there is no curator entered value for risk allele frequency don't save
            String riskFrequencyValue = null;
            if (riskFrequencyIterator != null) {
                riskFrequencyValue = riskFrequencyIterator.next().trim();
            }
            if (riskFrequencyValue != null) {
                newRiskAllele.setRiskFrequency(riskFrequencyValue);
            }
            // Handle snp statuses, these should only apply to SNP interaction associations
            String snpStatusValue = null;
            if (snpStatusIterator != null) {
                snpStatusValue = snpStatusIterator.next().trim();
            }
            if (snpStatus != null && !snpStatus.equalsIgnoreCase("NR")) {
                if (snpStatusValue.contains("GW") || snpStatusValue.contains("gw")) {
                    newRiskAllele.setGenomeWide(true);
                }
                if (snpStatusValue.contains("LL") || snpStatusValue.contains("ll")) {
                    newRiskAllele.setLimitedList(true);
                }
            }
            locusRiskAlleles.add(newRiskAllele);
        }
    } else {
        getLog().error("Mismatched number of snps and risk alleles");
    }
    return locusRiskAlleles;
}
Also used : 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