Search in sources :

Example 46 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class RemoteEntriesAsCSV method writeDataEntries.

protected void writeDataEntries(RemotePartner partner, List<PartData> entries, List<EntryFieldLabel> 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 (EntryFieldLabel 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 = SequenceUtil.dnaSequenceToSequence(featuredDNASequence);
                    GenbankFormatter genbankFormatter = new GenbankFormatter(name);
                    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
                    genbankFormatter.format(sequence, byteStream);
                    ByteArrayInputStream inputStream = new ByteArrayInputStream(byteStream.toByteArray());
                    InputStreamWrapper wrapper = new InputStreamWrapper(inputStream, name);
                    putZipEntry(wrapper, zos);
                } else {
                    line[i + 1] = "";
                }
            } catch (Exception e) {
                line[i + 1] = "";
            }
        } else {
            line[i + 1] = "";
        }
        writer.writeNext(line);
    }
}
Also used : FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) Date(java.util.Date) EntryFieldLabel(org.jbei.ice.lib.dto.entry.EntryFieldLabel) GenbankFormatter(org.jbei.ice.lib.entry.sequence.composers.formatters.GenbankFormatter) InputStreamWrapper(org.jbei.ice.lib.entry.sequence.InputStreamWrapper) PartData(org.jbei.ice.lib.dto.entry.PartData)

Example 47 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class RemoteSequence method get.

public InputStreamWrapper get(String type) {
    FeaturedDNASequence featuredDNASequence = remoteContact.getPublicEntrySequence(partner.getUrl(), Long.toString(remotePartId), partner.getApiKey());
    if (featuredDNASequence == null)
        return new InputStreamWrapper(new byte[] { '\0' }, "no_sequence");
    String name = featuredDNASequence.getName();
    try {
        Sequence sequence = SequenceUtil.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 "gff3":
                formatter = new GFF3Formatter();
                name = name + ".gff3";
                break;
        }
        formatter.format(sequence, byteStream);
        return new InputStreamWrapper(byteStream.toByteArray(), name);
    } catch (Exception e) {
        Logger.error(e);
        return new InputStreamWrapper(new byte[] { '\0' }, "no_sequence");
    }
}
Also used : InputStreamWrapper(org.jbei.ice.lib.entry.sequence.InputStreamWrapper) 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)

Aggregations

FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)47 Test (org.junit.Test)23 HibernateRepositoryTest (org.jbei.ice.storage.hibernate.HibernateRepositoryTest)17 Account (org.jbei.ice.storage.model.Account)17 Sequence (org.jbei.ice.storage.model.Sequence)14 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)8 Plasmid (org.jbei.ice.storage.model.Plasmid)8 IOException (java.io.IOException)5 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)5 Strain (org.jbei.ice.storage.model.Strain)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InvalidFormatParserException (org.jbei.ice.lib.parsers.InvalidFormatParserException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ArrayList (java.util.ArrayList)3 BioException (org.biojava.bio.BioException)3 PartData (org.jbei.ice.lib.dto.entry.PartData)3 BufferedReader (java.io.BufferedReader)2 StringReader (java.io.StringReader)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2