Skip to content

Commit

Permalink
updates to qbasepileup
Browse files Browse the repository at this point in the history
  • Loading branch information
holmeso committed Nov 6, 2023
1 parent 585f13c commit 367a891
Show file tree
Hide file tree
Showing 25 changed files with 297 additions and 493 deletions.
17 changes: 7 additions & 10 deletions qbasepileup/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@ mainClassName = 'org.qcmg.qbasepileup.QBasePileup'
def scriptname = 'qbasepileup'
def isExecutable = true

repositories {
flatDir(dirs:"$buildDir/deps/hdf-java/lib")
}

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

dependencies {
ant { untar(src: "../lib/hdf-java-2.8-bin.tar", dest: "build/deps") }
implementation name: 'jhdf'
implementation name: 'jhdf5'
implementation name: 'jhdfobj'
implementation name: 'jhdf5obj'

ant { untar(src: "../lib/hdf-java-2.8-bin.tar", dest: "build/deps") }

implementation project(':qcommon')
implementation project(':qpileup')
implementation project(':qbamfilter')
implementation project(':qpileup')
implementation 'com.github.samtools:htsjdk:2.24.1'
implementation 'net.sf.jopt-simple:jopt-simple:4.6'
testImplementation 'org.easymock:easymock:5.2.0'
Expand Down
23 changes: 7 additions & 16 deletions qbasepileup/src/org/qcmg/qbasepileup/InputBAM.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,25 @@ public InputBAM(Integer id, String donor, File bamFile, String inputType) {
public Integer getId() {
return id;
}
public String getDonor() {
return donor;
}

public File getBamFile() {
return bamFile;
}
public boolean exists() {
return this.bamFile.exists();
}
public String getInputType() {
return inputType;
}


public SamReader getSAMFileReader() throws IOException {
return SAMFileReaderFactory.createSAMFileReader(bamFile, null, ValidationStringency.SILENT);
}

@Override
public String toString() {
if (inputType.equals(Options.INPUT_BAM)) {
return "\t\t" + this.bamFile.getAbsolutePath();
} else if (inputType.equals(Options.INPUT_LIST)){
return this.id + "\t" + this.donor + "\t" + this.bamFile.getAbsolutePath();
} else if (inputType.equals(Options.INPUT_HDF)){
return "\t\t" + this.bamFile.getAbsolutePath();
} else {
return new String();
}
return switch (inputType) {
case Options.INPUT_BAM, Options.INPUT_HDF -> "\t\t" + this.bamFile.getAbsolutePath();
case Options.INPUT_LIST -> this.id + "\t" + this.donor + "\t" + this.bamFile.getAbsolutePath();
default -> "";
};
}


Expand Down
3 changes: 1 addition & 2 deletions qbasepileup/src/org/qcmg/qbasepileup/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

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

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

public static String getVersionMessage() throws Exception {
public static String getVersionMessage() {
return getProgramName() + ", version " + getProgramVersion();
}
}
106 changes: 43 additions & 63 deletions qbasepileup/src/org/qcmg/qbasepileup/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Options {
private boolean intron = true;
private boolean indel = true;
private int threadNo = 1;
private final List<InputBAM> inputBAMs = new ArrayList<InputBAM>();
private final List<InputBAM> inputBAMs = new ArrayList<>();
private File hdf;
private String inputType;
private int nearbyIndelWindow = 3;
Expand All @@ -61,7 +61,6 @@ public class Options {
private String filterQuery;
//private Integer minCoverage;
private Integer maxCoverage;
private Map<String, String[]> pindelMutations;
private Integer outputFormat = 1;

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

if (loglevel == null) {
loglevel = "INFO";
}

if (options.has("r")) {
reference = new File((String) options.valueOf("r"));
}
Expand Down Expand Up @@ -225,30 +220,35 @@ public Options(final String[] args) throws Exception {


//set filtering options
if (profile.equals("torrent")) {
baseQuality = 0;
mappingQuality = 1;
indel = true;
intron = true;
novelstarts = false;
strand=false;
} else if (profile.equals("RNA")) {
baseQuality = 7;
mappingQuality = 10;
indel = true;
intron = true;
novelstarts = true;
strand=false;
} else if (profile.equals("DNA")) {
baseQuality = 10;
mappingQuality = 10;
indel = true;
intron = false;
novelstarts = false;
strand=false;
} else if (profile.equals("indel")) {

}
switch (profile) {
case "torrent":
baseQuality = 0;
mappingQuality = 1;
indel = true;
intron = true;
novelstarts = false;
strand = false;
break;
case "RNA":
baseQuality = 7;
mappingQuality = 10;
indel = true;
intron = true;
novelstarts = true;
strand = false;
break;
case "DNA":
baseQuality = 10;
mappingQuality = 10;
indel = true;
intron = false;
novelstarts = false;
strand = false;
break;
case "indel":

break;
}

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

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

}
Expand Down Expand Up @@ -385,12 +385,8 @@ public Integer getOutputFormat() {
return outputFormat;
}

public Map<String, String[]> getPindelMutations() {
return pindelMutations;
}

private Map<String, String[]> getPindelMutations(OptionSet options) throws IOException {
Map<String, String[]> pindelMutations = new HashMap<String, String[]>();
Map<String, String[]> pindelMutations = new HashMap<>();

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

private void readPindelMutationFile(Map<String, String[]> pindelMutations,
File file, String type) throws IOException {
try (BufferedReader reader = new BufferedReader(new FileReader(file));) {
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
List<String> lines = new ArrayList<>();
while ((line = reader.readLine()) != null) {
if (line.startsWith("####")) {
if (lines.size() > 0) {
String[] infos = lines.get(0).split("\t");
String chr = infos[3].replace("ChrID ", "");
Integer start = new Integer(infos[4].replace("BP ", ""));
Integer end = new Integer(infos[5].replace("BP ", ""));
int start = Integer.parseInt(infos[4].replace("BP ", ""));
int end = Integer.parseInt(infos[5].replace("BP ", ""));
if ("DEL".equals(type)) {
start++;
end--;
}
String key = chr + ":" + start + ":" + end + ":" + type;
String normal = "";
String tumour = "";
StringBuilder normal = new StringBuilder();
StringBuilder tumour = new StringBuilder();
int normalCount = 0;
int tumourCount = 0;
for (int i=2; i<lines.size(); i++) {
String[] subLines = lines.get(i).split("\t");
String bam = subLines[subLines.length-2];
String name = subLines[subLines.length-1].replace("@", "");
String bam = subLines[subLines.length - 2];
String name = subLines[subLines.length - 1].replace("@", "");
if (bam.contains("Normal")) {
normal += name + ";";
normal.append(name).append(";");
normalCount++;
} else {
tumour += name + ";";
tumour.append(name).append(";");
tumourCount++;
}
}
String[] out = {tumourCount + ";" + normalCount, tumour, normal};
String[] out = {tumourCount + ";" + normalCount, tumour.toString(), normal.toString()};
pindelMutations.put(key, out);
}
lines.clear();
Expand Down Expand Up @@ -479,10 +475,6 @@ public boolean hasStrelkaOption() {
return options.has("strelka");
}

public String getInputType() {
return inputType;
}

private void getHDFBamList() throws Exception {
PileupHDF pileupHDF = new PileupHDF(hdf.getAbsolutePath(), false, false);
pileupHDF.open();
Expand All @@ -497,7 +489,7 @@ private void getHDFBamList() throws Exception {
}

private void getBamList(File bamList) throws IOException, QBasePileupException {
try (BufferedReader reader = new BufferedReader(new FileReader(bamList));) {
try (BufferedReader reader = new BufferedReader(new FileReader(bamList))) {
String line;
int count = 0;
while((line = reader.readLine()) != null) {
Expand Down Expand Up @@ -573,10 +565,6 @@ public File getHdf() {
return hdf;
}

public OptionParser getParser() {
return parser;
}

public OptionSet getOptions() {
return options;
}
Expand All @@ -595,14 +583,6 @@ boolean hasVersionOption() {
return options.has("v") || options.has("V") || options.has("version");
}

boolean hasLogOption() {
return options.has("log");
}

boolean hasLogLevelOption() {
return options.has("loglevel");
}

public void detectBadOptions() throws QBasePileupException {
if ( ! hasHelpOption() && ! hasVersionOption()) {

Expand Down
11 changes: 3 additions & 8 deletions qbasepileup/src/org/qcmg/qbasepileup/QBasePileup.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@
*/
package org.qcmg.qbasepileup;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.qcmg.common.log.QLogger;
import org.qcmg.common.log.QLoggerFactory;
import org.qcmg.common.meta.QExec;
import org.qcmg.common.util.LoadReferencedClasses;
import org.qcmg.qbasepileup.coverage.CoveragePileupMT;
import org.qcmg.qbasepileup.indel.IndelBasePileupByChrMT;
import org.qcmg.qbasepileup.indel.IndelBasePileupMT;
import org.qcmg.qbasepileup.snp.SnpBasePileupByFileMT;
import org.qcmg.qbasepileup.snp.SnpBasePileupMT;

import java.io.*;


public class QBasePileup {

Expand Down Expand Up @@ -175,7 +170,7 @@ private int runIndelMode() throws Exception {
int lineNumber = countLines(options.getGermlineIndelFile());
logger.info("Number of lines in file: " + lineNumber);
if (lineNumber > 50000) {
IndelBasePileupByChrMT mtGerm = new IndelBasePileupByChrMT(options.getGermlineIndelFile(), options.getGermlineOutputFile(), options.getOutput(), true, options);
IndelBasePileupByChrMT mtGerm = new IndelBasePileupByChrMT(options.getGermlineIndelFile(), options.getGermlineOutputFile(), true, options);
if (mtGerm.getExitStatus() > 0) {
return 1;
}
Expand Down
Loading

0 comments on commit 367a891

Please sign in to comment.