-
Notifications
You must be signed in to change notification settings - Fork 0
/
Protein.java
153 lines (135 loc) · 3.5 KB
/
Protein.java
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
public class Protein {
String pname;
LinkedList<Node> neighbours=new LinkedList<>();
Protein()
{}
Protein(String name)
{pname=name;
//neighbours=new LinkedList<>();
}
///////// PROTEIN CLONING: CREATE AN IDENTICAL COPY OF PROTEIN /////////////
public Protein proteinCopy()
{Protein newProtein=new Protein();
newProtein.pname=this.pname;
for(Node tnode:this.neighbours)
{ Node newNode=new Node();
newNode.nname=tnode.nname;
newProtein.neighbours.add(newNode);
}
return newProtein;
}
}
class Complex
{ArrayList<String> cProtein=new ArrayList<>();
ArrayList<String>core=new ArrayList<>();
ArrayList<String>attachment=new ArrayList<>();
}
class Pair
{String pair1;
String pair2;
double weight;
}
class Node
{
String nname;
}
class Interactions
{
String protein1;
String protein2;
String value;
}
class Gene{
String gname;
ArrayList<Double> expValue=new ArrayList<>();
}
class Graph {
ArrayList<Protein> ProteinChain=new ArrayList<>();
/////////// CREATES AN IDENTICAL COPY OF A GRAPH //////////
public Graph graphCopy()
{ Graph tgraph=new Graph();
for(Protein protein:ProteinChain)
{ Protein tProtein;
tProtein=protein.proteinCopy();
tgraph.ProteinChain.add(protein);
}
return tgraph;
}
///// TO FIND THE DENSITY OF A GRAPH /////////////////
public double find_density()
{ double density=0.0;
double tweight=0.0;
double n=ProteinChain.size();
for (Protein ProteinChain1 : ProteinChain)
{ double pweight=0.0;
for(Node tempNode:ProteinChain1.neighbours)
{pweight=pweight++;
}
tweight=tweight+pweight;
}
density= tweight/(n*(n-1));
return density;
}
/////////////////// ARRANGING GRAPH AGTER ADDING OR REMOVING VERTICES////////
public void arrangeGraph()
{LinkedList<String> tlist=new LinkedList<>();
for(Protein protein:ProteinChain)
{ tlist.add(protein.pname);
}
for(Protein protein:ProteinChain)
{ LinkedList<Node> nodeList=new LinkedList<>();
for(Node node:protein.neighbours)
{ if(tlist.contains(node.nname))
{ nodeList.add(node);
}
}
protein.neighbours=nodeList;
}
}
///////////// ARRANGING GRAPH SIMILAR TO arrangeGraph() /////////////
public Graph arrange()
{ ArrayList<String> graphProteins=new ArrayList<>();
ArrayList<Pair> pairList=new ArrayList<>();
Graph graph=new Graph();
for(Protein protein:ProteinChain)
{ String nameP=protein.pname;
graphProteins.add(nameP);
for(Node node:protein.neighbours)
{ Pair tpair=new Pair();
tpair.pair1=nameP;
tpair.pair2=node.nname;
pairList.add(tpair);
}
}
for(String nameP:graphProteins)
{ Protein protein=new Protein();
protein.pname=nameP;
ArrayList<String> tempNames=new ArrayList<>();
for(Pair pair:pairList)
{ if(pair.pair1.contentEquals(nameP))
{ if(graphProteins.contains(pair.pair2))
if(!tempNames.contains(pair.pair2))
{ Node node=new Node();
node.nname=pair.pair2;
protein.neighbours.add(node);
tempNames.add(node.nname);
}
}
else if(pair.pair2.contentEquals(nameP))
{ if(graphProteins.contains(pair.pair1))
{if(!tempNames.contains(pair.pair1))
{ Node node=new Node();
node.nname=pair.pair1;
protein.neighbours.add(node);
tempNames.add(node.nname);
}}
}
}
graph.ProteinChain.add(protein);
}
return graph;
}
}