Search in sources :

Example 1 with DNASequence

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

Example 2 with DNASequence

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;
}
Also used : DNASequence(org.jbei.ice.lib.dto.DNASequence) ABITrace(org.jbei.ice.lib.parsers.abi.ABITrace) SymbolList(org.biojava.bio.symbol.SymbolList)

Example 3 with 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;
}
Also used : SBOLDocument(org.sbolstandard.core.SBOLDocument) ICESBOLParserVisitor(org.jbei.ice.lib.parsers.sbol.ICESBOLParserVisitor) DNASequence(org.jbei.ice.lib.dto.DNASequence) Sequence(org.jbei.ice.storage.model.Sequence) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) DNASequence(org.jbei.ice.lib.dto.DNASequence) Entry(org.jbei.ice.storage.model.Entry) SBOLRootObject(org.sbolstandard.core.SBOLRootObject) SequenceController(org.jbei.ice.lib.entry.sequence.SequenceController)

Example 4 with DNASequence

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

Example 5 with DNASequence

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

Aggregations

DNASequence (org.jbei.ice.lib.dto.DNASequence)12 Test (org.junit.Test)6 Sequence (org.jbei.ice.storage.model.Sequence)3 IOException (java.io.IOException)2 SymbolList (org.biojava.bio.symbol.SymbolList)2 SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)2 InvalidFormatParserException (org.jbei.ice.lib.parsers.InvalidFormatParserException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 BioException (org.biojava.bio.BioException)1 SimpleSymbolList (org.biojava.bio.symbol.SimpleSymbolList)1 Curation (org.jbei.ice.lib.dto.Curation)1 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)1 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)1 SequenceController (org.jbei.ice.lib.entry.sequence.SequenceController)1 ABIParser (org.jbei.ice.lib.parsers.ABIParser)1 ABITrace (org.jbei.ice.lib.parsers.abi.ABITrace)1 GenBankParser (org.jbei.ice.lib.parsers.genbank.GenBankParser)1