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