Search in sources :

Example 21 with ComponentDefinition

use of org.sbolstandard.core2.ComponentDefinition in project libSBOLj by SynBioDex.

the class ComponentDefinition method getImpliedNucleicAcidSequence.

/**
 *  Return the elements of a nucleic acid sequence implied by the hierarchically included components.
 *  <p>
 *  This method first tries to obtain the length of a nucleic acid sequence from the set of sequences referenced by this component definition
 *  that has an {@link Sequence#IUPAC_DNA} encoding. It then iterates through this component defintion's
 *  sequence annotations, and update the length with the ending locations that have a larger value than the current length. It then populates
 *  the elements with this length with unknown bases. This method iterates through this component defintion's sequence annotations to recursively
 *  search for bases implied by the hierarchically included components, and fills the elements with these known bases.
 *
 *  @return the elements of a nucleic sequence implied by the hierarchically included components
 */
public String getImpliedNucleicAcidSequence() {
    URI type = null;
    if (this.getTypes().contains(ComponentDefinition.DNA)) {
        type = ComponentDefinition.DNA;
    } else if (this.getTypes().contains(ComponentDefinition.RNA)) {
        type = ComponentDefinition.RNA;
    } else {
        return null;
    }
    String elements = "";
    int length = 0;
    if (this.getSequenceByEncoding(Sequence.IUPAC_DNA) != null) {
        length = this.getSequenceByEncoding(Sequence.IUPAC_DNA).getElements().length();
    }
    for (SequenceAnnotation sequenceAnnotation : this.getSequenceAnnotations()) {
        for (Location location : sequenceAnnotation.getLocations()) {
            if (location instanceof Range) {
                Range range = (Range) location;
                if (range.getEnd() > length) {
                    length = range.getEnd();
                }
            }
        }
    }
    for (int i = 0; i < length; i++) {
        elements += "N";
    }
    char[] elementsArray = elements.toCharArray();
    for (SequenceAnnotation sequenceAnnotation : this.getSequenceAnnotations()) {
        String subElements = null;
        if (!sequenceAnnotation.isSetComponent())
            continue;
        if (sequenceAnnotation.getComponent().getDefinition() != null) {
            ComponentDefinition compDef = sequenceAnnotation.getComponent().getDefinition();
            if (compDef.getSequenceByEncoding(Sequence.IUPAC_DNA) != null) {
                subElements = compDef.getSequenceByEncoding(Sequence.IUPAC_DNA).getElements();
            } else {
                subElements = compDef.getImpliedNucleicAcidSequence();
            }
            for (Location location : sequenceAnnotation.getLocations()) {
                if (location instanceof Range) {
                    Range range = (Range) location;
                    if (range.isSetOrientation() && range.getOrientation().equals(OrientationType.REVERSECOMPLEMENT)) {
                        subElements = Sequence.reverseComplement(subElements, type);
                    }
                    for (int i = 0; i < subElements.length(); i++) {
                        // TODO: need to deal with when start index out of range
                        elementsArray[(range.getStart() + i) - 1] = subElements.charAt(i);
                    }
                }
            }
        }
    }
    elements = String.valueOf(elementsArray);
    return elements;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 22 with ComponentDefinition

use of org.sbolstandard.core2.ComponentDefinition in project libSBOLj by SynBioDex.

the class ComponentDefinition method copy.

/* (non-Javadoc)
	 * @see org.sbolstandard.core2.abstract_classes.TopLevel#copy(java.lang.String, java.lang.String, java.lang.String)
	 */
/**
 * @throws SBOLValidationException if an SBOL validation rule violation occurred in any of the following constructors or methods:
 * <ul>
 * <li>{@link #deepCopy()},</li>
 * <li>{@link URIcompliance#createCompliantURI(String, String, String)},</li>
 * <li>{@link #setDisplayId(String)},</li>
 * <li>{@link #setVersion(String)},</li>
 * <li>{@link #setWasDerivedFrom(URI)},</li>
 * <li>{@link #setIdentity(URI)}</li>
 * <li>{@link Component#setDisplayId(String)}</li>
 * <li>{@link Component#updateCompliantURI(String, String, String)},</li>
 * <li>{@link #addComponent(Component)},</li>
 * <li>{@link SequenceConstraint#setDisplayId(String)}</li>
 * <li>{@link SequenceConstraint#updateCompliantURI(String, String, String)},</li>
 * <li>{@link #addSequenceConstraint(SequenceConstraint)},</li>
 * <li>{@link SequenceAnnotation#setDisplayId(String)}</li>
 * <li>{@link SequenceAnnotation#updateCompliantURI(String, String, String)}, or</li>
 * <li>{@link #addSequenceAnnotation(SequenceAnnotation)},</li>
 * </ul>
 */
@Override
ComponentDefinition copy(String URIprefix, String displayId, String version) throws SBOLValidationException {
    ComponentDefinition cloned = this.deepCopy();
    cloned.setPersistentIdentity(createCompliantURI(URIprefix, displayId, ""));
    cloned.setDisplayId(displayId);
    cloned.setVersion(version);
    URI newIdentity = createCompliantURI(URIprefix, displayId, version);
    if (!this.getIdentity().equals(newIdentity)) {
        cloned.addWasDerivedFrom(this.getIdentity());
    } else {
        cloned.setWasDerivedFroms(this.getWasDerivedFroms());
    }
    cloned.setIdentity(newIdentity);
    int count = 0;
    for (Component component : cloned.getComponents()) {
        if (!component.isSetDisplayId())
            component.setDisplayId("component" + ++count);
        component.updateCompliantURI(cloned.getPersistentIdentity().toString(), component.getDisplayId(), version);
        cloned.removeChildSafely(component, cloned.components);
        cloned.addComponent(component);
    }
    count = 0;
    for (SequenceConstraint sequenceConstraint : cloned.getSequenceConstraints()) {
        if (!sequenceConstraint.isSetDisplayId())
            sequenceConstraint.setDisplayId("sequenceConstraint" + ++count);
        sequenceConstraint.updateCompliantURI(cloned.getPersistentIdentity().toString(), sequenceConstraint.getDisplayId(), version);
        cloned.removeChildSafely(sequenceConstraint, cloned.sequenceConstraints);
        cloned.addSequenceConstraint(sequenceConstraint);
    }
    count = 0;
    for (SequenceAnnotation sequenceAnnotation : cloned.getSequenceAnnotations()) {
        if (!sequenceAnnotation.isSetDisplayId())
            sequenceAnnotation.setDisplayId("sequenceAnnotation" + ++count);
        sequenceAnnotation.updateCompliantURI(cloned.getPersistentIdentity().toString(), sequenceAnnotation.getDisplayId(), version);
        cloned.removeChildSafely(sequenceAnnotation, cloned.sequenceAnnotations);
        cloned.addSequenceAnnotation(sequenceAnnotation);
    }
    return cloned;
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 23 with ComponentDefinition

use of org.sbolstandard.core2.ComponentDefinition in project libSBOLj by SynBioDex.

the class VariableComponent method addVariant.

/**
 * Adds the given variant to the list of variants.
 *
 * @param uriPrefix
 * 			URI prefix for variant
 * @param displayId
 * 			display id for variant
 * @param version
 * 			version for variant
 * @throws SBOLValidationException if the following SBOL validation rule was violated:
 */
public void addVariant(String uriPrefix, String displayId, String version) throws SBOLValidationException {
    URI uri = URIcompliance.createCompliantURI(uriPrefix, displayId, version);
    ComponentDefinition componentDefinition = this.getSBOLDocument().getComponentDefinition(uri);
    addVariant(componentDefinition.getIdentity());
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 24 with ComponentDefinition

use of org.sbolstandard.core2.ComponentDefinition in project libSBOLj by SynBioDex.

the class SBOLDocument method updateReferences.

// TODO: need to update persistentIdentities too
private void updateReferences(HashMap<URI, URI> uriMap) throws SBOLValidationException {
    for (TopLevel topLevel : getTopLevels()) {
        for (URI wasDerivedFrom : topLevel.getWasDerivedFroms()) {
            if (uriMap.get(wasDerivedFrom) != null) {
                topLevel.removeWasDerivedFrom(wasDerivedFrom);
                topLevel.addWasDerivedFrom(uriMap.get(wasDerivedFrom));
            }
        }
        for (URI wasGeneratedBy : topLevel.getWasGeneratedBys()) {
            if (uriMap.get(wasGeneratedBy) != null) {
                topLevel.removeWasGeneratedBy(wasGeneratedBy);
                topLevel.addWasGeneratedBy(uriMap.get(wasGeneratedBy));
            }
        }
        for (URI attachmentURI : topLevel.getAttachmentURIs()) {
            if (uriMap.get(attachmentURI) != null) {
                topLevel.removeAttachment(attachmentURI);
                topLevel.addAttachment(uriMap.get(attachmentURI));
            }
        }
    }
    for (Collection collection : getCollections()) {
        for (URI memberURI : collection.getMemberURIs()) {
            if (uriMap.get(memberURI) != null) {
                collection.removeMember(memberURI);
                collection.addMember(uriMap.get(memberURI));
            }
        }
        updateReferences(collection, uriMap);
    }
    for (ComponentDefinition componentDefinition : getComponentDefinitions()) {
        updateReferences(componentDefinition, uriMap);
        for (Component component : componentDefinition.getComponents()) {
            if (uriMap.get(component.getDefinitionURI()) != null) {
                component.setDefinition(uriMap.get(component.getDefinitionURI()));
                for (MapsTo mapsTo : component.getMapsTos()) {
                    ComponentDefinition cd = getComponentDefinition(component.getDefinitionURI());
                    if (cd != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(component, uriMap);
            for (MapsTo mapsTo : component.getMapsTos()) {
                updateReferences(mapsTo, uriMap);
            }
        }
        for (SequenceAnnotation sa : componentDefinition.getSequenceAnnotations()) {
            for (Location loc : sa.getLocations()) {
                updateReferences(loc, uriMap);
            }
            updateReferences(sa, uriMap);
        }
        for (SequenceConstraint sc : componentDefinition.getSequenceConstraints()) {
            updateReferences(sc, uriMap);
        }
        for (URI sequenceURI : componentDefinition.getSequenceURIs()) {
            if (uriMap.get(sequenceURI) != null) {
                componentDefinition.removeSequence(sequenceURI);
                componentDefinition.addSequence(uriMap.get(sequenceURI));
            }
        }
    }
    for (ModuleDefinition moduleDefinition : getModuleDefinitions()) {
        updateReferences(moduleDefinition, uriMap);
        for (FunctionalComponent functionalComponent : moduleDefinition.getFunctionalComponents()) {
            if (uriMap.get(functionalComponent.getDefinitionURI()) != null) {
                functionalComponent.setDefinition(uriMap.get(functionalComponent.getDefinitionURI()));
                for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
                    ComponentDefinition cd = getComponentDefinition(functionalComponent.getDefinitionURI());
                    if (cd != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(functionalComponent, uriMap);
            for (MapsTo mapsTo : functionalComponent.getMapsTos()) {
                updateReferences(mapsTo, uriMap);
            }
        }
        for (Module module : moduleDefinition.getModules()) {
            if (uriMap.get(module.getDefinitionURI()) != null) {
                module.setDefinition(uriMap.get(module.getDefinitionURI()));
                for (MapsTo mapsTo : module.getMapsTos()) {
                    ModuleDefinition md = getModuleDefinition(module.getDefinitionURI());
                    if (md != null) {
                        String displayId = URIcompliance.extractDisplayId(mapsTo.getRemoteURI());
                        URI newURI = URIcompliance.createCompliantURI(md.getPersistentIdentity().toString(), displayId, md.getVersion());
                        mapsTo.setRemote(newURI);
                    }
                }
            }
            updateReferences(module, uriMap);
            for (MapsTo mapsTo : module.getMapsTos()) {
                updateReferences(mapsTo, uriMap);
            }
        }
        for (Interaction interaction : moduleDefinition.getInteractions()) {
            updateReferences(interaction, uriMap);
            for (Participation participation : interaction.getParticipations()) {
                updateReferences(participation, uriMap);
            }
        }
        for (URI modelURI : moduleDefinition.getModelURIs()) {
            if (uriMap.get(modelURI) != null) {
                moduleDefinition.removeModel(modelURI);
                moduleDefinition.addModel(uriMap.get(modelURI));
            }
        }
    }
    for (Model model : getModels()) {
        updateReferences(model, uriMap);
    }
    for (Sequence sequence : getSequences()) {
        updateReferences(sequence, uriMap);
    }
    for (Attachment attachment : getAttachments()) {
        updateReferences(attachment, uriMap);
    }
    for (Implementation implementation : getImplementations()) {
        if (implementation.isSetBuilt()) {
            URI built = implementation.getBuiltURI();
            if (uriMap.get(built) != null) {
                implementation.setBuilt(uriMap.get(built));
            }
        }
        updateReferences(implementation, uriMap);
    }
    for (GenericTopLevel genericTopLevel : getGenericTopLevels()) {
        updateReferences(genericTopLevel, uriMap);
    }
    for (CombinatorialDerivation combinatorialDerivation : getCombinatorialDerivations()) {
        updateReferences(combinatorialDerivation, uriMap);
        if (uriMap.get(combinatorialDerivation.getTemplateURI()) != null) {
            combinatorialDerivation.setTemplate(uriMap.get(combinatorialDerivation.getTemplateURI()));
            ComponentDefinition cd = getComponentDefinition(combinatorialDerivation.getTemplateURI());
            if (cd != null) {
                for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
                    String displayId = URIcompliance.extractDisplayId(variableComponent.getVariableURI());
                    URI newURI = URIcompliance.createCompliantURI(cd.getPersistentIdentity().toString(), displayId, cd.getVersion());
                    variableComponent.setVariable(newURI);
                }
            }
        }
        for (VariableComponent variableComponent : combinatorialDerivation.getVariableComponents()) {
            updateReferences(variableComponent, uriMap);
        }
    }
    for (Activity activity : getActivities()) {
        updateReferences(activity, uriMap);
        for (Association association : activity.getAssociations()) {
            if (uriMap.get(association.getAgentURI()) != null) {
                association.setAgent(uriMap.get(association.getAgentURI()));
            }
            if (uriMap.get(association.getPlanURI()) != null) {
                association.setPlan(uriMap.get(association.getPlanURI()));
            }
            updateReferences(association, uriMap);
        }
        for (Usage usage : activity.getUsages()) {
            if (uriMap.get(usage.getEntityURI()) != null) {
                usage.setEntity(uriMap.get(usage.getEntityURI()));
            }
            updateReferences(usage, uriMap);
        }
    }
    for (Agent agent : getAgents()) {
        updateReferences(agent, uriMap);
    }
    for (Plan plan : getPlans()) {
        updateReferences(plan, uriMap);
    }
}
Also used : URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI)

Example 25 with ComponentDefinition

use of org.sbolstandard.core2.ComponentDefinition in project ice by JBEI.

the class SBOL2Visitor method visit.

public void visit(Sequence sequence) throws SBOLValidationException, URISyntaxException {
    // ice data model conflates the sequence and component
    Entry entry = sequence.getEntry();
    // Set required properties
    String partId = entry.getPartNumber();
    String dcUri = sequence.getComponentUri();
    if (dcUri == null) {
        componentDefinition = doc.createComponentDefinition(uriString, partId, "1", ComponentDefinition.DNA);
    } else {
        String displayId = StringUtils.isBlank(sequence.getIdentifier()) ? displayIdFromUri(dcUri) : sequence.getIdentifier();
        String prefix = prefixFromUri(dcUri);
        componentDefinition = doc.createComponentDefinition(prefix, displayId, "1", ComponentDefinition.DNA);
    }
    componentDefinition.setName(entry.getName());
    componentDefinition.setDescription(entry.getShortDescription());
    org.sbolstandard.core2.Sequence dnaSequence;
    String dsUri = sequence.getUri();
    if (dsUri == null || dsUri.isEmpty()) {
        dsUri = "sequence_" + sequence.getFwdHash().replaceAll("[\\s\\-()]", "");
        dnaSequence = doc.createSequence(uriString, dsUri, "1", sequence.getSequence(), org.sbolstandard.core2.Sequence.IUPAC_DNA);
    } else {
        dnaSequence = doc.createSequence(prefixFromUri(dsUri), displayIdFromUri(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()) {
            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()) {
            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) org.sbolstandard.core2(org.sbolstandard.core2)

Aggregations

URI (java.net.URI)30 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)23 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)18 SBOLDocument (org.sbolstandard.core2.SBOLDocument)15 QName (javax.xml.namespace.QName)12 HashSet (java.util.HashSet)9 ArrayList (java.util.ArrayList)7 IdentifiableDocument (org.sbolstandard.core.datatree.IdentifiableDocument)7 Literal (org.sbolstandard.core.datatree.Literal)7 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)7 Sequence (org.sbolstandard.core2.Sequence)7 NestedDocument (org.sbolstandard.core.datatree.NestedDocument)5 Activity (org.sbolstandard.core2.Activity)5 FunctionalComponent (org.sbolstandard.core2.FunctionalComponent)5 Component (org.sbolstandard.core2.Component)4 ModuleDefinition (org.sbolstandard.core2.ModuleDefinition)4 GenericTopLevel (org.sbolstandard.core2.GenericTopLevel)3 Interaction (org.sbolstandard.core2.Interaction)3 Module (org.sbolstandard.core2.Module)3 SequenceAnnotation (org.sbolstandard.core2.SequenceAnnotation)3