Skip to content

Commit aa40d1d

Browse files
committed
refactor: minor java21 refactoring of isize and report packages based on IDEA suggestions
1 parent 2a64e4e commit aa40d1d

File tree

6 files changed

+40
-53
lines changed

6 files changed

+40
-53
lines changed

qsv/src/org/qcmg/qsv/QSVPipeline.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public QSVPipeline(Options options, String resultsDir, Date analysisDate, String
139139
}
140140

141141
if (options.isQCMG()) {
142-
writeDCCHeader(options, analysisDate, analysisId, exec);
142+
writeDCCHeader(options, analysisId, exec);
143143
}
144144

145145
File countFile = new File(resultsDir + FILE_SEPARATOR + options.getSampleName()+ "_sv_counts.txt");
@@ -152,11 +152,11 @@ public QSVPipeline(Options options, String resultsDir, Date analysisDate, String
152152

153153
}
154154

155-
private void writeDCCHeader(Options options, Date analysisDate, String analysisId, QExec exec) throws IOException {
156-
new DCCReport(new File(resultsDir + FILE_SEPARATOR + options.getSampleName() + ".somatic.dcc"), analysisDate, analysisId, tumor, normal, options, exec);
155+
private void writeDCCHeader(Options options, String analysisId, QExec exec) throws IOException {
156+
new DCCReport(new File(resultsDir + FILE_SEPARATOR + options.getSampleName() + ".somatic.dcc"), analysisId, tumor, normal, options, exec);
157157
if (options.isTwoFileMode()) {
158-
new DCCReport(new File(resultsDir + FILE_SEPARATOR + options.getSampleName() + ".germline.dcc"), analysisDate, analysisId, tumor, normal, options, exec);
159-
new DCCReport(new File(resultsDir + FILE_SEPARATOR + options.getSampleName() + ".normal-germline.dcc"), analysisDate, analysisId, tumor, normal, options, exec);
158+
new DCCReport(new File(resultsDir + FILE_SEPARATOR + options.getSampleName() + ".germline.dcc"), analysisId, tumor, normal, options, exec);
159+
new DCCReport(new File(resultsDir + FILE_SEPARATOR + options.getSampleName() + ".normal-germline.dcc"), analysisId, tumor, normal, options, exec);
160160
}
161161
}
162162

qsv/src/org/qcmg/qsv/isize/SAMRecordCounterMT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private void execute() throws QSVException, IOException {
5959
//getReadGroups first
6060
getReadGroups();
6161

62-
final AbstractQueue<SAMRecord> readQueue = new ConcurrentLinkedQueue<SAMRecord>();
62+
final AbstractQueue<SAMRecord> readQueue = new ConcurrentLinkedQueue<>();
6363

6464
final CountDownLatch readLatch = new CountDownLatch(1); // reading
6565
// thread
@@ -85,7 +85,7 @@ private void execute() throws QSVException, IOException {
8585
processThreads.awaitTermination(Constants.EXECUTOR_SERVICE_AWAIT_TERMINATION, TimeUnit.HOURS);
8686

8787

88-
if (readQueue.size() != 0) {
88+
if (!readQueue.isEmpty()) {
8989
throw new Exception(
9090
" threads have completed but queue isn't empty (readQueue): "
9191
+ readQueue.size());
@@ -262,7 +262,7 @@ record = queueIn.poll();
262262
sleepcount++;
263263
} catch (InterruptedException e) {
264264
logger.info(Thread.currentThread().getName() + " "
265-
+ e.toString());
265+
+ e);
266266
}
267267

268268
} else {

qsv/src/org/qcmg/qsv/report/DCCReport.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.io.File;
99
import java.io.FileWriter;
1010
import java.io.IOException;
11-
import java.util.Date;
1211
import java.util.List;
1312

1413
import org.qcmg.common.meta.KeyValue;
@@ -34,7 +33,7 @@ public class DCCReport extends QSVReport {
3433
private String platform;
3534
private QExec exec;
3635

37-
public DCCReport(File file, Date runDate, String analysisId, QSVParameters tumor, QSVParameters normal, Options options, QExec exec) throws IOException {
36+
public DCCReport(File file, String analysisId, QSVParameters tumor, QSVParameters normal, Options options, QExec exec) throws IOException {
3837
super(file);
3938
this.analysisId = analysisId;
4039
this.options = options;
@@ -57,7 +56,7 @@ public DCCReport(File file, List<QSVCluster> records, String tumourFindType, Str
5756
@Override
5857
public void writeHeader() throws IOException {
5958

60-
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file));) {
59+
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
6160
writeExec(writer);
6261
writeDCCMeta(writer);
6362
writeLIMSMeta(writer);
@@ -122,15 +121,12 @@ public void writeReport() throws IOException {
122121
}
123122

124123
public static String getValidationPlatform(String platform) {
125-
if ("solid".equals(platform)) {
126-
return "4";
127-
} else if ("illumina".equals(platform)) {
128-
return"60";
129-
} else if ("bgi".equals(platform)) {
130-
return"81";
131-
} else {
132-
return "-999";
133-
}
124+
return switch (platform) {
125+
case "solid" -> "4";
126+
case "illumina" -> "60";
127+
case "bgi" -> "81";
128+
case null, default -> "-999";
129+
};
134130
}
135131

136132
@Override

qsv/src/org/qcmg/qsv/report/QSVClusterReport.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public class QSVClusterReport extends QSVReport {
2525
private String normalFindType;
2626
private boolean isQCMG;
2727
private final boolean isSingleSided;
28-
private static String TAB = "\t";
29-
28+
3029
public QSVClusterReport(String base, String mutationType, String end, String fileType, List<QSVCluster> qsvRecords, String tumourFindType, String normalFindType, boolean isSingleSided) throws IOException {
3130
super(new File(base + "." + mutationType + end));
3231
this.fileType = fileType;
@@ -35,7 +34,7 @@ public QSVClusterReport(String base, String mutationType, String end, String fil
3534
this.tumourFindType = tumourFindType;
3635
this.normalFindType = normalFindType;
3736
if (normalFindType == null) {
38-
normalFindType = "";
37+
this.normalFindType = "";
3938
}
4039

4140
writeHeader();
@@ -46,17 +45,14 @@ public QSVClusterReport(String base, String mutationType, String end, String fil
4645
this.fileType = fileType;
4746
this.qsvRecords = qsvRecords;
4847
this.isSingleSided = isSingleSided;
49-
if (normalFindType == null) {
50-
normalFindType = "";
51-
}
5248
writeHeader();
5349
writeReport();
5450
}
5551

5652
public QSVClusterReport(String base, String mutationType, String end, String fileType, QSVCluster r, String tumourFindType, String normalFindType, boolean isQCMG, boolean isSingleSided) throws IOException {
5753
super(new File(base + "." + r.getReference() + "." + mutationType + end));
5854
this.fileType = fileType;
59-
this.qsvRecords = new ArrayList<QSVCluster>();
55+
this.qsvRecords = new ArrayList<>();
6056
this.tumourFindType = tumourFindType;
6157
this.normalFindType = normalFindType;
6258
this.isQCMG = isQCMG;
@@ -71,21 +67,21 @@ public void writeHeader() throws IOException {
7167

7268
// print header for the file.
7369
if (!file.exists()) {
74-
try ( BufferedWriter writer = new BufferedWriter(new FileWriter(file, false));) {
70+
try ( BufferedWriter writer = new BufferedWriter(new FileWriter(file, false))) {
7571
writer.write(getHeader());
7672
}
7773
}
7874
}
7975

8076
@Override
8177
public synchronized void writeReport() throws IOException {
82-
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));) {
78+
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file, true))) {
8379
for (QSVCluster r: qsvRecords) {
8480
if (r.printRecord(isSingleSided)) {
8581

8682
String str = r.getDataString(fileType, tumourFindType, normalFindType, isQCMG);
8783
if (fileType.equals("softclip")) {
88-
if (!str.equals("") && r.hasSoftClipEvidence()) {
84+
if (!str.isEmpty() && r.hasSoftClipEvidence()) {
8985
writer.write(str + QSVUtil.getNewLine());
9086
}
9187
} else {
@@ -97,25 +93,26 @@ public synchronized void writeReport() throws IOException {
9793
}
9894

9995
@Override
100-
public String getHeader() {
101-
102-
103-
if (fileType.equals("tab")) {
104-
return "#analysis_id" + TAB + "sample_id" + TAB + "sv_id" + TAB + "sv_type" + TAB + "chr1" + TAB + "pos1" + TAB + "strand1" + TAB + "chr2" + TAB + "pos2" + TAB + "strand2" + TAB + QSVConstants.DISEASE_SAMPLE + "_discordant_pairs_count" + TAB + QSVConstants.CONTROL_SAMPLE + "_discordant_pairs_count"
96+
public String getHeader() {
97+
98+
99+
String TAB = "\t";
100+
if (fileType.equals("tab")) {
101+
return "#analysis_id" + TAB + "sample_id" + TAB + "sv_id" + TAB + "sv_type" + TAB + "chr1" + TAB + "pos1" + TAB + "strand1" + TAB + "chr2" + TAB + "pos2" + TAB + "strand2" + TAB + QSVConstants.DISEASE_SAMPLE + "_discordant_pairs_count" + TAB + QSVConstants.CONTROL_SAMPLE + "_discordant_pairs_count"
105102
+ TAB + QSVConstants.CONTROL_SAMPLE + "_low_qual_discordant_reads_count"
106103
+ TAB + QSVConstants.DISEASE_SAMPLE + "_clips_count_pos1"
107104
+ TAB + QSVConstants.DISEASE_SAMPLE + "_clips_count_pos2"
108105
+ TAB + QSVConstants.CONTROL_SAMPLE + "_clips_count_pos1"
109106
+ TAB + QSVConstants.CONTROL_SAMPLE + "_clips_count_pos2"
110107
+ TAB + "category"
111-
+ TAB + "microhomology" + TAB + "non-template" + TAB + "test_split_read_bp" + TAB + "control_split_read_bp" + TAB + "event_notes" + TAB + "contig" + QSVUtil.getNewLine();
108+
+ TAB + "microhomology" + TAB + "non-template" + TAB + "test_split_read_bp" + TAB + "control_split_read_bp" + TAB + "event_notes" + TAB + "contig" + QSVUtil.getNewLine();
112109
} else if (fileType.equals("softclip")){
113-
return "sv_id" + TAB + "chr1" + TAB + "bp1" + TAB + "contig1" +
114-
TAB + "read_strand_1" + TAB + "blat_align_chr1" + TAB + "blat_align_bp1" + TAB +
110+
return "sv_id" + TAB + "chr1" + TAB + "bp1" + TAB + "contig1" +
111+
TAB + "read_strand_1" + TAB + "blat_align_chr1" + TAB + "blat_align_bp1" + TAB +
115112
"blat_align_ref_start_pos_1" + TAB + "blat_align_ref_end_pos_1" + TAB + "blat_align_contig_start_1" + TAB + "blat_align_contig_end_1" + TAB +
116-
"blat_align_strand_1" +
117-
TAB + "chr2" + TAB + "bp2" + TAB + "contig2" +
118-
TAB + "read_strand_2" + TAB + "blat_align_chr2" + TAB + "blat_align_bp2" + TAB + "blat_align_contig_start_1" + TAB + "blat_align_contig_end_1" + TAB +
113+
"blat_align_strand_1" +
114+
TAB + "chr2" + TAB + "bp2" + TAB + "contig2" +
115+
TAB + "read_strand_2" + TAB + "blat_align_chr2" + TAB + "blat_align_bp2" + TAB + "blat_align_contig_start_1" + TAB + "blat_align_contig_end_1" + TAB +
119116
"blat_align_start_pos_2" + TAB + "blat_align_end_pos_2" + TAB + "blat_align_strand_2" +
120117
QSVUtil.getNewLine();
121118
}

qsv/src/org/qcmg/qsv/report/SVCountReport.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ public ConcurrentMap<String, AtomicInteger> getNormalGermline() {
4646
return normalGermline;
4747
}
4848

49-
public String getSampleName() {
50-
return sampleName;
51-
}
5249

53-
5450
@Override
5551
public String getHeader() {
5652
StringBuilder headings = new StringBuilder();
@@ -72,11 +68,9 @@ private synchronized ConcurrentMap<String, AtomicInteger> singleCountMap() {
7268
}
7369

7470
private String generateReport() {
75-
StringBuilder sb = new StringBuilder();
76-
sb.append(getCountString("somatic", somatic));
77-
sb.append(getCountString("germline", germline));
78-
sb.append(getCountString("normal-germline", normalGermline));
79-
return sb.toString();
71+
return getCountString("somatic", somatic) +
72+
getCountString("germline", germline) +
73+
getCountString("normal-germline", normalGermline);
8074
}
8175

8276
public String getCountString(String type, ConcurrentMap<String, AtomicInteger> mapOfCounts) {
@@ -119,7 +113,7 @@ public synchronized void addCountsToMap(PairGroup zp, int somaticCount,
119113
}
120114

121115
private int getCounts(ConcurrentMap<String, AtomicInteger> map) {
122-
return map.values().stream().mapToInt(ai -> ai.get()).sum();
116+
return map.values().stream().mapToInt(AtomicInteger::get).sum();
123117
}
124118

125119
public int getSomaticCounts() {

qsv/src/org/qcmg/qsv/report/SummaryReport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class SummaryReport extends QSVReport {
2626
private int germlineCount;
2727
private int normalGermlineCount;
2828
private final String analysisId;
29-
private static String NEWLINE = System.getProperty("line.separator");
29+
private static final String NEWLINE = System.lineSeparator();
3030

3131
public SummaryReport(File file, Date runDate, String analysisId, boolean isQCMG) {
3232
super(file);
@@ -42,7 +42,7 @@ public String getHeader() {
4242

4343
@Override
4444
public void writeReport() throws Exception {
45-
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file));) {
45+
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
4646

4747
if (options.isQCMG()) {
4848
writeQCMGReport(writer);

0 commit comments

Comments
 (0)