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);
}
}
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");
}
}
Aggregations