Search in sources :

Example 1 with Range

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

the class SBOLReader method parseSequenceAnnotationV1.

/**
 * @param SBOLDoc
 * @param sequenceAnnotation
 * @param precedePairs
 * @param parentURI
 * @param sa_num
 * @param instantiatedComponents
 * @return
 * @throws SBOLValidationException if either of the following conditions is satisfied:
 * <ul>
 * <li>if an SBOL validation rule violation occurred in any of the following constructors or methods:
 * 	<ul>
 * 		<li>{@link URIcompliance#createCompliantURI(String, String, String)}, </li>
 * 		<li>{@link #parseDnaComponentV1(SBOLDocument, IdentifiableDocument)}, </li>
 * 		<li>{@link Range#Range(URI, int, int)}, </li>
 * 		<li>{@link Range#setDisplayId(String)}, </li>
 * 		<li>{@link Range#setVersion(String)}, </li>
 * 		<li>{@link GenericLocation#GenericLocation(URI)}, </li>
 * 		<li>{@link SequenceAnnotation#SequenceAnnotation(URI, Set)}, </li>
 * 		<li>{@link SequenceAnnotation#setDisplayId(String)}, </li>
 * 		<li>{@link SequenceAnnotation#setVersion(String)}, </li>
 * 		<li>{@link SequenceAnnotation#setWasDerivedFrom(URI)}, </li>
 * 		<li>{@link SequenceAnnotation#setComponent(URI)}, or </li>
 * 		<li>{@link SequenceAnnotation#setAnnotations(List)}; or</li>
 * 	</ul>
 * </li>
 * <li>the following SBOL validation rule was violated: 11002.</li>
 * </ul>
 * @throws SBOLConversionException
 */
private static SequenceAnnotation parseSequenceAnnotationV1(SBOLDocument SBOLDoc, NestedDocument<QName> sequenceAnnotation, List<SBOLPair> precedePairs, String parentURI, int sa_num, Set<String> instantiatedComponents) throws SBOLValidationException, SBOLConversionException {
    Integer start = null;
    Integer end = null;
    String strand = null;
    URI componentURI = null;
    URI identity = sequenceAnnotation.getIdentity();
    String persIdentity = sequenceAnnotation.getIdentity().toString();
    List<Annotation> annotations = new ArrayList<>();
    if (URIPrefix != null) {
        persIdentity = createCompliantURI(parentURI, "annotation" + sa_num, "").toString();
        identity = createCompliantURI(parentURI, "annotation" + sa_num, version);
    }
    if (!sequenceAnnotation.getType().equals(Sbol1Terms.SequenceAnnotations.SequenceAnnotation)) {
        throw new SBOLConversionException("QName has to be" + Sbol1Terms.SequenceAnnotations.SequenceAnnotation.toString());
    }
    for (NamedProperty<QName> namedProperty : sequenceAnnotation.getProperties()) {
        if (namedProperty.getName().equals(Sbol1Terms.SequenceAnnotations.bioStart)) {
            if (!(namedProperty.getValue() instanceof Literal) || start != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-11102", sequenceAnnotation.getIdentity());
            }
            String temp = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            start = Integer.parseInt(temp);
        } else if (namedProperty.getName().equals(Sbol1Terms.SequenceAnnotations.bioEnd)) {
            if (!(namedProperty.getValue() instanceof Literal) || end != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-11103", sequenceAnnotation.getIdentity());
            }
            String temp2 = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
            end = Integer.parseInt(temp2);
        } else if (namedProperty.getName().equals(Sbol1Terms.SequenceAnnotations.strand)) {
            if (!(namedProperty.getValue() instanceof Literal) || strand != null || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof String))) {
                throw new SBOLValidationException("sbol-11002", sequenceAnnotation.getIdentity());
            }
            strand = ((Literal<QName>) namedProperty.getValue()).getValue().toString();
        } else if (namedProperty.getName().equals(Sbol1Terms.SequenceAnnotations.subComponent)) {
            if (componentURI != null) {
                throw new SBOLValidationException("sbol-10904", sequenceAnnotation.getIdentity());
            }
            if (namedProperty.getValue() instanceof NestedDocument) {
                componentURI = parseDnaComponentV1(SBOLDoc, (NestedDocument<QName>) namedProperty.getValue()).getIdentity();
            } else {
                if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                    throw new SBOLValidationException("sbol-10904", sequenceAnnotation.getIdentity());
                }
                componentURI = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
            }
        } else if (namedProperty.getName().equals(Sbol1Terms.SequenceAnnotations.precedes)) {
            URI left = sequenceAnnotation.getIdentity();
            URI right = null;
            if (namedProperty.getValue() instanceof NestedDocument) {
                // TODO: need to check if ++sa_num here okay
                right = parseSequenceAnnotationV1(SBOLDoc, (NestedDocument<QName>) namedProperty.getValue(), precedePairs, parentURI, ++sa_num, instantiatedComponents).getIdentity();
            } else {
                if (!(namedProperty.getValue() instanceof Literal) || (!(((Literal<QName>) namedProperty.getValue()).getValue() instanceof URI))) {
                    throw new SBOLValidationException("sbol-11404", sequenceAnnotation.getIdentity());
                }
                right = URI.create(((Literal<QName>) namedProperty.getValue()).getValue().toString());
            }
            SBOLPair pair = new SBOLPair(left, right);
            precedePairs.add(pair);
        } else {
            annotations.add(new Annotation(namedProperty));
        }
    }
    String componentDisplayId = URIcompliance.extractDisplayId(componentURI);
    String displayId = "annotation" + sa_num;
    if (compliant && componentDisplayId != null && !instantiatedComponents.contains(componentDisplayId)) {
        identity = createCompliantURI(parentURI, componentDisplayId + "_annotation", version);
        persIdentity = createCompliantURI(parentURI, componentDisplayId + "_annotation", "").toString();
        displayId = componentDisplayId + "_annotation";
    }
    // Note: Do not create a seqAnnotation if Location is empty
    Location location = null;
    if (// create SequenceAnnotation & Component
    start != null && end != null) {
        URI range_identity = createCompliantURI(persIdentity, "range", version);
        location = new Range(range_identity, start, end);
        if (!persIdentity.equals("")) {
            location.setPersistentIdentity(createCompliantURI(persIdentity, "range", ""));
            location.setDisplayId("range");
            location.setVersion(version);
        }
        if (strand != null) {
            if (strand.equals("+")) {
                location.setOrientation(OrientationType.INLINE);
            } else if (strand.equals("-")) {
                location.setOrientation(OrientationType.REVERSECOMPLEMENT);
            }
        }
    } else {
        URI dummyGenericLoc_id = createCompliantURI(persIdentity, "genericLocation", version);
        location = new GenericLocation(dummyGenericLoc_id);
        if (!persIdentity.equals("")) {
            location.setPersistentIdentity(createCompliantURI(persIdentity, "genericLocation", ""));
            location.setDisplayId("genericLocation");
            location.setVersion(version);
        }
        if (strand != null) {
            if (strand.equals("+")) {
                location.setOrientation(OrientationType.INLINE);
            } else if (strand.equals("-")) {
                location.setOrientation(OrientationType.REVERSECOMPLEMENT);
            }
        }
    }
    Set<Location> locations = new HashSet<>();
    locations.add(location);
    SequenceAnnotation s = new SequenceAnnotation(identity, locations);
    if (!persIdentity.equals("")) {
        s.setPersistentIdentity(URI.create(persIdentity));
        s.setDisplayId(displayId);
        s.setVersion(version);
    }
    if (identity != sequenceAnnotation.getIdentity())
        s.addWasDerivedFrom(sequenceAnnotation.getIdentity());
    if (componentURI != null)
        s.setComponent(componentURI);
    if (!annotations.isEmpty())
        s.setAnnotations(annotations);
    return s;
}
Also used : StringifyQName(org.sbolstandard.core.io.json.StringifyQName) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI) URI(java.net.URI) NestedDocument(org.sbolstandard.core.datatree.NestedDocument) Literal(org.sbolstandard.core.datatree.Literal) HashSet(java.util.HashSet)

Example 2 with Range

use of org.sbolstandard.core2.Range 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 3 with Range

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

the class SequenceAnnotation method copy.

void copy(SequenceAnnotation sequenceAnnotation) throws SBOLValidationException {
    ((Identified) this).copy((Identified) sequenceAnnotation);
    for (Location location : sequenceAnnotation.getLocations()) {
        String displayId = URIcompliance.findDisplayId(location);
        if (location instanceof Range) {
            Range range = (Range) location;
            Range newRange;
            if (range.isSetOrientation()) {
                newRange = this.addRange(displayId, range.getStart(), range.getEnd(), range.getOrientation());
            } else {
                newRange = this.addRange(displayId, range.getStart(), range.getEnd());
            }
            newRange.copy(range);
        } else if (location instanceof Cut) {
            Cut cut = (Cut) location;
            Cut newCut;
            if (cut.isSetOrientation()) {
                newCut = this.addCut(displayId, cut.getAt(), cut.getOrientation());
            } else {
                newCut = this.addCut(displayId, cut.getAt());
            }
            newCut.copy(cut);
        } else if (location instanceof GenericLocation) {
            GenericLocation genericLocation = (GenericLocation) location;
            GenericLocation newGenericLocation;
            if (genericLocation.isSetOrientation()) {
                newGenericLocation = this.addGenericLocation(displayId, genericLocation.getOrientation());
            } else {
                newGenericLocation = this.addGenericLocation(displayId);
            }
            newGenericLocation.copy(genericLocation);
        }
    }
    Location location = this.getLocation("DUMMY__LOCATION");
    if (location != null) {
        this.removeLocation(location);
    }
    if (sequenceAnnotation.isSetComponent()) {
        String componentDisplayId = URIcompliance.findDisplayId(sequenceAnnotation.getComponent());
        this.setComponent(componentDisplayId);
    }
    this.roles = new HashSet<>();
    for (URI role : sequenceAnnotation.getRoles()) {
        this.addRole(URI.create(role.toString()));
    }
}
Also used : URI(java.net.URI) URIcompliance.createCompliantURI(org.sbolstandard.core2.URIcompliance.createCompliantURI)

Example 4 with Range

use of org.sbolstandard.core2.Range in project sirix by sirixdb.

the class AbstractSunburstControl method controlEvent.

/**
 * Called on every change of the GUI.
 *
 * @param paramControlEvent
 *          the {@link ControlEvent}
 */
@Override
public void controlEvent(final ControlEvent paramControlEvent) {
    assert paramControlEvent != null;
    if (paramControlEvent.isController()) {
        if (paramControlEvent.getController().getId() == 50) {
            mModel.evaluateXPath(paramControlEvent.getController().getStringValue());
        } else {
            if (paramControlEvent.getController() instanceof Toggle) {
                final Toggle toggle = (Toggle) paramControlEvent.getController();
                switch(paramControlEvent.getController().getId()) {
                    case 0:
                        mGUI.setShowArcs(toggle.getState());
                        break;
                    case 1:
                        mGUI.setShowLines(toggle.getState());
                        break;
                    case 2:
                        mGUI.setUseBezierLine(toggle.getState());
                        break;
                }
            } else if (paramControlEvent.getController() instanceof Slider) {
                switch(paramControlEvent.getController().getId()) {
                    case 0:
                        mGUI.setInnerNodeArcScale(paramControlEvent.getController().getValue());
                        break;
                    case 1:
                        mGUI.setLeafArcScale(paramControlEvent.getController().getValue());
                        break;
                    case 2:
                        mGUI.setModificationWeight(paramControlEvent.getController().getValue());
                        break;
                    case 3:
                        mGUI.setDotSize(paramControlEvent.getController().getValue());
                        break;
                    case 4:
                        mGUI.setDotBrightness(paramControlEvent.getController().getValue());
                        break;
                    case 5:
                        mGUI.setBackgroundBrightness(paramControlEvent.getController().getValue());
                        break;
                }
            } else if (paramControlEvent.getController() instanceof Range) {
                final float[] f = paramControlEvent.getController().getArrayValue();
                switch(paramControlEvent.getController().getId()) {
                    case 0:
                        mGUI.setHueStart(f[0]);
                        mGUI.setHueEnd(f[1]);
                        break;
                    case 1:
                        mGUI.setSaturationStart(f[0]);
                        mGUI.setSaturationEnd(f[1]);
                        break;
                    case 2:
                        mGUI.setBrightnessStart(f[0]);
                        mGUI.setBrightnessEnd(f[1]);
                        break;
                    case 3:
                        mGUI.setInnerNodeBrightnessStart(f[0]);
                        mGUI.setInnerNodeBrightnessEnd(f[1]);
                        break;
                    case 4:
                        mGUI.setInnerNodeStrokeBrightnessStart(f[0]);
                        mGUI.setInnerNodeStrokeBrightnessEnd(f[1]);
                        break;
                    case 5:
                        mGUI.setStrokeWeightStart(f[0]);
                        mGUI.setStrokeWeightEnd(f[1]);
                        break;
                }
            }
            mGUI.update(EResetZoomer.YES);
        }
    }
}
Also used : Slider(controlP5.Slider) Toggle(controlP5.Toggle) Range(controlP5.Range)

Example 5 with Range

use of org.sbolstandard.core2.Range in project sirix by sirixdb.

the class AbstractSunburstGUI method setupGUI.

/**
 * Initial setup of the GUI.
 */
private void setupGUI() {
    mParent.textFont(mFont);
    mParent.smooth();
    mParent.background(255f);
    final int activeColor = mParent.color(0, 130, 164);
    mControlP5.setColorActive(activeColor);
    mControlP5.setColorBackground(mParent.color(170));
    mControlP5.setColorForeground(mParent.color(50));
    mControlP5.setColorLabel(mParent.color(50));
    mControlP5.setColorValue(mParent.color(255));
    final int len = 300;
    final Range hueRange = mControlP5.addRange("leaf node hue range", 0, 360, getHueStart(), getHueEnd(), LEFT, TOP + mPosY + 0, len, 15);
    mRanges.add(hueRange);
    final Range saturationRange = mControlP5.addRange("leaf node saturation range", 0, 100, getSaturationStart(), getSaturationEnd(), LEFT, TOP + mPosY + 20, len, 15);
    mRanges.add(saturationRange);
    final Range brightnessRange = mControlP5.addRange("leaf node brightness range", 0, 100, getBrightnessStart(), getBrightnessEnd(), LEFT, TOP + mPosY + 40, len, 15);
    mRanges.add(brightnessRange);
    mPosY += 70;
    final Range innerNodebrightnessRange = mControlP5.addRange("inner node brightness range", 0, 100, getInnerNodeBrightnessStart(), getInnerNodeBrightnessEnd(), LEFT, TOP + mPosY + 0, len, 15);
    mRanges.add(innerNodebrightnessRange);
    final Range innerNodeStrokeBrightnessRange = mControlP5.addRange("inner node stroke brightness range", 0, 100, getInnerNodeStrokeBrightnessStart(), getInnerNodeStrokeBrightnessEnd(), LEFT, TOP + mPosY + 20, len, 15);
    mRanges.add(innerNodeStrokeBrightnessRange);
    mPosY += 50;
    // name, minimum, maximum, default value (float), x, y, width, height
    final Slider innerNodeArcScale = mControlP5.addSlider("setInnerNodeArcScale", 0, 1, getInnerNodeArcScale(), LEFT, TOP + mPosY + 0, len, 15);
    innerNodeArcScale.setCaptionLabel("innerNodeArcScale");
    mSliders.add(innerNodeArcScale);
    final Slider leafNodeArcScale = mControlP5.addSlider("setLeafArcScale", 0, 1, getLeafArcScale(), LEFT, TOP + mPosY + 20, len, 15);
    leafNodeArcScale.setCaptionLabel("leafNodeArcScale");
    mSliders.add(leafNodeArcScale);
    mPosY += 50;
    final Slider modWeight = mControlP5.addSlider("setModificationWeight", 0, 1, getModificationWeight(), LEFT, TOP + mPosY + 0, len, 15);
    modWeight.setCaptionLabel("modification weight");
    mSliders.add(modWeight);
    mPosY += 50;
    final Range strokeWeight = mControlP5.addRange("stroke weight range", 0, 10, getStrokeWeightStart(), getStrokeWeightEnd(), LEFT, TOP + mPosY + 0, len, 15);
    mRanges.add(strokeWeight);
    mPosY += 30;
    final Slider dotSize = mControlP5.addSlider("setDotSize", 0, 10, mDotSize, LEFT, TOP + mPosY + 0, len, 15);
    dotSize.setCaptionLabel("dot size");
    mSliders.add(dotSize);
    final Slider dotBrightness = mControlP5.addSlider("setDotBrightness", 0, 100, mDotBrightness, LEFT, TOP + mPosY + 20, len, 15);
    dotBrightness.setCaptionLabel("dot brightness");
    mSliders.add(dotBrightness);
    mPosY += 50;
    final Slider backgroundBrightness = mControlP5.addSlider("setBackgroundBrightness", 0, 100, getBackgroundBrightness(), LEFT, TOP + mPosY + 0, len, 15);
    backgroundBrightness.setCaptionLabel("background brightness");
    mSliders.add(backgroundBrightness);
    mPosY += 50;
    final Toggle showArcs = mControlP5.addToggle("isShowArcs", isShowArcs(), LEFT + 0, TOP + mPosY, 15, 15);
    showArcs.setCaptionLabel("show arcs");
    mToggles.add(showArcs);
    final Toggle showLines = mControlP5.addToggle("isShowLines", isShowLines(), LEFT + 0, TOP + mPosY + 20, 15, 15);
    showLines.setCaptionLabel("show lines");
    mToggles.add(showLines);
    final Toggle useBezier = mControlP5.addToggle("isUseBezierLine", isUseBezierLine(), LEFT + 0, TOP + mPosY + 40, 15, 15);
    useBezier.setCaptionLabel("Bezier / Line");
    mToggles.add(useBezier);
    setup();
    style();
}
Also used : Slider(controlP5.Slider) Toggle(controlP5.Toggle) Range(controlP5.Range)

Aggregations

Range (org.apache.commons.lang3.Range)11 Date (java.util.Date)9 Test (org.junit.jupiter.api.Test)9 URI (java.net.URI)6 URIcompliance.createCompliantURI (org.sbolstandard.core2.URIcompliance.createCompliantURI)6 Range (controlP5.Range)3 Slider (controlP5.Slider)3 Toggle (controlP5.Toggle)3 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 QName (javax.xml.namespace.QName)2 Literal (org.sbolstandard.core.datatree.Literal)2 StringifyQName (org.sbolstandard.core.io.json.StringifyQName)2 ControllerStyle (controlP5.ControllerStyle)1 Group (controlP5.Group)1 Label (controlP5.Label)1 List (java.util.List)1 ItemStack (net.minecraft.item.ItemStack)1 ProfilePeriod (org.apache.metron.profiler.ProfilePeriod)1