Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/prok/StatsContainer.java @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 package prok; | |
2 | |
3 import java.util.Arrays; | |
4 | |
5 import shared.Tools; | |
6 import stream.Read; | |
7 import structures.ByteBuilder; | |
8 import structures.LongHashSet; | |
9 | |
10 class StatsContainer { | |
11 | |
12 /*--------------------------------------------------------------*/ | |
13 /*---------------- Initialization ----------------*/ | |
14 /*--------------------------------------------------------------*/ | |
15 | |
16 StatsContainer(int type_, int kInner, int framesInner, int kStart, int framesStart, int offsetStart, int kStop, int framesStop, int offsetStop){ | |
17 type=type_; | |
18 name=ProkObject.typeStrings[type]; | |
19 setInner(kInner, framesInner); | |
20 setStart(kStart, framesStart, offsetStart); | |
21 setStop(kStop, framesStop, offsetStop); | |
22 } | |
23 | |
24 StatsContainer(int type_){ | |
25 type=type_; | |
26 name=ProkObject.typeStrings[type]; | |
27 } | |
28 | |
29 void setInner(int kInner, int framesInner){ | |
30 assert(inner==null); | |
31 statsArray[0]=inner=new FrameStats(name+" inner", kInner, framesInner, 0); | |
32 } | |
33 | |
34 void setStart(int kStart, int framesStart, int offsetStart){ | |
35 assert(start==null); | |
36 statsArray[1]=start=new FrameStats(name+" start", kStart, framesStart, offsetStart); | |
37 } | |
38 | |
39 void setStop(int kStop, int framesStop, int offsetStop){ | |
40 assert(stop==null); | |
41 statsArray[2]=stop=new FrameStats(name+" stop", kStop, framesStop, offsetStop); | |
42 } | |
43 | |
44 void setInner(FrameStats fs){ | |
45 assert(inner==null); | |
46 assert(fs!=null); | |
47 statsArray[0]=inner=fs; | |
48 } | |
49 | |
50 void setStart(FrameStats fs){ | |
51 assert(start==null); | |
52 statsArray[1]=start=fs; | |
53 } | |
54 | |
55 void setStop(FrameStats fs){ | |
56 assert(stop==null); | |
57 statsArray[2]=stop=fs; | |
58 } | |
59 | |
60 /*--------------------------------------------------------------*/ | |
61 /*---------------- Methods ----------------*/ | |
62 /*--------------------------------------------------------------*/ | |
63 | |
64 @Override | |
65 public String toString(){ | |
66 return appendTo(new ByteBuilder()).toString(); | |
67 } | |
68 | |
69 public ByteBuilder appendTo(ByteBuilder bb) { | |
70 bb.append("#name\t").append(name).nl(); | |
71 bb.append("#type\t").append(type).nl(); | |
72 bb.append("#count\t").append(lengthCount).nl(); | |
73 bb.append("#lengthSum\t").append(lengthSum).nl(); | |
74 //lengths | |
75 bb.append("#contains\t").append(3).nl(); | |
76 if(ProkObject.processType(type)) { | |
77 for(FrameStats fs : statsArray){ | |
78 fs.appendTo(bb); | |
79 } | |
80 }else{ | |
81 for(FrameStats fs : statsArray){ | |
82 fs.append0(bb); | |
83 } | |
84 } | |
85 return bb; | |
86 } | |
87 | |
88 public void clear(){ | |
89 for(int i=0; i<statsArray.length; i++){ | |
90 if(statsArray[i]!=null){ | |
91 statsArray[i].clear(); | |
92 } | |
93 } | |
94 | |
95 assert(inner==statsArray[0]); | |
96 assert(start==statsArray[1]); | |
97 assert(stop==statsArray[2]); | |
98 | |
99 Arrays.fill(lengths, 0); | |
100 lengthSum=0; | |
101 lengthCount=0; | |
102 calculate(); | |
103 } | |
104 | |
105 public void setFrom(StatsContainer sc){ | |
106 assert(sc.name.equals(name)); | |
107 for(int i=0; i<statsArray.length; i++){ | |
108 FrameStats fs=sc.statsArray[i]; | |
109 if(statsArray[i]==null){ | |
110 statsArray[i]=new FrameStats(fs.name, fs.k, fs.frames, fs.leftOffset); | |
111 statsArray[i].add(fs); | |
112 }else{ | |
113 statsArray[i].setFrom(fs); | |
114 } | |
115 } | |
116 inner=statsArray[0]; | |
117 start=statsArray[1]; | |
118 stop=statsArray[2]; | |
119 | |
120 for(int i=0; i<lengths.length; i++){lengths[i]=sc.lengths[i];} | |
121 lengthSum=sc.lengthSum; | |
122 lengthCount=sc.lengthCount; | |
123 calculate(); | |
124 } | |
125 | |
126 public void add(StatsContainer sc){ | |
127 assert(sc.name.equals(name)); | |
128 for(int i=0; i<statsArray.length; i++){ | |
129 FrameStats fs=sc.statsArray[i]; | |
130 if(statsArray[i]==null){ | |
131 statsArray[i]=new FrameStats(fs.name, fs.k, fs.frames, fs.leftOffset); | |
132 } | |
133 statsArray[i].add(fs); | |
134 } | |
135 | |
136 inner=statsArray[0]; | |
137 start=statsArray[1]; | |
138 stop=statsArray[2]; | |
139 | |
140 Tools.add(lengths, sc.lengths); | |
141 lengthSum+=sc.lengthSum; | |
142 lengthCount+=sc.lengthCount; | |
143 calculate(); | |
144 } | |
145 | |
146 public void multiplyBy(double mult) { | |
147 for(int i=0; i<statsArray.length; i++){ | |
148 FrameStats fs=statsArray[i]; | |
149 fs.multiplyBy(mult); | |
150 } | |
151 | |
152 Tools.multiplyBy(lengths, mult); | |
153 lengthSum=Math.round(lengthSum*mult); | |
154 lengthCount=Math.round(lengthCount*mult); | |
155 calculate(); | |
156 } | |
157 | |
158 public void calculate(){ | |
159 for(int i=0; i<statsArray.length; i++){ | |
160 statsArray[i].calculate(); | |
161 } | |
162 lengthAvg=(int)(lengthSum/Tools.max(1.0, lengthCount)); | |
163 invLengthAvg=1f/Tools.max(1, lengthAvg); | |
164 } | |
165 | |
166 public void addLength(int x){ | |
167 lengthSum+=x; | |
168 lengthCount++; | |
169 lengths[Tools.min(x, lengths.length-1)]++; | |
170 } | |
171 | |
172 /*--------------------------------------------------------------*/ | |
173 /*---------------- Fields ----------------*/ | |
174 /*--------------------------------------------------------------*/ | |
175 | |
176 FrameStats inner; | |
177 FrameStats start; | |
178 FrameStats stop; | |
179 final FrameStats[] statsArray=new FrameStats[3]; | |
180 | |
181 int kLongLen(){return ProkObject.kLongLen(type);} | |
182 LongHashSet kmerSet(){return ProkObject.kmerSet(type);} | |
183 Read[] consensusSequence(){return ProkObject.consensusReads(type);} | |
184 float minIdentity(){return ProkObject.minID(type);} | |
185 | |
186 public int startSlop(){return ProkObject.startSlop(type);} | |
187 public int stopSlop(){return ProkObject.stopSlop(type);} | |
188 | |
189 final String name; | |
190 long lengthSum=0; | |
191 long lengthCount=0; | |
192 int lengthAvg=-1; | |
193 float invLengthAvg; | |
194 | |
195 int[] lengths=new int[5000]; | |
196 public final int type; | |
197 | |
198 } |