-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGatkThread.java
169 lines (138 loc) · 7.69 KB
/
GatkThread.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package gatkUtils;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Iterator;
import org.apache.commons.io.FilenameUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class GatkThread implements Runnable {
@Override
public void run() {
JSONArray stepsArray = GatkUtils.readConfigJson(GatkUtils.configPath);
Iterator iter = stepsArray.iterator();
String inputFileNameNoExt = FilenameUtils.getBaseName(GatkUtils.inputBam.getFileName().toString());
Path inputFileLocation = GatkUtils.inputBam.getParent();
String origInputFileName = GatkUtils.inputBam.getFileName().toString();
System.out.println(inputFileNameNoExt);
System.out.println(inputFileLocation);
System.out.println(origInputFileName);
// run sort on input file
String stepFileName = inputFileNameNoExt + ".sorted.bam";
String listFileName = "";
String recalGrpFile = "";
String command = "C:\\Program Files\\Java\\jdk1.8.0_192\\bin\\java.exe " + GatkUtils.maxHeapSpace + " -jar "
+ GatkUtils.picardPath + " SortSam " + " SO=coordinate " + " I=" + GatkUtils.inputBam + " O="
+ inputFileLocation.resolve(stepFileName);
// System.out.println(command);
Runtime r = Runtime.getRuntime();
try {
Process p2 = r.exec(command);
StreamGobbler errGobler = new StreamGobbler(p2.getErrorStream(), "ERROR");
StreamGobbler opGobler = new StreamGobbler(p2.getInputStream(), "OUTPUT");
errGobler.start();
opGobler.start();
p2.waitFor();
} catch (IOException | InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
while (iter.hasNext()) {
JSONObject obj1 = (JSONObject) iter.next();
System.out.println(obj1.keySet().contains("MarkDuplicates") && ((JSONObject)obj1.get("MarkDuplicates")).values().contains("true") );
if (obj1.keySet().contains("MarkDuplicates") && ((JSONObject)obj1.get("MarkDuplicates")).values().contains("true")) {
String newStepFileName = inputFileLocation.resolve(FilenameUtils.getBaseName(stepFileName)).toString()
+ ".mdup.bam";
String mdupCommand = "C:\\Program Files\\Java\\jdk1.8.0_192\\bin\\java.exe " + GatkUtils.maxHeapSpace
+ " -jar " + GatkUtils.picardPath + " MarkDuplicates " + " I="
+ inputFileLocation.resolve(stepFileName) + " O=" + inputFileLocation.resolve(newStepFileName)
+ " M=" + inputFileLocation.resolve(newStepFileName + ".metricFile")
+ " VALIDATION_STRINGENCY=LENIENT";
System.out.println(mdupCommand);
runAndGobbleCommand(mdupCommand, r);
stepFileName = newStepFileName;
} else if (obj1.keySet().contains("BuildBamIndex")) {
String bamIndexCommand = "C:\\Program Files\\Java\\jdk1.8.0_192\\bin\\java.exe "
+ GatkUtils.maxHeapSpace + " -jar " + GatkUtils.picardPath + " BuildBamIndex " + " I="
+ inputFileLocation.resolve(stepFileName);
System.out.println(bamIndexCommand);
runAndGobbleCommand(bamIndexCommand, r);
} else if (obj1.keySet().contains("RealignerTargetCreator")) {
listFileName = inputFileLocation.resolve(FilenameUtils.getBaseName(stepFileName)).toString() + ".list";
String realignerCommand = "C:\\Program Files\\Java\\jdk1.8.0_192\\bin\\java.exe "
+ GatkUtils.maxHeapSpace + " -jar " + GatkUtils.gatkPath + " -T RealignerTargetCreator "
+ " -R " + GatkUtils.referencePath + " -I " + inputFileLocation.resolve(stepFileName) + " -o "
+ inputFileLocation.resolve(listFileName);
System.out.println(realignerCommand);
runAndGobbleCommand(realignerCommand, r);
} else if (obj1.keySet().contains("IndelRealigner")) {
String newStepFileName = inputFileLocation.resolve(FilenameUtils.getBaseName(stepFileName)).toString()
+ ".realigned.bam";
String indelRealignerCommand = "C:\\Program Files\\Java\\jdk1.8.0_192\\bin\\java.exe "
+ GatkUtils.maxHeapSpace + " -jar " + GatkUtils.gatkPath + " -T IndelRealigner " + " -R "
+ GatkUtils.referencePath + " -I " + inputFileLocation.resolve(stepFileName) + " -o "
+ inputFileLocation.resolve(newStepFileName) + " -targetIntervals "
+ inputFileLocation.resolve(listFileName);
System.out.println(indelRealignerCommand);
runAndGobbleCommand(indelRealignerCommand, r);
stepFileName = newStepFileName;
}
else if (obj1.keySet().contains("FixMateInformation")) {
// java -Xmx1g -jar
// tools\picard-tools-1.82\picard-tools-1.82\FixMateInformation.jar
// INPUT=%sampleName%.sorted.realigned.bam
// OUTPUT=%sampleName%.sorted.realigned.fixed.bam SO=coordinate
// VALIDATION_STRINGENCY=LENIENT CREATE_INDEX=true
String newStepFileName = inputFileLocation.resolve(FilenameUtils.getBaseName(stepFileName)).toString()
+ ".fixed.bam";
String mateFixCommand = "C:\\Program Files\\Java\\jdk1.8.0_192\\bin\\java.exe " + GatkUtils.maxHeapSpace
+ " -jar " + GatkUtils.picardPath + " FixMateInformation " + " I="
+ inputFileLocation.resolve(stepFileName) + " O=" + inputFileLocation.resolve(newStepFileName)
+ " VALIDATION_STRINGENCY=LENIENT";
runAndGobbleCommand(mateFixCommand, r);
stepFileName = newStepFileName;
} else if (obj1.keySet().contains("BaseRecalibrator")) {
recalGrpFile = inputFileLocation.resolve(FilenameUtils.getBaseName(stepFileName)).toString()
+ ".recal.grp";
String baseRecalCommand = "C:\\Program Files\\Java\\jdk1.8.0_192\\bin\\java.exe "
+ GatkUtils.maxHeapSpace + " -jar " + GatkUtils.gatkPath + " -T BaseRecalibrator " + " -R "
+ GatkUtils.referencePath + " -I " + inputFileLocation.resolve(stepFileName) + " -o "
+ inputFileLocation.resolve(recalGrpFile) + " -bqsrBAQGOP 40 ";
runAndGobbleCommand(baseRecalCommand, r);
} else if (obj1.keySet().contains("PrintReads")) {
// java -Xmx1g -jar tools\GenomeAnalysisTK.jar -T PrintReads -R %genomeRef% -I
// %sampleName%.sorted.realigned.fixed.bam -BQSR %sampleName%.recal.grp -o
// %sampleName%.sorted.realigned.fixed.bqsr.bam
String newStepFile = inputFileLocation.resolve(FilenameUtils.getBaseName(stepFileName)).toString()
+ ".bqsr.bam";
String printReadCommand = "C:\\Program Files\\Java\\jdk1.8.0_192\\bin\\java.exe "
+ GatkUtils.maxHeapSpace + " -jar " + GatkUtils.gatkPath + " -T PrintReads " + " -R "
+ GatkUtils.referencePath + " -I " + inputFileLocation.resolve(stepFileName) + " -o "
+ inputFileLocation.resolve(newStepFile) + " -BQSR " + inputFileLocation.resolve(recalGrpFile);
runAndGobbleCommand(printReadCommand, r);
stepFileName = newStepFile;
} else if (obj1.keySet().contains("UnifiedGenotyper")) {
// java -Xmx1g -jar tools\GenomeAnalysisTK.jar -R %genomeRef% -T
// UnifiedGenotyper -I %sampleName%.sorted.realigned.fixed.bqsr.bam -mbq 13 -glm
// BOTH -indelGCP 20 -indelGOP 40 -o %sampleName%_snps.raw.vcf -L %targetBed%
String resultVcf = inputFileLocation.resolve(inputFileNameNoExt + ".raw.vcf").toString();
String UnifiedGenotyperCommand = "C:\\Program Files\\Java\\jdk1.8.0_192\\bin\\java.exe "
+ GatkUtils.maxHeapSpace + " -jar " + GatkUtils.gatkPath + " -T UnifiedGenotyper " + " -R "
+ GatkUtils.referencePath + " -I " + inputFileLocation.resolve(stepFileName) + " -o "
+ inputFileLocation.resolve(resultVcf) + " -BQSR " + inputFileLocation.resolve(recalGrpFile)
+ " -mbq 13 -glm BOTH -indelGCP 20 -indelGOP 40 " + " -L " + GatkUtils.targetBedFile;
runAndGobbleCommand(UnifiedGenotyperCommand, r);
}
}
}
public void runAndGobbleCommand(String command, Runtime r) {
try {
Process p2 = r.exec(command);
new StreamGobbler(p2.getErrorStream(), "ERROR").start();
new StreamGobbler(p2.getInputStream(), "INPUT").start();
p2.waitFor();
} catch (IOException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}