Search in sources :

Example 1 with EntryPartWriterTSV

use of org.nextprot.api.core.export.EntryPartWriterTSV in project nextprot-api by calipho-sib.

the class EntryPartWriterTSVTest method getExpressionProfileOutputString.

@Test
public void getExpressionProfileOutputString() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    String subpart = "expression-profile";
    Entry entry = entryBuilderService.build(EntryConfig.newConfig("NX_P01308").with(subpart));
    EntryPartWriterTSV writer = new EntryPartWriterTSV(EntryPartExporterImpl.fromSubPart(subpart), baos);
    writer.write(entry);
    String output = baos.toString(StandardCharsets.UTF_8.name());
    baos.close();
    String[] headers = output.split("\n");
    Assert.assertTrue(headers.length > 534);
    Assert.assertEquals("ENTRY_ACCESSION\tCATEGORY\tTERM_ACCESSION\tTERM_NAME\tQUALITY\tECO_ACCESSION\tECO_NAME\tNEGATIVE\tEXPRESSION_LEVEL\tSTAGE_ACCESSION\tSTAGE_NAME\tSOURCE\tURL", headers[0]);
}
Also used : EntryPartWriterTSV(org.nextprot.api.core.export.EntryPartWriterTSV) Entry(org.nextprot.api.core.domain.Entry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreUnitBaseTest(org.nextprot.api.core.test.base.CoreUnitBaseTest) Test(org.junit.Test)

Example 2 with EntryPartWriterTSV

use of org.nextprot.api.core.export.EntryPartWriterTSV 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

ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 EntryPartWriterTSV (org.nextprot.api.core.export.EntryPartWriterTSV)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 NextProtException (org.nextprot.api.commons.exception.NextProtException)1 Entry (org.nextprot.api.core.domain.Entry)1 CoreUnitBaseTest (org.nextprot.api.core.test.base.CoreUnitBaseTest)1