Search in sources :

Example 1 with GenbankFormatter

use of org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter in project ice by JBEI.

the class RemoteEntriesAsCSV method writeDataEntries.

protected void writeDataEntries(RemotePartner partner, List<PartData> entries, List<EntryField> fields, CSVWriter writer, ZipOutputStream zos) {
    if (entries == null)
        return;
    for (PartData partData : entries) {
        String[] line = new String[fields.size() + 4];
        line[0] = partner.getUrl();
        line[1] = new Date(partData.getCreationTime()).toString();
        line[2] = partData.getPartId();
        int i = 2;
        for (EntryField field : fields) {
            line[i + 1] = PartDataUtil.entryFieldToValue(partData, field);
            i += 1;
        }
        // write sequence to zip file
        if (partData.isHasSequence()) {
            try {
                // get remote sequence
                FeaturedDNASequence featuredDNASequence = remoteEntries.getPublicEntrySequence(partner.getId(), Long.toString(partData.getId()));
                if (featuredDNASequence != null) {
                    String name = partData.getPartId() + ".gb";
                    // write sequence to zip
                    line[i + 1] = name;
                    Sequence sequence = SequenceController.dnaSequenceToSequence(featuredDNASequence);
                    GenbankFormatter genbankFormatter = new GenbankFormatter(name);
                    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
                    genbankFormatter.format(sequence, byteStream);
                    ByteArrayWrapper wrapper = new ByteArrayWrapper(byteStream.toByteArray(), name);
                    putZipEntry(wrapper, zos);
                } else {
                    line[i + 1] = "";
                }
            } catch (Exception e) {
                line[i + 1] = "";
            }
        } else {
            line[i + 1] = "";
        }
        writer.writeNext(line);
    }
}
Also used : GenbankFormatter(org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper) PartData(org.jbei.ice.lib.dto.entry.PartData) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) Date(java.util.Date) EntryField(org.jbei.ice.lib.dto.entry.EntryField)

Example 2 with GenbankFormatter

use of org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter in project ice by JBEI.

the class RemoteEntriesAsCSV method writeLocalEntries.

protected void writeLocalEntries(List<Entry> entries, List<EntryField> fields, CSVWriter writer, ZipOutputStream zos) {
    if (entries == null)
        return;
    SequenceDAO sequenceDAO = DAOFactory.getSequenceDAO();
    Configuration configuration = DAOFactory.getConfigurationDAO().get(ConfigurationKey.URI_PREFIX);
    String thisUrl = configuration == null ? "" : configuration.getValue();
    for (Entry entry : entries) {
        String[] line = new String[fields.size() + 4];
        line[0] = thisUrl;
        line[1] = entry.getCreationTime().toString();
        line[2] = entry.getPartNumber();
        int i = 2;
        for (EntryField field : fields) {
            line[i + 1] = EntryUtil.entryFieldToValue(entry, field);
            i += 1;
        }
        // write sequence to zip file
        long entryId = entry.getId();
        if (sequenceDAO.hasSequence(entryId)) {
            String name = entry.getPartNumber() + ".gb";
            try {
                Sequence sequence = sequenceDAO.getByEntry(entry);
                line[i + 1] = name;
                GenbankFormatter genbankFormatter = new GenbankFormatter(name);
                ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
                genbankFormatter.format(sequence, byteStream);
                ByteArrayWrapper wrapper = new ByteArrayWrapper(byteStream.toByteArray(), name);
                putZipEntry(wrapper, zos);
            } catch (Exception e) {
                line[i + 1] = "";
            }
        } else {
            line[i + 1] = "";
        }
        writer.writeNext(line);
    }
}
Also used : FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) EntryField(org.jbei.ice.lib.dto.entry.EntryField) GenbankFormatter(org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter) ZipEntry(java.util.zip.ZipEntry) ByteArrayWrapper(org.jbei.ice.lib.entry.sequence.ByteArrayWrapper) SequenceDAO(org.jbei.ice.storage.hibernate.dao.SequenceDAO)

Example 3 with GenbankFormatter

use of org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter 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)

Aggregations

GenbankFormatter (org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter)3 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)2 EntryField (org.jbei.ice.lib.dto.entry.EntryField)2 PartData (org.jbei.ice.lib.dto.entry.PartData)2 ByteArrayWrapper (org.jbei.ice.lib.entry.sequence.ByteArrayWrapper)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Date (java.util.Date)1 ZipEntry (java.util.zip.ZipEntry)1 SequenceDAO (org.jbei.ice.storage.hibernate.dao.SequenceDAO)1 Entry (org.jbei.ice.storage.model.Entry)1 Sequence (org.jbei.ice.storage.model.Sequence)1