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