Debian Codegraph @

current/tracker/PalindromeTracker.java

raw symbols SCIP
1 package tracker;
2
3 import repeat.Palindrome;
4 import shared.Tools;
5 import structures.ByteBuilder;
6 import structures.LongList;
7
8 /**
9 * Tracks palindrome stats to determine which kind occur in a given feature.
10 *
11 * @author Brian Bushnell
12 * @date Sept 3, 2023
13 *
14 */
15 public class PalindromeTracker {
16
17 /*--------------------------------------------------------------*/
18 /*---------------- Initialization ----------------*/
19 /*--------------------------------------------------------------*/
20
21 public void add(final Palindrome p, final int a0, final int b0) {
22 int tail1=p.a-a0, tail2=b0-p.a;
23 if(tail1>tail2) {
24 int x=tail1;
25 tail1=tail2;
26 tail2=x;
27 }
28 int tailDif=tail2-tail1;
29 int rlen=b0-a0+1;
30 plenList.increment(p.plen());
31 loopList.increment(p.loop());
32 tailList.increment(tail1);
33 tailList.increment(tail2);
34 tailDifList.increment(tailDif);
35 matchList.increment(p.matches);
36 mismatchList.increment(p.mismatches);
37 rlenList.increment(rlen);
38 found++;
39 }
40
41 /*--------------------------------------------------------------*/
42 /*---------------- Methods ----------------*/
43 /*--------------------------------------------------------------*/
44
45 public PalindromeTracker add(PalindromeTracker p) {
46 for(int i=0; i<lists.length; i++) {
47 lists[i].incrementBy(p.lists[i]);
48 }
49 found+=p.found;
50 return this;
51 }
52
53 public ByteBuilder appendTo(ByteBuilder bb) {
54 return append(bb, "#Value\tplen\tloop\ttail\ttaildif\tmatch\tmismtch\trlen", lists, histmax);
55 }
56
57 @Override
58 public String toString() {
59 return appendTo(new ByteBuilder()).toString();
60 }
61
62 /*--------------------------------------------------------------*/
63 /*---------------- Static Methods ----------------*/
64 /*--------------------------------------------------------------*/
65
66 /** Can be used to make generic histograms */
67 public static ByteBuilder append(ByteBuilder bb, String header, LongList[] lists, int histmax) {
68 int maxSize=1;
69 for(LongList ll : lists) {
70 ll.capHist(histmax);
71 maxSize=Tools.max(maxSize, ll.size);
72 }
73
74 bb.append(header).nl();
75
76 for(int i=0; i<maxSize; i++) {
77 bb.append(i);
78 for(LongList ll : lists) {
79 bb.tab().append(ll.get(i));
80 }
81 bb.nl();
82 }
83 return bb;
84 }
85
86 /*--------------------------------------------------------------*/
87 /*---------------- Fields ----------------*/
88 /*--------------------------------------------------------------*/
89
90 public long found=0;
91
92 public LongList plenList=new LongList();
93 public LongList loopList=new LongList();
94 public LongList tailList=new LongList();
95 public LongList tailDifList=new LongList();
96 public LongList matchList=new LongList();
97 public LongList mismatchList=new LongList();
98 public LongList rlenList=new LongList();//Region of interest length
99
100 public final LongList[] lists={plenList, loopList, tailList,
101 tailDifList, matchList, mismatchList, rlenList};
102
103 /*--------------------------------------------------------------*/
104 /*---------------- Statics ----------------*/
105 /*--------------------------------------------------------------*/
106
107 public static int histmax=50;
108
109 }