Search in sources :

Example 61 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class Mdata method convertXmlToMDataContext.

static MDataContext convertXmlToMDataContext(String xml) {
    try {
        JSONObject jObject = XML.toJSONObject(xml);
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        return mapper.readValue(jObject.toString(), MDataContext.class);
    } catch (IOException e) {
        throw new NextProtException("Failed to convert XML mdata to object ", e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) JSONObject(org.json.JSONObject) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 62 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class FilePatternDictionary method loadResources.

protected void loadResources() {
    resourcesMap = new TreeMap<>();
    Resource[] resources;
    try {
        resources = new PathMatchingResourcePatternResolver().getResources(getLocation());
        for (Resource r : resources) {
            resourcesMap.put(r.getFilename().replace(getExtension(), ""), Resources.toString(r.getURL(), Charsets.UTF_8));
        }
    } catch (IOException e) {
        throw new NextProtException("Error on loading SQL Dict", e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 63 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class PepXServiceImpl method buildEntryWithVirtualAnnotations.

static List<Annotation> buildEntryWithVirtualAnnotations(String peptide, boolean modeIsoleucine, List<PepXIsoformMatch> pepXisoforms, List<Annotation> varAnnotations, List<Isoform> isoforms) {
    List<Annotation> finalAnnotations = new ArrayList<>();
    for (PepXIsoformMatch isoNameAndOptionalPosition : pepXisoforms) {
        String isoformAc = isoNameAndOptionalPosition.getIsoformAccession();
        Annotation annotation = new Annotation();
        annotation.setAnnotationCategory(AnnotationCategory.PEPX_VIRTUAL_ANNOTATION);
        annotation.setCvTermName(peptide);
        annotation.setDescription("This virtual annotation describes the peptide " + peptide + " found in " + isoformAc);
        AnnotationIsoformSpecificity is = new AnnotationIsoformSpecificity();
        is.setIsoformAccession(isoformAc);
        if (isoNameAndOptionalPosition.getPosition() != null) {
            // It means there is a variant!!!
            int startPeptidePosition = isoNameAndOptionalPosition.getPosition();
            int endPeptidePosition = startPeptidePosition + peptide.length();
            List<Annotation> variantAnnotations = AnnotationUtils.filterAnnotationsBetweenPositions(startPeptidePosition, endPeptidePosition, varAnnotations, isoformAc);
            Isoform iso = IsoformUtils.getIsoformByIsoName(isoforms, isoformAc);
            if (iso == null) {
                throw new NextProtException("The variant at " + startPeptidePosition + " is not specific for this isoform " + isoformAc);
            }
            List<Annotation> validAnnotations = filterValidVariantAnnotations(peptide, modeIsoleucine, variantAnnotations, isoformAc, iso.getSequence());
            if ((validAnnotations == null) || validAnnotations.isEmpty()) {
                LOGGER.warn("No valid variants found for isoform " + isoformAc + " at position " + startPeptidePosition + " for peptide " + peptide + " in mode IL:" + modeIsoleucine);
                continue;
            // We used to throw an exception, but now we just skip
            // throw new NextProtException("No valid variants found for isoform " + isoformName + " at position" + startPeptidePosition + " for peptide " + peptide + " in mode IL:" + modeIsoleucine);
            }
            if (validAnnotations.size() > 1) {
                LOGGER.warn("There is more than 1 valid variant (" + validAnnotations.size() + ") for isoform (returning the 1st) " + isoformAc + " between position " + startPeptidePosition + " and " + endPeptidePosition + " for peptide " + peptide + " in mode IL:" + modeIsoleucine);
                // Takes only the first valid
                int startPos = validAnnotations.get(0).getStartPositionForIsoform(isoformAc);
                int endPos = validAnnotations.get(0).getEndPositionForIsoform(isoformAc);
                is.setFirstPosition(startPos);
                is.setLastPosition(endPos);
                AnnotationVariant var = validAnnotations.get(0).getVariant();
                annotation.setVariant(var);
            } else {
                // one variant on that position
                int startPos = validAnnotations.get(0).getStartPositionForIsoform(isoformAc);
                int endPos = validAnnotations.get(0).getEndPositionForIsoform(isoformAc);
                is.setFirstPosition(startPos);
                is.setLastPosition(endPos);
                AnnotationVariant var = validAnnotations.get(0).getVariant();
                annotation.setVariant(var);
            }
        } else {
            // No variant
            Isoform iso = IsoformUtils.getIsoformByIsoName(isoforms, isoformAc);
            String sequence = (iso != null) ? iso.getSequence() : null;
            boolean isPeptideContained = PeptideUtils.isPeptideContainedInTheSequence(peptide, sequence, modeIsoleucine);
            if (!isPeptideContained) {
                LOGGER.warn("PepX returned a peptide (" + peptide + ") for an isoform (" + isoformAc + ") that is not in the current isoform in neXtProt");
                continue;
            }
        // We used to throw an exception, but this would break the program (the algorithm could be improved to detect the specific case where pepx return a peptide of length 6 and generate a real error on other cases)
        // NPreconditions.checkTrue(isPeptideContained, "PepX returned a peptide (" + peptide + ") for an isoform (" + isoformName + ") that is not in the current isoform in neXtProt");
        }
        annotation.addTargetingIsoforms(Arrays.asList(is));
        finalAnnotations.add(annotation);
    }
    return finalAnnotations;
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) PepXIsoformMatch(org.nextprot.api.web.domain.PepXResponse.PepXIsoformMatch) AnnotationVariant(org.nextprot.api.core.domain.annotation.AnnotationVariant) AnnotationIsoformSpecificity(org.nextprot.api.core.domain.annotation.AnnotationIsoformSpecificity) Isoform(org.nextprot.api.core.domain.Isoform) Annotation(org.nextprot.api.core.domain.annotation.Annotation)

Example 64 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class SearchServiceImpl method getAccessionsForSimple.

private Set<String> getAccessionsForSimple(QueryRequest queryRequest) {
    Set<String> set = new LinkedHashSet<>();
    try {
        Query query = this.queryBuilderService.buildQueryForSearchIndexes("entry", "simple", queryRequest);
        SearchResult results = solrService.executeIdQuery(query);
        for (Map<String, Object> f : results.getFoundFacets("id")) {
            String entry = (String) f.get("name");
            set.add(entry);
        }
    } catch (SearchQueryException e) {
        e.printStackTrace();
        throw new NextProtException("Error when retrieving accessions");
    }
    return set;
}
Also used : SearchQueryException(org.nextprot.api.commons.exception.SearchQueryException) NextProtException(org.nextprot.api.commons.exception.NextProtException) Query(org.nextprot.api.solr.Query) UserQuery(org.nextprot.api.user.domain.UserQuery) SearchResult(org.nextprot.api.solr.SearchResult)

Example 65 with NextProtException

use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.

the class EntryController method getSubPart.

@RequestMapping("/entry/{entry}/{blockOrSubpart}")
public String getSubPart(@PathVariable("entry") String entryName, @PathVariable("blockOrSubpart") String blockOrSubpart, @RequestParam(value = "term-child-of", required = false) String ancestorTerm, @RequestParam(value = "property-name", required = false) String propertyName, @RequestParam(value = "property-value", required = false) String propertyValueOrAccession, HttpServletRequest request, Model model) {
    boolean goldOnly = "true".equalsIgnoreCase(request.getParameter("goldOnly"));
    boolean bed = null == request.getParameter("bed") ? true : Boolean.valueOf(request.getParameter("bed"));
    Entry entry = this.entryBuilderService.build(EntryConfig.newConfig(entryName).with(blockOrSubpart).withGoldOnly(goldOnly).withBed(bed));
    if (ancestorTerm != null || propertyName != null) {
        filterEntryAnnotations(entry, ancestorTerm, propertyName, propertyValueOrAccession);
    }
    if (request.getRequestURI().toLowerCase().endsWith(".tsv")) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            EntryPartWriterTSV writer = new EntryPartWriterTSV(EntryPartExporterImpl.fromSubPart(blockOrSubpart), baos);
            writer.write(entry);
            model.addAttribute("tsv", baos.toString(StandardCharsets.UTF_8.name()));
            baos.close();
        } catch (IOException e) {
            throw new NextProtException("cannot export " + entryName + " " + blockOrSubpart + " in tsv format", e);
        }
    }
    model.addAttribute("entry", entry);
    return "entry";
}
Also used : EntryPartWriterTSV(org.nextprot.api.core.export.EntryPartWriterTSV) NextProtException(org.nextprot.api.commons.exception.NextProtException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

NextProtException (org.nextprot.api.commons.exception.NextProtException)68 IOException (java.io.IOException)30 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ApiMethod (org.jsondoc.core.annotation.ApiMethod)8 OutputStream (java.io.OutputStream)7 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)7 Cacheable (org.springframework.cache.annotation.Cacheable)6 Isoform (org.nextprot.api.core.domain.Isoform)5 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 Annotation (org.nextprot.api.core.domain.annotation.Annotation)4 NextprotMediaType (org.nextprot.api.core.service.export.format.NextprotMediaType)4 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)4 java.util (java.util)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 CvTerm (org.nextprot.api.core.domain.CvTerm)3 AnnotationVariant (org.nextprot.api.core.domain.annotation.AnnotationVariant)3 Query (org.nextprot.api.solr.Query)3 SearchResult (org.nextprot.api.solr.SearchResult)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2