Debian Codegraph @

current/tracker/CrisprTracker.java

raw symbols SCIP
1 package tracker;
2
3 import shared.Tools;
4 import structures.ByteBuilder;
5 import structures.Crispr;
6 import structures.LongList;
7 import structures.Range;
8
9 /**
10 * Tracks crispr stats.
11 *
12 * @author Brian Bushnell
13 * @date Sept 5, 2023
14 *
15 */
16 public class CrisprTracker {
17
18 /*--------------------------------------------------------------*/
19 /*---------------- Initialization ----------------*/
20 /*--------------------------------------------------------------*/
21
22 public void add(final Crispr p, final byte[] s) {
23 Range r=(p.b.length()>p.a.length() ? p.b : p.a);
24 int sstart=p.a.b+1, sstop=p.b.a-1;
25 float rgc=Tools.calcGC(s, r.a, r.b);
26 float sgc=Tools.calcGC(s, sstart, sstop);
27 int rgci=(int)(Math.round(rgc*gcMult));
28 int sgci=(int)(Math.round(sgc*gcMult));
29 int rlen=r.length();
30 int slen=sstop-sstart+1;
31 int ulen=rlen+slen;
32 int tlen=p.b.b-p.a.a+1;
33
34 rlenList.increment(rlen);
35 slenList.increment(slen);
36 ulenList.increment(ulen);
37 tlenList.increment(tlen);
38 rgcList.increment(rgci);
39 sgcList.increment(sgci);
40 matchList.increment(p.matches);
41 mismatchList.increment(p.mismatches);
42 crisprsFound++;
43 // partialTipRepeats+=((p.a.length()==p.b.length()) ? 0 : 1);
44 partialTipRepeats+=((p.a.length()==p.b.length() && p.a.a>0 && p.b.b<s.length-1) ? 0 : 1);
45 //Matches, mismatches, and copies need to be incremented manually
46 }
47
48 /*--------------------------------------------------------------*/
49 /*---------------- Methods ----------------*/
50 /*--------------------------------------------------------------*/
51
52 public CrisprTracker add(CrisprTracker p) {
53 for(int i=0; i<lists.length; i++) {
54 lists[i].incrementBy(p.lists[i]);
55 }
56 crisprsFound+=p.crisprsFound;
57 readsWithCrisprs+=p.readsWithCrisprs;
58 trimmedByConsensus+=p.trimmedByConsensus;
59 partialTipRepeats+=p.partialTipRepeats;
60 modifiedByRef+=p.modifiedByRef;
61 alignedToRef+=p.alignedToRef;
62 failedAlignment+=p.failedAlignment;
63 alignments+=p.alignments;
64 alignmentRequested+=p.alignmentRequested;
65 return this;
66 }
67
68
69 public ByteBuilder appendTo(ByteBuilder bb) {
70 return PalindromeTracker.append(bb,
71 "#Value\trepeat\tspacer\tperiod\ttotal\trGC\tsGC\tmatch\tmismtch\tcopies\trefmm\trefmmv",
72 lists, histmax);
73 }
74
75 @Override
76 public String toString() {
77 return appendTo(new ByteBuilder()).toString();
78 }
79
80 /*--------------------------------------------------------------*/
81 /*---------------- Fields ----------------*/
82 /*--------------------------------------------------------------*/
83
84 private final int[] acgtn=new int[5];
85
86 public long crisprsFound=0;
87 public long readsWithCrisprs=0;
88 public long trimmedByConsensus=0;
89 public long partialTipRepeats=0;
90 public long alignedToRef=0;
91 public long modifiedByRef=0;
92 public long failedAlignment=0;
93 public long alignments=0;
94 public long alignmentRequested=0;
95
96 /** Repeat length */
97 public LongList rlenList=new LongList();
98 /** Spacer length */
99 public LongList slenList=new LongList();
100 /** Length of a spacer+repeat */
101 public LongList ulenList=new LongList();
102 /** Total length */
103 public LongList tlenList=new LongList();
104 /** Number of matches */
105 public LongList matchList=new LongList();
106 /** Number of mismatches between repeats */
107 public LongList mismatchList=new LongList();
108 /** Copy count of this repeat */
109 public LongList copyList=new LongList();
110 /** Repeat gc, in 2% increments */
111 public LongList rgcList=new LongList(51);
112 /** Spacer gc, in 2% increments */
113 public LongList sgcList=new LongList(51);
114 /** Number of mismatches with reference */
115 public LongList refMismatchList=new LongList(51);
116 /** Number of mismatches with reference for valid alignments */
117 public LongList refMismatchListValid=new LongList(51);
118
119 public final LongList[] lists={rlenList, slenList, ulenList, tlenList,
120 rgcList, sgcList, matchList, mismatchList,
121 copyList, refMismatchList, refMismatchListValid};
122
123 /*--------------------------------------------------------------*/
124 /*---------------- Statics ----------------*/
125 /*--------------------------------------------------------------*/
126
127 public static int histmax=150;
128 public static int gcMult=100;
129
130 }