Skip to content

Commit bb2a6ee

Browse files
authored
Merge pull request #393 from AdamaJava/cluster_down_cleanup_2
style(q3indel): updates suggested and implemented by IDEA
2 parents 1997fbb + 39a532d commit bb2a6ee

File tree

14 files changed

+281
-303
lines changed

14 files changed

+281
-303
lines changed

q3indel/src/au/edu/qimr/indel/Options.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ public Options(final String[] args) throws IOException, Q3IndelException {
109109
controlVcf = getIOFromIni(iniFile, INI_SEC_IOS, "controlVcf");
110110
} else if (runMode.equalsIgnoreCase(RUNMODE_DEFAULT)) {
111111
String[] inputs = iniFile.get(INI_SEC_IOS).getAll("inputVcf",String[].class);
112-
for (int i = 0; i < inputs.length; i ++) {
113-
pindelVcfs.add(new File(inputs[i]));
114-
}
112+
for (String input : inputs) {
113+
pindelVcfs.add(new File(input));
114+
}
115115
}
116116

117117
nearbyIndelWindow = Integer.parseInt( iniFile.fetch(INI_SEC_PARAM, "window.nearbyIndel"));
@@ -140,7 +140,7 @@ private File getIOFromIni(Ini ini, String parent, String child) throws Q3IndelEx
140140
}
141141

142142
String f = ini.fetch(parent, child);
143-
if ( StringUtils.isNullOrEmpty(f) || f.toLowerCase().equals("null")) {
143+
if ( StringUtils.isNullOrEmpty(f) || f.equalsIgnoreCase("null")) {
144144
return null;
145145
}
146146

@@ -236,14 +236,14 @@ public void detectBadOptions() throws Q3IndelException {
236236
throw new Q3IndelException("FILE_EXISTS_ERROR","(control gatk vcf) " + controlVcf.getAbsolutePath());
237237
}
238238
} else if (RUNMODE_DEFAULT.equalsIgnoreCase(runMode)) {
239-
if (pindelVcfs.size() == 0) {
239+
if (pindelVcfs.isEmpty()) {
240240
throw new Q3IndelException("INPUT_OPTION_ERROR","(pindel input vcf) not specified" );
241241
}
242-
for (int i = 0; i < pindelVcfs.size(); i ++) {
243-
if ( pindelVcfs.get(i) != null && ! pindelVcfs.get(i).exists()) {
244-
throw new Q3IndelException("FILE_EXISTS_ERROR","(control indel vcf) " + pindelVcfs.get(i).getAbsolutePath());
245-
}
246-
}
242+
for (File pindelVcf : pindelVcfs) {
243+
if (pindelVcf != null && !pindelVcf.exists()) {
244+
throw new Q3IndelException("FILE_EXISTS_ERROR", "(control indel vcf) " + pindelVcf.getAbsolutePath());
245+
}
246+
}
247247
} else {
248248
throw new Q3IndelException("UNKNOWN_RUNMODE_ERROR", runMode);
249249
}

q3indel/src/au/edu/qimr/indel/pileup/IndelMT.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
import java.io.IOException;
55
import java.text.DateFormat;
66
import java.text.SimpleDateFormat;
7-
import java.util.AbstractQueue;
8-
import java.util.ArrayList;
9-
import java.util.Calendar;
10-
import java.util.List;
11-
import java.util.Map;
7+
import java.util.*;
128
import java.util.Map.Entry;
139
import java.util.concurrent.ConcurrentLinkedQueue;
1410
import java.util.concurrent.CountDownLatch;
@@ -157,17 +153,16 @@ public void run() {
157153
}
158154
}
159155
/**
160-
* it swap SAMRecord between currentPool and nextPool. After then, the currentPool will contain all SAMRecord overlapping topPos position,
161-
* the nextPool will contain all SAMRecord start after topPos position. All SAMRecord end before topPos position will be remvoved from both pool.
156+
* it swap SAMRecord between currentPool and nextPool. After then, the currentPool will contain all SAMRecord overlapping topPos positions,
157+
* the nextPool will contain all SAMRecord start after topPos position. All SAMRecord end before topPos position will be removed from both pools.
162158
* @param topPos pileup position
163-
* @param currentPool a list of SAMRecord overlapped previous pileup Position
159+
* @param currentPool a list of SAMRecord overlapped the previous pileup Position
164160
* @param nextPool a list of SAMRecord behind previous pileup Position
165161
*/
166162
void resetPool(IndelPosition topPos, List<SAMRecord> currentPool, List<SAMRecord> nextPool) {
167163

168-
List<SAMRecord> tmpCurrentPool = new ArrayList<>();
169-
List<SAMRecord> tmpPool = new ArrayList<>();
170-
tmpPool.addAll(nextPool);
164+
List<SAMRecord> tmpCurrentPool = new ArrayList<>();
165+
List<SAMRecord> tmpPool = new ArrayList<>(nextPool);
171166

172167
//check read record behind on current position
173168
for (SAMRecord re : tmpPool ) {
@@ -237,14 +232,14 @@ public IndelMT(Options options, QLogger logger) throws IOException {
237232
}
238233
logger.info(indelload.getCountsNewIndel() + " indels are found from control vcf input.");
239234
logger.info(indelload.getCountsMultiIndel() + " indels are split from multi alleles in control vcf.");
240-
logger.info(indelload.getCountsInputLine() + " variant records exsit inside control vcf input.");
241-
logger.info(indelload.getCountsInputMultiAlt() + " variant records with multi alleles exsits inside control vcf input.");
235+
logger.info(indelload.getCountsInputLine() + " variant records exist inside control vcf input.");
236+
logger.info(indelload.getCountsInputMultiAlt() + " variant records with multi alleles exists inside control vcf input.");
242237
}
243238
//then test second column
244239
if (options.getTestInputVcf() != null) {
245240
indelload.appendTestIndels(options.getTestInputVcf());
246-
logger.info(indelload.getCountsInputLine() + " variant records exsit inside test vcf input.");
247-
logger.info(indelload.getCountsInputMultiAlt() + " variants record with multi alleles exsits inside test vcf input.");
241+
logger.info(indelload.getCountsInputLine() + " variant records exist inside test vcf input.");
242+
logger.info(indelload.getCountsInputMultiAlt() + " variants record with multi alleles exists inside test vcf input.");
248243
logger.info(indelload.getCountsMultiIndel() + " indels are split from multi alleles inside test vcf");
249244
logger.info(indelload.getCountsNewIndel() + " new indels are found in test vcf input only.");
250245
logger.info(indelload.getCountsOverlapIndel() + " indels are found in both control and test vcf inputs.");
@@ -390,7 +385,7 @@ private void writeVCF(AbstractQueue<IndelPileup> tumourQueue, AbstractQueue<Inde
390385
}
391386
}
392387
}
393-
logger.info("outputed VCF record: " + count);
388+
logger.info("outputted VCF record: " + count);
394389
logger.info("including somatic record: " + somaticCount);
395390
}
396391
}
@@ -470,7 +465,7 @@ private void getHeaderForIndel(VcfHeader header ) throws IOException {
470465
header.addInfo(IndelUtils.INFO_SVTYPE, "1", "String",IndelUtils.DESCRIPTION_INFO_SVTYPE);
471466

472467
header.addFormat(VcfHeaderUtils.FORMAT_GENOTYPE_DETAILS, "1","String", "Genotype details: specific alleles");
473-
header.addFormat(IndelUtils.FORMAT_ACINDEL, ".", "String", IndelUtils.DESCRIPTION_FORMAT_ACINDEL); //vcf validataion
468+
header.addFormat(IndelUtils.FORMAT_ACINDEL, ".", "String", IndelUtils.DESCRIPTION_FORMAT_ACINDEL); //vcf validation
474469

475470
/*
476471
* overwrite the AD and PL header supplied by GATK as we will have samples with no data/coverage, and a number set to 'R' for the AD field causes the validator to complain
@@ -491,7 +486,7 @@ private void getHeaderForIndel(VcfHeader header ) throws IOException {
491486
* @return a sorted list of IndelPotion on this contig; return whole reference indels if contig is null
492487
*/
493488
private AbstractQueue<IndelPosition> getIndelList( SAMSequenceRecord contig) {
494-
if (positionRecordMap == null || positionRecordMap.size() == 0) {
489+
if (positionRecordMap == null || positionRecordMap.isEmpty()) {
495490
return new ConcurrentLinkedQueue<>();
496491
}
497492

@@ -504,7 +499,7 @@ private AbstractQueue<IndelPosition> getIndelList( SAMSequenceRecord contig) {
504499
}
505500

506501
//lambda expression to replace abstract method
507-
list.sort( (IndelPosition o1, IndelPosition o2) -> o1.getChrRangePosition().compareTo( o2.getChrRangePosition()) );
502+
list.sort(Comparator.comparing(IndelPosition::getChrRangePosition));
508503

509504
return new ConcurrentLinkedQueue<>(list);
510505
}

q3indel/src/au/edu/qimr/indel/pileup/IndelPileup.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private List<SAMRecord> getRegionIndels(List<SAMRecord> pool, int window) {
113113
for (CigarElement ce : cigar.getCigarElements()) {
114114
//insertion only one base, eg, start = 100; end = 101
115115
if (CigarOperator.I == ce.getOperator()) {
116-
//check whether it is supporting or partical indel
116+
//check whether it is supporting or partial indel
117117
//if(refPos == indelStart ){
118118
if (refPos >= indelStart && refPos <= indelEnd) {
119119
if (type.equals(SVTYPE.DEL) ) {
@@ -122,7 +122,7 @@ private List<SAMRecord> getRegionIndels(List<SAMRecord> pool, int window) {
122122
support = true; // refPos==indelStart=indelEnd
123123
}
124124
} else if (refPos > windowStart && refPos < windowEnd) {
125-
nearby = true; //nearby insertion overlap the window
125+
nearby = true; //nearby insertion overlaps the window
126126
}
127127
} else if ( CigarOperator.D == ce.getOperator()) {
128128
//deletion overlaps variants, full/part supporting reads
@@ -133,7 +133,7 @@ private List<SAMRecord> getRegionIndels(List<SAMRecord> pool, int window) {
133133
//indel chock have base on both side of indel region
134134
|| (refPos <= indelStart && refPos + ce.getLength() - 1 >= indelEnd)) {
135135
if (type.equals(SVTYPE.INS)) {
136-
nearby = true; //nearyby deletion
136+
nearby = true; //nearby deletion
137137
} else {
138138
support = true; // supporting or partial
139139
}
@@ -163,7 +163,7 @@ private List<SAMRecord> getRegionIndels(List<SAMRecord> pool, int window) {
163163

164164
this.nearbyIndel = count;
165165

166-
// all nearby/faraway indle reads are removed
166+
// all nearby/faraway indel reads are removed
167167
return regionPool;
168168
}
169169

@@ -191,7 +191,7 @@ private int[] getCounts(List<SAMRecord> pool, String motif) {
191191
Cigar cigar = re.getCigar();
192192
for (CigarElement ce : cigar.getCigarElements()) {
193193
if (CigarOperator.I == ce.getOperator() && (refPos == indelEnd && type.equals(SVTYPE.INS))) {
194-
//if insert rePos go next cigar block after cigar.I, which is indel end position
194+
//if insert rePos go next cigar block after cigar. I, which is indel end position
195195
if (ce.getLength() != motif.length()) {
196196
partialflag = true;
197197
} else {

q3indel/src/au/edu/qimr/indel/pileup/IndelPosition.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public IndelPosition(VcfRecord re, SVTYPE type) {
5555
position = new ChrRangePosition(fullChromosome, start, end);
5656
}
5757

58-
//next job: check all vcfs are same type, start and end
58+
//next job: check all vcfs are the same type, start and end
5959
public IndelPosition(List<VcfRecord> res, SVTYPE type) {
60-
this(res.get(0), type);
60+
this(res.getFirst(), type);
6161
//append all vcfs
6262
vcfs.clear();
6363
vcfs.addAll(res);
@@ -154,21 +154,15 @@ public List<String> getMotifs( ) {
154154
@Override
155155
public boolean equals(final Object o) {
156156

157-
if (!(o instanceof IndelPosition)) {
157+
if (!(o instanceof IndelPosition other)) {
158158
return false;
159159
}
160-
161-
final IndelPosition other = (IndelPosition) o;
162-
163-
if (! this.mutationType .equals(other.mutationType)) {
164-
return false;
165-
}
166-
167-
if ( ! this.position.equals(other.position)) {
160+
161+
if (! this.mutationType .equals(other.mutationType)) {
168162
return false;
169163
}
170-
171-
return true;
164+
165+
return this.position.equals(other.position);
172166
}
173167

174168
@Override
@@ -203,14 +197,14 @@ public VcfRecord getPileupedVcf(int index, final int gematicNNS, final float gem
203197
return re;
204198
}
205199

206-
boolean somatic = (re.getFilter().equals(ReadIndels.FILTER_SOMATIC)) ? true : false;
200+
boolean somatic = re.getFilter().equals(ReadIndels.FILTER_SOMATIC);
207201
if (normalPileup != null && somatic) {
208202
if ( normalPileup.getSupportReadCount(index) > gematicNNS ) {
209203
somatic = false;
210204
} else if (normalPileup.getInformativeCount() > 0) {
211205
int scount = normalPileup.getSupportReadCount(index);
212206
int icount = normalPileup.getInformativeCount();
213-
if ((100 * scount / icount) >= (gematicSOI * 100)) {
207+
if (((float) (100 * scount) / icount) >= (gematicSOI * 100)) {
214208
somatic = false;
215209
}
216210
}
@@ -285,7 +279,7 @@ public VcfRecord getPileupedVcf(int index, final int gematicNNS, final float gem
285279
//future job should check GT column
286280
//control always on first column and then test
287281
List<String> field = new ArrayList<>();
288-
field.add( 0, (genotypeField.size() > 0) ? genotypeField.get(0) + ":" + IndelUtils.FORMAT_ACINDEL : IndelUtils.FORMAT_ACINDEL );
282+
field.add( 0, (!genotypeField.isEmpty()) ? genotypeField.get(0) + ":" + IndelUtils.FORMAT_ACINDEL : IndelUtils.FORMAT_ACINDEL );
289283
field.add( 1, (genotypeField.size() > 1) ? genotypeField.get(1) + ":" + nd : nd);
290284
field.add( 2, (genotypeField.size() > 2) ? genotypeField.get(2) + ":" + td : td);
291285
re.setFormatFields( field );

q3indel/src/au/edu/qimr/indel/pileup/ReadIndels.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public class ReadIndels {
2727
private VcfHeader header;
2828

2929
private static final int errRecordLimit = 100;
30-
//counts from each input, {No of new indel, No of overlap indel, No of indels with mult Allel, No of inputs variants, No of input variants with multi Allel}
30+
//counts from each input, {No of new indel, No of overlap indel, No of indels with multi Allele, No of inputs variants, No of input variants with multi Allele}
3131
private final int[] counts = {0, 0, 0, 0, 0};
3232

33-
//here key will be uniq for indel: chr, start, end, allel
33+
//here key will be uniq for indel: chr, start, end, allele
3434
private final Map<VcfRecord, VcfRecord> positionRecordMap = new ConcurrentHashMap<>();
3535

3636
public ReadIndels( QLogger logger) {
@@ -49,7 +49,7 @@ public void appendTestIndels(File f) throws IOException {
4949
List<String> format = vcf.getFormatFields();
5050
if (format != null) {
5151
while (format.size() > 2) {
52-
format.remove(format.size() - 1);
52+
format.removeLast();
5353
}
5454
vcf.setFormatFields(format);
5555
VcfUtils.addMissingDataToFormatFields(vcf, 2);
@@ -94,12 +94,12 @@ private boolean mergeTestIndel(VcfRecord secVcf) {
9494
//only keep first sample column of second vcf
9595
List<String> secformat = secVcf.getFormatFields();
9696
while (secformat != null && secformat.size() > 2 ) {
97-
secformat.remove(secformat.size() - 1);
97+
secformat.removeLast();
9898
}
9999

100100
//copy secVcf with sample column "FORMAT <missing data> oriSample" only
101101
if (existingvcf == null) {
102-
//the test only indel always set as somatic, even gatkeTest runMode
102+
//the test only indel always set as somatic, even gatk Test runMode
103103
existingvcf = new VcfRecord.Builder(secVcf.getChrPosition(), secVcf.getRef())
104104
.id(secVcf.getId()).allele(secVcf.getAlt()).filter(FILTER_SOMATIC).build();
105105

@@ -116,15 +116,15 @@ private boolean mergeTestIndel(VcfRecord secVcf) {
116116
return false;
117117
} else {
118118
//gatk mode already set filter as "." (germline) ignore pileup, since they are also appear on control vcf
119-
//only keep first sample column of exsiting vcf
119+
//only keep first sample column of existing vcf
120120
List<String> format1 = existingvcf.getFormatFields();
121121

122122
if (format1 != null) {
123123
while (format1.size() > 2 ) {
124-
format1.remove(format1.size() - 1);
124+
format1.removeLast();
125125
}
126126
existingvcf.setFormatFields(format1);
127-
//merge exiting and second vcf format, the exsitingvcf already inside map
127+
//merge exiting and second vcf format, the existing vcf already inside map
128128
VcfUtils.addAdditionalSampleToFormatField(existingvcf, secformat) ;
129129
}
130130
return true;
@@ -178,7 +178,7 @@ public void loadIndels(File f) throws IOException {
178178
vcf1.setFilter(Constants.MISSING_DATA_STRING);
179179

180180
if (positionRecordMap.containsKey(vcf1) && (indelOverlap ++) < errRecordLimit) {
181-
logger.warn("same variants already exsits, this one will be discard:\n" + positionRecordMap.get(vcf1).toString() );
181+
logger.warn("same variants already exists, this one will be discard:\n" + positionRecordMap.get(vcf1).toString() );
182182
continue; //no overwrite but just warning
183183
}
184184
positionRecordMap.put(vcf1, vcf1);
@@ -197,7 +197,7 @@ public void loadIndels(File f) throws IOException {
197197
}
198198

199199
/**
200-
* change the input vcf by putting '.' on "GT" field if there are multi Alleles existis;
200+
* change the input vcf by putting '.' on "GT" field if multi Alleles exists;
201201
* do nothing if not multi Alleles or not GT field on format column
202202
* @param vcf input vcf record
203203
*/
@@ -211,7 +211,7 @@ public void resetGenotype(VcfRecord vcf) {
211211
//add GD to second field
212212
VcfFormatFieldRecord[] frecords = new VcfFormatFieldRecord[format.size() - 1];
213213
for (int i = 1; i < format.size(); i ++) {
214-
VcfFormatFieldRecord re = new VcfFormatFieldRecord(format.get(0), format.get(i));
214+
VcfFormatFieldRecord re = new VcfFormatFieldRecord(format.getFirst(), format.get(i));
215215
String gd = IndelUtils.getGenotypeDetails(re, vcf.getRef(), vcf.getAlt() );
216216
re.setField(1, VcfHeaderUtils.FORMAT_GENOTYPE_DETAILS, gd == null ? Constants.MISSING_DATA_STRING : gd);
217217

@@ -229,7 +229,7 @@ public void resetGenotype(VcfRecord vcf) {
229229
for (int i = 1; i < frecords.length; i++) {
230230
//the exception shouldn't happen
231231
if ( !frecords[i].getFormatColumnString().equals(frecords[0].getFormatColumnString())) {
232-
throw new IllegalArgumentException("both sample column with differnt format column: \n"
232+
throw new IllegalArgumentException("both sample column with different format column: \n"
233233
+ frecords[0].getFormatColumnString() + "\n" + frecords[i].getFormatColumnString());
234234
}
235235
format.add(frecords[i].getSampleColumnString());
@@ -241,7 +241,6 @@ public void resetGenotype(VcfRecord vcf) {
241241
/**
242242
*
243243
* @return a map of, key is the indel position, value is the list a vcf record on that position.
244-
* @throws Exception
245244
*/
246245
public Map<ChrRangePosition, IndelPosition> getIndelMap() throws Q3IndelException {
247246

0 commit comments

Comments
 (0)