Skip to content

Commit

Permalink
Simplify calling mutation server
Browse files Browse the repository at this point in the history
  • Loading branch information
seppinho committed Oct 9, 2018
1 parent 2ffb812 commit 9ad32a8
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 52 deletions.
100 changes: 57 additions & 43 deletions src/main/java/genepi/mut/pileup/PileupToolLocal.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.HashMap;

import genepi.base.Tool;
import genepi.io.FileUtil;
import genepi.io.text.LineWriter;
import genepi.mut.objects.BasePosition;
import genepi.mut.objects.VariantLine;
Expand All @@ -22,7 +23,7 @@

public class PileupToolLocal extends Tool {

String version = "v1.1.6";
String version = "v1.1.7";

public PileupToolLocal(String[] args) {
super(args);
Expand All @@ -33,20 +34,19 @@ public PileupToolLocal(String[] args) {
public void createParameters() {

addParameter("input", "input bam folder", Tool.STRING);
addParameter("outputRaw", "output raw file", Tool.STRING);
addParameter("outputVar", "output variants file", Tool.STRING);
addParameter("output", "output folder", Tool.STRING);
addParameter("level", "detection level", Tool.DOUBLE);
addParameter("reference", "reference as fasta", Tool.STRING);
addParameter("indel", "call deletions?", Tool.STRING);
addParameter("baq", "apply BAQ?", Tool.STRING);
addParameter("baseQ", "base quality", Tool.INTEGER);
addParameter("mapQ", "mapping quality", Tool.INTEGER);
addParameter("alignQ", "alignment quality", Tool.INTEGER);
addOptionalParameter("baseQ", "base quality", Tool.STRING);
addOptionalParameter("mapQ", "mapping quality", Tool.STRING);
addOptionalParameter("alignQ", "alignment quality", Tool.STRING);
addFlag("baq", "Apply BAQ");
addFlag("indel", "Call indels");
}

@Override
public void init() {
System.out.println("Mutation Server " + version + " -- Low-frequency Variant Detection");
System.out.println("Low-frequency Variant Detection" + version);
System.out.println("Division of Genetic Epidemiology - Medical University of Innsbruck");
System.out.println("(c) Sebastian Schoenherr, Hansi Weissensteiner, Lukas Forer");
System.out.println("");
Expand All @@ -55,25 +55,37 @@ public void init() {
@Override
public int run() {

String version = "mtdna";

String input = (String) getValue("input");

String outputRaw = (String) getValue("outputRaw");

String outputVar = (String) getValue("outputVar");
String output = (String) getValue("output");

String indel = (String) getValue("indel");
boolean baq = isFlagSet("baq");

String baq = (String) getValue("baq");
boolean indel = isFlagSet("indel");

double level = (double) getValue("level");

int baseQ = (int) getValue("baseQ");
int baseQ;

int mapQ = (int) getValue("mapQ");
if (getValue("baseQ") == null) {
baseQ = 20;
} else {
baseQ = Integer.valueOf((String) getValue("baseQ"));
}

int alignQ = (int) getValue("alignQ");
int mapQ;
if (getValue("mapQ") == null) {
mapQ = 30;
} else {
mapQ = Integer.valueOf((String) getValue("mapQ"));
}

int alignQ;
if (getValue("alignQ") == null) {
alignQ = 30;
} else {
alignQ = Integer.valueOf((String) getValue("alignQ"));
}

String refPath = (String) getValue("reference");

Expand Down Expand Up @@ -103,10 +115,13 @@ public boolean accept(File dir, String name) {
}

try {

File outRaw = new File(outputRaw);

File outVar = new File(outputVar);

long time = System.currentTimeMillis();
String varOut = FileUtil.path(output,"variants_"+time+".txt");
String rawOut = FileUtil.path(output,"raw_"+time+".txt");

File outRaw = new File(rawOut);
File outVar = new File(varOut);

File parentRaw = outRaw.getParentFile();
File parentVar = outVar.getParentFile();
Expand Down Expand Up @@ -134,11 +149,23 @@ public boolean accept(File dir, String name) {

long start = System.currentTimeMillis();

System.out.println("");
System.out.println("Input: " + input);
System.out.println("Input: " + output);
System.out.println("Detection limit: " + level);
System.out.println("Base Quality: " + baseQ);
System.out.println("Map Quality: " + mapQ);
System.out.println("Alignment Quality: " + alignQ);
System.out.println("BAQ: " + baq);
System.out.println("Indel: " + indel);
System.out.println("BaseQ: " + baseQ);
System.out.println("");

for (File file : files) {

Reference reference = ReferenceUtil.determineReference(file);

if (version.equals("mtdna") && reference == Reference.hg19) {
if (reference == Reference.hg19) {

System.out.println(" File " + file.getName()
+ " excluded! File is aligned to Yoruba (Reference length 16571) and not rCRS. ");
Expand All @@ -147,16 +174,16 @@ public boolean accept(File dir, String name) {

}

else if (version.equals("mtdna") && reference == Reference.rcrs) {
else if (reference == Reference.rcrs || reference == Reference.precisionId) {

BamAnalyser analyser = new BamAnalyser(file.getName(), refPath, baseQ, mapQ, alignQ,
Boolean.valueOf(baq), version);
BamAnalyser analyser = new BamAnalyser(file.getName(), refPath, baseQ, mapQ, alignQ, baq, version);

System.out.println(" Processing: " + file.getName());
System.out.println(" Detected reference: " + reference.toString());

try {

analyseReads(file, analyser, Boolean.valueOf(indel));
analyseReads(file, analyser, indel);

determineVariants(analyser, writerRaw, writerVar, level);

Expand Down Expand Up @@ -185,8 +212,6 @@ else if (version.equals("mtdna") && reference == Reference.rcrs) {
e.printStackTrace();
}

System.out.println("Raw file written to " + new File(outputRaw).getAbsolutePath());
System.out.println("Variants file written to " + new File(outputVar).getAbsolutePath());
System.out.println("Time: " + (System.currentTimeMillis() - start) / 1000 + " sec");
return 0;
}
Expand Down Expand Up @@ -241,7 +266,6 @@ private void determineVariants(BamAnalyser analyser, LineWriter writerRaw, LineW
char ref = 'N';

BasePosition basePos = counts.get(key);

basePos.setId(idKey);

basePos.setPos(pos);
Expand Down Expand Up @@ -332,35 +356,25 @@ private void determineVariants(BamAnalyser analyser, LineWriter writerRaw, LineW
String res = VariantCaller.writeVariant(varResult);

writerVariants.write(res);

}

}

// raw data
String raw = line.toRawString();
writerRaw.write(raw);

}

}

// }
}

public static void main(String[] args) {

String input = "test-data/mtdna/bam/input/";
String outputVar = "test-data/tmp/out_var.txt";
String outputRaw = "test-data/tmp/out_raw.txt";
String output = "test-data/tmp/";
String fasta = "test-data/mtdna/bam/reference/rCRS.fasta";

// input = "/home/seb/Downloads/mt_bam";
fasta = "test-data/mtdna/bam/reference/rCRS.fasta";

PileupToolLocal pileup = new PileupToolLocal(new String[] { "--input", input, "--reference", fasta,
"--outputVar", outputVar, "--outputRaw", outputRaw, "--level", "0.01", "--baq", "true", "--indel",
"true", "--baseQ", "20", "--mapQ", "20", "--alignQ", "30" });
"--output", output, "--level", "0.01"});

pileup.start();

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/genepi/mut/util/ReferenceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class ReferenceUtil {

public enum Reference {
hg19, rcrs, UNKNOWN, MISLEADING
hg19, rcrs, precisionId, UNKNOWN, MISLEADING,
};

private static Set<Integer> hotSpots = new HashSet<Integer>(
Expand Down Expand Up @@ -113,6 +113,9 @@ public static Reference determineReference(File file) {
if (record.getSequenceLength() == 16569) {
ref = Reference.rcrs;
}
if (record.getSequenceLength() == 16649) {
ref = Reference.precisionId;
}
}

try {
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/genepi/mut/util/VariantCaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class VariantCaller {
public static int LOW_LEVEL_DELETION = 3;

public static int DELETION = 4;

public static int INSERTION = 5;

public static boolean isFinalVariant(VariantLine line) {
Expand Down Expand Up @@ -45,10 +45,9 @@ public static VariantResult determineVariants(VariantLine line) {

if (line.getTopBaseFWD() == 'D') {
type = DELETION;
} else if (line.isInsertion()){
} else if (line.isInsertion()) {
type = INSERTION;
}
else {
} else {
type = VARIANT;
}

Expand Down Expand Up @@ -370,13 +369,19 @@ public static String writeVariant(VariantResult result) throws IOException {
build.append(getVariantBase(result) + "\t");

build.append(df.format(result.getLevel()) + "\t");

build.append(result.getTop() + "/" + result.getMinor() + "\t");

char minor = result.getMinor();

if (result.getType() == 1) {
minor = '-';
}

build.append(result.getTop() + "/" + minor + "\t");

build.append(df.format(result.getLevelTop()) + "/" + df.format(result.getLevelMinor()) + "\t");

build.append((result.getCovFWD() + result.getCovREV()) +"\t");
build.append((result.getCovFWD() + result.getCovREV()) + "\t");

build.append(result.getType());

build.append("\r");
Expand Down

0 comments on commit 9ad32a8

Please sign in to comment.