use of org.jbei.ice.lib.dto.DNASequence 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.lib.dto.DNASequence in project ice by JBEI.
the class ABIParser method parse.
public DNASequence parse(byte[] bytes) throws InvalidFormatParserException {
DNASequence DNASequence = null;
try {
ABITrace abiTrace = new ABITrace(bytes);
SymbolList symbolList = abiTrace.getSequence();
if (symbolList != null) {
DNASequence = new DNASequence(symbolList.seqString().toLowerCase());
}
} catch (Exception e) {
throw new InvalidFormatParserException(e);
}
return DNASequence;
}
use of org.jbei.ice.lib.dto.DNASequence 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.lib.dto.DNASequence in project ice by JBEI.
the class SequenceDAOTest method testHasSequence.
@Test
public void testHasSequence() throws Exception {
// create account and sequence
Account account = AccountCreator.createTestAccount("SequenceDAOTest.testHasSequence", false);
Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
Assert.assertFalse(sequenceDAO.hasSequence(plasmid.getId()));
DNASequence dnaSequence = GeneralParser.getInstance().parse(sequenceString);
Sequence sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
sequence.setEntry(plasmid);
sequence = sequenceDAO.saveSequence(sequence);
Assert.assertNotNull(sequence);
Assert.assertTrue(sequenceDAO.hasSequence(plasmid.getId()));
}
use of org.jbei.ice.lib.dto.DNASequence in project ice by JBEI.
the class SequenceDAOTest method testGetByEntry.
@Test
public void testGetByEntry() throws Exception {
// create account and sequence
Account account = AccountCreator.createTestAccount("SequenceDAOTest.testGetByEntry", false);
Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
DNASequence dnaSequence = GeneralParser.getInstance().parse(sequenceString);
Sequence sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
sequence.setEntry(plasmid);
sequence = sequenceDAO.saveSequence(sequence);
Assert.assertNotNull(sequence);
Assert.assertNotNull(sequenceDAO.getByEntry(plasmid));
}
Aggregations