use of org.sbolstandard.core2.Sequence in project jasn1 by openmuc.
the class ModulesTest method encodingDecoding.
@Test
public void encodingDecoding() throws IOException {
ReverseByteArrayOutputStream berOS = new ReverseByteArrayOutputStream(1000);
MyDate1 dateOfHire = new MyDate1();
// MyDate1 dateOfHire = new MyDate1("19710917");
dateOfHire.value = new String("19710917").getBytes();
dateOfHire.encode(berOS, true);
MyInt2 myInt2Encode = new MyInt2(2);
berOS.reset();
myInt2Encode.encode(berOS, true);
MyInt2 myInt2Decode = new MyInt2();
byte[] code = HexConverter.fromShortHexString("a303020102");
InputStream is = new ByteArrayInputStream(code);
myInt2Decode.decode(is, true);
Assert.assertEquals(myInt2Decode.value.intValue(), 2);
PersonnelRecord pr = new PersonnelRecord();
Name name = new Name();
name.setGivenName(new BerVisibleString("givenName".getBytes()));
name.setFamilyName(new BerVisibleString("familyName".getBytes()));
name.setInitial(new BerVisibleString("initial".getBytes()));
pr.setName(name);
pr.setTitle(new BerVisibleString("title".getBytes()));
pr.setNumber(new EmployeeNumberZ(1));
pr.setDateOfHire(new Date("23121981".getBytes()));
pr.setNameOfSpouse(name);
ChildInformation child = new ChildInformation();
child.setName(new Name("child name".getBytes()));
child.setDateOfBirth(new Date("12121912".getBytes()));
PersonnelRecord.Children children = new PersonnelRecord.Children();
List<ChildInformation> childInformation = children.getChildInformation();
childInformation.add(child);
childInformation.add(child);
pr.setTestBitString(new MyBitString(new byte[] { (byte) 0x80, (byte) 0xff }, 10));
pr.setTest(new MyInt(3));
TestChoice testChoice = new TestChoice();
testChoice.setChoiceElement1(child);
pr.setTest2(testChoice);
pr.setTest3(testChoice);
pr.setTest4(testChoice);
pr.setTest5(testChoice);
pr.setTest6(testChoice);
TestSequenceOf testSequenceOf = new TestSequenceOf();
List<BerInteger> berIntegers = testSequenceOf.getBerInteger();
for (int i = 0; i < 10; i++) {
berIntegers.add(new BerInteger(i));
}
pr.setTestSequenceOf(testSequenceOf);
TestSequenceOf2 testSequenceOf2 = new TestSequenceOf2();
List<SEQUENCE> sequences = testSequenceOf2.getSEQUENCE();
for (int i = 0; i < 10; i++) {
SEQUENCE sequence = new SEQUENCE();
sequence.setTest1(new BerInteger(i++));
sequence.setTest2(new BerInteger(i));
sequences.add(sequence);
}
pr.setTestSequenceOf2(testSequenceOf2);
BerEmbeddedPdv berEmbeddedPdv = new BerEmbeddedPdv();
pr.setEmbeddedPdv(berEmbeddedPdv);
System.out.println("PersonnelRecord.toString():\n" + pr);
}
use of org.sbolstandard.core2.Sequence in project ice by JBEI.
the class SBOL2Formatter method format.
@Override
public void format(Sequence sequence, OutputStream outputStream) throws IOException {
SBOLDocument doc = new SBOLDocument();
try {
SBOL2Visitor visitor = new SBOL2Visitor(doc);
visitor.visit(sequence);
doc.write(outputStream);
} catch (SBOLValidationException | SBOLConversionException | URISyntaxException e) {
throw new IOException(e);
}
}
use of org.sbolstandard.core2.Sequence in project ice by JBEI.
the class SBOL2Visitor method visit.
public void visit(Sequence sequence) throws SBOLValidationException {
// ice data model conflates the sequence and component
Entry entry = sequence.getEntry();
// Set required properties
String partId = entry.getPartNumber();
componentDefinition = doc.createComponentDefinition(uriString, partId, "1", ComponentDefinition.DNA);
componentDefinition.setName(entry.getName());
componentDefinition.setDescription(entry.getShortDescription());
String dsUri = "sequence_" + sequence.getFwdHash().replaceAll("[\\s\\-()]", "");
org.sbolstandard.core2.Sequence dnaSequence = doc.createSequence(uriString, dsUri, "1", sequence.getSequence(), org.sbolstandard.core2.Sequence.IUPAC_DNA);
dnaSequence.setElements(sequence.getSequence());
componentDefinition.addSequence(dnaSequence);
List<SequenceFeature> features = new ArrayList<>(sequence.getSequenceFeatures());
Collections.sort(features, new SequenceFeatureComparator());
for (SequenceFeature feature : features) {
visit(feature);
}
componentDefinition.createAnnotation(new QName(ICE_NS, "id", ICE_PREFIX), entry.getId());
if (entry.getRecordId() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "recordId", ICE_PREFIX), entry.getRecordId());
if (entry.getVersionId() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "versionId", ICE_PREFIX), entry.getVersionId());
if (entry.getRecordType() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "recordType", ICE_PREFIX), entry.getRecordType());
if (entry.getOwner() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "owner", ICE_PREFIX), entry.getOwner());
if (entry.getOwnerEmail() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "ownerEmail", ICE_PREFIX), entry.getOwnerEmail());
if (entry.getCreator() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "creator", ICE_PREFIX), entry.getCreator());
if (entry.getCreatorEmail() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "creatorEmail", ICE_PREFIX), entry.getCreatorEmail());
if (entry.getStatus() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "status", ICE_PREFIX), entry.getStatus());
if (entry.getAlias() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "alias", ICE_PREFIX), entry.getAlias());
for (SelectionMarker selectionMarker : entry.getSelectionMarkers()) {
componentDefinition.createAnnotation(new QName(ICE_NS, "selectionMarker", ICE_PREFIX), selectionMarker.getName());
}
if (entry.getLinks() != null) {
for (Link link : entry.getLinks()) {
if (StringUtils.isNotEmpty(link.getLink()) && StringUtils.isNotEmpty(link.getUrl()))
componentDefinition.createAnnotation(new QName(ICE_NS, link.getLink(), ICE_PREFIX), link.getUrl());
}
}
if (entry.getKeywords() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "keywords", ICE_PREFIX), entry.getKeywords());
if (entry.getShortDescription() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "shortDescription", ICE_PREFIX), entry.getShortDescription());
if (entry.getLongDescription() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "longDescription", ICE_PREFIX), entry.getLongDescription());
if (entry.getLongDescriptionType() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "longDescriptionType", ICE_PREFIX), entry.getLongDescriptionType());
if (entry.getReferences() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "references", ICE_PREFIX), entry.getReferences());
if (entry.getCreationTime() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "creationTime", ICE_PREFIX), entry.getCreationTime().toString());
if (entry.getModificationTime() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "modificationTime", ICE_PREFIX), entry.getModificationTime().toString());
if (entry.getBioSafetyLevel() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "bioSafetyLevel", ICE_PREFIX), entry.getBioSafetyLevel());
if (entry.getIntellectualProperty() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "intellectualProperty", ICE_PREFIX), entry.getIntellectualProperty());
if (entry.getVisibility() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "visibility", ICE_PREFIX), entry.getVisibility());
if (entry.getParameters() != null) {
for (Parameter parameter : entry.getParameters()) {
if (StringUtils.isNotEmpty(parameter.getKey()) && StringUtils.isNotEmpty(parameter.getValue()))
componentDefinition.createAnnotation(new QName(ICE_NS, parameter.getKey(), ICE_PREFIX), parameter.getValue());
}
}
if (entry.getFundingSource() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "fundingSource", ICE_PREFIX), entry.getFundingSource());
if (entry.getPrincipalInvestigator() != null)
componentDefinition.createAnnotation(new QName(ICE_NS, "principalInvestigator", ICE_PREFIX), entry.getPrincipalInvestigator());
// TODO: samples
// TODO: attachments
}
Aggregations