Search in sources :

Example 16 with FeaturedDNASequence

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);
}
Also used : Plasmid(org.jbei.ice.storage.model.Plasmid) Account(org.jbei.ice.storage.model.Account) Sequence(org.jbei.ice.storage.model.Sequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) Test(org.junit.Test) HibernateRepositoryTest(org.jbei.ice.storage.hibernate.HibernateRepositoryTest)

Example 17 with FeaturedDNASequence

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));
}
Also used : Plasmid(org.jbei.ice.storage.model.Plasmid) Account(org.jbei.ice.storage.model.Account) Sequence(org.jbei.ice.storage.model.Sequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) Test(org.junit.Test) HibernateRepositoryTest(org.jbei.ice.storage.hibernate.HibernateRepositoryTest)

Example 18 with FeaturedDNASequence

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;
}
Also used : FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 19 with FeaturedDNASequence

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;
}
Also used : GenBankParser(org.jbei.ice.lib.parsers.genbank.GenBankParser) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Sequence(org.jbei.ice.storage.model.Sequence) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) IOException(java.io.IOException) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Example 20 with FeaturedDNASequence

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);
}
Also used : Annotations(org.jbei.ice.lib.entry.sequence.annotation.Annotations) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence)

Aggregations

FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)47 Test (org.junit.Test)23 HibernateRepositoryTest (org.jbei.ice.storage.hibernate.HibernateRepositoryTest)17 Account (org.jbei.ice.storage.model.Account)17 Sequence (org.jbei.ice.storage.model.Sequence)14 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)8 Plasmid (org.jbei.ice.storage.model.Plasmid)8 IOException (java.io.IOException)5 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)5 Strain (org.jbei.ice.storage.model.Strain)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InvalidFormatParserException (org.jbei.ice.lib.parsers.InvalidFormatParserException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ArrayList (java.util.ArrayList)3 BioException (org.biojava.bio.BioException)3 PartData (org.jbei.ice.lib.dto.entry.PartData)3 BufferedReader (java.io.BufferedReader)2 StringReader (java.io.StringReader)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2