[61e40d]: / network / DisGraph.java

Download this file

128 lines (103 with data), 2.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package network;
import java.util.Iterator;
import java.util.Map;
/**
* Provides routine methods for DisGraph operation
* @author zhengc
*
*/
public class DisGraph {
private SparseMatrix disnet;
/**
* Initialize a DisGraph represented as a SparseMatrix
* @param n number of nodes
*/
public DisGraph(int n) {
disnet = new SparseMatrix(n);
}
/**
* Add edge between two nodes (Integer)
* @param d1
* @param d2
* @param score
*/
public void addEdge(int d1, int d2, double score) {
disnet.put(d1, d2, score);
disnet.put(d2, d1, score);
}
/**
* Add edge between two nodes (Integer), weight is set to 1
* @param d1
* @param d2
*/
public void addEdge(int d1, int d2) {
disnet.put(d1, d2, 1);
disnet.put(d2, d1, 1);
}
/**
* Add edge between two nodes (CommNode)
* @param node1
* @param node2
*/
public void addEdge(CommNode node1, CommNode node2) {
int d1 = node1.getIndex();
int d2 = node2.getIndex();
disnet.put(d1, d2, 1);
disnet.put(d2, d1, 1);
}
/**
* Get neighbor nodes for given node
* @param d
* @return a SparseVector representing the neighbor nodes
*/
public SparseVector getNeibor(int d) {
return disnet.getNeibor(d);
}
/**
* Remove one edge
* @param d1 node 1
* @param d2 node 2
*/
public void removeEdge(int d1, int d2) {
disnet.put(d1, d2, 0);
disnet.put(d2, d1, 0);
}
/**
* Remove all edges between disease and its OMIM genes
* @param dis a disease node
*/
public void removeEdges(int dis) {
SparseVector nb = disnet.getNeibor(dis);
Iterator<Integer> keys = nb.iterator();
while(keys.hasNext()) {
int key = keys.next();
// System.out.println(key);
if (key > CommGeneticsLoader.num_disease) {
// System.out.println("Removing link " + key);
keys.remove();
removeEdge(dis, key);
}
}
}
/**
* Get number of edges of the DisGraph
* @return number of edges of the DisGraph
*/
public int getEdges() {
return this.getNet().nnz() / 2; // symmetric network
}
/**
* Get number of nodes of the DisGraph
* @return number of nodes of the DisGraph
*/
public int getNodes() {
return disnet.size();
}
/**
* Get the SparseMatrix of the DisGraph
* @return
*/
public SparseMatrix getNet() {
return disnet;
}
}