use of org.cytoscape.model.CyIdentifiable in project EnrichmentMapApp by BaderLab.
the class SessionModelIO method mapSuids.
private static Set<Long> mapSuids(Set<Long> oldSuids, CySession session, Class<? extends CyIdentifiable> type) {
Set<Long> newSuids = new HashSet<>();
for (Long suid : oldSuids) {
if (session != null) {
// If we are loading from a session file then we need to re-map the ids
CyIdentifiable obj = session.getObject(suid, type);
suid = obj.getSUID();
}
newSuids.add(suid);
}
return newSuids;
}
use of org.cytoscape.model.CyIdentifiable in project cytoscape-api by cytoscape.
the class SUIDUtil method saveSUIDs.
/**
* This method may be used to save a list of SUIDs that have been sent to a remote
* service so that they may be restored later
*
* @param job the job that we're saving the SUIDs for
* @param network the network that the SUIDs are part of
* @param objs the Cytoscape objects whose SUIDs we want to save
*/
public static void saveSUIDs(CyJob job, CyNetwork network, List<? extends CyIdentifiable> objs) {
Map<Identifiable, CyTable> suidMap = new HashMap<>();
// Add the network table to the map, we depend on having the network
// available to us for the restore
String columnName = getColumnName(job);
// First, make sure we've saved the network SUID
CyTable hiddenTable = createColumn(network, Identifiable.NETWORK, columnName);
CyRow netRow = hiddenTable.getRow(network.getSUID());
if (netRow != null)
netRow.set(columnName, network.getSUID());
for (CyIdentifiable cyId : objs) {
Identifiable type = getType(cyId);
if (!suidMap.containsKey(type)) {
hiddenTable = createColumn(network, type, columnName);
if (hiddenTable != null)
suidMap.put(type, hiddenTable);
}
CyRow row = suidMap.get(type).getRow(cyId.getSUID());
if (row != null)
row.set(columnName, cyId.getSUID());
}
}
use of org.cytoscape.model.CyIdentifiable in project EnrichmentMapApp by BaderLab.
the class RadialHeatMapChart method getLayers.
@Override
public List<RadialHeatMapLayer> getLayers(final CyNetworkView networkView, final View<? extends CyIdentifiable> view) {
final CyNetwork network = networkView.getModel();
final CyIdentifiable model = view.getModel();
final double startAngle = get(START_ANGLE, Double.class, 0.0);
final Rotation rotation = get(ROTATION, Rotation.class, Rotation.ANTICLOCKWISE);
final List<String> labels = getItemLabels(network, model);
final Map<String, List<Double>> data = getData(network, model);
final List<Color> colors = getColors(data);
final double size = 32;
final Rectangle2D bounds = new Rectangle2D.Double(-size / 2, -size / 2, size, size);
final boolean showLabels = get(SHOW_ITEM_LABELS, Boolean.class, false);
final float itemFontSize = convertFontSize(get(ITEM_LABEL_FONT_SIZE, Integer.class, 1));
final float borderWidth = get(BORDER_WIDTH, Float.class, 0.25f);
final Color borderColor = get(BORDER_COLOR, Color.class, Color.DARK_GRAY);
final boolean global = get(GLOBAL_RANGE, Boolean.class, true);
final List<Double> range = global ? getList(RANGE, Double.class) : null;
final RadialHeatMapLayer layer = new RadialHeatMapLayer(data, labels, showLabels, itemFontSize, colors, borderWidth, borderColor, startAngle, rotation, range, bounds);
return Collections.singletonList(layer);
}
use of org.cytoscape.model.CyIdentifiable in project cytoscape-api by cytoscape.
the class CySessionTest method testSetObjectMap.
@Test
public void testSetObjectMap() {
Map<Object, CyNetwork> netMap = new HashMap<Object, CyNetwork>();
CyNetwork net1 = mock(CyNetwork.class);
netMap.put("A", net1);
CyNetwork net2 = mock(CyNetwork.class);
netMap.put("B", net2);
Map<Object, CyNetworkView> viewMap = new HashMap<Object, CyNetworkView>();
CyNetworkView view1 = mock(CyNetworkView.class);
viewMap.put("A", view1);
Map<Object, CyNode> nodeMap = new HashMap<Object, CyNode>();
CyNode n1 = mock(CyNode.class);
nodeMap.put(new Long(1), n1);
CyNode n2 = mock(CyNode.class);
nodeMap.put(new Long(2), n2);
Map<Object, CyEdge> edgeMap = new HashMap<Object, CyEdge>();
CyEdge e1 = mock(CyEdge.class);
edgeMap.put(new Long(3), e1);
Map<Class<? extends CyIdentifiable>, Map<Object, ? extends CyIdentifiable>> objMap = new HashMap<Class<? extends CyIdentifiable>, Map<Object, ? extends CyIdentifiable>>();
objMap.put(CyNetwork.class, netMap);
objMap.put(CyNetworkView.class, viewMap);
objMap.put(CyNode.class, nodeMap);
objMap.put(CyEdge.class, edgeMap);
session = new CySession.Builder().objectMap(objMap).build();
assertNotNull(session);
assertSame(net1, session.getObject("A", CyNetwork.class));
assertSame(net2, session.getObject("B", CyNetwork.class));
assertSame(view1, session.getObject("A", CyNetworkView.class));
assertSame(n1, session.getObject(new Long(1), CyNode.class));
assertSame(n2, session.getObject(new Long(2), CyNode.class));
assertSame(e1, session.getObject(new Long(3), CyEdge.class));
assertNull(session.getObject("A", View.class));
assertNull(session.getObject("B", CyNetworkView.class));
}
use of org.cytoscape.model.CyIdentifiable in project cytoscape-api by cytoscape.
the class SUIDUtil method restoreSUIDs.
/**
* Method to restore Cytoscape objects based on a list of SUIDs that were sent to the remote
* service as saved in the hidden table.
*
* @param job the {@link CyJob} we're restoring
* @param network the network the SUIDs are part of. See {@link SaveSUID.restoreNetwork()} for
* a method to get the network
* @param oldIds the list of old SUIDs that were sent to the remote server and saved
* in the session
* @param clear if true, remove the columns for this job
* @return a map that relates the original id to the Cytoscape object
*/
public static Map<Long, CyIdentifiable> restoreSUIDs(CyJob job, CyNetwork network, List<Long> oldIds, boolean clear) {
Map<Long, CyIdentifiable> objMap = new HashMap<>();
Set<Long> suidSet = new HashSet<Long>(oldIds);
String columnName = getColumnName(job);
// First, determine which types have our column
CyTable networkTable = network.getTable(CyNetwork.class, CyNetwork.HIDDEN_ATTRS);
if (networkTable.getColumn(columnName) != null) {
Long id = network.getRow(network).get(columnName, Long.class);
if (suidSet.contains(id))
objMap.put(id, network);
if (clear)
networkTable.deleteColumn(columnName);
}
CyTable nodeTable = network.getTable(CyNode.class, CyNetwork.HIDDEN_ATTRS);
if (nodeTable.getColumn(columnName) != null) {
for (CyNode node : network.getNodeList()) {
Long id = nodeTable.getRow(node.getSUID()).get(columnName, Long.class);
if (id == null)
continue;
if (suidSet.contains(id)) {
objMap.put(id, node);
}
}
if (clear)
nodeTable.deleteColumn(columnName);
}
CyTable edgeTable = network.getTable(CyEdge.class, CyNetwork.HIDDEN_ATTRS);
if (edgeTable.getColumn(columnName) != null) {
for (CyEdge edge : network.getEdgeList()) {
Long id = edgeTable.getRow(edge.getSUID()).get(columnName, Long.class);
if (id == null)
continue;
if (suidSet.contains(id))
objMap.put(id, edge);
}
if (clear)
edgeTable.deleteColumn(columnName);
}
return objMap;
}
Aggregations