Search in sources :

Example 31 with Sequence

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);
}
Also used : BerVisibleString(org.openmuc.jasn1.ber.types.string.BerVisibleString) MyBitString(org.openmuc.jasn1.compiler.modules.module1.MyBitString) PersonnelRecord(org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord) EmployeeNumberZ(org.openmuc.jasn1.compiler.modules.module2.EmployeeNumberZ) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Name(org.openmuc.jasn1.compiler.modules.module1.Name) BerEmbeddedPdv(org.openmuc.jasn1.ber.types.BerEmbeddedPdv) SEQUENCE(org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord.TestSequenceOf2.SEQUENCE) BerVisibleString(org.openmuc.jasn1.ber.types.string.BerVisibleString) MyBitString(org.openmuc.jasn1.compiler.modules.module1.MyBitString) ChildInformation(org.openmuc.jasn1.compiler.modules.module1.ChildInformation) TestSequenceOf(org.openmuc.jasn1.compiler.modules.module1.TestSequenceOf) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestChoice(org.openmuc.jasn1.compiler.modules.module1.TestChoice) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) TestSequenceOf2(org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord.TestSequenceOf2) Date(org.openmuc.jasn1.compiler.modules.module1.Date) MyDate1(org.openmuc.jasn1.compiler.modules.module1.MyDate1) ByteArrayInputStream(java.io.ByteArrayInputStream) MyInt(org.openmuc.jasn1.compiler.modules.module1.MyInt) MyInt2(org.openmuc.jasn1.compiler.modules.module1.MyInt2) Test(org.junit.Test)

Example 32 with Sequence

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);
    }
}
Also used : SBOLDocument(org.sbolstandard.core2.SBOLDocument) SBOLConversionException(org.sbolstandard.core2.SBOLConversionException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) SBOLValidationException(org.sbolstandard.core2.SBOLValidationException)

Example 33 with Sequence

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
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) org.sbolstandard.core2(org.sbolstandard.core2)

Aggregations

URI (java.net.URI)21 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)15 Sequence (org.sbolstandard.core2.Sequence)9 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)8 SBOLDocument (org.sbolstandard.core2.SBOLDocument)8 QName (javax.xml.namespace.QName)6 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 SEQUENCE (org.mozilla.jss.asn1.SEQUENCE)4 BMPString (org.mozilla.jss.asn1.BMPString)3 SET (org.mozilla.jss.asn1.SET)3 Literal (org.sbolstandard.core.datatree.Literal)3 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)3 AMPassword (com.sun.identity.security.keystore.AMPassword)2 MessageDigest (java.security.MessageDigest)2 Test (org.junit.Test)2 ASN1Value (org.mozilla.jss.asn1.ASN1Value)2 OCTET_STRING (org.mozilla.jss.asn1.OCTET_STRING)2 AuthenticatedSafes (org.mozilla.jss.pkcs12.AuthenticatedSafes)2 PFX (org.mozilla.jss.pkcs12.PFX)2