Search in sources :

Example 51 with NextProtException

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

the class TerminologyServiceImpl method findPsiModName.

// http://psidev.cvs.sourceforge.net/viewvc/psidev/psi/mod/data/PSI-MOD.obo
@Override
public Optional<String> findPsiModName(String cvTermAccession) {
    Optional<String> psiModAccessionOpt = findPsiModAccession(cvTermAccession);
    if (!psiModAccessionOpt.isPresent()) {
        return Optional.empty();
    }
    String psiModAccession = psiModAccessionOpt.get();
    InputStream is = getClass().getResourceAsStream("peff/PSI-MOD.obo");
    try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
        String line;
        while ((line = br.readLine()) != null) {
            // if the psi term is found...
            if (line.startsWith("id: " + psiModAccession)) {
                return findTermName(br);
            }
        }
        // no psi term found
        return Optional.empty();
    } catch (IOException e) {
        throw new NextProtException(e.getMessage() + ": cannot find PSI-MOD name for cv term " + cvTermAccession);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 52 with NextProtException

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

the class StreamEntryServiceImpl method streamAllEntries.

@Override
public void streamAllEntries(NextprotMediaType format, HttpServletResponse response) {
    try {
        setResponseHeader(response, format, "nextprot_all" + "." + format.getExtension());
        streamEntries(masterIdentifierService.findUniqueNames(), format, "entry", response.getOutputStream(), "complete release");
    } catch (IOException e) {
        throw new NextProtException(format.getExtension() + " streaming failed: cannot export all " + masterIdentifierService.findUniqueNames().size() + " entries", e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) IOException(java.io.IOException)

Example 53 with NextProtException

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

the class StreamEntryServiceImpl method streamQueriedEntries.

@Override
public void streamQueriedEntries(QueryRequest queryRequest, NextprotMediaType format, String viewName, HttpServletResponse response) {
    List<String> entries = getAccessions(queryRequest);
    try {
        setResponseHeader(response, format, getFilename(queryRequest, viewName, format));
        streamEntries(entries, format, viewName, response.getOutputStream(), getHeaderDescription(queryRequest));
    } catch (IOException e) {
        throw new NextProtException(format.getExtension() + " streaming failed: cannot export " + entries.size() + " entries (query=" + queryRequest.getQuery() + ")", e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) IOException(java.io.IOException)

Example 54 with NextProtException

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

the class PepXServiceTest method shouldThrowAnExceptionWhenPepXGivesAVariantNotSpecificToTheIsoform.

@Test(expected = NextProtException.class)
public void shouldThrowAnExceptionWhenPepXGivesAVariantNotSpecificToTheIsoform() throws Exception {
    try {
        // Taking example NX_Q9H6T3
        String peptide = "GANAP";
        boolean modeIsoleucine = true;
        String isoName = "NX_Q9H6T3-3";
        Isoform iso1 = mock(Isoform.class);
        when(iso1.getIsoformAccession()).thenReturn("another-iso-name");
        when(iso1.getSequence()).thenReturn("MDADPYNPVLPTNRASAYFRLKKFAVAESDCNLAVALNRSYTKAYSRRGAARFALQKLEEAKKDYERVLELEPNNFEATNELRKISQALASKENSYPKEADIVIKSTEGERKQIEAQQNKQQAISEKDRGNGFFKEGKYERAIECYTRGIAADGANALLPANRAMAYLKIQKYEEAEKDCTQAILLDGSYSKAFARRGTARTFLGKLNEAKQDFETVLLLEPGNKQAVTELSKIKKELIEKGHWDDVFLDSTQRQNVVKPIDNPPHPGSTKPLKKVIIEETGNLIQTIDVPDSTTAAAPENNPINLANVIAATGTTSKKNSSQDDLFPTSDTPRAKVLKIEEVSDTSSLQPQASLKQDVCQSYSEKMPIEIEQKPAQFATTVLPPIPANSFQLESDFRQLKSSPDMLYQYLKQIEPSLYPKLFQKNLDPDVFNQIVKILHDFYIEKEKPLLIFEILQRLSELKRFDMAVMFMSETEKKIARALFNHIDKSGLKDSSVEELKKRYGG");
        PepXIsoformMatch pepXIsoformMatch = new PepXIsoformMatch(isoName, 154);
        List<Annotation> annots = Arrays.asList(getMockedAnnotation("L", "P", 158, isoName, true));
        List<Isoform> isoforms = Arrays.asList(iso1);
        // empty
        PepXServiceImpl.buildEntryWithVirtualAnnotations(peptide, modeIsoleucine, Arrays.asList(pepXIsoformMatch), annots, isoforms);
    // or
    // null
    // annotations
    } catch (NextProtException e) {
        if (e.getMessage().contains("is not specific for this isoform")) {
            // success tests
            throw e;
        } else
            fail();
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) PepXIsoformMatch(org.nextprot.api.web.domain.PepXResponse.PepXIsoformMatch) Isoform(org.nextprot.api.core.domain.Isoform) Annotation(org.nextprot.api.core.domain.annotation.Annotation) WebUnitBaseTest(org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest) Test(org.junit.Test)

Example 55 with NextProtException

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

the class DbXrefController method getRequestedFormat.

private NextprotMediaType getRequestedFormat(HttpServletRequest request) {
    NextprotMediaType format;
    String uri = request.getRequestURI();
    if (uri.toLowerCase().endsWith(".ttl")) {
        format = NextprotMediaType.TURTLE;
    } else if (uri.toLowerCase().endsWith(".xml")) {
        format = NextprotMediaType.XML;
    } else if (uri.toLowerCase().endsWith(".json")) {
        format = NextprotMediaType.JSON;
    } else if (uri.toLowerCase().endsWith(".txt")) {
        format = NextprotMediaType.TXT;
    } else
        throw new NextProtException("Format not recognized");
    return format;
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) NextprotMediaType(org.nextprot.api.core.service.export.format.NextprotMediaType)

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