Search in sources :

Example 6 with Sequence

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

the class SBOLVisualDownloadServlet method getSBOLVisualType.

private void getSBOLVisualType(String userId, String entryId, HttpServletResponse response) {
    Entry entry = DAOFactory.getEntryDAO().getByRecordId(entryId);
    if (entry == null)
        return;
    Sequence sequence = DAOFactory.getSequenceDAO().getByEntry(entry);
    if (sequence == null) {
        return;
    }
    EntryAuthorization authorization = new EntryAuthorization();
    authorization.expectRead(userId, entry);
    // retrieve cached pigeon image or generate and cache
    String tmpDir = Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY);
    Path filePath = Paths.get(tmpDir, sequence.getFwdHash() + ".png");
    URI uri = PigeonSBOLv.generatePigeonVisual(sequence);
    if (uri != null) {
        try {
            IOUtils.copy(uri.toURL().openStream(), new FileOutputStream(filePath.toFile()));
        } catch (IOException e) {
            Logger.error(e);
            return;
        }
    }
    response.setContentType("image/png");
    if (!Files.exists(filePath) || !Files.isReadable(filePath))
        return;
    response.setContentLength((int) filePath.toFile().length());
    try {
        IOUtils.copy(new FileInputStream(filePath.toFile()), response.getOutputStream());
    } catch (IOException ioe) {
        Logger.error(ioe);
    }
}
Also used : Path(java.nio.file.Path) Entry(org.jbei.ice.storage.model.Entry) FileOutputStream(java.io.FileOutputStream) Sequence(org.jbei.ice.storage.model.Sequence) IOException(java.io.IOException) EntryAuthorization(org.jbei.ice.lib.entry.EntryAuthorization) URI(java.net.URI) FileInputStream(java.io.FileInputStream)

Example 7 with Sequence

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

the class RemoteTransfer method performTransfer.

/**
     * Transfers the sequence file for the part and any parts that are linked to it.
     * If the attached sequence was uploaded as a file or pasted, the system
     * transfers that. If not if attempts to convert the attached sequence to genbank format
     * and transfers that
     *
     * @param partner destination for the sequence transfer
     * @param data    data for part whose sequences are to be transferred
     */
protected void performTransfer(RemotePartner partner, PartData data) {
    String url = partner.getUrl();
    // check main entry for sequence
    if (sequenceDAO.hasSequence(data.getId())) {
        Entry entry = entryDAO.get(data.getId());
        Sequence sequence = sequenceDAO.getByEntry(entry);
        String sequenceString = sequence.getSequenceUser();
        if (StringUtils.isEmpty(sequenceString)) {
            GenbankFormatter genbankFormatter = new GenbankFormatter(entry.getName());
            genbankFormatter.setCircular(true);
            try {
                ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
                genbankFormatter.format(sequence, byteStream);
                sequenceString = byteStream.toString();
            } catch (Exception e) {
                Logger.error(e);
                sequenceString = sequence.getSequence();
            }
        }
        if (!StringUtils.isEmpty(sequenceString))
            remoteContact.transferSequence(url, data.getRecordId(), data.getType(), sequenceString);
    }
    // check child entries
    if (data.getLinkedParts() == null)
        return;
    for (PartData linked : data.getLinkedParts()) {
        performTransfer(partner, linked);
    }
}
Also used : GenbankFormatter(org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter) Entry(org.jbei.ice.storage.model.Entry) PartData(org.jbei.ice.lib.dto.entry.PartData) Sequence(org.jbei.ice.storage.model.Sequence) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 8 with Sequence

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

the class RemoteSequence method get.

public ByteArrayWrapper get(String type) {
    FeaturedDNASequence featuredDNASequence = remoteContact.getPublicEntrySequence(partner.getUrl(), Long.toString(remotePartId), partner.getApiKey());
    if (featuredDNASequence == null)
        return new ByteArrayWrapper(new byte[] { '\0' }, "no_sequence");
    String name = featuredDNASequence.getName();
    try {
        Sequence sequence = SequenceController.dnaSequenceToSequence(featuredDNASequence);
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        AbstractFormatter formatter;
        switch(type.toLowerCase()) {
            case "genbank":
            default:
                name = name + ".gb";
                formatter = new GenbankFormatter(name);
                break;
            case "fasta":
                formatter = new FastaFormatter();
                break;
            case "sbol1":
                formatter = new SBOLFormatter();
                name = name + ".xml";
                break;
            case "sbol2":
                formatter = new SBOL2Formatter();
                name = name + ".xml";
                break;
            case "pigeoni":
                URI uri = PigeonSBOLv.generatePigeonVisual(sequence);
                byte[] bytes = IOUtils.toByteArray(uri.toURL().openStream());
                return new ByteArrayWrapper(bytes, name + ".png");
            case "pigeons":
                String sequenceString = PigeonSBOLv.generatePigeonScript(sequence);
                name = name + ".txt";
                return new ByteArrayWrapper(sequenceString.getBytes(), name);
        }
        formatter.format(sequence, byteStream);
        return new ByteArrayWrapper(byteStream.toByteArray(), name);
    } catch (Exception e) {
        Logger.error(e);
        return new ByteArrayWrapper(new byte[] { '\0' }, "no_sequence");
    }
}
Also used : Sequence(org.jbei.ice.storage.model.Sequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) URI(java.net.URI) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper)

Example 9 with Sequence

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

the class BlastPlus method writeBigFastaFile.

/**
     * Retrieve all the sequences from the database, and writes it out to a fasta file on disk.
     *
     * @throws BlastException
     */
private static void writeBigFastaFile(BufferedWriter writer) throws BlastException {
    SequenceDAO sequenceDAO = DAOFactory.getSequenceDAO();
    long count = sequenceDAO.getSequenceCount();
    if (count <= 0)
        return;
    int offset = 0;
    while (offset < count) {
        Sequence sequence = sequenceDAO.getSequence(offset++);
        if (sequence == null || sequence.getEntry() == null)
            continue;
        long id = sequence.getEntry().getId();
        String sequenceString = "";
        String temp = sequence.getSequence();
        //            int sequenceLength = 0;
        if (temp != null) {
            SymbolList symL;
            try {
                symL = DNATools.createDNA(sequence.getSequence().trim());
            } catch (IllegalSymbolException e1) {
                // maybe it's rna?
                try {
                    symL = RNATools.createRNA(sequence.getSequence().trim());
                } catch (IllegalSymbolException e2) {
                    // skip this sequence
                    Logger.debug("Invalid characters in sequence for " + sequence.getEntry().getId() + ". Skipped for indexing");
                    Logger.debug(e2.toString());
                    continue;
                }
            }
            //                sequenceLength = symL.seqString().length();
            sequenceString = SequenceUtils.breakUpLines(symL.seqString() + symL.seqString());
        }
        if (sequenceString.length() > 0) {
            try {
                String idString = ">" + id;
                idString += DELIMITER + sequence.getEntry().getRecordType();
                String name = sequence.getEntry().getName() == null ? "None" : sequence.getEntry().getName();
                idString += DELIMITER + name;
                String pNumber = sequence.getEntry().getPartNumber();
                idString += DELIMITER + pNumber;
                idString += "\n";
                writer.write(idString);
                writer.write(sequenceString + "\n");
            } catch (IOException e) {
                throw new BlastException(e);
            }
        }
    }
}
Also used : IllegalSymbolException(org.biojava.bio.symbol.IllegalSymbolException) SequenceDAO(org.jbei.ice.storage.hibernate.dao.SequenceDAO) Sequence(org.jbei.ice.storage.model.Sequence) SymbolList(org.biojava.bio.symbol.SymbolList)

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