Skip to content

Commit

Permalink
Fixed issues where overlapping indels having same start coordinates c…
Browse files Browse the repository at this point in the history
…ounted as same
  • Loading branch information
manojbhosale committed May 6, 2019
1 parent 57394b9 commit 33a43cf
Show file tree
Hide file tree
Showing 70 changed files with 599 additions and 90 deletions.
1 change: 1 addition & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
Expand Down
45 changes: 45 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,42 @@
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
<transformers>
<transformer>
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer>
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer>
<mainClass>com.psl.automation.main.MainGui</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
Expand All @@ -40,4 +76,13 @@
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

50 changes: 49 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
<artifactId>httpclient</artifactId>
<version>4.2.5</version>
</dependency>

<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
<dependency>
Expand All @@ -40,6 +44,12 @@
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>


</dependencies>
Expand All @@ -59,6 +69,44 @@


<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.psl.automation.main.MainGui</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
Expand Down
169 changes: 169 additions & 0 deletions src/gatkUtils/GatkThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
}

}
}
63 changes: 63 additions & 0 deletions src/gatkUtils/GatkUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package gatkUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

public class GatkUtils {

public static File logFile = new File("D:\\SureCall\\SureCall4111\\GATKcomparison\\Autommation\\gatkProcess.log");
public static Path configPath = Paths.get("D:\\SureCall\\SureCall4111\\GATKcomparison\\Autommation\\config.json");
//public static Path javaPath = Paths.get("java");
public static Path gatkPath = Paths.get("D:\\SureCall\\SureCall4111\\GATKcomparison\\tools\\GenomeAnalysisTK.jar");
public static Path picardPath = Paths.get("D:\\SureCall\\SureCall4111\\GATKcomparison\\tools\\picard.jar");
public static String maxHeapSpace = "-Xmx4g";
public static Path inputBam = Paths.get("D:\\SureCall\\SureCall4111\\GATKcomparison\\L004_I003_chr22_child.bam");
public static Path referencePath = Paths.get("D:\\SureCall\\SURECALL_VALID\\Surecall_Test_plans\\Genomeanalysis_softwares\\IGV\\IGVTools\\hg19\\hg19.fasta");
public static Path targetBedFile = Paths.get("D:\\SureCall\\SureCall4111\\GATKcomparison\\targets_subset_Exons.bed");



public static void main(String args[]) throws IOException {
readConfigJson(Paths.get("D:\\SureCall\\SureCall4111\\GATKcomparison\\Autommation\\config.json"));
if(logFile.createNewFile()) {
System.out.println("Created file successfully !!");
}

Thread th = new Thread(new GatkThread());

th.start();
}


public static JSONArray readConfigJson(Path configPath) {

JSONParser jsonParser = new JSONParser();
JSONArray gatkSteps = null;
try (FileReader reader = new FileReader(configPath.toFile()))
{
//Read JSON file
Object obj = jsonParser.parse(reader);

gatkSteps = (JSONArray) obj;
// System.out.println(gatkSteps);

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}

return gatkSteps;
}

}
Loading

0 comments on commit 33a43cf

Please sign in to comment.