| 1 | package prok; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | |
| 5 | import json.JsonObject; |
| 6 | import shared.Tools; |
| 7 | import structures.ByteBuilder; |
| 8 | |
| 9 | public class ScoreTracker { |
| 10 | |
| 11 | public ScoreTracker(int type_){ |
| 12 | type=type_; |
| 13 | } |
| 14 | |
| 15 | public void add(ScoreTracker st){ |
| 16 | geneStartScoreSum+=st.geneStartScoreSum; |
| 17 | geneStopScoreSum+=st.geneStopScoreSum; |
| 18 | geneInnerScoreSum+=st.geneInnerScoreSum; |
| 19 | lengthSum+=st.lengthSum; |
| 20 | |
| 21 | geneStartScoreCount+=st.geneStartScoreCount; |
| 22 | geneStopScoreCount+=st.geneStopScoreCount; |
| 23 | geneInnerScoreCount+=st.geneInnerScoreCount; |
| 24 | lengthCount+=st.lengthCount; |
| 25 | } |
| 26 | |
| 27 | public void add(ArrayList<Orf>[] array){ |
| 28 | for(ArrayList<Orf> list : array){add(list);} |
| 29 | } |
| 30 | |
| 31 | public void add(ArrayList<Orf> list){ |
| 32 | if(list==null){return;} |
| 33 | for(Orf orf : list){ |
| 34 | if(orf.type==type){add(orf);} |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | public void add(Orf orf){ |
| 39 | if(orf==null || orf.type!=type){return;} |
| 40 | geneStartScoreSum+=orf.startScore; |
| 41 | geneStopScoreSum+=orf.stopScore; |
| 42 | geneInnerScoreSum+=orf.averageKmerScore(); |
| 43 | lengthSum+=orf.length(); |
| 44 | |
| 45 | geneStartScoreCount++; |
| 46 | geneStopScoreCount++; |
| 47 | geneInnerScoreCount++; |
| 48 | lengthCount++; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public String toString(){ |
| 53 | ByteBuilder bb=new ByteBuilder(); |
| 54 | bb.append("Start Score: \t ").append(geneStartScoreSum/geneStartScoreCount, 4).nl(); |
| 55 | bb.append("Stop Score: \t ").append(geneStopScoreSum/geneStopScoreCount, 4).nl(); |
| 56 | bb.append("Inner Score: \t ").append(geneInnerScoreSum/geneInnerScoreCount, 4).nl(); |
| 57 | bb.append("Length: \t ").append(lengthSum/(double)lengthCount, 2).nl(); |
| 58 | if(genomeSize>0){ |
| 59 | bb.append("Approx Genic Fraction:\t ").append(Tools.min(1.0, lengthSum/(double)genomeSize), 4).nl(); |
| 60 | } |
| 61 | return bb.toString(); |
| 62 | } |
| 63 | |
| 64 | public JsonObject toJson(){ |
| 65 | JsonObject jo=new JsonObject(); |
| 66 | jo.addLiteral("Start Score", geneStartScoreSum/geneStartScoreCount, 4); |
| 67 | jo.addLiteral("Stop Score", geneStopScoreSum/geneStopScoreCount, 4); |
| 68 | jo.addLiteral("Inner Score", geneInnerScoreSum/geneInnerScoreCount, 4); |
| 69 | jo.addLiteral("Length", lengthSum/(double)lengthCount, 2); |
| 70 | if(genomeSize>0){ |
| 71 | jo.addLiteral("Approx Genic Fraction", Tools.min(1.0, lengthSum/(double)genomeSize), 4); |
| 72 | } |
| 73 | return jo; |
| 74 | } |
| 75 | |
| 76 | long geneStartScoreCount=0; |
| 77 | long geneStopScoreCount=0; |
| 78 | long geneInnerScoreCount=0; |
| 79 | long lengthCount=0; |
| 80 | |
| 81 | double geneStartScoreSum=0; |
| 82 | double geneStopScoreSum=0; |
| 83 | double geneInnerScoreSum=0; |
| 84 | long lengthSum=0; |
| 85 | |
| 86 | long genomeSize=0; |
| 87 | |
| 88 | final int type; |
| 89 | |
| 90 | } |