use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.
the class CopyExistingViewTask method run.
@Override
public void run(TaskMonitor tm) {
if (sourceView == null)
throw new NullPointerException("source network view is null.");
if (newView == null)
throw new NullPointerException("new network view is null.");
tm.setProgress(0.0);
final Collection<RenderingEngine<?>> engines = renderingEngineMgr.getAllRenderingEngines();
Collection<VisualProperty<?>> nodeProps = null;
Collection<VisualProperty<?>> edgeProps = null;
if (!engines.isEmpty()) {
final VisualLexicon lexicon = engines.iterator().next().getVisualLexicon();
nodeProps = lexicon.getAllDescendants(BasicVisualLexicon.NODE);
edgeProps = lexicon.getAllDescendants(BasicVisualLexicon.EDGE);
}
// Copy some network view properties
if (!fitContent) {
newView.setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_X_LOCATION, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_CENTER_X_LOCATION));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_Y_LOCATION, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_CENTER_Y_LOCATION));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_CENTER_Z_LOCATION, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_CENTER_Z_LOCATION));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_SCALE_FACTOR, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_SCALE_FACTOR));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_WIDTH, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_WIDTH));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT));
newView.setVisualProperty(BasicVisualLexicon.NETWORK_DEPTH, sourceView.getVisualProperty(BasicVisualLexicon.NETWORK_DEPTH));
}
// Copy node locations and locked visual properties
for (final View<CyNode> newNodeView : newView.getNodeViews()) {
final View<CyNode> origNodeView = getOriginalNodeView(newNodeView);
if (origNodeView == null)
continue;
newNodeView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, origNodeView.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION));
newNodeView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, origNodeView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION));
if (nodeProps != null) {
// Set lock (if necessary)
for (final VisualProperty vp : nodeProps) {
if (origNodeView.isValueLocked(vp))
newNodeView.setLockedValue(vp, origNodeView.getVisualProperty(vp));
}
}
}
tm.setProgress(0.5);
// Copy edge locked visual properties
for (final View<CyEdge> newEdgeView : newView.getEdgeViews()) {
final View<CyEdge> origEdgeView = getOriginalEdgeView(newEdgeView);
if (origEdgeView != null && edgeProps != null) {
// Set lock (if necessary)
for (final VisualProperty vp : edgeProps) {
if (origEdgeView.isValueLocked(vp))
newEdgeView.setLockedValue(vp, origEdgeView.getVisualProperty(vp));
}
}
}
tm.setProgress(0.9);
if (style != null) {
style.apply(newView);
newView.updateView();
}
if (fitContent)
newView.fitContent();
tm.setProgress(1.0);
}
use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.
the class SelectAdjacentEdgesTaskTest method testRun.
@Test
public void testRun() throws Exception {
UndoSupport undoSupport = mock(UndoSupport.class);
when(r3.get("selected", Boolean.class)).thenReturn(true);
when(r4.get("selected", Boolean.class)).thenReturn(false);
Set<Long> selectedNodes = new HashSet<>();
selectedNodes.add(r3.get(CyNetwork.SUID, Long.class));
when(nodeTable.getMatchingKeys(CyNetwork.SELECTED, true, Long.class)).thenReturn(selectedNodes);
List<CyEdge> el = new ArrayList<CyEdge>();
el.add(e1);
when(net.getAdjacentEdgeList(e3, CyEdge.Type.ANY)).thenReturn(el);
// run the task
Task t = new SelectAdjacentEdgesTask(undoSupport, net, networkViewManager, eventHelper);
t.run(tm);
// check that the expected rows were set
verify(r1, times(1)).set("selected", true);
}
use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.
the class NumericFilter method apply.
public void apply() {
List<CyNode> nodes_list = null;
List<CyEdge> edges_list = null;
int objectCount = -1;
if (index_type == QuickFind.INDEX_NODES) {
nodes_list = network.getNodeList();
objectCount = nodes_list.size();
// all the bits are false initially
node_bits = new BitSet(objectCount);
} else if (index_type == QuickFind.INDEX_EDGES) {
edges_list = network.getEdgeList();
objectCount = edges_list.size();
// all the bits are false initially
edge_bits = new BitSet(objectCount);
} else {
LoggerFactory.getLogger("org.cytoscape.application.userlog").error("StringFilter: Index_type is undefined.");
return;
}
if (lowBound == null || highBound == null || network == null || !FilterUtil.hasSuchAttribute(network, controllingAttribute, index_type)) {
return;
}
// If quickFind_index does not exist, build the Index
// if (quickFind_index == null) {
quickFind_index = FilterUtil.getQuickFindIndex(quickFind, controllingAttribute, network, index_type);
// }
// System.out.println(" NumberFilter.apply(): objectCount = " + objectCount);
NumberIndex numberIndex = (NumberIndex) quickFind_index;
List<?> list = numberIndex.getRange(lowBound, highBound);
if (list.size() == 0) {
return;
}
int index;
if (index_type == QuickFind.INDEX_NODES) {
for (Object obj : list) {
index = nodes_list.lastIndexOf(obj);
node_bits.set(index, true);
}
} else if (index_type == QuickFind.INDEX_EDGES) {
for (Object obj : list) {
index = edges_list.lastIndexOf(obj);
edge_bits.set(index, true);
}
}
if (negation) {
if (index_type == QuickFind.INDEX_NODES) {
node_bits.flip(0, objectCount);
}
if (index_type == QuickFind.INDEX_EDGES) {
edge_bits.flip(0, objectCount);
}
}
}
use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.
the class StringFilter method apply.
/**
* Caculate the bitSet based on the existing TextIndex and search string.
* The size of the bitSet is the number of nodes/edges in the given network,
* All bits are initially set to false, those with hits are set to true.
* @param none.
* @return none.
*/
public void apply() {
List<CyNode> nodes_list = null;
List<CyEdge> edges_list = null;
// Initialize the bitset
int objectCount = -1;
if (index_type == QuickFind.INDEX_NODES) {
nodes_list = network.getNodeList();
objectCount = nodes_list.size();
// all the bits are false at very beginning
node_bits = new BitSet(objectCount);
} else if (index_type == QuickFind.INDEX_EDGES) {
edges_list = network.getEdgeList();
objectCount = edges_list.size();
// all the bits are false at very beginning
edge_bits = new BitSet(objectCount);
} else {
LoggerFactory.getLogger("org.cytoscape.application.userlog").error("StringFilter: Index_type is undefined.");
return;
}
if (searchStr == null || network == null || !FilterUtil.hasSuchAttribute(network, controllingAttribute, index_type)) {
return;
}
// If quickFind_index does not exist, build the Index
// if (quickFind_index == null) {
quickFind_index = FilterUtil.getQuickFindIndex(quickFind, controllingAttribute, network, index_type);
// }
TextIndex theIndex = (TextIndex) quickFind_index;
Hit[] hits = theIndex.getHits(searchStr, Integer.MAX_VALUE);
if (hits.length == 0) {
return;
}
Hit hit0 = hits[0];
Object[] hit_objs = hit0.getAssociatedObjects();
int index = -1;
if (index_type == QuickFind.INDEX_NODES) {
for (Object obj : hit_objs) {
index = nodes_list.indexOf(obj);
node_bits.set(index, true);
}
} else if (index_type == QuickFind.INDEX_EDGES) {
for (Object obj : hit_objs) {
index = edges_list.indexOf(obj);
edge_bits.set(index, true);
}
}
if (negation) {
if (index_type == QuickFind.INDEX_NODES) {
node_bits.flip(0, objectCount);
}
if (index_type == QuickFind.INDEX_EDGES) {
edge_bits.flip(0, objectCount);
}
}
}
use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.
the class ApplyFilterThread method passAtomicFilter.
private boolean passAtomicFilter(CyNetwork network, Object pObject, AtomicFilter pAtomicFilter) {
CyRow data = null;
if (pObject instanceof CyNode) {
CyNode node = (CyNode) pObject;
data = network.getRow(node);
} else {
CyEdge edge = (CyEdge) pObject;
data = network.getRow(edge);
}
if (pAtomicFilter instanceof StringFilter) {
StringFilter theStringFilter = (StringFilter) pAtomicFilter;
String value = data.get(theStringFilter.getControllingAttribute().substring(5), String.class);
if (value == null) {
return false;
}
if (theStringFilter == null) {
return false;
}
if (theStringFilter.getSearchStr() == null) {
return false;
}
String[] pattern = theStringFilter.getSearchStr().split("\\s");
for (int p = 0; p < pattern.length; ++p) {
if (!Strings.isLike(value, pattern[p], 0, true)) {
// this is an OR function
return false;
}
}
} else if (pAtomicFilter instanceof NumericFilter) {
NumericFilter theNumericFilter = (NumericFilter) pAtomicFilter;
Number value;
if (data.getTable().getColumn(theNumericFilter.getControllingAttribute().substring(5)).getType() == Double.class)
value = data.get(theNumericFilter.getControllingAttribute().substring(5), Double.class);
else
value = data.get(theNumericFilter.getControllingAttribute().substring(5), Integer.class);
if (value == null) {
return false;
}
Double lowValue = (Double) theNumericFilter.getLowBound();
Double highValue = (Double) theNumericFilter.getHighBound();
// To correct the boundary values for lowValue and highValue
if (lowValue.doubleValue() > 0.0) {
lowValue = lowValue * 0.99999;
} else {
lowValue = lowValue * 1.00001;
}
if (highValue.doubleValue() > 0.0) {
highValue = highValue * 1.00001;
} else {
highValue = highValue * 0.99999;
}
// if (!(value.doubleValue() >= lowValue.doubleValue() && value.doubleValue()<= highValue.doubleValue())) {
if (!((Double.compare(value.doubleValue(), lowValue.doubleValue()) >= 0) && (Double.compare(value.doubleValue(), highValue.doubleValue())) <= 0)) {
return false;
}
}
return true;
}
Aggregations