1 |
duarte |
420 |
package proteinstructure; |
2 |
|
|
|
3 |
|
|
import java.util.HashMap; |
4 |
|
|
import java.util.TreeMap; |
5 |
|
|
|
6 |
|
|
import edu.uci.ics.jung.graph.util.EdgeType; |
7 |
|
|
import edu.uci.ics.jung.graph.util.Pair; |
8 |
|
|
|
9 |
|
|
/** |
10 |
|
|
* An Atom Interaction Graph |
11 |
|
|
* |
12 |
|
|
*/ |
13 |
|
|
public class AIGraph extends ProtStructGraph<AIGNode,AIGEdge> { |
14 |
|
|
|
15 |
|
|
private static final long serialVersionUID = 1L; |
16 |
|
|
|
17 |
|
|
private boolean crossed; // true if this AIGraph has been obtained from a cross contact type (the ones with "/") |
18 |
|
|
private double distCutoff; |
19 |
|
|
|
20 |
|
|
public AIGraph() { |
21 |
|
|
super(); |
22 |
|
|
this.crossed = false; |
23 |
|
|
this.distCutoff = 0; |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
public double getCutoff() { |
27 |
|
|
return distCutoff; |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
public void setCutoff(double distCutoff) { |
31 |
|
|
this.distCutoff = distCutoff; |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
public boolean isCrossed() { |
35 |
|
|
return crossed; |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
public void setCrossed(boolean crossed) { |
39 |
|
|
this.crossed = crossed; |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
/** |
43 |
|
|
* Returns a RIGraph by collapsing atom contacts into residue contacts, |
44 |
|
|
* using the number of atom edges per residue as the atom weights for the RIGEdges |
45 |
|
|
* TODO eventually we can pass a parameter for other ways of assigning atom contact weights |
46 |
|
|
* @return |
47 |
|
|
*/ |
48 |
|
|
public RIGraph getRIGraph() { |
49 |
|
|
EdgeType et = EdgeType.UNDIRECTED; |
50 |
duarte |
421 |
|
51 |
|
|
// TODO we still use here DIRECTED as default for crossed, eventually this should change by taking another parameter "boolean directed", so crossed could have DIRECTED/UNDIRECTED versions |
52 |
duarte |
420 |
if (this.isCrossed()) { |
53 |
|
|
et = EdgeType.DIRECTED; |
54 |
|
|
} |
55 |
|
|
RIGraph resGraph = new RIGraph(); |
56 |
|
|
resGraph.setPdbCode(this.pdbCode); |
57 |
|
|
resGraph.setChainCode(this.chainCode); |
58 |
|
|
resGraph.setPdbChainCode(this.pdbChainCode); |
59 |
|
|
resGraph.setModel(this.model); |
60 |
|
|
resGraph.setSequence(this.sequence); |
61 |
|
|
|
62 |
|
|
TreeMap<Integer,RIGNode> rignodes = new TreeMap<Integer,RIGNode>(); |
63 |
|
|
for (AIGNode atomNode:this.getVertices()) { |
64 |
|
|
RIGNode resNode = atomNode.getParent(); |
65 |
|
|
int resser = resNode.getResidueSerial(); |
66 |
|
|
rignodes.put(resser, resNode); // we put in the map each RIGNode several times, that should be fine |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
resGraph.setSerials2NodesMap(rignodes); |
70 |
|
|
|
71 |
|
|
// putting the RIGnodes into the RIGraph |
72 |
|
|
for (int resser:rignodes.keySet()){ |
73 |
|
|
resGraph.addVertex(rignodes.get(resser)); |
74 |
|
|
} |
75 |
|
|
// collapsing atomPairs into resPairs and counting atom contacts to assign atom weights |
76 |
|
|
HashMap<Pair<RIGNode>,Integer> pairs2weights = new HashMap<Pair<RIGNode>, Integer>(); |
77 |
|
|
for (AIGEdge atomEdge: this.getEdges()){ |
78 |
|
|
Pair<AIGNode> atomPair = this.getEndpoints(atomEdge); |
79 |
|
|
RIGNode v1 = atomPair.getFirst().getParent(); |
80 |
|
|
RIGNode v2 = atomPair.getSecond().getParent(); |
81 |
|
|
Pair<RIGNode> resPair = new Pair<RIGNode>(v1,v2); |
82 |
|
|
if (v1!=v2) { |
83 |
|
|
if (!pairs2weights.containsKey(resPair)) { |
84 |
duarte |
421 |
//NOTE the pairs2weights map takes care of eliminating duplicate residue pairs (Maps don't accept duplicate as keys) |
85 |
duarte |
420 |
pairs2weights.put(resPair, 1); |
86 |
|
|
} else { |
87 |
|
|
pairs2weights.put(resPair,pairs2weights.get(resPair)+1); |
88 |
|
|
} |
89 |
|
|
} |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
// putting the RIGEdges in the resGraph |
93 |
|
|
for (Pair<RIGNode> resPair:pairs2weights.keySet()) { |
94 |
|
|
//TODO put distance in the RIGEdge objects (only makes sense in single atom contact types) |
95 |
|
|
RIGEdge e = new RIGEdge(pairs2weights.get(resPair)); |
96 |
|
|
resGraph.addEdge(e, resPair, et);//(e, pair, et); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
return resGraph; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
public int getContactRange(AIGEdge edge) { |
103 |
|
|
Pair<AIGNode> pair = this.getEndpoints(edge); |
104 |
|
|
return Math.abs(pair.getFirst().getParent().getResidueSerial()-pair.getSecond().getParent().getResidueSerial()); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
} |