use of org.jbei.ice.storage.model.Sequence in project ice by JBEI.
the class FileResource method downloadSequence.
@GET
@Path("{partId}/sequence/{type}")
public Response downloadSequence(@PathParam("partId") final long partId, @PathParam("type") final String downloadType, @DefaultValue("-1") @QueryParam("remoteId") long remoteId, @QueryParam("sid") String sid) {
if (StringUtils.isEmpty(sessionId))
sessionId = sid;
final String userId = getUserId(sessionId);
final ByteArrayWrapper wrapper;
if (remoteId != -1) {
RemoteSequence sequence = new RemoteSequence(remoteId, partId);
wrapper = sequence.get(downloadType);
} else {
wrapper = sequenceController.getSequenceFile(userId, partId, downloadType);
}
StreamingOutput stream = output -> {
final ByteArrayInputStream input = new ByteArrayInputStream(wrapper.getBytes());
ByteStreams.copy(input, output);
};
return addHeaders(Response.ok(stream), wrapper.getName());
}
use of org.jbei.ice.storage.model.Sequence in project ice by JBEI.
the class FileResource method getSBOLVisual.
@GET
@Produces("image/png")
@Path("sbolVisual/{rid}")
public Response getSBOLVisual(@PathParam("rid") String recordId) {
final String tmpDir = Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY);
final Entry entry = DAOFactory.getEntryDAO().getByRecordId(recordId);
final Sequence sequence = entry.getSequence();
final String hash = sequence.getFwdHash();
final File png = Paths.get(tmpDir, hash + ".png").toFile();
if (png.exists()) {
return addHeaders(Response.ok(png), entry.getPartNumber() + ".png");
}
final URI uri = PigeonSBOLv.generatePigeonVisual(sequence);
if (uri != null) {
try (final InputStream in = uri.toURL().openStream();
final OutputStream out = new FileOutputStream(png)) {
ByteStreams.copy(in, out);
} catch (IOException e) {
Logger.error(e);
return respond(false);
}
return addHeaders(Response.ok(png), entry.getPartNumber() + ".png");
}
return respond(false);
}
use of org.jbei.ice.storage.model.Sequence in project ice by JBEI.
the class SBOLParser method parseToGenBank.
/**
* Parse the SBOL document to genbank format, save and associate with entry
*
* @param sbolDocument SBOL document to parse
* @param fileName name of file that was parsed to extract the SBOL information
* @param entry ICE entry to associate sequence document with
* @param uri optional uri to associate with sequence
* @return Sequence info data transfer object for saved sequence
*/
protected SequenceInfo parseToGenBank(SBOLDocument sbolDocument, String fileName, Entry entry, String uri) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
String rdf;
// convert to rdf string to save raw document
try {
sbolDocument.write(out);
rdf = out.toString();
} catch (SBOLConversionException e) {
rdf = null;
}
// convert to genbank
Sequence sequence = null;
DNASequence dnaSequence = null;
try {
out.reset();
SBOLWriter.write(sbolDocument, out, "GENBANK");
if (out.size() > 0) {
GenBankParser parser = new GenBankParser();
dnaSequence = parser.parse(new String(out.toByteArray()));
sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
}
} catch (InvalidFormatParserException e) {
Logger.error("Error parsing generated genBank: " + e.getMessage());
} catch (SBOLConversionException | IOException e) {
Logger.error("Error converting SBOL to genBank: " + e.getMessage());
}
// convert to ice data model (sequence)
if (sequence == null) {
sequence = new Sequence();
}
if (!StringUtils.isEmpty(rdf))
sequence.setSequenceUser(rdf);
sequence.setFormat(SequenceFormat.SBOL2);
sequence.setEntry(entry);
if (fileName != null)
sequence.setFileName(fileName);
if (!StringUtils.isEmpty(uri))
sequence.setUri(uri);
sequence = DAOFactory.getSequenceDAO().saveSequence(sequence);
SequenceInfo sequenceInfo = new SequenceInfo();
sequenceInfo.setEntryId(entry.getId());
sequenceInfo.setSequence(dnaSequence);
sequenceInfo.setFormat(sequence.getFormat());
if (fileName != null)
sequenceInfo.setFilename(fileName);
return sequenceInfo;
}
use of org.jbei.ice.storage.model.Sequence in project ice by JBEI.
the class BulkFileSBOLUpload method processUpload.
public long processUpload() throws IOException {
BulkUploadController controller = new BulkUploadController();
long bulkUploadId = 0;
SBOLDocument document = SBOLFactory.read(new FileInputStream(filePath.toFile()));
try {
// walk top level object
for (SBOLRootObject rootObject : document.getContents()) {
ICESBOLParserVisitor visitor = new ICESBOLParserVisitor(addType);
rootObject.accept(visitor);
BulkUploadAutoUpdate update = visitor.getUpdate();
update.setBulkUploadId(bulkUploadId);
Logger.info(userId + ": " + update.toString());
update = controller.autoUpdateBulkUpload(userId, update, addType);
if (bulkUploadId == 0)
bulkUploadId = update.getBulkUploadId();
// get "user sequence"
String sequenceUser = getSequenceDocument(rootObject);
long entryId = update.getEntryId();
DNASequence dnaSequence = visitor.getFeaturedDNASequence();
Sequence sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
Entry entry = DAOFactory.getEntryDAO().get(entryId);
sequence.setEntry(entry);
if (sequenceUser != null)
sequence.setSequenceUser(sequenceUser);
new SequenceController().save(userId, sequence);
}
} catch (Exception e) {
Logger.error(e);
throw new IOException(e);
}
return bulkUploadId;
}
use of org.jbei.ice.storage.model.Sequence in project ice by JBEI.
the class AbstractParser method save.
protected SequenceInfo save(DNASequence dnaSequence, String sequenceString) {
Sequence sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
sequence.setSequenceUser(sequenceString);
sequence.setEntry(entry);
if (!StringUtils.isBlank(fileName))
sequence.setFileName(fileName);
Sequence result = sequenceDAO.saveSequence(sequence);
BlastPlus.scheduleBlastIndexRebuildTask(true);
SequenceInfo info = result.toDataTransferObject();
info.setSequence(dnaSequence);
return info;
}
Aggregations