-
Notifications
You must be signed in to change notification settings - Fork 0
/
goParal.java
176 lines (156 loc) · 6.48 KB
/
goParal.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package biomarker1;
/*
* Paralell process for microsatellite search
*/
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
public class goParal {
ArrayList Respaldo = new ArrayList();
public void primerCorrida(int inic, int finl, int filtro, String subseq, String path) throws InstantiationException, ClassNotFoundException, IllegalAccessException {
ArrayList seqs = new ArrayList();
ArrayList workers = new ArrayList();
ArrayList names = new ArrayList();
FastaFileConsole FR = new FastaFileConsole();
panel panel = new panel();
panel.filtro = filtro;
panel.subseq = subseq;
panel.tamanio_final = finl;
panel.tamanio_inicial = inic;
panel.path = path;
panel.actualiza();
System.out.println(panel.path);
FR.use(panel.path);
seqs = FR.armaSeqs();
names = FR.armaNames();
this.Respaldo = (ArrayList) seqs.clone();
names.add(">MicroSat");
final String name1 = (String) names.get(0); //saves the first sequence as the problem sequence
final String S1 = (String) seqs.get(0);
seqs.remove(0);
names.remove(0);
panel.seqs = seqs;
panel.names = names;
String SubSeqS1 = "";
int rangooffsetA = inic;
int rangooffsetB = finl;
worker wk1 = new worker(); //the parallel readers are named workers
worker wk2 = new worker();
ArrayList record = new ArrayList();
for (int i = rangooffsetA; i <= rangooffsetB; i++) {
int offset = i;
int indxI = 0;
int indxF = indxI + offset;
System.out.println("longitud actual: " + offset); //stablish the microsatellite length
int contador = 0;
Class miclase = Class.forName("biomarker1.worker");
printer printer = new printer();
while (indxF <= S1.length()) {
int c = 0;//**
while (seqs.size() > 0) {
System.out.println("seqs size " + seqs.size());
if (indxF <= S1.length()) {
SubSeqS1 = S1.substring(indxI, indxF);
String sTextoBuscado = SubSeqS1;
wk1.setup(sTextoBuscado, (String) seqs.get(seqs.size() - 1), seqs.size() - 1, printer);
seqs.remove(seqs.size() - 1);
wk2.setup(sTextoBuscado, (String) seqs.get(seqs.size() - 1), seqs.size() - 1, printer);
seqs.remove(seqs.size() - 1);
wk1.start(); //start the work
wk2.start();
try {
wk2.join();
wk1.join();
} catch (InterruptedException ex) {
Logger.getLogger(goParal.class.getName()).log(Level.SEVERE, null, ex);
}
wk1 = (worker) miclase.newInstance();
wk2 = (worker) miclase.newInstance();
}
System.gc();
}
indxI++;
indxF++;
while (this.compruebaBusy(workers) > 0) { //empty
}
workers.clear();
}
}
}
public void otraCorrida(int inic, int finl, int filtro, String subseq, String path) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
//process for a second run
ArrayList seqs = new ArrayList();
ArrayList workers = new ArrayList();
ArrayList names = new ArrayList();
FastaFileConsole FR = new FastaFileConsole();
panel panel = new panel();
panel.filtro = filtro;
panel.subseq = subseq;
panel.tamanio_final = finl;
panel.tamanio_inicial = inic;
panel.path = path;
panel.actualiza();
System.out.println(panel.path);
seqs = (ArrayList) this.Respaldo.clone();
System.out.println("segunda vez!!");
names.add(">Human");
String name1 = (String) names.get(0);
String S1 = (String) seqs.get(0);
seqs.remove(0);
names.remove(0);
panel.seqs = seqs;
panel.names = names;
String SubSeqS1 = "";
int rangooffsetA = inic;
int rangooffsetB = finl;
ArrayList record = new ArrayList();
for (int i = rangooffsetA; i <= rangooffsetB; i++) {
int offset = i;
int indxI = 0;
int indxF = indxI + offset;
int contador = 0;
String SeqTurno = null;
Class miclase = Class.forName("biomarker1.worker");
printer printer = new printer();
while (indxF <= S1.length()) {
int c = 0;//**
while (c <= seqs.size() - 1) {
if (this.compruebaBusy(workers) <= 4) {
SeqTurno = (String) seqs.get(c);
if (indxF <= S1.length()) { //creates worker
SubSeqS1 = S1.substring(indxI, indxF);
String sTextoBuscado = SubSeqS1;
worker miobjeto = (worker) miclase.newInstance();
miobjeto.setup(sTextoBuscado, SeqTurno, c, printer);
miobjeto.start();
workers.add(miobjeto);
c++;
}
}
System.gc();
}
indxI++;
indxF++;
while (this.compruebaBusy(workers) > 0) { //vacía
}
workers.clear();
}
}
}
public int compruebaBusy(ArrayList Lista) { //validation of busy readers
Iterator iT = Lista.iterator();
int c = 0;
while (iT.hasNext()) {
worker rd = new worker();
rd = (worker) iT.next();
if (rd.isAlive()) {
c++;
} else {
iT.remove();
}
}
return c;
}
}