/** * Retrieve a vocabulary given its identifier. * * @param vocabularyId the vocabulary identifier, which is also used as a prefix in every term identifier from that * vocabulary, or a {@link Vocabulary#getAliases() known alias} for it, for example {@code MIM}, * {@code hpo}, {@code HP} or {@code HPO} * @return the requested vocabulary, or {@code null} if it doesn't exist or isn't available in the platform */ public Vocabulary getVocabulary(String vocabularyId) { return this.manager.getVocabulary(vocabularyId); }
/** * Retrieve a vocabulary given its identifier. This is a shortcut for {@link #getVocabulary(String)} which allows * scripts to use the shorter {@code $services.vocabularies.hpo} notation for accessing a vocabulary. * * @param vocabularyId the vocabulary identifier, which is also used as a prefix in every term identifier from that * vocabulary, or a {@link Vocabulary#getAliases() known alias} for it, for example {@code MIM}, * {@code HP} or {@code HPO} * @return the requested vocabulary, or {@code null} if it doesn't exist or isn't available in the platform */ public Vocabulary get(String vocabularyId) { return this.manager.getVocabulary(vocabularyId); }
/** * Retrieve a vocabulary given its identifier. * * @param vocabularyId the vocabulary identifier, which is also used as a prefix in every term identifier from that * vocabulary, or a {@link Vocabulary#getAliases() known alias} for it, for example {@code MIM}, * {@code hpo}, {@code HP} or {@code HPO} * @return the requested vocabulary, or {@code null} if it doesn't exist or isn't available in the platform * @deprecated use {@link VocabularyScriptService#getVocabulary(String) $services.vocabularies.getVocabulary} instead */ @Deprecated public Vocabulary getOntology(String vocabularyId) { return this.manager.getVocabulary(vocabularyId); }
/** * Retrieve a vocabulary given its identifier. This is a shortcut for {@link #getOntology(String)} which allows * scripts to use the shorter {@code $services.ontologies.hpo} notation for accessing a vocabulary. * * @param vocabularyId the vocabulary identifier, which is also used as a prefix in every term identifier from that * vocabulary, or a {@link Vocabulary#getAliases() known alias} for it, for example {@code MIM}, * {@code HP} or {@code HPO} * @return the requested vocabulary, or {@code null} if it doesn't exist or isn't available in the platform * @deprecated use {@link VocabularyScriptService#get(String) $services.vocabularies.get} instead */ @Deprecated public Vocabulary get(String vocabularyId) { return this.manager.getVocabulary(vocabularyId); } }
private Vocabulary getHGNCVocabulary() { try { return vocabularyManager.getVocabulary("HGNC"); } catch (Exception ex) { // this should not happen except when mocking, but does not hurt to catch in any case this.logger.error("Error loading component [{}]", ex.getMessage(), ex); return null; } }
private Vocabulary getHGNCVocabulary() { try { return this.vocabularyManager.getVocabulary(HGNC); } catch (Exception ex) { // this should not happen except when mocking, but does not hurt to catch in any case this.logger.error("Error loading component [{}]", ex.getMessage(), ex); return null; } } }
private Vocabulary getHGNCVocabulary() { try { return this.vocabularyManager.getVocabulary("HGNC"); } catch (Exception ex) { // this should not happen except when mocking, but does not hurt to catch in any case this.logger.error("Error loading component [{}]", ex.getMessage(), ex); return null; } }
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; }
/** * Given the {@code vocabularyPrefix}, tries to retrieve data for provided {@code termIds}. * * @param vocabPrefix a vocabulary prefix (e.g. HP) * @param termIds a {@link Set} of term identifiers, as strings * @return a {@link Stream} of {@link JSONObject} for each specified term ID */ @Nullable private Stream<JSONObject> getTerms(@Nonnull final String vocabPrefix, @Nonnull final Set<String> termIds) { // Try to get the vocabulary by prefix. final Vocabulary vocabulary = this.vm.getVocabulary(vocabPrefix); if (vocabulary == null) { // If no matching vocabulary can be found, log a warning. this.slf4Jlogger.warn("Could not resolve terms [{}]. No matching vocabulary found.", termIds); return null; } // Return a stream of JSONObject for the retrieved terms return vocabulary.getTerms(termIds).stream().map(this::getTermJsonWithLinks); }
/** * Simple constructor, passing in a collection of {@code presentTerms} and a collection of {@code absentTerms}, as * {@link VocabularyTerm} objects, a collection of {@code rejectedGenes rejected genes}, and a * {@link VocabularyManager}. * * @param presentTerms a collection of {@link VocabularyTerm feature identifiers} that are present * @param absentTerms a collection of {@link VocabularyTerm feature identifiers} that are absent * @param rejectedGenes a collection of genes that were tested to be negative or rejected as candidate * @param generateMatchCount iff true, generate a term to number of associated genes mapping * @param vocabularyManager the {@link VocabularyManager} for accessing the required vocabularies */ DefaultGenePanelImpl( @Nonnull final Collection<VocabularyTerm> presentTerms, @Nonnull final Collection<VocabularyTerm> absentTerms, @Nonnull final Collection<VocabularyTerm> rejectedGenes, final boolean generateMatchCount, @Nonnull final VocabularyManager vocabularyManager) { this.hgnc = vocabularyManager.getVocabulary(HGNC_LABEL); this.presentTerms = Collections.unmodifiableSet(new HashSet<>(presentTerms)); this.absentTerms = Collections.unmodifiableSet(new HashSet<>(absentTerms)); buildTermsForGeneList(rejectedGenes, generateMatchCount); }
@Override public org.phenotips.vocabularies.rest.model.Vocabulary getVocabulary(String vocabularyId) { Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); } return this.objectFactory.createLinkedVocabularyRepresentation(vocabulary, getVocabularyLinks(), this::getCategoriesForVocabulary); }
@Override public Response reindex(String vocabularyId, String url) { // Check permissions, the user must have admin rights on the entire wiki if (!this.userIsAdmin()) { return Response.status(Response.Status.FORBIDDEN).build(); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { return Response.status(Response.Status.NOT_FOUND).build(); } Response result; try { int reindexStatus = vocabulary.reindex(url); if (reindexStatus == 0) { result = Response.ok().build(); } else if (reindexStatus == 1) { result = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } else { result = Response.status(Response.Status.BAD_REQUEST).build(); } } catch (UnsupportedOperationException e) { result = Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); } return result; }
@Override public Response getTerm(String vocabularyId, String termId) { if (StringUtils.isEmpty(vocabularyId) || StringUtils.isEmpty(termId)) { return Response.status(Response.Status.BAD_REQUEST).build(); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { return Response.status(Response.Status.NOT_FOUND).build(); } VocabularyTerm term = vocabulary.getTerm(termId); if (term == null) { return Response.status(Response.Status.NOT_FOUND).build(); } JSONObject rep = term.toJSON(); rep.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); } }
/** * Gets a connection to the targeted core, used for sending the schema requests. * * @return a valid solr client */ protected SolrClient getClient() { return this.coreConnection.getSolrConnection(this.vocabularyManager.getVocabulary(getTargetVocabularyId())); }
@Override public Response getTerm(String vocabularyId, String termId) { if (StringUtils.isEmpty(vocabularyId) || StringUtils.isEmpty(termId)) { return Response.status(Response.Status.BAD_REQUEST).build(); } Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { return Response.status(Response.Status.NOT_FOUND).build(); } VocabularyTerm term = vocabulary.getTerm(termId); if (term == null) { return Response.status(Response.Status.NOT_FOUND).build(); } JSONObject rep = term.toJSON(); rep.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); } }
private Vocabulary getHGNCVocabulary() { try { VocabularyManager vm = ComponentManagerRegistry.getContextComponentManager().getInstance(VocabularyManager.class); return vm.getVocabulary(HGNC); } catch (ComponentLookupException ex) { this.logger.error("Error loading component [{}]", ex.getMessage(), ex); } return null; }
@Override public Vocabularies getAllVocabularies() { Vocabularies result = new Vocabularies(); List<String> vocabularyIDs = this.vm.getAvailableVocabularies(); List<org.phenotips.vocabularies.rest.model.Vocabulary> availableVocabs = vocabularyIDs.stream() .map(vocabularyID -> this.vm.getVocabulary(vocabularyID)) .map(vocab -> this.objectFactory.createLinkedVocabularyRepresentation(vocab, getVocabularyLinks(), this::getCategoriesForVocabulary)) .collect(Collectors.toList()); result.withVocabularies(availableVocabs); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return result; }
/** * Extracts rejected genes from provided {@code genes} data. * * @param genes a {@link PatientData} object containing gene data for the {@link #patient} * @return a set of rejected {@link VocabularyTerm genes} */ private Set<VocabularyTerm> extractRejectedGenes(@Nullable final PatientData<Gene> genes) { if (genes == null) { return Collections.emptySet(); } final Set<VocabularyTerm> rejected = new HashSet<>(); final Vocabulary hgnc = this.vocabularyManager.getVocabulary(HGNC); for (final Gene gene : genes) { if (REJECTED.equals(gene.getStatus()) || REJECTED_CANDIDATE.equals(gene.getStatus())) { final String geneID = gene.getId(); final VocabularyTerm geneObj = hgnc.getTerm(geneID); CollectionUtils.addIgnoreNull(rejected, geneObj); } } return rejected; }
@Override public org.phenotips.vocabularies.rest.model.Vocabulary getVocabulary(String vocabularyId) { Vocabulary vocabulary = this.vm.getVocabulary(vocabularyId); if (vocabulary == null) { throw new WebApplicationException(Response.Status.NOT_FOUND); } org.phenotips.vocabularies.rest.model.Vocabulary rep = this.objectFactory.createVocabularyRepresentation(vocabulary); rep.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW).build()); return rep; }
@Override public Vocabularies getAllVocabularies() { Vocabularies result = new Vocabularies(); List<String> vocabularyIDs = this.vm.getAvailableVocabularies(); List<org.phenotips.vocabularies.rest.model.Vocabulary> availableVocabs = new ArrayList<>(); for (String vocabularyID : vocabularyIDs) { Vocabulary vocab = this.vm.getVocabulary(vocabularyID); org.phenotips.vocabularies.rest.model.Vocabulary rep = this.objectFactory.createVocabularyRepresentation(vocab); rep.withLinks(this.autolinker.get().forSecondaryResource(VocabularyResource.class, this.uriInfo) .withActionableResources(VocabularyTermSuggestionsResource.class) .withExtraParameters("vocabulary-id", vocabularyID) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW) .build()); availableVocabs.add(rep); } result.withVocabularies(availableVocabs); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return result; }