Search in sources :

Example 1 with SequenceInfo

use of org.jbei.ice.lib.dto.entry.SequenceInfo 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 SequenceInfo

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

the class SBOLParser method parseToEntry.

public SequenceInfo parseToEntry(String textSequence, String fileName) throws InvalidFormatParserException {
    SBOLDocument document;
    try {
        document = SBOLReader.read(new ByteArrayInputStream(textSequence.getBytes(StandardCharsets.UTF_8)));
    } catch (SBOLValidationException e) {
        Logger.error(e);
        throw new InvalidFormatParserException("Invalid SBOL file: " + e.getMessage());
    } catch (IOException e) {
        Logger.error(e);
        throw new InvalidFormatParserException("Server error parsing file");
    } catch (SBOLConversionException e) {
        Logger.error(e);
        throw new InvalidFormatParserException("Error converting file to SBOL 2.0");
    }
    // parse raw document and return
    SequenceInfo sequenceInfo = parseToGenBank(document, fileName, entry, null);
    // document parsed successfully, go through module definitions
    for (ModuleDefinition moduleDefinition : document.getModuleDefinitions()) {
        try {
            createICEModuleDefinitionRecord(document, moduleDefinition);
        } catch (SBOLValidationException e) {
            Logger.error("Could not import module definition", e);
        }
    }
    // go through component definitions
    for (ComponentDefinition componentDefinition : document.getComponentDefinitions()) {
        try {
            createICEComponentDefinitionRecord(document, componentDefinition);
        } catch (SBOLValidationException e) {
            Logger.error("Could not import component definition", e);
        }
    }
    return sequenceInfo;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) InvalidFormatParserException(org.jbei.ice.lib.parsers.InvalidFormatParserException) IOException(java.io.IOException)

Example 3 with SequenceInfo

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

the class Sequence method toDataTransferObject.

@Override
public SequenceInfo toDataTransferObject() {
    SequenceInfo info = new SequenceInfo();
    if (this.entry != null) {
        info.setEntryId(entry.getId());
    }
    info.setFilename(fileName);
    return info;
}
Also used : SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo)

Example 4 with SequenceInfo

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

the class PartSequenceTest method testParseSequence.

@Test
public void testParseSequence() throws Exception {
    Account account = AccountCreator.createTestAccount("PartSequenceTest.testParseSequence", false);
    PartSequence partSequence = new PartSequence(account.getEmail(), EntryType.PART);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(fasta.getBytes());
    SequenceInfo sequenceInfo = partSequence.parseSequenceFile(inputStream, "fasta.fa");
    Assert.assertNotNull(sequenceInfo);
    Assert.assertNotNull(sequenceInfo.getSequence());
}
Also used : Account(org.jbei.ice.storage.model.Account) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) Test(org.junit.Test)

Example 5 with SequenceInfo

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

the class AbstractParser method save.

protected SequenceInfo save(DNASequence dnaSequence, String sequenceString) {
    Sequence sequence = SequenceController.dnaSequenceToSequence(dnaSequence);
    sequence.setSequenceUser(sequenceString);
    sequence.setEntry(entry);
    if (!StringUtils.isBlank(fileName))
        sequence.setFileName(fileName);
    Sequence result = sequenceDAO.saveSequence(sequence);
    BlastPlus.scheduleBlastIndexRebuildTask(true);
    SequenceInfo info = result.toDataTransferObject();
    info.setSequence(dnaSequence);
    return info;
}
Also used : SequenceInfo(org.jbei.ice.lib.dto.entry.SequenceInfo) Sequence(org.jbei.ice.storage.model.Sequence) DNASequence(org.jbei.ice.lib.dto.DNASequence)

Aggregations

SequenceInfo (org.jbei.ice.lib.dto.entry.SequenceInfo)9 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 DNASequence (org.jbei.ice.lib.dto.DNASequence)2 InvalidFormatParserException (org.jbei.ice.lib.parsers.InvalidFormatParserException)2 Account (org.jbei.ice.storage.model.Account)2 Sequence (org.jbei.ice.storage.model.Sequence)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)1 EntryType (org.jbei.ice.lib.dto.entry.EntryType)1 PartSequence (org.jbei.ice.lib.entry.sequence.PartSequence)1 GenBankParser (org.jbei.ice.lib.parsers.genbank.GenBankParser)1 Strain (org.jbei.ice.storage.model.Strain)1