Skip to content

Commit 367a891

Browse files
committed
updates to qbasepileup
1 parent 585f13c commit 367a891

25 files changed

+297
-493
lines changed

qbasepileup/build.gradle

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@ mainClassName = 'org.qcmg.qbasepileup.QBasePileup'
44
def scriptname = 'qbasepileup'
55
def isExecutable = true
66

7-
repositories {
8-
flatDir(dirs:"$buildDir/deps/hdf-java/lib")
9-
}
10-
117
//control the ordering of jars, make sure junit before <tool>.jar
128
configurations { junit }
9+
repositories {
10+
flatDir(dirs:["$buildDir/deps/hdf-java/lib", "/opt/local/genomeinfo/hdf-java/hdf-java-2.8/lib"])
11+
}
1312

1413
dependencies {
15-
ant { untar(src: "../lib/hdf-java-2.8-bin.tar", dest: "build/deps") }
16-
implementation name: 'jhdf'
17-
implementation name: 'jhdf5'
18-
implementation name: 'jhdfobj'
19-
implementation name: 'jhdf5obj'
14+
15+
ant { untar(src: "../lib/hdf-java-2.8-bin.tar", dest: "build/deps") }
16+
2017
implementation project(':qcommon')
21-
implementation project(':qpileup')
2218
implementation project(':qbamfilter')
19+
implementation project(':qpileup')
2320
implementation 'com.github.samtools:htsjdk:2.24.1'
2421
implementation 'net.sf.jopt-simple:jopt-simple:4.6'
2522
testImplementation 'org.easymock:easymock:5.2.0'

qbasepileup/src/org/qcmg/qbasepileup/InputBAM.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,25 @@ public InputBAM(Integer id, String donor, File bamFile, String inputType) {
3535
public Integer getId() {
3636
return id;
3737
}
38-
public String getDonor() {
39-
return donor;
40-
}
38+
4139
public File getBamFile() {
4240
return bamFile;
4341
}
4442
public boolean exists() {
4543
return this.bamFile.exists();
4644
}
47-
public String getInputType() {
48-
return inputType;
49-
}
50-
45+
5146
public SamReader getSAMFileReader() throws IOException {
5247
return SAMFileReaderFactory.createSAMFileReader(bamFile, null, ValidationStringency.SILENT);
5348
}
5449

5550
@Override
5651
public String toString() {
57-
if (inputType.equals(Options.INPUT_BAM)) {
58-
return "\t\t" + this.bamFile.getAbsolutePath();
59-
} else if (inputType.equals(Options.INPUT_LIST)){
60-
return this.id + "\t" + this.donor + "\t" + this.bamFile.getAbsolutePath();
61-
} else if (inputType.equals(Options.INPUT_HDF)){
62-
return "\t\t" + this.bamFile.getAbsolutePath();
63-
} else {
64-
return new String();
65-
}
52+
return switch (inputType) {
53+
case Options.INPUT_BAM, Options.INPUT_HDF -> "\t\t" + this.bamFile.getAbsolutePath();
54+
case Options.INPUT_LIST -> this.id + "\t" + this.donor + "\t" + this.bamFile.getAbsolutePath();
55+
default -> "";
56+
};
6657
}
6758

6859

qbasepileup/src/org/qcmg/qbasepileup/Messages.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
public final class Messages {
1313
static final ResourceBundle messages = ResourceBundle.getBundle("org.qcmg.qbasepileup.messages");
14-
static final String ERROR_PREFIX = getProgramName() + ": ";
1514
static final String USAGE = getMessage("USAGE");
1615

1716
public static String getMessage(final String identifier) {
@@ -38,7 +37,7 @@ static String getProgramVersion() {
3837
return Messages.class.getPackage().getImplementationVersion();
3938
}
4039

41-
public static String getVersionMessage() throws Exception {
40+
public static String getVersionMessage() {
4241
return getProgramName() + ", version " + getProgramVersion();
4342
}
4443
}

qbasepileup/src/org/qcmg/qbasepileup/Options.java

Lines changed: 43 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class Options {
4545
private boolean intron = true;
4646
private boolean indel = true;
4747
private int threadNo = 1;
48-
private final List<InputBAM> inputBAMs = new ArrayList<InputBAM>();
48+
private final List<InputBAM> inputBAMs = new ArrayList<>();
4949
private File hdf;
5050
private String inputType;
5151
private int nearbyIndelWindow = 3;
@@ -61,7 +61,6 @@ public class Options {
6161
private String filterQuery;
6262
//private Integer minCoverage;
6363
private Integer maxCoverage;
64-
private Map<String, String[]> pindelMutations;
6564
private Integer outputFormat = 1;
6665

6766
public Options(final String[] args) throws Exception {
@@ -120,10 +119,6 @@ public Options(final String[] args) throws Exception {
120119
log = (String) options.valueOf("log");
121120
String loglevel = (String) options.valueOf("loglevel");
122121

123-
if (loglevel == null) {
124-
loglevel = "INFO";
125-
}
126-
127122
if (options.has("r")) {
128123
reference = new File((String) options.valueOf("r"));
129124
}
@@ -225,30 +220,35 @@ public Options(final String[] args) throws Exception {
225220

226221

227222
//set filtering options
228-
if (profile.equals("torrent")) {
229-
baseQuality = 0;
230-
mappingQuality = 1;
231-
indel = true;
232-
intron = true;
233-
novelstarts = false;
234-
strand=false;
235-
} else if (profile.equals("RNA")) {
236-
baseQuality = 7;
237-
mappingQuality = 10;
238-
indel = true;
239-
intron = true;
240-
novelstarts = true;
241-
strand=false;
242-
} else if (profile.equals("DNA")) {
243-
baseQuality = 10;
244-
mappingQuality = 10;
245-
indel = true;
246-
intron = false;
247-
novelstarts = false;
248-
strand=false;
249-
} else if (profile.equals("indel")) {
250-
251-
}
223+
switch (profile) {
224+
case "torrent":
225+
baseQuality = 0;
226+
mappingQuality = 1;
227+
indel = true;
228+
intron = true;
229+
novelstarts = false;
230+
strand = false;
231+
break;
232+
case "RNA":
233+
baseQuality = 7;
234+
mappingQuality = 10;
235+
indel = true;
236+
intron = true;
237+
novelstarts = true;
238+
strand = false;
239+
break;
240+
case "DNA":
241+
baseQuality = 10;
242+
mappingQuality = 10;
243+
indel = true;
244+
intron = false;
245+
novelstarts = false;
246+
strand = false;
247+
break;
248+
case "indel":
249+
250+
break;
251+
}
252252

253253
if (options.has("bq")) {
254254
baseQuality = (Integer) options.valueOf("bq");
@@ -337,7 +337,7 @@ public Options(final String[] args) throws Exception {
337337
normalBam = new InputBAM(null, null, new File((String) options.valueOf("in")), inputType);
338338

339339
if (options.has("pd") || options.has("pi")) {
340-
this.pindelMutations = getPindelMutations(options);
340+
Map<String, String[]> pindelMutations = getPindelMutations(options);
341341
}
342342

343343
}
@@ -385,12 +385,8 @@ public Integer getOutputFormat() {
385385
return outputFormat;
386386
}
387387

388-
public Map<String, String[]> getPindelMutations() {
389-
return pindelMutations;
390-
}
391-
392388
private Map<String, String[]> getPindelMutations(OptionSet options) throws IOException {
393-
Map<String, String[]> pindelMutations = new HashMap<String, String[]>();
389+
Map<String, String[]> pindelMutations = new HashMap<>();
394390

395391
if (options.has("pd")) {
396392
File file = new File((String)options.valueOf("pd"));
@@ -405,38 +401,38 @@ private Map<String, String[]> getPindelMutations(OptionSet options) throws IOExc
405401

406402
private void readPindelMutationFile(Map<String, String[]> pindelMutations,
407403
File file, String type) throws IOException {
408-
try (BufferedReader reader = new BufferedReader(new FileReader(file));) {
404+
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
409405
String line;
410406
List<String> lines = new ArrayList<>();
411407
while ((line = reader.readLine()) != null) {
412408
if (line.startsWith("####")) {
413409
if (lines.size() > 0) {
414410
String[] infos = lines.get(0).split("\t");
415411
String chr = infos[3].replace("ChrID ", "");
416-
Integer start = new Integer(infos[4].replace("BP ", ""));
417-
Integer end = new Integer(infos[5].replace("BP ", ""));
412+
int start = Integer.parseInt(infos[4].replace("BP ", ""));
413+
int end = Integer.parseInt(infos[5].replace("BP ", ""));
418414
if ("DEL".equals(type)) {
419415
start++;
420416
end--;
421417
}
422418
String key = chr + ":" + start + ":" + end + ":" + type;
423-
String normal = "";
424-
String tumour = "";
419+
StringBuilder normal = new StringBuilder();
420+
StringBuilder tumour = new StringBuilder();
425421
int normalCount = 0;
426422
int tumourCount = 0;
427423
for (int i=2; i<lines.size(); i++) {
428424
String[] subLines = lines.get(i).split("\t");
429-
String bam = subLines[subLines.length-2];
430-
String name = subLines[subLines.length-1].replace("@", "");
425+
String bam = subLines[subLines.length - 2];
426+
String name = subLines[subLines.length - 1].replace("@", "");
431427
if (bam.contains("Normal")) {
432-
normal += name + ";";
428+
normal.append(name).append(";");
433429
normalCount++;
434430
} else {
435-
tumour += name + ";";
431+
tumour.append(name).append(";");
436432
tumourCount++;
437433
}
438434
}
439-
String[] out = {tumourCount + ";" + normalCount, tumour, normal};
435+
String[] out = {tumourCount + ";" + normalCount, tumour.toString(), normal.toString()};
440436
pindelMutations.put(key, out);
441437
}
442438
lines.clear();
@@ -479,10 +475,6 @@ public boolean hasStrelkaOption() {
479475
return options.has("strelka");
480476
}
481477

482-
public String getInputType() {
483-
return inputType;
484-
}
485-
486478
private void getHDFBamList() throws Exception {
487479
PileupHDF pileupHDF = new PileupHDF(hdf.getAbsolutePath(), false, false);
488480
pileupHDF.open();
@@ -497,7 +489,7 @@ private void getHDFBamList() throws Exception {
497489
}
498490

499491
private void getBamList(File bamList) throws IOException, QBasePileupException {
500-
try (BufferedReader reader = new BufferedReader(new FileReader(bamList));) {
492+
try (BufferedReader reader = new BufferedReader(new FileReader(bamList))) {
501493
String line;
502494
int count = 0;
503495
while((line = reader.readLine()) != null) {
@@ -573,10 +565,6 @@ public File getHdf() {
573565
return hdf;
574566
}
575567

576-
public OptionParser getParser() {
577-
return parser;
578-
}
579-
580568
public OptionSet getOptions() {
581569
return options;
582570
}
@@ -595,14 +583,6 @@ boolean hasVersionOption() {
595583
return options.has("v") || options.has("V") || options.has("version");
596584
}
597585

598-
boolean hasLogOption() {
599-
return options.has("log");
600-
}
601-
602-
boolean hasLogLevelOption() {
603-
return options.has("loglevel");
604-
}
605-
606586
public void detectBadOptions() throws QBasePileupException {
607587
if ( ! hasHelpOption() && ! hasVersionOption()) {
608588

qbasepileup/src/org/qcmg/qbasepileup/QBasePileup.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,17 @@
66
*/
77
package org.qcmg.qbasepileup;
88

9-
import java.io.BufferedInputStream;
10-
import java.io.File;
11-
import java.io.FileInputStream;
12-
import java.io.IOException;
13-
import java.io.InputStream;
14-
159
import org.qcmg.common.log.QLogger;
1610
import org.qcmg.common.log.QLoggerFactory;
1711
import org.qcmg.common.meta.QExec;
18-
import org.qcmg.common.util.LoadReferencedClasses;
1912
import org.qcmg.qbasepileup.coverage.CoveragePileupMT;
2013
import org.qcmg.qbasepileup.indel.IndelBasePileupByChrMT;
2114
import org.qcmg.qbasepileup.indel.IndelBasePileupMT;
2215
import org.qcmg.qbasepileup.snp.SnpBasePileupByFileMT;
2316
import org.qcmg.qbasepileup.snp.SnpBasePileupMT;
2417

18+
import java.io.*;
19+
2520

2621
public class QBasePileup {
2722

@@ -175,7 +170,7 @@ private int runIndelMode() throws Exception {
175170
int lineNumber = countLines(options.getGermlineIndelFile());
176171
logger.info("Number of lines in file: " + lineNumber);
177172
if (lineNumber > 50000) {
178-
IndelBasePileupByChrMT mtGerm = new IndelBasePileupByChrMT(options.getGermlineIndelFile(), options.getGermlineOutputFile(), options.getOutput(), true, options);
173+
IndelBasePileupByChrMT mtGerm = new IndelBasePileupByChrMT(options.getGermlineIndelFile(), options.getGermlineOutputFile(), true, options);
179174
if (mtGerm.getExitStatus() > 0) {
180175
return 1;
181176
}

0 commit comments

Comments
 (0)