/** * Returns a list of {@link VocabularyTerm genes}, given an {@link VocabularyTerm HPO term}. * * @param term an HPO {@link VocabularyTerm} * @return a list of {@link VocabularyTerm genes} associated with the provided {@code term}, or an empty list */ private List<String> getGeneDataFromTerm(@Nonnull final VocabularyTerm term) { @SuppressWarnings("unchecked") final List<String> geneList = (List<String>) term.get(ASSOCIATED_GENES); return CollectionUtils.isNotEmpty(geneList) ? geneList : Collections.emptyList(); }
/** * Tries to obtain the preferred gene symbol, given entered {@code symbol}, and {@code geneTerm} vocabulary term. * * @param symbol the provided gene symbol * @param geneTerm the {@link VocabularyTerm} gene vocabulary term * @return the preferred gene symbol, or entered {@code symbol} if no symbol is recorded */ private String getGeneSymbol(@Nonnull final String symbol, @Nullable final VocabularyTerm geneTerm) { return geneTerm != null ? StringUtils.defaultIfBlank((String) geneTerm.get(SYMBOL_LABEL), symbol) : symbol; }
/** * Returns a stream of gene names, as strings. * * @param gene a gene {@link VocabularyTerm} * @return a stream of all known names for {@code gene} */ private Stream<String> getGeneNameStream(@Nonnull final VocabularyTerm gene) { final String symbol = (String) gene.get(SYMBOL_LABEL); // Contains alias_symbol, prev_symbol, entrez_id, ensembl_gene_id, refseq_accession, and ena. final Collection<String> aliases = (Collection<String>) gene.get("alt_id"); // Get the stream of all names. return Stream.concat(Stream.of(symbol), aliases != null ? aliases.stream() : Stream.empty()); }
/** * Compares the scores for {@code o1} and {@code o2}. * * @param o1 the {@link VocabularyTerm} that is being compared * @param o2 the {@link VocabularyTerm} that {@code o1} is being compared to * @return {@code 0} if {@code o1} and {@code o2} are equivalent, a value less than {@code 0} if {@code o2} should * be ahead of {@code o1}, a value greater than {@code 0} if {@code o1} should be ahead of {@code o2} */ private int compareScores(@Nonnull final VocabularyTerm o1, @Nonnull final VocabularyTerm o2) { final Object scoreObj1 = o1.get(SCORE_LABEL); final Object scoreObj2 = o2.get(SCORE_LABEL); final Float scoreO1 = scoreObj1 != null ? (Float) scoreObj1 : 0; final Float scoreO2 = scoreObj2 != null ? (Float) scoreObj2 : 0; return scoreO2.compareTo(scoreO1); }
@SuppressWarnings("unchecked") private List<String> getCategoriesFromOntology(String value) { if (!value.startsWith("HP:")) { return Collections.emptyList(); } VocabularyTerm termObj = this.ontologyService.getTerm(value); if (termObj != null && termObj.get(INDEXED_CATEGORY_KEY) != null && List.class.isAssignableFrom(termObj.get(INDEXED_CATEGORY_KEY).getClass())) { return (List<String>) termObj.get(INDEXED_CATEGORY_KEY); } return new LinkedList<>(); }
@SuppressWarnings("unchecked") private List<String> getCategoriesFromOntology(String value) { if (!value.startsWith("HP:")) { return Collections.emptyList(); } VocabularyTerm termObj = this.ontologyService.getTerm(value); if (termObj != null && termObj.get(INDEXED_CATEGORY_KEY) != null && List.class.isAssignableFrom(termObj.get(INDEXED_CATEGORY_KEY).getClass())) { return (List<String>) termObj.get(INDEXED_CATEGORY_KEY); } return new LinkedList<>(); }
/** * Tries to obtain the preferred gene ID, given {@code symbol}. * * @param symbol the GeneCards gene symbol * @param geneTerm the {@link VocabularyTerm} gene vocabulary term * @return the preferred gene ID, or {@code symbol} if no preferred ID is recorded */ private String getGeneId(@Nonnull final String symbol, @Nullable final VocabularyTerm geneTerm) { if (geneTerm != null) { @SuppressWarnings("unchecked") final List<String> geneIdList = (List<String>) geneTerm.get(ENSEMBL_ID_LABEL); return CollectionUtils.isEmpty(geneIdList) ? symbol : geneIdList.get(0); } return symbol; }
private String getSymbol(String gene) { final VocabularyTerm term = this.getTerm(gene); final String symbol = (term != null) ? (String) term.get(SYMBOL_PROPERTY_NAME) : null; return StringUtils.isBlank(symbol) ? gene : symbol; }
/** * Given an HPO id, finds categories to which the id belongs to. * * @param value must start with "HP:" * @return a list of categories as HPO ids, excluding the passed in id, or an empty list if the categories could not * be determined */ @SuppressWarnings("unchecked") private List<String> getCategoriesFromOntology(String value) { if (!value.startsWith("HP:")) { return Collections.emptyList(); } VocabularyTerm termObj = this.ontologyService.getTerm(value); if (termObj != null && termObj.get(PropertyDisplayer.INDEXED_CATEGORY_KEY) != null && List.class.isAssignableFrom(termObj.get(PropertyDisplayer.INDEXED_CATEGORY_KEY).getClass())) { return (List<String>) termObj.get(PropertyDisplayer.INDEXED_CATEGORY_KEY); } return new LinkedList<>(); }
/** * Given an HPO id, finds categories to which the id belongs to. * * @param value must start with "HP:" * @return a list of categories as HPO ids, excluding the passed in id, or an empty list if the categories could not * be determined */ @SuppressWarnings("unchecked") private List<String> getCategoriesFromOntology(String value) { if (!value.startsWith("HP:")) { return Collections.emptyList(); } VocabularyTerm termObj = this.ontologyService.getTerm(value); if (termObj != null && termObj.get(PropertyDisplayer.INDEXED_CATEGORY_KEY) != null && List.class.isAssignableFrom(termObj.get(PropertyDisplayer.INDEXED_CATEGORY_KEY).getClass())) { return (List<String>) termObj.get(PropertyDisplayer.INDEXED_CATEGORY_KEY); } return new LinkedList<>(); }
/** * Gets EnsemblID corresponding to the HGNC symbol. * * @param geneSymbol the string representation of a gene symbol (e.g. NOD2). * @return the string representation of the corresponding Ensembl ID. */ private String getEnsemblId(String geneSymbol) { final VocabularyTerm term = this.hgnc.getTerm(geneSymbol); @SuppressWarnings("unchecked") final List<String> ensemblIdList = term != null ? (List<String>) term.get("ensembl_gene_id") : null; final String ensemblId = ensemblIdList != null && !ensemblIdList.isEmpty() ? ensemblIdList.get(0) : null; // Retain information as is if we can't find Ensembl ID. return ensemblId != null ? ensemblId : geneSymbol; } }
/** * Gets EnsemblID corresponding to the HGNC symbol. * * @param gene the string representation a gene, either geneSymbol (e.g. NOD2) or some other kind of ID * @return if gene is a valid geneSymbol, the corresponding Ensembl ID. Otherwise the original gene value */ private String getEnsemblId(String gene) { final VocabularyTerm term = this.getTerm(gene); @SuppressWarnings("unchecked") final List<String> ensemblIdList = term != null ? (List<String>) term.get("ensembl_gene_id") : null; final String ensemblId = ensemblIdList != null && !ensemblIdList.isEmpty() ? ensemblIdList.get(0) : null; // retain information as is if we can't find Ensembl ID. return StringUtils.isBlank(ensemblId) ? gene : ensemblId; }
/** * Gets EnsemblID corresponding to the HGNC symbol. * * @param gene the string representation a gene, either geneSymbol (e.g. NOD2) or some other kind of ID * @return if gene is a valid geneSymbol, the corresponding Ensembl ID. Otherwise the original gene value */ private String getEnsemblId(String gene) { final VocabularyTerm term = this.getTerm(gene); @SuppressWarnings("unchecked") final List<String> ensemblIdList = term != null ? (List<String>) term.get("ensembl_gene_id") : null; final String ensemblId = ensemblIdList != null && !ensemblIdList.isEmpty() ? ensemblIdList.get(0) : null; // retain information as is if we can't find Ensembl ID. return StringUtils.isBlank(ensemblId) ? gene : ensemblId; }
/** * Gets EnsemblID corresponding to the HGNC symbol. * * @param geneSymbol the string representation of a gene symbol (e.g. NOD2). * @return the string representation of the corresponding Ensembl ID. */ private String getEnsemblId(final String geneSymbol) { final VocabularyTerm term = this.hgnc.getTerm(geneSymbol); @SuppressWarnings("unchecked") final List<String> ensemblIdList = term != null ? (List<String>) term.get("ensembl_gene_id") : null; final String ensemblId = ensemblIdList != null && !ensemblIdList.isEmpty() ? ensemblIdList.get(0) : null; // Retain information as is if we can't find Ensembl ID. return ensemblId != null ? ensemblId : geneSymbol; } }
/** * Gets EnsemblID corresponding to the HGNC symbol. * * @param geneSymbol the string representation of a gene symbol (e.g. NOD2). * @return the string representation of the corresponding Ensembl ID. */ private String getEnsemblId(String geneSymbol) { final VocabularyTerm term = this.hgnc.getTerm(geneSymbol); @SuppressWarnings("unchecked") final List<String> ensemblIdList = term != null ? (List<String>) term.get("ensembl_gene_id") : null; final String ensemblId = ensemblIdList != null && !ensemblIdList.isEmpty() ? ensemblIdList.get(0) : null; // Retain information as is if we can't find Ensembl ID. return ensemblId != null ? ensemblId : geneSymbol; } }
/** * Gets EnsemblID corresponding to the HGNC symbol. * * @param geneSymbol the string representation of a gene symbol (e.g. NOD2). * @return the string representation of the corresponding Ensembl ID. */ private String getEnsemblId(final String geneSymbol) { final VocabularyTerm term = this.hgnc.getTerm(geneSymbol); @SuppressWarnings("unchecked") final List<String> ensemblIdList = term != null ? (List<String>) term.get("ensembl_gene_id") : null; final String ensemblId = ensemblIdList != null && !ensemblIdList.isEmpty() ? ensemblIdList.get(0) : null; // Retain information as is if we can't find Ensembl ID. return ensemblId != null ? ensemblId : geneSymbol; } }
private Set<String> getGeneSymbols(Set<String> set, String status) { Set<String> result = new HashSet<>(); Vocabulary hgnc = VOCABULARY_MANAGER.getVocabulary("HGNC"); for (String geneEnsemblId : set) { VocabularyTerm term = hgnc.getTerm(geneEnsemblId); String symbol = (term != null) ? (String) term.get("symbol") : null; symbol = StringUtils.isBlank(symbol) ? geneEnsemblId : symbol; symbol = StringUtils.isBlank(status) ? symbol : symbol + " (" + status + ")"; result.add(symbol); } return result; }
/** * Normalize the given gene symbol or identifier to an Ensembl ID. If a corresponding Ensembl ID is not found, the * passed string is returned. * * @param geneId a gene symbol or identifier * @return the string representation of the corresponding resolved Ensembl ID, or {@code geneId} if the lookup failed. */ private String normalizeGeneId(String geneId) { final VocabularyTerm term = HGNC_VOCABULARY.getTerm(geneId); if (term == null) { LOGGER.error("Patient genomic features parser: gene id [{}] was not found in the vocabulary", geneId); } @SuppressWarnings("unchecked") final List<String> ensemblIdList = term != null ? (List<String>) term.get("ensembl_gene_id") : null; final String ensemblId = ensemblIdList != null && !ensemblIdList.isEmpty() ? ensemblIdList.get(0) : null; // Retain information as is if we can't find Ensembl ID. return ensemblId != null ? ensemblId : geneId; } }
/** * Gets EnsemblID corresponding to the HGNC symbol. * * FIXME: refactor HGNC vocabulary to have "ensembl_gene_id" as a single value not a list? * FIXME: if done, refactor VocabularyTerm to simplify access to a String value using getString() instead of get()? * currently VocabularyTerm.get() is only ever used here and in gene migrator * FIXME: in any case refactoring vocabulary code in _some_ way to avoid code duplication every time we need * to convert geneSymbol to ensembleID? * * @param gene the string representation a gene, either geneSymbol (e.g. NOD2) or some other kind of ID * @return if gene is a vlaid geneSymbol, the corresponding Ensembl ID. Otherwise the original gene value */ private String getEnsemblId(String gene) { final VocabularyTerm term = this.getTerm(gene); @SuppressWarnings("unchecked") final List<String> ensemblIdList = term != null ? (List<String>) term.get(ENSEMBL_ID_PROPERTY_NAME) : null; final String ensemblId = ensemblIdList != null && !ensemblIdList.isEmpty() ? ensemblIdList.get(0) : null; // retain information as is if we can't find Ensembl ID. return StringUtils.isBlank(ensemblId) ? gene : ensemblId; }
/** * Sets gene Ensembl ID and status via HGNC Vocabulary term. * * @param geneName either gene Ensembl ID or gene symbol */ @SuppressWarnings("unchecked") public void setNames(String geneName) { VocabularyTerm term = getTerm(geneName); if (term != null) { // FIXME: refactor HGNC vocabulary to have "ensembl_gene_id" as a single value not a list // FIXME: refactor VocabularyTerm to simplify access to a String value using getString() instead of // get()? currently VocabularyTerm.get() is only ever used here and in gene migrator List<String> ensemblIdList = (List<String>) term.get(ENSEMBL_ID_PROPERTY_NAME); String ensemblId = (ensemblIdList != null && !ensemblIdList.isEmpty()) ? ensemblIdList.get(0) : null; // retain information as is if we can't find Ensembl ID. this.setId(StringUtils.isBlank(ensemblId) ? geneName : ensemblId); String geneSymbol = (term != null) ? (String) term.get(SYMBOL_PROPERTY_NAME) : null; this.setName(StringUtils.isBlank(geneSymbol) ? geneName : geneSymbol); } else { this.setId(geneName); this.setName(geneName); } }