Search in sources :

Example 41 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class SequenceDAOTest method testGetSequence.

@Test
public void testGetSequence() throws Exception {
    Account account = AccountCreator.createTestAccount("SequenceDAOTest.testGetSequence", 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);
    Assert.assertNotNull(sequenceDAO.getSequence(0));
}
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 42 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class SequenceDAOTest method testDelete.

@Test
public void testDelete() throws Exception {
    Account account = AccountCreator.createTestAccount("SequenceDAOTest.testDelete", false);
    Strain strain = TestEntryCreator.createTestStrain(account);
    Assert.assertNotNull(strain);
    // parse sequence and associate with strain
    FeaturedDNASequence dnaSequence = GeneralParser.parse(sequenceString);
    Sequence sequence = SequenceUtil.dnaSequenceToSequence(dnaSequence);
    Assert.assertNotNull(sequence);
    sequence.setEntry(strain);
    sequence = sequenceDAO.create(sequence);
    Assert.assertNotNull(sequence);
    // get
    Sequence result = sequenceDAO.get(sequence.getId());
    Assert.assertNotNull(result);
    Assert.assertEquals(result, sequence);
    // delete
    sequenceDAO.delete(result);
    // get
    Assert.assertNull(sequenceDAO.get(sequence.getId()));
    Assert.assertNull(sequenceDAO.getByEntry(strain));
}
Also used : 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) Strain(org.jbei.ice.storage.model.Strain) Test(org.junit.Test) HibernateRepositoryTest(org.jbei.ice.storage.hibernate.HibernateRepositoryTest)

Example 43 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class GeneralParserTest method parse.

@Test
public void parse() {
    FeaturedDNASequence sequence = GeneralParser.parse(TestInputSequences.fromAPE);
    Assert.assertNotNull(sequence);
    Assert.assertEquals(sequence.getFeatures().size(), 25);
    Assert.assertTrue(hasCorrectNotes(sequence, "promoter", "AOX1 promoter", 8));
    Assert.assertTrue(hasCorrectNotes(sequence, "CDS", "alpha-factor secretion signal", 10));
    // Assert.assertTrue(hasCorrectNotes(sequence, "misc_feature", "jgi_PenbrAgRF18_1_353857_MatureChain_29_961", 0));
    Assert.assertTrue(hasCorrectNotes(sequence, "source", "source:synthetic DNA construct", 9));
}
Also used : FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) HibernateRepositoryTest(org.jbei.ice.storage.hibernate.HibernateRepositoryTest) Test(org.junit.Test)

Example 44 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class GenBankParserTest method testParse.

@Test
public void testParse() throws Exception {
    GenBankParser parser = new GenBankParser();
    FeaturedDNASequence sequence = parser.parse(IOUtils.lineIterator(new ByteArrayInputStream(genbank.getBytes()), Charset.defaultCharset()));
    Assert.assertNotNull(sequence);
    Assert.assertEquals(3, sequence.getFeatures().size());
    Assert.assertEquals(936, sequence.getSequence().length());
    // parse genbank 2
    FeaturedDNASequence sequence2 = parser.parse(IOUtils.lineIterator(new ByteArrayInputStream(getGenbank2.getBytes()), Charset.defaultCharset()));
    Assert.assertNotNull(sequence2);
    Assert.assertEquals(3, sequence2.getFeatures().size());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) Test(org.junit.Test)

Example 45 with FeaturedDNASequence

use of org.jbei.ice.lib.dto.FeaturedDNASequence in project ice by JBEI.

the class FastaParser method parse.

@Override
public FeaturedDNASequence parse(Iterator<String> iterator, String... entryType) throws InvalidFormatParserException {
    try {
        String textSequence = getSequence(iterator);
        textSequence = cleanSequence(textSequence);
        textSequence = textSequence.replaceAll("\t", "\n");
        try (BufferedReader br = new BufferedReader(new StringReader(textSequence))) {
            FeaturedDNASequence sequence;
            RichSequenceIterator richSequences;
            if (entryType.length > 0 && entryType[0].equals("protein")) {
                richSequences = IOTools.readFastaProtein(br, null);
            } else {
                richSequences = IOTools.readFastaDNA(br, null);
            }
            if (richSequences.hasNext()) {
                RichSequence richSequence = richSequences.nextRichSequence();
                sequence = new FeaturedDNASequence(richSequence.seqString(), new LinkedList<>());
            } else {
                throw new InvalidFormatParserException("No sequence found in sequence file!");
            }
            return sequence;
        }
    } catch (BioException | IOException e) {
        throw new InvalidFormatParserException("Couldn't parse FASTA sequence!", e);
    }
}
Also used : BioException(org.biojava.bio.BioException) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) RichSequenceIterator(org.biojavax.bio.seq.RichSequenceIterator) InvalidFormatParserException(org.jbei.ice.lib.parsers.InvalidFormatParserException) IOException(java.io.IOException) FeaturedDNASequence(org.jbei.ice.lib.dto.FeaturedDNASequence) LinkedList(java.util.LinkedList) RichSequence(org.biojavax.bio.seq.RichSequence)

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