Search in sources :

Example 1 with ContinuousMappingPoint

use of org.cytoscape.io.internal.util.vizmap.model.ContinuousMappingPoint in project cytoscape-impl by cytoscape.

the class CalculatorConverter method getMappingFunction.

/**
 * @param props
 *            All the visual properties
 * @param mapperName
 *            Example: "MyStyle-Edge Color-Discrete Mapper"
 * @return A {@link org.cytoscape.io.internal.util.vizmap.model.DiscreteMapping},
 *           {@link org.cytoscape.io.internal.util.vizmap.model.ContinuousMapping} or
 *           {@link org.cytoscape.io.internal.util.vizmap.model.PassThroughMapping} object
 */
private Object getMappingFunction(Properties props, String mapperName, VisualProperty vp) {
    String baseKey = null;
    String functionType = null;
    while (functionType == null) {
        // e.g. "edgeColorCalculator.MyStyle-Edge Color-Discrete Mapper.mapping."
        baseKey = (legacyKey != null ? legacyKey : key) + "." + mapperName + ".mapping.";
        functionType = props.getProperty(baseKey + "type");
        if (functionType == null) {
            // Try with Cytoscape v2.3 calculator names...
            if (baseKey.startsWith("nodeFillColorCalculator.")) {
                legacyKey = "nodeColorCalculator";
            } else if (baseKey.startsWith("edgeSourceArrowCalculator.") || baseKey.startsWith("edgeTargetArrowCalculator.")) {
                legacyKey = "edgeArrowCalculator";
            } else {
                return null;
            }
        }
    }
    String attrName = props.getProperty(baseKey + "controller");
    if (attrName == null)
        return null;
    // "ID" is actually the "name" column!!!
    if ("ID".equalsIgnoreCase(attrName))
        attrName = "name";
    if ("DiscreteMapping".equalsIgnoreCase(functionType)) {
        String controllerTypeProp = props.getProperty(baseKey + "controllerType");
        byte controllerType = controllerTypeProp != null ? Byte.parseByte(controllerTypeProp) : TYPE_STRING;
        AttributeType attrType = null;
        if (attrName.equals("has_nested_network")) {
            // Force to boolean (in Cy2, this attribute is a "yes\no" string type)
            attrType = AttributeType.BOOLEAN;
        } else {
            switch(controllerType) {
                case TYPE_BOOLEAN:
                    attrType = AttributeType.BOOLEAN;
                    break;
                case TYPE_FLOATING_POINT:
                    attrType = AttributeType.FLOAT;
                    break;
                case TYPE_INTEGER:
                    attrType = AttributeType.INTEGER;
                    break;
                default:
                    attrType = AttributeType.STRING;
                    break;
            }
        }
        DiscreteMapping dm = new DiscreteMapping();
        dm.setAttributeName(attrName);
        dm.setAttributeType(attrType);
        String entryKey = baseKey + "map.";
        for (String sk : props.stringPropertyNames()) {
            if (sk.contains(entryKey)) {
                String attrValue = sk.replace(entryKey, "");
                String sv = props.getProperty(sk);
                String value = getValue(sv);
                if (attrName.equals("has_nested_network"))
                    attrValue = attrValue.matches("(?i)yes|true") ? "true" : "false";
                DiscreteMappingEntry entry = new DiscreteMappingEntry();
                entry.setAttributeValue(attrValue);
                entry.setValue(value);
                dm.getDiscreteMappingEntry().add(entry);
            }
        }
        return dm;
    } else if ("ContinuousMapping".equalsIgnoreCase(functionType)) {
        ContinuousMapping cm = new ContinuousMapping();
        cm.setAttributeName(attrName);
        cm.setAttributeType(AttributeType.FLOAT);
        int boundaryValues = 0;
        try {
            String s = props.getProperty(baseKey + "boundaryvalues");
            boundaryValues = Integer.parseInt(s);
        } catch (NumberFormatException nfe) {
        // TODO: warning
        }
        for (int i = 0; i < boundaryValues; i++) {
            try {
                BigDecimal value = new BigDecimal(props.getProperty(baseKey + "bv" + i + ".domainvalue"));
                String lesser = getValue(props.getProperty(baseKey + "bv" + i + ".lesser"));
                String equal = getValue(props.getProperty(baseKey + "bv" + i + ".equal"));
                String greater = getValue(props.getProperty(baseKey + "bv" + i + ".greater"));
                ContinuousMappingPoint point = new ContinuousMappingPoint();
                point.setAttrValue(value);
                point.setLesserValue(lesser);
                point.setEqualValue(equal);
                point.setGreaterValue(greater);
                cm.getContinuousMappingPoint().add(point);
            } catch (Exception e) {
            // TODO: warning
            }
        }
        return cm;
    } else if ("PassThroughMapping".equalsIgnoreCase(functionType)) {
        PassthroughMapping pm = new PassthroughMapping();
        pm.setAttributeName(attrName);
        // Cy2 doesn't write the "controllerType" property for PassThroughMappings, so just set STRING
        // (it should work, anyway).
        pm.setAttributeType(AttributeType.STRING);
        return pm;
    }
    return null;
}
Also used : ContinuousMapping(org.cytoscape.io.internal.util.vizmap.model.ContinuousMapping) AttributeType(org.cytoscape.io.internal.util.vizmap.model.AttributeType) DiscreteMapping(org.cytoscape.io.internal.util.vizmap.model.DiscreteMapping) PassthroughMapping(org.cytoscape.io.internal.util.vizmap.model.PassthroughMapping) ContinuousMappingPoint(org.cytoscape.io.internal.util.vizmap.model.ContinuousMappingPoint) DiscreteMappingEntry(org.cytoscape.io.internal.util.vizmap.model.DiscreteMappingEntry) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)1 AttributeType (org.cytoscape.io.internal.util.vizmap.model.AttributeType)1 ContinuousMapping (org.cytoscape.io.internal.util.vizmap.model.ContinuousMapping)1 ContinuousMappingPoint (org.cytoscape.io.internal.util.vizmap.model.ContinuousMappingPoint)1 DiscreteMapping (org.cytoscape.io.internal.util.vizmap.model.DiscreteMapping)1 DiscreteMappingEntry (org.cytoscape.io.internal.util.vizmap.model.DiscreteMappingEntry)1 PassthroughMapping (org.cytoscape.io.internal.util.vizmap.model.PassthroughMapping)1