Search in sources :

Example 1 with Sequence

use of org.jbei.ice.storage.model.Sequence in project ice by JBEI.

the class FileResource method downloadSequence.

@GET
@Path("{partId}/sequence/{type}")
public Response downloadSequence(@PathParam("partId") final long partId, @PathParam("type") final String downloadType, @DefaultValue("-1") @QueryParam("remoteId") long remoteId, @QueryParam("sid") String sid) {
    if (StringUtils.isEmpty(sessionId))
        sessionId = sid;
    final String userId = getUserId(sessionId);
    final ByteArrayWrapper wrapper;
    if (remoteId != -1) {
        RemoteSequence sequence = new RemoteSequence(remoteId, partId);
        wrapper = sequence.get(downloadType);
    } else {
        wrapper = sequenceController.getSequenceFile(userId, partId, downloadType);
    }
    StreamingOutput stream = output -> {
        final ByteArrayInputStream input = new ByteArrayInputStream(wrapper.getBytes());
        ByteStreams.copy(input, output);
    };
    return addHeaders(Response.ok(stream), wrapper.getName());
}
Also used : RemoteSequence(org.jbei.ice.lib.net.RemoteSequence) AttachmentInfo(org.jbei.ice.lib.dto.entry.AttachmentInfo) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) Setting(org.jbei.ice.lib.dto.Setting) SequenceAnalysisController(org.jbei.ice.lib.entry.sequence.SequenceAnalysisController) ConfigurationKey(org.jbei.ice.lib.dto.ConfigurationKey) EntryField(org.jbei.ice.lib.dto.entry.EntryField) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Entries(org.jbei.ice.lib.entry.Entries) Sequence(org.jbei.ice.storage.model.Sequence) MediaType(javax.ws.rs.core.MediaType) ConfigurationController(org.jbei.ice.lib.config.ConfigurationController) DAOFactory(org.jbei.ice.storage.DAOFactory) Logger(org.jbei.ice.lib.common.logging.Logger) FileBulkUpload(org.jbei.ice.lib.bulkupload.FileBulkUpload) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) PigeonSBOLv(org.jbei.ice.lib.entry.sequence.composers.pigeon.PigeonSBOLv) Entry(org.jbei.ice.storage.model.Entry) EntryType(org.jbei.ice.lib.dto.entry.EntryType) URI(java.net.URI) Utils(org.jbei.ice.lib.utils.Utils) AttachmentController(org.jbei.ice.lib.entry.attachment.AttachmentController) EntrySelection(org.jbei.ice.lib.entry.EntrySelection) FileUtils(org.apache.commons.io.FileUtils) StreamingOutput(javax.ws.rs.core.StreamingOutput) SequenceController(org.jbei.ice.lib.entry.sequence.SequenceController) Collectors(java.util.stream.Collectors) RemoteEntries(org.jbei.ice.lib.net.RemoteEntries) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) List(java.util.List) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) java.io(java.io) Paths(java.nio.file.Paths) ByteStreams(com.google.common.io.ByteStreams) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper) ShotgunSequenceDAO(org.jbei.ice.storage.hibernate.dao.ShotgunSequenceDAO) TraceSequence(org.jbei.ice.storage.model.TraceSequence) EntriesAsCSV(org.jbei.ice.lib.entry.EntriesAsCSV) ShotgunSequence(org.jbei.ice.storage.model.ShotgunSequence) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper) StreamingOutput(javax.ws.rs.core.StreamingOutput) RemoteSequence(org.jbei.ice.lib.net.RemoteSequence)

Example 2 with Sequence

use of org.jbei.ice.storage.model.Sequence in project ice by JBEI.

the class FileResource method getSBOLVisual.

@GET
@Produces("image/png")
@Path("sbolVisual/{rid}")
public Response getSBOLVisual(@PathParam("rid") String recordId) {
    final String tmpDir = Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY);
    final Entry entry = DAOFactory.getEntryDAO().getByRecordId(recordId);
    final Sequence sequence = entry.getSequence();
    final String hash = sequence.getFwdHash();
    final File png = Paths.get(tmpDir, hash + ".png").toFile();
    if (png.exists()) {
        return addHeaders(Response.ok(png), entry.getPartNumber() + ".png");
    }
    final URI uri = PigeonSBOLv.generatePigeonVisual(sequence);
    if (uri != null) {
        try (final InputStream in = uri.toURL().openStream();
            final OutputStream out = new FileOutputStream(png)) {
            ByteStreams.copy(in, out);
        } catch (IOException e) {
            Logger.error(e);
            return respond(false);
        }
        return addHeaders(Response.ok(png), entry.getPartNumber() + ".png");
    }
    return respond(false);
}
Also used : Entry(org.jbei.ice.storage.model.Entry) RemoteSequence(org.jbei.ice.lib.net.RemoteSequence) PartSequence(org.jbei.ice.lib.entry.sequence.PartSequence) Sequence(org.jbei.ice.storage.model.Sequence) TraceSequence(org.jbei.ice.storage.model.TraceSequence) ShotgunSequence(org.jbei.ice.storage.model.ShotgunSequence) URI(java.net.URI)

Example 3 with Sequence

use of org.jbei.ice.storage.model.Sequence in project ice by JBEI.

the class SBOLParser method parseToGenBank.

/**
     * Parse the SBOL document to genbank format, save and associate with entry
     *
     * @param sbolDocument SBOL document to parse
     * @param fileName     name of file that was parsed to extract the SBOL information
     * @param entry        ICE entry to associate sequence document with
     * @param uri          optional uri to associate with sequence
     * @return Sequence info data transfer object for saved sequence
     */
protected SequenceInfo parseToGenBank(SBOLDocument sbolDocument, String fileName, Entry entry, String uri) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    String rdf;
    // convert to rdf string to save raw document
    try {
        sbolDocument.write(out);
        rdf = out.toString();
    } catch (SBOLConversionException e) {
        rdf = null;
    }
    // convert to genbank
    Sequence sequence = null;
    DNASequence dnaSequence = null;
    try {
        out.reset();
        SBOLWriter.write(sbolDocument, out, "GENBANK");
        if (out.size() > 0) {
            GenBankParser parser = new GenBankParser();
            dnaSequence = parser.parse(new String(out.toByteArray()));
            sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
        }
    } catch (InvalidFormatParserException e) {
        Logger.error("Error parsing generated genBank: " + e.getMessage());
    } catch (SBOLConversionException | IOException e) {
        Logger.error("Error converting SBOL to genBank: " + e.getMessage());
    }
    // convert to ice data model (sequence)
    if (sequence == null) {
        sequence = new Sequence();
    }
    if (!StringUtils.isEmpty(rdf))
        sequence.setSequenceUser(rdf);
    sequence.setFormat(SequenceFormat.SBOL2);
    sequence.setEntry(entry);
    if (fileName != null)
        sequence.setFileName(fileName);
    if (!StringUtils.isEmpty(uri))
        sequence.setUri(uri);
    sequence = DAOFactory.getSequenceDAO().saveSequence(sequence);
    SequenceInfo sequenceInfo = new SequenceInfo();
    sequenceInfo.setEntryId(entry.getId());
    sequenceInfo.setSequence(dnaSequence);
    sequenceInfo.setFormat(sequence.getFormat());
    if (fileName != null)
        sequenceInfo.setFilename(fileName);
    return sequenceInfo;
}
Also used : GenBankParser(org.jbei.ice.lib.parsers.genbank.GenBankParser) DNASequence(org.jbei.ice.lib.dto.DNASequence) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DNASequence(org.jbei.ice.lib.dto.DNASequence) Sequence(org.jbei.ice.storage.model.Sequence) InvalidFormatParserException(org.jbei.ice.lib.parsers.InvalidFormatParserException) IOException(java.io.IOException)

Example 4 with Sequence

use of org.jbei.ice.storage.model.Sequence in project ice by JBEI.

the class BulkFileSBOLUpload method processUpload.

public long processUpload() throws IOException {
    BulkUploadController controller = new BulkUploadController();
    long bulkUploadId = 0;
    SBOLDocument document = SBOLFactory.read(new FileInputStream(filePath.toFile()));
    try {
        // walk top level object
        for (SBOLRootObject rootObject : document.getContents()) {
            ICESBOLParserVisitor visitor = new ICESBOLParserVisitor(addType);
            rootObject.accept(visitor);
            BulkUploadAutoUpdate update = visitor.getUpdate();
            update.setBulkUploadId(bulkUploadId);
            Logger.info(userId + ": " + update.toString());
            update = controller.autoUpdateBulkUpload(userId, update, addType);
            if (bulkUploadId == 0)
                bulkUploadId = update.getBulkUploadId();
            // get "user sequence"
            String sequenceUser = getSequenceDocument(rootObject);
            long entryId = update.getEntryId();
            DNASequence dnaSequence = visitor.getFeaturedDNASequence();
            Sequence sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
            Entry entry = DAOFactory.getEntryDAO().get(entryId);
            sequence.setEntry(entry);
            if (sequenceUser != null)
                sequence.setSequenceUser(sequenceUser);
            new SequenceController().save(userId, sequence);
        }
    } catch (Exception e) {
        Logger.error(e);
        throw new IOException(e);
    }
    return bulkUploadId;
}
Also used : SBOLDocument(org.sbolstandard.core.SBOLDocument) ICESBOLParserVisitor(org.jbei.ice.lib.parsers.sbol.ICESBOLParserVisitor) DNASequence(org.jbei.ice.lib.dto.DNASequence) Sequence(org.jbei.ice.storage.model.Sequence) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) DNASequence(org.jbei.ice.lib.dto.DNASequence) Entry(org.jbei.ice.storage.model.Entry) SBOLRootObject(org.sbolstandard.core.SBOLRootObject) SequenceController(org.jbei.ice.lib.entry.sequence.SequenceController)

Example 5 with Sequence

use of org.jbei.ice.storage.model.Sequence in project ice by JBEI.

the class AbstractParser method save.

protected SequenceInfo save(DNASequence dnaSequence, String sequenceString) {
    Sequence sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
    sequence.setSequenceUser(sequenceString);
    sequence.setEntry(entry);
    if (!StringUtils.isBlank(fileName))
        sequence.setFileName(fileName);
    Sequence result = sequenceDAO.saveSequence(sequence);
    BlastPlus.scheduleBlastIndexRebuildTask(true);
    SequenceInfo info = result.toDataTransferObject();
    info.setSequence(dnaSequence);
    return info;
}
Also used : SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) Sequence(org.jbei.ice.storage.model.Sequence) DNASequence(org.jbei.ice.lib.dto.DNASequence)

Aggregations

Sequence (org.jbei.ice.storage.model.Sequence)9 Entry (org.jbei.ice.storage.model.Entry)5 URI (java.net.URI)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 DNASequence (org.jbei.ice.lib.dto.DNASequence)3 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)3 FileInputStream (java.io.FileInputStream)2 ByteArrayWrapper (org.jbei.ice.lib.entry.sequence.ByteArrayWrapper)2 PartSequence (org.jbei.ice.lib.entry.sequence.PartSequence)2 SequenceController (org.jbei.ice.lib.entry.sequence.SequenceController)2 RemoteSequence (org.jbei.ice.lib.net.RemoteSequence)2 ShotgunSequence (org.jbei.ice.storage.model.ShotgunSequence)2 TraceSequence (org.jbei.ice.storage.model.TraceSequence)2 ByteStreams (com.google.common.io.ByteStreams)1 java.io (java.io)1 FileOutputStream (java.io.FileOutputStream)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1