Search in sources :

Example 6 with NextProtException

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

the class StatementTranformerServiceImpl method transformStatements.

@Override
public Set<Statement> transformStatements(Set<Statement> rawStatements, ReportBuilder report) {
    Map<String, Statement> sourceStatementsById = rawStatements.stream().collect(Collectors.toMap(Statement::getStatementId, Function.identity()));
    Set<Statement> mappedStatementsToLoad = new HashSet<>();
    for (Statement originalStatement : rawStatements) {
        // If statements are complex with subject
        if ((originalStatement.getSubjectStatementIds() != null) && (!originalStatement.getSubjectStatementIds().isEmpty())) {
            String[] subjectStatemendIds = originalStatement.getSubjectStatementIdsArray();
            Set<Statement> subjectStatements = getSubjects(subjectStatemendIds, sourceStatementsById);
            subjectStatements.forEach(s -> s.processed());
            originalStatement.processed();
            String entryAccession = subjectStatements.iterator().next().getValue(StatementField.ENTRY_ACCESSION);
            boolean isIsoSpecific = false;
            String isoformName = validateSubject(subjectStatements);
            String isoformSpecificAccession = null;
            if (isSubjectIsoSpecific(subjectStatements)) {
                if (isoformName != null) {
                    isIsoSpecific = true;
                    String featureName = subjectStatements.iterator().next().getValue(StatementField.ANNOTATION_NAME);
                    isoformSpecificAccession = getIsoAccession(featureName, entryAccession);
                } else
                    throw new NextProtException("Something wrong occured when checking for iso specificity");
            }
            mappedStatementsToLoad.addAll(transformStatements(originalStatement, sourceStatementsById, subjectStatements, entryAccession, isIsoSpecific, isoformSpecificAccession, report));
        }
    }
    // Currently only includes cases where we have the reciprocal binary interactions
    Set<Statement> remainingRawStatements = getRemainingRawStatements(rawStatements);
    Set<String> distinctCategories = remainingRawStatements.stream().map(s -> s.getValue(StatementField.ANNOTATION_CATEGORY)).distinct().collect(Collectors.toSet());
    if (distinctCategories.contains(AnnotationCategory.PHENOTYPIC_VARIATION.getDbAnnotationTypeName())) {
        throw new NextProtException("Not expecting phenotypic variation at this stage.");
    }
    LOGGER.info("Remaining categories are " + distinctCategories);
    Set<Statement> remainingMappedStatements = transformRemainingRawStatementsToMappedStatements(remainingRawStatements);
    mappedStatementsToLoad.addAll(remainingMappedStatements);
    return mappedStatementsToLoad;
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException)

Example 7 with NextProtException

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

the class TerminologyUtils method populateTree.

static void populateTree(Tree.Node<CvTerm> currentNode, Map<String, CvTerm> termMap, int depth, final int maxDepth) {
    if (depth > maxDepth)
        return;
    if (depth > 100)
        throw new NextProtException("Getting stuck in building graph");
    if (currentNode.getValue() == null || currentNode.getValue().getChildAccession() == null || currentNode.getValue().getChildAccession().isEmpty()) {
        return;
    }
    for (String childAccession : currentNode.getValue().getChildAccession()) {
        CvTerm childTerm = termMap.get(childAccession);
        if (childTerm != null) {
            if (currentNode.getChildren() == null) {
                currentNode.setChildren(new ArrayList<Tree.Node<CvTerm>>());
            }
            Tree.Node<CvTerm> childNode = new Tree.Node<CvTerm>(childTerm);
            childNode.setParents(Arrays.asList(currentNode));
            currentNode.getChildren().add(childNode);
            populateTree(childNode, termMap, depth + 1, maxDepth);
        }
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) CvTerm(org.nextprot.api.core.domain.CvTerm) Node(org.nextprot.api.commons.utils.Tree.Node) Tree(org.nextprot.api.commons.utils.Tree)

Example 8 with NextProtException

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

the class StreamEntryServiceImpl method streamAllChromosomeEntries.

@Override
public void streamAllChromosomeEntries(String chromosome, NextprotMediaType format, HttpServletResponse response) {
    if (!Chromosome.exists(chromosome)) {
        ChromosomeNotFoundException ex = new ChromosomeNotFoundException(chromosome);
        response.setStatus(HttpStatus.SC_NOT_FOUND);
        try {
            response.getWriter().print(ex.getMessage());
        } catch (IOException e) {
            throw new NextProtException(format.getExtension() + " streaming failed: " + ex.getMessage(), e);
        }
    } else {
        try {
            setResponseHeader(response, format, "nextprot_chromosome_" + chromosome + "." + format.getExtension());
            streamEntries(masterIdentifierService.findUniqueNamesOfChromosome(chromosome), format, "entry", response.getOutputStream(), "chromosome " + chromosome);
        } catch (IOException e) {
            throw new NextProtException(format.getExtension() + " streaming failed: cannot export all " + masterIdentifierService.findUniqueNames().size() + " entries from chromosome " + chromosome, e);
        }
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) ChromosomeNotFoundException(org.nextprot.api.commons.exception.ChromosomeNotFoundException) IOException(java.io.IOException)

Example 9 with NextProtException

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

the class PepXServiceImpl method getPepXResponse.

private PepXResponse getPepXResponse(String peptides, boolean modeIsoleucine) {
    String httpRequest = pepXUrl + "?format=json" + (modeIsoleucine ? ("&mode=IL&pep=" + peptides) : ("&pep=" + peptides));
    try {
        URL pepXUrl = new URL(httpRequest);
        URLConnection px = pepXUrl.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(px.getInputStream()));
        String line;
        StringBuilder sb = new StringBuilder();
        while ((line = in.readLine()) != null) {
            sb.append(line);
        }
        in.close();
        return PepxUtils.parsePepxResponse(sb.toString());
    } catch (IOException e) {
        throw new NextProtException(e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 10 with NextProtException

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

the class SearchServiceImpl method sortAccessions.

@Override
public List<String> sortAccessions(QueryRequest queryRequest, Set<String> accessions) {
    List<String> sortedAccessions = new ArrayList<String>();
    try {
        String queryString = "id:" + (accessions.size() > 1 ? "(" + Joiner.on(" ").join(accessions) + ")" : accessions.iterator().next());
        queryRequest.setQuery(queryString);
        Query query = queryBuilderService.buildQueryForSearchIndexes("entry", "pl_search", queryRequest);
        SearchResult result = this.solrService.executeQuery(query);
        List<Map<String, Object>> results = result.getResults();
        for (Map<String, Object> res : results) {
            String entry = (String) res.get("id");
            sortedAccessions.add(entry);
        }
    } catch (SearchQueryException e) {
        e.printStackTrace();
        throw new NextProtException("Error when retrieving accessions");
    }
    return sortedAccessions;
}
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)

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