annotate NGSrich_0.5.5/src/datastructures/GenomeFrame.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 datastructures;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3 import java.util.Vector;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 * @author Ali Abdallah
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7 * @version 01.2011
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 * @since jdk 1.6.0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11 public class GenomeFrame extends Frame{
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 int limit;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14 Vector<Integer> hits;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 public GenomeFrame(int start, int length) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 super(start, length);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 limit = end;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19 hits = new Vector<Integer>(length);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 hits.setSize(length);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 for(int i = 0; i < length; i++){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 hits.set(i, 0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 public int getHit(int base){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27 if(base-start < hits.size())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 return hits.get(base-start);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 else
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 return -1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 public void setHit(int base, int bhits){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 if(base-start < hits.size()){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35 hits.set(base-start, bhits);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 public boolean contains(ReadFrame r){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 return (start <= r.start() && end >= r.end());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 public boolean overlaps(ReadFrame r){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 return (end >= r.start() && end < r.end());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 public void addBases(int nr){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 for(int i = 0; i < nr; i++){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 hits.add(1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 public String toString(){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56 return start+":"+end+" ("+limit+")";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60 public void updateHits(ReadFrame read) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 for(int base = read.start(); base <= read.end(); base++){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 setHit(base, getHit(base)+1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 public void updateFrameFromRightEnd(ReadFrame readF) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 // TODO Auto-generated method stub
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 for(int i = end+1; i <= readF.end(); i++)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 hits.add(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 end = readF.end();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 public boolean limitExceeded(ReadFrame readF) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 return readF.start() > limit;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 public void updateFrameFromBothEnds(ReadFrame readF, int length) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 for(int i = end-readF.start()+1; i < length; i++ )
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 hits.add(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 for(int i = 0; i < readF.start()-start; i++)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 hits.remove(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 start = readF.start();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 end = start+length-1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 limit = end;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 }