File: PalindromeTracker.java

package info (click to toggle)
bbmap 39.20%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,024 kB
  • sloc: java: 312,743; sh: 18,099; python: 5,247; ansic: 2,074; perl: 96; makefile: 39; xml: 38
file content (109 lines) | stat: -rwxr-xr-x 3,288 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package tracker;

import repeat.Palindrome;
import shared.Tools;
import structures.ByteBuilder;
import structures.LongList;

/**
 * Tracks palindrome stats to determine which kind occur in a given feature.
 * 
 * @author Brian Bushnell
 * @date Sept 3, 2023
 *
 */
public class PalindromeTracker {
	
	/*--------------------------------------------------------------*/
	/*----------------        Initialization        ----------------*/
	/*--------------------------------------------------------------*/
	
	public void add(final Palindrome p, final int a0, final int b0) {
		int tail1=p.a-a0, tail2=b0-p.a;
		if(tail1>tail2) {
			int x=tail1;
			tail1=tail2;
			tail2=x;
		}
		int tailDif=tail2-tail1;
		int rlen=b0-a0+1;
		plenList.increment(p.plen());
		loopList.increment(p.loop());
		tailList.increment(tail1);
		tailList.increment(tail2);
		tailDifList.increment(tailDif);
		matchList.increment(p.matches);
		mismatchList.increment(p.mismatches);
		rlenList.increment(rlen);
		found++;
	}
	
	/*--------------------------------------------------------------*/
	/*----------------           Methods            ----------------*/
	/*--------------------------------------------------------------*/
	
	public PalindromeTracker add(PalindromeTracker p) {
		for(int i=0; i<lists.length; i++) {
			lists[i].incrementBy(p.lists[i]);
		}
		found+=p.found;
		return this;
	}
	
	public ByteBuilder appendTo(ByteBuilder bb) {
		return append(bb, "#Value\tplen\tloop\ttail\ttaildif\tmatch\tmismtch\trlen", lists, histmax);
	}
	
	@Override
	public String toString() {
		return appendTo(new ByteBuilder()).toString();
	}
	
	/*--------------------------------------------------------------*/
	/*----------------        Static Methods        ----------------*/
	/*--------------------------------------------------------------*/
	
	/** Can be used to make generic histograms */
	public static ByteBuilder append(ByteBuilder bb, String header, LongList[] lists, int histmax) {
		int maxSize=1;
		for(LongList ll : lists) {
			ll.capHist(histmax);
			maxSize=Tools.max(maxSize, ll.size);
		}
		
		bb.append(header).nl();
		
		for(int i=0; i<maxSize; i++) {
			bb.append(i);
			for(LongList ll : lists) {
				bb.tab().append(ll.get(i));
			}
			bb.nl();
		}
		return bb;
	}
	
	/*--------------------------------------------------------------*/
	/*----------------            Fields            ----------------*/
	/*--------------------------------------------------------------*/

	public long found=0;
	
	public LongList plenList=new LongList();
	public LongList loopList=new LongList();
	public LongList tailList=new LongList();
	public LongList tailDifList=new LongList();
	public LongList matchList=new LongList();
	public LongList mismatchList=new LongList();
	public LongList rlenList=new LongList();//Region of interest length
	
	public final LongList[] lists={plenList, loopList, tailList, 
			tailDifList, matchList, mismatchList, rlenList};
	
	/*--------------------------------------------------------------*/
	/*----------------           Statics            ----------------*/
	/*--------------------------------------------------------------*/
	
	public static int histmax=50;
	
}