Debian Codegraph @

current/bin/Key.java

raw symbols SCIP
1 package bin;
2
3 import shared.Tools;
4
5 class Key implements Cloneable {
6
7 static boolean parse(String arg, String a, String b) {
8
9 if(a.equalsIgnoreCase("gcwidth")){
10 float f=Float.parseFloat(b);
11 setGCWidth(f);
12 }else if(a.equalsIgnoreCase("gcmult")){
13 float f=Float.parseFloat(b);
14 setGCMult(f);
15 }else if(a.equalsIgnoreCase("depthwidth")){
16 float f=Float.parseFloat(b);
17 setDepthWidth(f);
18 }else if(a.equalsIgnoreCase("depthmult")){
19 float f=Float.parseFloat(b);
20 setDepthMult(f);
21 }else {
22 return false;
23 }
24 return true;
25 }
26
27 public Key(float gc, float cov, float cov2) {
28 setValue(gc, cov, cov2);
29 }
30
31 public Key() {}
32
33 public Key set(Bin a) {
34 return setValue(a.gc(), a.depth(0), a.depth(1));
35 }
36
37 public Key setLevel(int gcLevel_, int covLevel_, int covLevel2_) {
38 gcLevel=gcLevel_;
39 covLevel=covLevel_;
40 covLevel2=covLevel2_;
41 assert(gcLevel>=0 && gcLevel<=(int)gcLevelMult);
42 assert(covLevel>=0 && covLevel<=maxDepthLevel) : covLevel+", "+maxDepthLevel;
43 assert(covLevel2>=0 && covLevel2<=maxDepthLevel) : covLevel2+", "+maxDepthLevel;
44 return this;
45 }
46
47 public Key setValue(float gc, float cov, float cov2) {
48 assert(gc>=0 && gc<=1) : gc;
49 assert(cov>=0) : cov;
50 assert(cov2>=0) : cov;
51 return setLevel(quantizeGC(gc), quantizeDepth(cov), quantizeDepth(cov2));
52 }
53
54 @Override
55 public boolean equals(Object other) {
56 return equals((Key)other);
57 }
58
59 public boolean equals(Key b) {
60 return gcLevel==b.gcLevel && covLevel==b.covLevel && covLevel2==b.covLevel2;
61 }
62
63 @Override
64 public int hashCode() {
65 return covLevel+(covLevel2<<10)+(gcLevel<<20);
66 }
67
68 @Override
69 public Key clone() {
70 try {
71 return (Key)(super.clone());
72 } catch (CloneNotSupportedException e) {
73 throw new RuntimeException(e);
74 }
75 }
76
77 //This is probably faster but not as simple to explain or adjust
78 // public static int quantizeDepth(float depth) {
79 // float yf=depth*depth*16;
80 // long y=(long)yf;
81 // int zeros=Long.numberOfLeadingZeros(y);
82 // int level=Tools.min(maxDepthLevel, 64-zeros);
83 // return level;
84 // }
85
86 public static int quantizeDepth(float depth) {
87 depth=Tools.min(depth, maxDepth);
88 float yf=((float)(Tools.log2(depth+0.0625f)+4));
89 int level=(int)(yf*depthLevelMult);
90 return level;
91 }
92
93 public static int quantizeGC(float gc) {
94 return (int)(Tools.mid(0,gc,1)*gcLevelMult);
95 }
96
97 public String toString() {
98 return "("+gcLevel+","+covLevel+","+covLevel2+")";
99 }
100
101 static final void setGCMult(float f) {
102 assert(f>=2);
103 setGCWidth(1/f);
104 }
105
106 static final void setGCWidth(float f) {
107 assert(f>0 && f<=0.5f);
108 gcLevelWidth=f;
109 gcLevelMult=1f/gcLevelWidth;
110 }
111
112 static final void setDepthWidth(float f) {
113 assert(f>0);
114 setDepthMult(1/f);
115 }
116
117 static final void setDepthMult(float f) {
118 assert(f>0);
119 depthLevelMult=f;
120 maxDepthLevel=quantizeDepth(maxDepth);
121 assert(maxDepthLevel>0) : "maxDepthLevel="+maxDepthLevel+", depthLevelMult="+depthLevelMult+
122 ", maxDepth="+maxDepth+", yf="+(Tools.log2(maxDepth+0.0625f)+4);
123 }
124
125 int gcLevel;
126 int covLevel;
127 int covLevel2;
128
129 //gcwidth=0.01, depthwidth=0.25 seems faster, more sensitive, and more specific (halving both of them).
130 private static final float maxDepth=1000000;
131 private static float depthLevelMult=2f;
132 private static float gcLevelWidth=0.02f;
133 private static float gcLevelMult=1f/gcLevelWidth;
134 private static int maxDepthLevel=quantizeDepth(maxDepth);
135
136 }