Skip to content

Commit 2f484e0

Browse files
authored
Merge pull request #392 from AdamaJava/cluster_down_cleanup
style(qsignature): updates based on IDEA suggestions
2 parents 0c2547c + e66b799 commit 2f484e0

32 files changed

+488
-643
lines changed

qsignature/src/org/qcmg/sig/Compare.java

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,22 @@ public class Compare {
7474
private float lowerHetCutoff = SignatureUtil.HET_LOWER_CUTOFF;
7575

7676
private String excludeVcfsFile;
77-
private List<String> excludes;
78-
private String logFile;
79-
80-
private int maxCacheSize = -1;
77+
78+
private int maxCacheSize = -1;
8179

8280
private final Map<String, int[]> fileIdsAndCounts = new THashMap<>();
8381
private final List<Comparison> allComparisons = new CopyOnWriteArrayList<>();
8482

8583
private final ConcurrentMap<File, Pair<SigMeta,TIntByteHashMap>> cache = new ConcurrentHashMap<>();
86-
87-
List<String> suspiciousResults = new ArrayList<>();
88-
84+
8985
private int engage() throws Exception {
9086

9187
// get excludes
9288
logger.info("Retrieving excludes list from: " + excludeVcfsFile);
93-
excludes = SignatureUtil.getEntriesFromExcludesFile(excludeVcfsFile);
89+
List<String> excludes = SignatureUtil.getEntriesFromExcludesFile(excludeVcfsFile);
9490

9591
// get qsig vcf files
96-
logger.info("Retrieving qsig vcf files from: " + Arrays.stream(paths).collect(Collectors.joining(",")));
92+
logger.info("Retrieving qsig vcf files from: " + String.join(",", paths));
9793
Set<File> uniqueFiles = new THashSet<>();
9894
for (String path : paths) {
9995
uniqueFiles.addAll(FileUtils.findFilesEndingWithFilterNIO(path, SignatureUtil.QSIG_VCF));
@@ -112,18 +108,16 @@ private int engage() throws Exception {
112108
logger.info("Total number of files to be compared (minus excluded files): " + files.size());
113109

114110
if (files.isEmpty()) {
115-
logger.warn("No files left after removing exlcuded files");
111+
logger.warn("No files left after removing excluded files");
116112
return 0;
117113
}
118114

119115
/*
120116
* Match files on additionalSearchStrings
121117
*/
122118
if (null != additionalSearchStrings && additionalSearchStrings.length > 0) {
123-
Predicate<File> p = (File f) -> {
124-
return Arrays.stream(additionalSearchStrings).anyMatch(s -> f.getAbsolutePath().contains(s));
125-
};
126-
files = files.stream().filter(f -> p.test(f)).collect(Collectors.toList());
119+
Predicate<File> p = (File f) -> Arrays.stream(additionalSearchStrings).anyMatch(s -> f.getAbsolutePath().contains(s));
120+
files = files.stream().filter(p).collect(Collectors.toList());
127121
}
128122

129123

@@ -236,7 +230,7 @@ Pair<SigMeta, TIntByteHashMap> getSignatureData(File f) throws IOException {
236230

237231
Comparison c = ComparisonUtil.compareRatiosUsingSnpsFloat(r1, r2, new File(rg1), new File(rg2));
238232
if (c.getScore() < cutoff) {
239-
logger.warn("rgs don't match!: " + c.toString());
233+
logger.warn("rgs don't match!: " + c);
240234
}
241235
}
242236
}
@@ -270,12 +264,12 @@ private void performComparisons(List<File> files) {
270264
Integer in;
271265
while ((in = queue.poll()) != null) {
272266

273-
logger.info("performing comparison for : " + in.intValue());
267+
logger.info("performing comparison for : " + in);
274268

275269
File f1 = files.get(in);
276270
Pair<SigMeta, TIntByteHashMap> r1 = cache.get(f1);
277271

278-
for (int j = in.intValue() + 1 ; j < size ; j ++ ) {
272+
for (int j = in + 1; j < size ; j ++ ) {
279273
File f2 = files.get(j);
280274
Pair<SigMeta, TIntByteHashMap> r2 = cache.get(f2);
281275

@@ -394,7 +388,7 @@ protected int setup(String args[]) throws Exception{
394388
System.err.println(Messages.COMPARE_USAGE);
395389
} else {
396390
// configure logging
397-
logFile = options.getLog();
391+
String logFile = options.getLog();
398392
logger = QLoggerFactory.getLogger(Compare.class, logFile, options.getLogLevel());
399393

400394

@@ -412,16 +406,16 @@ protected int setup(String args[]) throws Exception{
412406
cutoff = options.getCutoff();
413407
}
414408

415-
options.getMinCoverage().ifPresent(i -> {minimumCoverage = i.intValue();});
416-
options.getNoOfThreads().ifPresent(i -> {nThreads = i.intValue();});
417-
options.getMinRGCoverage().ifPresent(i -> {minimumRGCoverage = i.intValue();});
418-
options.getMaxCacheSize().ifPresent(i -> {maxCacheSize = i.intValue();});
419-
options.getHomCutoff().ifPresent(s -> {homCutoff = s;});
420-
options.getHetUpperCutoff().ifPresent(s -> {upperHetCutoff = s;});
421-
options.getHetLowerCutoff().ifPresent(s -> {lowerHetCutoff = s;});
409+
options.getMinCoverage().ifPresent(i -> minimumCoverage = i);
410+
options.getNoOfThreads().ifPresent(i -> nThreads = i);
411+
options.getMinRGCoverage().ifPresent(i -> minimumRGCoverage = i);
412+
options.getMaxCacheSize().ifPresent(i -> maxCacheSize = i);
413+
options.getHomCutoff().ifPresent(s -> homCutoff = s);
414+
options.getHetUpperCutoff().ifPresent(s -> upperHetCutoff = s);
415+
options.getHetLowerCutoff().ifPresent(s -> lowerHetCutoff = s);
422416
logger.tool("Number of threads to use: " + nThreads);
423-
logger.tool("Setting minumim coverage to: " + minimumCoverage);
424-
logger.tool("Setting minumim RG coverage to: " + minimumRGCoverage);
417+
logger.tool("Setting minimum coverage to: " + minimumCoverage);
418+
logger.tool("Setting minimum RG coverage to: " + minimumRGCoverage);
425419
logger.tool("Setting max cache size to: " + maxCacheSize);
426420
logger.tool("Setting homCutoff to: " + homCutoff);
427421
logger.tool("Setting upperHetCutoff to: " + upperHetCutoff);

qsignature/src/org/qcmg/sig/CompareIlluminaData.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
public class CompareIlluminaData {
3535

3636
private static QLogger logger;
37-
private String logFile;
38-
private String[] cmdLineInputFiles;
37+
private String[] cmdLineInputFiles;
3938
private int exitStatus;
4039

4140
private final Map<ChrPosition, IlluminaRecord> normalIlluminaMap = new HashMap<>();
@@ -110,7 +109,7 @@ private void compareIlluminaData() {
110109

111110
static void loadIlluminaData(File illuminaFile, Map<ChrPosition, IlluminaRecord> illuminaMap) throws IOException {
112111

113-
try (IlluminaFileReader reader = new IlluminaFileReader(illuminaFile);) {
112+
try (IlluminaFileReader reader = new IlluminaFileReader(illuminaFile)) {
114113

115114
for (IlluminaRecord rec : reader) {
116115

@@ -153,7 +152,7 @@ public static void main(String[] args) throws Exception {
153152
System.exit(exitStatus);
154153
}
155154

156-
protected int setup(String args[]) throws Exception{
155+
protected int setup(String[] args) throws Exception{
157156
int returnStatus = 1;
158157
if (null == args || args.length == 0) {
159158
System.err.println(Messages.COMPARE_USAGE);
@@ -176,7 +175,7 @@ protected int setup(String args[]) throws Exception{
176175
options.displayHelp();
177176
} else {
178177
// configure logging
179-
logFile = options.getLog();
178+
String logFile = options.getLog();
180179
logger = QLoggerFactory.getLogger(CompareIlluminaData.class, logFile, options.getLogLevel());
181180
logger.logInitialExecutionStats("CompareIlluminaData", CompareIlluminaData.class.getPackage().getImplementationVersion(), args);
182181

@@ -186,11 +185,11 @@ protected int setup(String args[]) throws Exception{
186185
throw new QSignatureException("INSUFFICIENT_ARGUMENTS");
187186
} else {
188187
// loop through supplied files - check they can be read
189-
for (int i = 0 ; i < cmdLineInputFiles.length ; i++ ) {
190-
if ( ! FileUtils.canFileBeRead(cmdLineInputFiles[i])) {
191-
throw new QSignatureException("INPUT_FILE_READ_ERROR" , cmdLineInputFiles[i]);
192-
}
193-
}
188+
for (String cmdLineInputFile : cmdLineInputFiles) {
189+
if (!FileUtils.canFileBeRead(cmdLineInputFile)) {
190+
throw new QSignatureException("INPUT_FILE_READ_ERROR", cmdLineInputFile);
191+
}
192+
}
194193
}
195194

196195
return engage();

qsignature/src/org/qcmg/sig/CompareRG.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,21 @@ public class CompareRG {
6666
private String [] additionalSearchStrings;
6767

6868
private String excludeVcfsFile;
69-
private List<String> excludes;
70-
private String logFile;
71-
72-
private final List<Comparison> allComparisons = new ArrayList<>();
69+
70+
private final List<Comparison> allComparisons = new ArrayList<>();
7371

7472
private final Map<File, Pair<SigMeta, TMap<String, TIntByteHashMap>>> cache = new THashMap<>();
7573

76-
List<String> suspiciousResults = new ArrayList<String>();
74+
List<String> suspiciousResults = new ArrayList<>();
7775

7876
private int engage() throws Exception {
7977

8078
// get excludes
8179
logger.info("Retrieving excludes list from: " + excludeVcfsFile);
82-
excludes = SignatureUtil.getEntriesFromExcludesFile(excludeVcfsFile);
80+
List<String> excludes = SignatureUtil.getEntriesFromExcludesFile(excludeVcfsFile);
8381

8482
// get qsig vcf files for this donor
85-
logger.info("Retrieving qsig vcf files from: " + Arrays.stream(paths).collect(Collectors.joining(",")));
83+
logger.info("Retrieving qsig vcf files from: " + String.join(",", paths));
8684
Set<File> uniqueFiles = new THashSet<>();
8785
for (String path : paths) {
8886
uniqueFiles.addAll(FileUtils.findFilesEndingWithFilterNIO(path, SignatureUtil.BAM_QSIG_VCF));
@@ -100,18 +98,16 @@ private int engage() throws Exception {
10098
logger.info("Total number of files to be compared (minus excluded files): " + files.size());
10199

102100
if (files.isEmpty()) {
103-
logger.warn("No files left after removing exlcuded files");
101+
logger.warn("No files left after removing excluded files");
104102
return 0;
105103
}
106104

107105
/*
108106
* Match files on additionalSearchStrings
109107
*/
110108
if (null != additionalSearchStrings && additionalSearchStrings.length > 0) {
111-
Predicate<File> p = (File f) -> {
112-
return Arrays.stream(additionalSearchStrings).anyMatch(s -> f.getAbsolutePath().contains(s));
113-
};
114-
files = files.stream().filter(f -> p.test(f)).collect(Collectors.toList());
109+
Predicate<File> p = (File f) -> Arrays.stream(additionalSearchStrings).anyMatch(s -> f.getAbsolutePath().contains(s));
110+
files = files.stream().filter(p).collect(Collectors.toList());
115111
}
116112

117113
final int numberOfFiles = files.size();
@@ -151,7 +147,7 @@ private int engage() throws Exception {
151147

152148
Comparison c = ComparisonUtil.compareRatiosUsingSnpsFloat(r1, r2, f.getAbsolutePath() + "-" + rg1, f.getAbsolutePath() + "-" + rg2);
153149
if (c.getScore() < genotypeCutoff) {
154-
logger.warn("rgs don't match!: " + c.toString());
150+
logger.warn("rgs don't match!: " + c);
155151
}
156152
allComparisons.add(c);
157153
}
@@ -313,7 +309,7 @@ protected int setup(String args[]) throws Exception{
313309
options.displayHelp();
314310
} else {
315311
// configure logging
316-
logFile = options.getLog();
312+
String logFile = options.getLog();
317313
logger = QLoggerFactory.getLogger(CompareRG.class, logFile, options.getLogLevel());
318314

319315

@@ -333,10 +329,10 @@ protected int setup(String args[]) throws Exception{
333329
}
334330
logger.tool("Setting cutoff to: " + genotypeCutoff);
335331

336-
options.getMinCoverage().ifPresent(i -> {minimumCoverage = i.intValue();});
337-
options.getMinRGCoverage().ifPresent(i -> {minimumRGCoverage = i.intValue();});
338-
logger.tool("Setting minumim coverage to: " + minimumCoverage);
339-
logger.tool("Setting minumim RG coverage to: " + minimumRGCoverage);
332+
options.getMinCoverage().ifPresent(i -> minimumCoverage = i);
333+
options.getMinRGCoverage().ifPresent(i -> minimumRGCoverage = i);
334+
logger.tool("Setting minimum coverage to: " + minimumCoverage);
335+
logger.tool("Setting minimum RG coverage to: " + minimumRGCoverage);
340336

341337
additionalSearchStrings = options.getAdditionalSearchString();
342338
logger.tool("Setting additionalSearchStrings to: " + Arrays.deepToString(additionalSearchStrings));

0 commit comments

Comments
 (0)