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;
}
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;
}
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;
}
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());
}
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;
}
Aggregations