comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/kmer/KmerNode1D.java @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
comparison
equal deleted inserted replaced
67:0e9998148a16 68:5028fdace37b
1 package kmer;
2
3 import java.util.concurrent.atomic.AtomicLong;
4
5 import fileIO.ByteStreamWriter;
6 import structures.ByteBuilder;
7
8 /**
9 * @author Brian Bushnell
10 * @date Oct 22, 2013
11 *
12 */
13 public class KmerNode1D extends KmerNode {
14
15 /*--------------------------------------------------------------*/
16 /*---------------- Initialization ----------------*/
17 /*--------------------------------------------------------------*/
18
19 public KmerNode1D(long pivot_){
20 super(pivot_);
21 }
22
23 public KmerNode1D(long pivot_, int value_){
24 super(pivot_);
25 value=value_;
26 }
27
28 @Override
29 public final KmerNode makeNode(long pivot_, int value_){
30 return new KmerNode1D(pivot_, value_);
31 }
32
33 @Override
34 public final KmerNode makeNode(long pivot_, int[] values_, int vlen){
35 throw new RuntimeException("Unimplemented");
36 }
37
38 /*--------------------------------------------------------------*/
39 /*---------------- Public Methods ----------------*/
40 /*--------------------------------------------------------------*/
41
42 @Override
43 public final int set(long kmer, int[] vals, int vlen) {
44 throw new RuntimeException("Unimplemented.");
45 }
46
47 /*--------------------------------------------------------------*/
48 /*---------------- Nonpublic Methods ----------------*/
49 /*--------------------------------------------------------------*/
50
51 @Override
52 public int value(){return value;}
53
54 @Override
55 protected int[] values(int[] singleton){
56 assert(singleton.length==1);
57 singleton[0]=value;
58 return singleton;
59 }
60
61 @Override
62 public int set(int value_){return value=value_;}
63
64 @Override
65 protected int set(int[] values_, int vlen){
66 throw new RuntimeException("Unimplemented");
67 }
68
69 @Override
70 int numValues(){return value<1 ? 0 : 1;}
71
72 /*--------------------------------------------------------------*/
73 /*---------------- Private Methods ----------------*/
74 /*--------------------------------------------------------------*/
75
76 /*--------------------------------------------------------------*/
77 /*---------------- Resizing and Rebalancing ----------------*/
78 /*--------------------------------------------------------------*/
79
80 @Override
81 boolean canResize() {
82 return false;
83 }
84
85 @Override
86 public boolean canRebalance() {
87 return true;
88 }
89
90 @Deprecated
91 @Override
92 public int arrayLength() {
93 throw new RuntimeException("Unsupported.");
94 }
95
96 @Deprecated
97 @Override
98 void resize() {
99 throw new RuntimeException("Unsupported.");
100 }
101
102 @Deprecated
103 @Override
104 public void rebalance() {
105 throw new RuntimeException("Please call rebalance(ArrayList<KmerNode>) instead, with an empty list.");
106 }
107
108 /*--------------------------------------------------------------*/
109 /*---------------- Info Dumping ----------------*/
110 /*--------------------------------------------------------------*/
111
112 @Override
113 public final boolean dumpKmersAsBytes(ByteStreamWriter bsw, int k, int mincount, int maxcount, AtomicLong remaining){
114 if(value<1){return true;}
115 if(value>=mincount){
116 if(remaining!=null && remaining.decrementAndGet()<0){return true;}
117 bsw.printlnKmer(pivot, value, k);
118 }
119 if(left!=null){left.dumpKmersAsBytes(bsw, k, mincount, maxcount, remaining);}
120 if(right!=null){right.dumpKmersAsBytes(bsw, k, mincount, maxcount, remaining);}
121 return true;
122 }
123
124 @Override
125 public final boolean dumpKmersAsBytes_MT(final ByteStreamWriter bsw, final ByteBuilder bb, final int k, final int mincount, int maxcount, AtomicLong remaining){
126 if(value<1){return true;}
127 if(value>=mincount){
128 if(remaining!=null && remaining.decrementAndGet()<0){return true;}
129 toBytes(pivot, value, k, bb);
130 bb.nl();
131 if(bb.length()>=16000){
132 ByteBuilder bb2=new ByteBuilder(bb);
133 synchronized(bsw){bsw.addJob(bb2);}
134 bb.clear();
135 }
136 }
137 if(left!=null){left.dumpKmersAsBytes_MT(bsw, bb, k, mincount, maxcount, remaining);}
138 if(right!=null){right.dumpKmersAsBytes_MT(bsw, bb, k, mincount, maxcount, remaining);}
139 return true;
140 }
141
142 @Override
143 protected final StringBuilder dumpKmersAsText(StringBuilder sb, int k, int mincount, int maxcount){
144 if(value<1){return sb;}
145 if(sb==null){sb=new StringBuilder(32);}
146 if(value>=mincount){sb.append(AbstractKmerTable.toText(pivot, value, k)).append('\n');}
147 if(left!=null){left.dumpKmersAsText(sb, k, mincount, maxcount);}
148 if(right!=null){right.dumpKmersAsText(sb, k, mincount, maxcount);}
149 return sb;
150 }
151
152 @Override
153 protected final ByteBuilder dumpKmersAsText(ByteBuilder bb, int k, int mincount, int maxcount){
154 if(value<1){return bb;}
155 if(bb==null){bb=new ByteBuilder(32);}
156 if(value>=mincount){bb.append(AbstractKmerTable.toBytes(pivot, value, k)).append('\n');}
157 if(left!=null){left.dumpKmersAsText(bb, k, mincount, maxcount);}
158 if(right!=null){right.dumpKmersAsText(bb, k, mincount, maxcount);}
159 return bb;
160 }
161
162 @Override
163 final boolean TWOD(){return false;}
164
165 /*--------------------------------------------------------------*/
166 /*---------------- Invalid Methods ----------------*/
167 /*--------------------------------------------------------------*/
168
169 /*--------------------------------------------------------------*/
170 /*---------------- Fields ----------------*/
171 /*--------------------------------------------------------------*/
172
173 int value;
174
175 }