Search in sources :

Example 16 with Gene

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

the class SnpGenomicContextMappingService method createOrRetrieveEntrezExternalId.

/**
     * Method to create an Entrez gene, this database table holds entrez gene IDs
     *
     * @param id       Entrez gene ID
     * @param geneName Gene name allows method to check if this id is actually already linked to another gene
     */
private EntrezGene createOrRetrieveEntrezExternalId(String id, String geneName) {
    EntrezGene entrezGene = entrezGeneQueryService.findByEntrezGeneId(id);
    // Create new entry in ENTREZ_GENE table for this ID
    if (entrezGene == null) {
        entrezGene = new EntrezGene();
        entrezGene.setEntrezGeneId(id);
        entrezGeneRepository.save(entrezGene);
    } else // Check this ID is not linked to a gene with a different name
    {
        Gene existingGeneLinkedToId = entrezGene.getGene();
        if (existingGeneLinkedToId != null) {
            if (!Objects.equals(existingGeneLinkedToId.getGeneName(), geneName)) {
                getLog().warn("Entrez ID: " + id + ", is already used in database by a different gene(s): " + existingGeneLinkedToId.getGeneName() + ". Will update so links to " + geneName);
                // For gene already linked to this entrez ID remove the entrez ID
                existingGeneLinkedToId.getEntrezGeneIds().remove(entrezGene);
                geneRepository.save(existingGeneLinkedToId);
            }
        }
    }
    return entrezGene;
}
Also used : EntrezGene(uk.ac.ebi.spot.goci.model.EntrezGene) EnsemblGene(uk.ac.ebi.spot.goci.model.EnsemblGene) Gene(uk.ac.ebi.spot.goci.model.Gene) EntrezGene(uk.ac.ebi.spot.goci.model.EntrezGene)

Example 17 with Gene

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

the class SnpGenomicContextMappingService method storeGenes.

/**
     * Create/update genes with latest mapping information
     *
     * @param geneToExternalIdMap map of a gene name and all external database IDs from current mapping run
     * @param source              the source of mapping, either Ensembl or Entrez
     */
private void storeGenes(Map<String, Set<String>> geneToExternalIdMap, String source) {
    for (String geneName : geneToExternalIdMap.keySet()) {
        Set<String> externalIds = geneToExternalIdMap.get(geneName);
        // Find any existing database genes that match the gene name
        // IgnoreCase query is not used here as we want
        // the exact gene name returned from mapping
        Gene existingGeneInDatabase = geneQueryService.findByGeneName(geneName);
        // If gene is not found in database then create one
        if (existingGeneInDatabase == null) {
            createGene(geneName, externalIds, source);
        } else // Update gene
        {
            if (source.equalsIgnoreCase("Ensembl")) {
                // Get a list of current Ensembl IDs linked to existing gene
                Collection<EnsemblGene> oldEnsemblGenesLinkedToGene = existingGeneInDatabase.getEnsemblGeneIds();
                Collection<Long> oldEnsemblIdsLinkedToGene = new ArrayList<>();
                for (EnsemblGene oldEnsemblGeneLinkedToGene : oldEnsemblGenesLinkedToGene) {
                    oldEnsemblIdsLinkedToGene.add(oldEnsemblGeneLinkedToGene.getId());
                }
                Collection<EnsemblGene> newEnsemblGenes = new ArrayList<>();
                for (String id : externalIds) {
                    EnsemblGene ensemblGene = createOrRetrieveEnsemblExternalId(id, geneName);
                    newEnsemblGenes.add(ensemblGene);
                }
                // Set latest IDs from mapping run
                existingGeneInDatabase.setEnsemblGeneIds(newEnsemblGenes);
                // Save changes
                geneRepository.save(existingGeneInDatabase);
                // Clean-up any Ensembl IDs that may now be left without a gene linked
                for (Long oldEnsemblIdLinkedToGene : oldEnsemblIdsLinkedToGene) {
                    cleanUpEnsemblGenes(oldEnsemblIdLinkedToGene);
                }
            }
            if (source.equalsIgnoreCase("Entrez")) {
                // Get a list of of current Entrez IDs linked to existing gene
                Collection<EntrezGene> oldEntrezGenesLinkedToGene = existingGeneInDatabase.getEntrezGeneIds();
                Collection<Long> oldEntrezGenesIdsLinkedToGene = new ArrayList<>();
                for (EntrezGene oldEntrezGeneLinkedToGene : oldEntrezGenesLinkedToGene) {
                    oldEntrezGenesIdsLinkedToGene.add(oldEntrezGeneLinkedToGene.getId());
                }
                Collection<EntrezGene> newEntrezGenes = new ArrayList<>();
                for (String id : externalIds) {
                    EntrezGene entrezGene = createOrRetrieveEntrezExternalId(id, geneName);
                    newEntrezGenes.add(entrezGene);
                }
                // Set latest IDs from mapping run
                existingGeneInDatabase.setEntrezGeneIds(newEntrezGenes);
                // Save changes
                geneRepository.save(existingGeneInDatabase);
                // Clean-up any Entrez IDs that may now be left without a gene linked
                for (Long oldEntrezGenesIdLinkedToGene : oldEntrezGenesIdsLinkedToGene) {
                    cleanUpEntrezGenes(oldEntrezGenesIdLinkedToGene);
                }
            }
        }
    }
}
Also used : EntrezGene(uk.ac.ebi.spot.goci.model.EntrezGene) EnsemblGene(uk.ac.ebi.spot.goci.model.EnsemblGene) Gene(uk.ac.ebi.spot.goci.model.Gene) EntrezGene(uk.ac.ebi.spot.goci.model.EntrezGene) ArrayList(java.util.ArrayList) EnsemblGene(uk.ac.ebi.spot.goci.model.EnsemblGene)

Example 18 with Gene

use of uk.ac.ebi.spot.goci.model.Gene 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 19 with Gene

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

the class AssociationAttributeService method createGene.

private Collection<Gene> createGene(Collection<String> authorReportedGenes) {
    Collection<Gene> locusGenes = new ArrayList<Gene>();
    for (String authorReportedGene : authorReportedGenes) {
        authorReportedGene = StringProcessingService.tidy_curator_entered_string(authorReportedGene);
        Gene gene = new Gene();
        gene.setGeneName(authorReportedGene);
        locusGenes.add(gene);
    }
    return locusGenes;
}
Also used : Gene(uk.ac.ebi.spot.goci.model.Gene) ArrayList(java.util.ArrayList)

Example 20 with Gene

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

the class SingleSnpMultiSnpAssociationService method createAssociation.

public Association createAssociation(SnpAssociationStandardMultiForm form) {
    // Set common string, boolean and float association attributes
    Association association = setCommonAssociationElements(form);
    association.setSnpInteraction(false);
    // Add loci to association, for multi-snp and standard snps we assume their is only one locus
    Collection<Locus> loci = new ArrayList<>();
    Locus locus = new Locus();
    // Set locus description and haplotype count
    // Set this number to the number of rows entered by curator
    Integer numberOfRows = form.getSnpFormRows().size();
    if (numberOfRows > 1) {
        locus.setHaplotypeSnpCount(numberOfRows);
        association.setMultiSnpHaplotype(true);
    }
    if (form.getMultiSnpHaplotypeDescr() != null && !form.getMultiSnpHaplotypeDescr().isEmpty()) {
        locus.setDescription(form.getMultiSnpHaplotypeDescr());
    } else {
        if (numberOfRows > 1) {
            locus.setDescription(numberOfRows + "-SNP haplotype");
        } else {
            locus.setDescription("Single variant");
        }
    }
    // Create gene from each string entered, may sure to check pre-existence
    Collection<String> authorReportedGenes = form.getAuthorReportedGenes();
    Collection<Gene> locusGenes = lociAttributesService.createGene(authorReportedGenes);
    // Set locus genes
    locus.setAuthorReportedGenes(locusGenes);
    // Handle rows entered for haplotype by curator
    Collection<SnpFormRow> rows = form.getSnpFormRows();
    Collection<RiskAllele> locusRiskAlleles = new ArrayList<>();
    for (SnpFormRow row : rows) {
        // Create snps from row information
        String curatorEnteredSNP = row.getSnp();
        SingleNucleotidePolymorphism snp = lociAttributesService.createSnp(curatorEnteredSNP);
        // Get the curator entered risk allele
        String curatorEnteredRiskAllele = row.getStrongestRiskAllele();
        // Create a new risk allele and assign newly created snp
        RiskAllele riskAllele = lociAttributesService.createRiskAllele(curatorEnteredRiskAllele, snp);
        // If association is not a multi-snp haplotype save frequency to risk allele
        if (!form.getMultiSnpHaplotype()) {
            riskAllele.setRiskFrequency(form.getRiskFrequency());
        }
        // Check for proxies and if we have one create a proxy snps
        if (row.getProxySnps() != null && !row.getProxySnps().isEmpty()) {
            Collection<SingleNucleotidePolymorphism> riskAlleleProxySnps = new ArrayList<>();
            for (String curatorEnteredProxySnp : row.getProxySnps()) {
                SingleNucleotidePolymorphism proxySnp = lociAttributesService.createSnp(curatorEnteredProxySnp);
                riskAlleleProxySnps.add(proxySnp);
            }
            riskAllele.setProxySnps(riskAlleleProxySnps);
        }
        locusRiskAlleles.add(riskAllele);
    }
    // Assign all created risk alleles to locus
    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) SnpFormRow(uk.ac.ebi.spot.goci.curation.model.SnpFormRow) Gene(uk.ac.ebi.spot.goci.model.Gene) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Locus(uk.ac.ebi.spot.goci.model.Locus)

Aggregations

Gene (uk.ac.ebi.spot.goci.model.Gene)21 ArrayList (java.util.ArrayList)16 RiskAllele (uk.ac.ebi.spot.goci.model.RiskAllele)11 SingleNucleotidePolymorphism (uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)9 Locus (uk.ac.ebi.spot.goci.model.Locus)8 Association (uk.ac.ebi.spot.goci.model.Association)6 EnsemblGene (uk.ac.ebi.spot.goci.model.EnsemblGene)6 EntrezGene (uk.ac.ebi.spot.goci.model.EntrezGene)6 GenomicContext (uk.ac.ebi.spot.goci.model.GenomicContext)5 Location (uk.ac.ebi.spot.goci.model.Location)4 Test (org.junit.Test)3 HashSet (java.util.HashSet)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 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1