annotate NGSrich_0.5.5/src/middlewares/HitsCounter.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1 package middlewares;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
2 import java.util.Vector;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 * Counts the number of bases hit at least 1, 5, 10, 20 or 30 times.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7 * @author Ali Abdallah
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 * @version 22.07.2011
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 * @since Java 1.6
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11 public class HitsCounter {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14 * The hits vector with the number of bases hit at different levels.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 private Vector<Integer> hits;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19 * The number of bases hit at the five different levels for a specific
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 * target.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 private Vector<Integer> currentHits;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 * The levels at which the number of bases is counted.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27 private int[] levels = { 1, 5, 10, 20, 30 };
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 * Creates and initializes a hit counter.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 public HitsCounter() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 hits = new Vector<Integer>();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 currentHits = new Vector<Integer>();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35 for (int i = 0; i < levels.length; i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 hits.add(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 currentHits.add(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 * Update the number of bases hit at the specified different levels.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 public void updateHits() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 for (int i = 0; i < hits.size(); i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 hits.set(i, hits.get(i) + currentHits.get(i));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 * Reset the number of bases hit at the specified different leverls for
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 * a specific target for user for the next target.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54 public void resetCurrentHits() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 currentHits = new Vector<Integer>();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56 for (int i = 0; i < levels.length; i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 currentHits.add(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 * Increments the number of bases hit at some levels by one, if the number
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 * of hits on this base reach or exceed this level.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 * @param hitsOnBase
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 public void updateCurrentHits(int hitsOnBase) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 for (int i = 0; i < currentHits.size(); i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 if (hitsOnBase >= levels[i]) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 currentHits.set(i, currentHits.get(i) + 1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 // Index of the bases level of the current target.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 int currHit = 0;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 * @return the number of bases hit at the next higher level in the current
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 * target.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 public int getNextLevelCurrentHits() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 if (currHit < currentHits.size())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 return currentHits.get(currHit++);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 currHit = 1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 return currentHits.get(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 // Index of the bases level of the target.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 int hit = -1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95 * @return the number of bases hit at the next higher level.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 public int getNextLevelHits() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98 if (++hit < hits.size()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99 return hits.get(hit);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101 return (hit = -1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 }