use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.
the class SequenceDAOTest method testGetSequenceCount.
@Test
public void testGetSequenceCount() throws Exception {
Account account = AccountCreator.createTestAccount("SequenceDAOTest.testGetSequenceCount", false);
Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
Assert.assertNotNull(plasmid);
// parse sequence and associate with plasmid
FeaturedDNASequence dnaSequence = GeneralParser.parse(sequenceString);
Sequence sequence = SequenceUtil.dnaSequenceToSequence(dnaSequence);
Assert.assertNotNull(sequence);
sequence.setEntry(plasmid);
sequence = sequenceDAO.create(sequence);
Assert.assertNotNull(sequence);
// create 3 additional sequences
Plasmid plasmid2 = TestEntryCreator.createTestPlasmid(account);
Assert.assertNotNull(plasmid2);
dnaSequence = GeneralParser.parse(sequenceString + "a");
sequence = SequenceUtil.dnaSequenceToSequence(dnaSequence);
Assert.assertNotNull(sequence);
sequence.setEntry(plasmid2);
sequence = sequenceDAO.create(sequence);
Assert.assertNotNull(sequence);
Plasmid plasmid3 = TestEntryCreator.createTestPlasmid(account);
Assert.assertNotNull(plasmid3);
dnaSequence = GeneralParser.parse(sequenceString + "t");
sequence = SequenceUtil.dnaSequenceToSequence(dnaSequence);
Assert.assertNotNull(sequence);
sequence.setEntry(plasmid3);
sequence = sequenceDAO.create(sequence);
Assert.assertNotNull(sequence);
Plasmid plasmid4 = TestEntryCreator.createTestPlasmid(account);
Assert.assertNotNull(plasmid4);
dnaSequence = GeneralParser.parse(sequenceString + "c");
sequence = SequenceUtil.dnaSequenceToSequence(dnaSequence);
Assert.assertNotNull(sequence);
sequence.setEntry(plasmid4);
sequence = sequenceDAO.create(sequence);
Assert.assertNotNull(sequence);
Assert.assertTrue(sequenceDAO.getSequenceCount() >= 4);
}
use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.
the class SequenceDAOTest method testGetByEntry.
@Test
public void testGetByEntry() throws Exception {
Account account = AccountCreator.createTestAccount("SequenceDAOTest.testGetByEntry", false);
Plasmid plasmid = TestEntryCreator.createTestPlasmid(account);
Assert.assertNotNull(plasmid);
// parse sequence and associate with plasmid
FeaturedDNASequence dnaSequence = GeneralParser.parse(sequenceString);
Sequence sequence = SequenceUtil.dnaSequenceToSequence(dnaSequence);
Assert.assertNotNull(sequence);
sequence.setEntry(plasmid);
sequence = sequenceDAO.create(sequence);
Assert.assertNotNull(sequence);
// get
Sequence result = sequenceDAO.getByEntry(plasmid);
Assert.assertNotNull(result);
Assert.assertEquals(result, sequence);
Assert.assertNull(sequenceDAO.getByEntry(null));
}
use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.
the class GenBankParser method parse.
@Override
public FeaturedDNASequence parse(Iterator<String> iterator, String... entryType) {
sequence = new FeaturedDNASequence();
GenBankSection currentSection = null;
while (iterator.hasNext()) {
String line = iterator.next();
String firstWord = getFirstWordFromLine(line);
GenbankTag genbankTag = GenbankTag.getTagForString(firstWord);
// encountered new tag
if (genbankTag != null) {
currentSection = process(genbankTag);
}
if (currentSection != null)
currentSection.process(line);
}
// todo : however, it is still being held in memory
return sequence;
}
use of org.jbei.ice.lib.dto.FeaturedDNASequence 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
*/
private 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;
FeaturedDNASequence dnaSequence = null;
try {
out.reset();
SBOLWriter.write(sbolDocument, out, "GENBANK");
if (out.size() > 0) {
GenBankParser parser = new GenBankParser();
dnaSequence = parser.parse(IOUtils.lineIterator(new ByteArrayInputStream(out.toByteArray()), Charset.defaultCharset()));
sequence = SequenceUtil.dnaSequenceToSequence(dnaSequence);
}
} 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().create(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.FeaturedDNASequence in project ice by JBEI.
the class AnnotationResource method getAnnotationsForSequence.
/**
* Generates annotations for the passed sequence
*
* @param sequence sequence wrapper.
* @return annotations for sequence
*/
@POST
public Response getAnnotationsForSequence(FeaturedDNASequence sequence) {
String userId = getUserId();
Annotations annotations = new Annotations(userId);
FeaturedDNASequence annotatedSequence = annotations.generate(sequence);
if (annotatedSequence == null)
throw new WebApplicationException();
return super.respond(annotatedSequence);
}
Aggregations