Skip to content
This repository was archived by the owner on May 22, 2026. It is now read-only.

Commit a2c4846

Browse files
committed
Refactoring of printer variants for simplicity.
1 parent b217c6d commit a2c4846

4 files changed

Lines changed: 49 additions & 157 deletions

File tree

src/main/java/com/astrazeneca/vardict/Utils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public static double roundHalfEven(String pattern, double value) {
102102
return Double.parseDouble(new DecimalFormat(pattern).format(value));
103103
}
104104

105+
public static String getRoundedValueToPrint(String pattern, double value) {
106+
return value == Math.round(value)
107+
? new DecimalFormat("0").format(value)
108+
: new DecimalFormat(pattern).format(value).replaceAll("0+$", "");
109+
}
110+
105111
/**
106112
* Method creates substring of string begin from specified idx.
107113
* If idx is negative, it returns substring, counted from the right end of string.

src/main/java/com/astrazeneca/vardict/printers/AmpliconOutputVariant.java

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.text.DecimalFormat;
99
import java.util.List;
1010

11+
import static com.astrazeneca.vardict.Utils.getRoundedValueToPrint;
1112
import static com.astrazeneca.vardict.data.scopedata.GlobalReadOnlyScope.instance;
1213
import static com.astrazeneca.vardict.Utils.join;
1314

@@ -143,33 +144,9 @@ public String toString() {
143144
*/
144145
private String create_amplicon_variant_40columns() {
145146
String outputVariant;
146-
String frequency_f = frequency == Math.round(frequency)
147-
? new DecimalFormat("0").format(frequency)
148-
: new DecimalFormat("0.0000").format(frequency).replaceAll("0+$", "");
149-
String pmean_f = pmean == Math.round(pmean)
150-
? new DecimalFormat("0").format(pmean)
151-
: new DecimalFormat("0.0").format(pmean).replaceAll("0+$", "");
152-
String qual_f = qual == Math.round(qual)
153-
? new DecimalFormat("0").format(qual)
154-
: new DecimalFormat("0.0").format(qual).replaceAll("0+$", "");
155-
String pvalue_f = pvalue == Math.round(pvalue)
156-
? new DecimalFormat("0").format(pvalue)
157-
: new DecimalFormat("0.00000").format(pvalue).replaceAll("0+$", "");
158-
String mapq_f = mapq == Math.round(mapq)
159-
? new DecimalFormat("0").format(mapq)
160-
: new DecimalFormat("0.0").format(mapq).replaceAll("0+$", "");
161-
String qratio_f = qratio == Math.round(qratio)
162-
? new DecimalFormat("0").format(qratio)
163-
: new DecimalFormat("0.000").format(qratio).replaceAll("0+$", "");
164147
String hifreq_f = hifreq == 0
165148
? "0"
166149
: new DecimalFormat("0.0000").format(hifreq);
167-
String extrafreq_f = extrafreq == Math.round(extrafreq)
168-
? new DecimalFormat("0").format(extrafreq)
169-
: new DecimalFormat("0.0000").format(extrafreq).replaceAll("0+$", "");
170-
String msi_f = msi == Math.round(msi)
171-
? new DecimalFormat("0").format(msi)
172-
: new DecimalFormat("0.000").format(msi).replaceAll("0+$", "");
173150
nm = nm > 0 ? nm : 0;
174151
String nm_f = nm == 0
175152
? "0"
@@ -191,23 +168,23 @@ private String create_amplicon_variant_40columns() {
191168
variantForwardCount,
192169
variantReverseCount,
193170
genotype,
194-
frequency_f,
171+
getRoundedValueToPrint("0.0000", frequency),
195172
bias,
196-
pmean_f,
173+
getRoundedValueToPrint("0.0", pmean),
197174
pstd,
198-
qual_f,
175+
getRoundedValueToPrint("0.0", qual),
199176
qstd,
200177

201-
String.valueOf(pvalue_f),
178+
getRoundedValueToPrint("0.00000", pvalue),
202179
oddratio,
203180

204-
mapq_f,
205-
qratio_f,
181+
getRoundedValueToPrint("0.0", mapq),
182+
getRoundedValueToPrint("0.000", qratio),
206183
hifreq_f,
207-
extrafreq_f,
184+
getRoundedValueToPrint("0.0000", extrafreq),
208185

209186
shift3,
210-
msi_f,
187+
getRoundedValueToPrint("0.000", msi),
211188
msint,
212189
nm_f,
213190
hicnt,

src/main/java/com/astrazeneca/vardict/printers/SimpleOutputVariant.java

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.text.DecimalFormat;
88

9+
import static com.astrazeneca.vardict.Utils.getRoundedValueToPrint;
910
import static com.astrazeneca.vardict.data.scopedata.GlobalReadOnlyScope.instance;
1011
import static com.astrazeneca.vardict.Utils.join;
1112
/**
@@ -123,40 +124,14 @@ public String toString() {
123124
*/
124125
private String create_simple_variant_38columns() {
125126
String outputVariant;
126-
String frequency_f = frequency == Math.round(frequency)
127-
? new DecimalFormat("0").format(frequency)
128-
: new DecimalFormat("0.0000").format(frequency).replaceAll("0+$", "");
129-
String pmean_f = pmean == Math.round(pmean)
130-
? new DecimalFormat("0").format(pmean)
131-
: new DecimalFormat("0.0").format(pmean).replaceAll("0+$", "");
132-
String qual_f = qual == Math.round(qual)
133-
? new DecimalFormat("0").format(qual)
134-
: new DecimalFormat("0.0").format(qual).replaceAll("0+$", "");
135-
String pvalue_f = pvalue == Math.round(pvalue)
136-
? new DecimalFormat("0").format(pvalue)
137-
: new DecimalFormat("0.00000").format(pvalue).replaceAll("0+$", "");
138-
String mapq_f = mapq == Math.round(mapq)
139-
? new DecimalFormat("0").format(mapq)
140-
: new DecimalFormat("0.0").format(mapq).replaceAll("0+$", "");
141-
String qratio_f = qratio == Math.round(qratio)
142-
? new DecimalFormat("0").format(qratio)
143-
: new DecimalFormat("0.000").format(qratio).replaceAll("0+$", "");
144127
String hifreq_f = hifreq == 0
145128
? "0"
146129
: new DecimalFormat("0.0000").format(hifreq);
147-
String extrafreq_f = extrafreq == Math.round(extrafreq)
148-
? new DecimalFormat("0").format(extrafreq)
149-
: new DecimalFormat("0.0000").format(extrafreq).replaceAll("0+$", "");
150-
String msi_f = msi == Math.round(msi)
151-
? new DecimalFormat("0").format(msi)
152-
: new DecimalFormat("0.000").format(msi).replaceAll("0+$", "");
153130
nm = nm > 0 ? nm : 0;
154131
String nm_f = nm == 0
155132
? "0"
156133
: new DecimalFormat("0.0").format(nm);
157-
String duprate_f = duprate == Math.round(duprate)
158-
? new DecimalFormat("0").format(duprate)
159-
: new DecimalFormat("0.0").format(duprate).replaceAll("0+$", "");
134+
160135
outputVariant = join(delimiter,
161136
sample,
162137
gene,
@@ -173,31 +148,31 @@ private String create_simple_variant_38columns() {
173148
variantForwardCount,
174149
variantReverseCount,
175150
genotype,
176-
frequency_f,
151+
getRoundedValueToPrint("0.0000", frequency),
177152
bias,
178-
pmean_f,
153+
getRoundedValueToPrint("0.0", pmean),
179154
pstd,
180-
qual_f,
155+
getRoundedValueToPrint("0.0", qual),
181156
qstd,
182157

183-
String.valueOf(pvalue_f),
158+
getRoundedValueToPrint("0.00000", pvalue),
184159
oddratio,
185160

186-
mapq_f,
187-
qratio_f,
161+
getRoundedValueToPrint("0.0", mapq),
162+
getRoundedValueToPrint("0.000", qratio),
188163
hifreq_f,
189-
extrafreq_f,
164+
getRoundedValueToPrint("0.0000", extrafreq),
190165

191166
shift3,
192-
msi_f,
167+
getRoundedValueToPrint("0.000", msi),
193168
msint,
194169
nm_f,
195170
hicnt,
196171
hicov,
197172
leftSequence, rightSequence,
198173
region,
199174
varType,
200-
duprate_f,
175+
getRoundedValueToPrint("0.00", duprate),
201176
sv
202177
);
203178
return outputVariant;

src/main/java/com/astrazeneca/vardict/printers/SomaticOutputVariant.java

Lines changed: 23 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.text.DecimalFormat;
88

9+
import static com.astrazeneca.vardict.Utils.getRoundedValueToPrint;
910
import static com.astrazeneca.vardict.Utils.join;
1011
import static com.astrazeneca.vardict.data.scopedata.GlobalReadOnlyScope.instance;
1112

@@ -200,76 +201,9 @@ public String toString() {
200201
*/
201202
private String create_somatic_variant_61columns() {
202203
String outputVariant;
203-
String var1frequency_f = var1frequency == Math.round(var1frequency)
204-
? new DecimalFormat("0").format(var1frequency)
205-
: new DecimalFormat("0.0000").format(var1frequency).replaceAll("0+$", "");
206-
String var1meanPosition_f = var1meanPosition == Math.round(var1meanPosition)
207-
? new DecimalFormat("0").format(var1meanPosition)
208-
: new DecimalFormat("0.0").format(var1meanPosition).replaceAll("0+$", "");
209-
String var1meanQuality_f = var1meanQuality == Math.round(var1meanQuality)
210-
? new DecimalFormat("0").format(var1meanQuality)
211-
: new DecimalFormat("0.0").format(var1meanQuality).replaceAll("0+$", "");
212-
String var1meanMappingQuality_f = var1meanMappingQuality == Math.round(var1meanMappingQuality)
213-
? new DecimalFormat("0").format(var1meanMappingQuality)
214-
: new DecimalFormat("0.0").format(var1meanMappingQuality).replaceAll("0+$", "");
215-
String var1highQualityToLowQualityRatio_f = var1highQualityToLowQualityRatio == Math.round(var1highQualityToLowQualityRatio)
216-
? new DecimalFormat("0").format(var1highQualityToLowQualityRatio)
217-
: new DecimalFormat("0.000").format(var1highQualityToLowQualityRatio).replaceAll("0+$", "");
218-
String var1highQualityReadsFrequency_f = var1highQualityReadsFrequency== Math.round(var1highQualityReadsFrequency)
219-
? new DecimalFormat("0").format(var1highQualityReadsFrequency)
220-
: new DecimalFormat("0.0000").format(var1highQualityReadsFrequency).replaceAll("0+$", "");
221-
String var1extraFrequency_f = var1extraFrequency == Math.round(var1extraFrequency)
222-
? new DecimalFormat("0").format(var1extraFrequency)
223-
: new DecimalFormat("0.0000").format(var1extraFrequency).replaceAll("0+$", "");
224204
var1nm = var1nm > 0 ? var1nm : 0;
225-
String var1nm_f = var1nm == Math.round(var1nm)
226-
? new DecimalFormat("0").format(var1nm)
227-
: new DecimalFormat("0.0").format(var1nm).replaceAll("0+$", "");
228-
String var1pvalue_f = pvalue1 == Math.round(pvalue1)
229-
? new DecimalFormat("0").format(pvalue1)
230-
: new DecimalFormat("0.00000").format(pvalue1).replaceAll("0+$", "");
231-
232-
String var2frequency_f = var2frequency == Math.round(var2frequency)
233-
? new DecimalFormat("0").format(var2frequency)
234-
: new DecimalFormat("0.0000").format(var2frequency).replaceAll("0+$", "");
235-
String var2meanPosition_f = var2meanPosition == Math.round(var2meanPosition)
236-
? new DecimalFormat("0").format(var2meanPosition)
237-
: new DecimalFormat("0.0").format(var2meanPosition).replaceAll("0+$", "");
238-
String var2meanQuality_f = var2meanQuality == Math.round(var2meanQuality)
239-
? new DecimalFormat("0").format(var2meanQuality)
240-
: new DecimalFormat("0.0").format(var2meanQuality).replaceAll("0+$", "");
241-
String var2meanMappingQuality_f = var2meanMappingQuality == Math.round(var2meanMappingQuality)
242-
? new DecimalFormat("0").format(var2meanMappingQuality)
243-
: new DecimalFormat("0.0").format(var2meanMappingQuality).replaceAll("0+$", "");
244-
String var2highQualityToLowQualityRatio_f = var2highQualityToLowQualityRatio == Math.round(var2highQualityToLowQualityRatio)
245-
? new DecimalFormat("0").format(var2highQualityToLowQualityRatio)
246-
: new DecimalFormat("0.000").format(var2highQualityToLowQualityRatio).replaceAll("0+$", "");
247-
String var2highQualityReadsFrequency_f = var2highQualityReadsFrequency == Math.round(var2highQualityReadsFrequency)
248-
? new DecimalFormat("0").format(var2highQualityReadsFrequency)
249-
: new DecimalFormat("0.0000").format(var2highQualityReadsFrequency).replaceAll("0+$", "");
250-
String var2extraFrequency_f = var2extraFrequency == Math.round(var2extraFrequency)
251-
? new DecimalFormat("0").format(var2extraFrequency)
252-
: new DecimalFormat("0.0000").format(var2extraFrequency).replaceAll("0+$", "");
253205
var2nm = var2nm > 0 ? var2nm : 0;
254-
String var2nm_f = var2nm == Math.round(var2nm)
255-
? new DecimalFormat("0").format(var2nm)
256-
: new DecimalFormat("0.0").format(var2nm).replaceAll("0+$", "");
257-
String var2pvalue_f = pvalue2 == Math.round(pvalue2)
258-
? new DecimalFormat("0").format(pvalue2)
259-
: new DecimalFormat("0.00000").format(pvalue2).replaceAll("0+$", "");
260-
261-
String msi_f = msi == 0
262-
? "0"
263-
: new DecimalFormat("0.000").format(msi);
264-
String var1duprate_f = var1duprate == Math.round(var1duprate)
265-
? new DecimalFormat("0").format(var1duprate)
266-
: new DecimalFormat("0.0").format(var1duprate).replaceAll("0+$", "");
267-
String var2duprate_f = var2duprate == Math.round(var2duprate)
268-
? new DecimalFormat("0").format(var2duprate)
269-
: new DecimalFormat("0.0").format(var2duprate).replaceAll("0+$", "");
270-
String pvalue_f = pvalue == Math.round(pvalue)
271-
? new DecimalFormat("0").format(pvalue)
272-
: new DecimalFormat("0.00000").format(pvalue).replaceAll("0+$", "");
206+
String msi_f = msi == 0 ? "0" : new DecimalFormat("0.000").format(msi);
273207

274208
outputVariant = join(delimiter,
275209
sample,
@@ -287,18 +221,18 @@ private String create_somatic_variant_61columns() {
287221
var1variantForwardCount,
288222
var1variantReverseCount,
289223
var1genotype,
290-
var1frequency_f,
224+
getRoundedValueToPrint("0.0000", var1frequency),
291225
var1strandBiasFlag,
292-
var1meanPosition_f,
226+
getRoundedValueToPrint("0.0", var1meanPosition),
293227
var1isAtLeastAt2Position,
294-
var1meanQuality_f,
228+
getRoundedValueToPrint("0.0", var1meanQuality),
295229
var1hasAtLeast2DiffQualities,
296-
var1meanMappingQuality_f,
297-
var1highQualityToLowQualityRatio_f,
298-
var1highQualityReadsFrequency_f,
299-
var1extraFrequency_f,
300-
var1nm_f,
301-
var1pvalue_f,
230+
getRoundedValueToPrint("0.0", var1meanMappingQuality),
231+
getRoundedValueToPrint("0.000", var1highQualityToLowQualityRatio),
232+
getRoundedValueToPrint("0.0000", var1highQualityReadsFrequency),
233+
getRoundedValueToPrint("0.0000", var1extraFrequency),
234+
getRoundedValueToPrint("0.0", var1nm),
235+
getRoundedValueToPrint("0.00000", pvalue1),
302236
oddratio1,
303237

304238
var2totalCoverage,
@@ -308,18 +242,18 @@ private String create_somatic_variant_61columns() {
308242
var2variantForwardCount,
309243
var2variantReverseCount,
310244
var2genotype,
311-
var2frequency_f,
245+
getRoundedValueToPrint("0.0000", var2frequency),
312246
var2strandBiasFlag,
313-
var2meanPosition_f,
247+
getRoundedValueToPrint("0.0", var2meanPosition),
314248
var2isAtLeastAt2Position,
315-
var2meanQuality_f,
249+
getRoundedValueToPrint("0.0", var2meanQuality),
316250
var2hasAtLeast2DiffQualities,
317-
var2meanMappingQuality_f,
318-
var2highQualityToLowQualityRatio_f,
319-
var2highQualityReadsFrequency_f,
320-
var2extraFrequency_f,
321-
var2nm_f,
322-
var2pvalue_f,
251+
getRoundedValueToPrint("0.0", var2meanMappingQuality),
252+
getRoundedValueToPrint("0.000", var2highQualityToLowQualityRatio),
253+
getRoundedValueToPrint("0.0000", var2highQualityReadsFrequency),
254+
getRoundedValueToPrint("0.0000", var2extraFrequency),
255+
getRoundedValueToPrint("0.0", var2nm),
256+
getRoundedValueToPrint("0.00000", pvalue2),
323257
oddratio2,
324258

325259
shift3,
@@ -329,11 +263,11 @@ private String create_somatic_variant_61columns() {
329263
region,
330264
varLabel,
331265
varType,
332-
var1duprate_f,
266+
getRoundedValueToPrint("0.0", var1duprate),
333267
var1sv,
334-
var2duprate_f,
268+
getRoundedValueToPrint("0.0", var2duprate),
335269
var2sv,
336-
pvalue_f,
270+
getRoundedValueToPrint("0.00000", pvalue),
337271
oddratio
338272
);
339273
return outputVariant;

0 commit comments

Comments
 (0)