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