package com.github.sparkcaller.preprocessing;

import com.github.sparkcaller.Utils;
import org.apache.spark.api.java.function.Function;
import org.broadinstitute.gatk.engine.CommandLineGATK;
import scala.Tuple2;

import java.io.File;
import java.util.ArrayList;

public class RealignIndels implements Function<Tuple2<File, File>, File> {
    final private String pathToReference;

    public RealignIndels(String pathToReference) {
        this.pathToReference = pathToReference;
    }
    public File call(Tuple2<File, File> indelTargetTuple) throws Exception {
        File inputBam = indelTargetTuple._1;
        File intelIntervals = indelTargetTuple._2;

        ArrayList<String> alignerArgs = new ArrayList<String>();
        alignerArgs.add("-T");
        alignerArgs.add("IndelRealigner");

        alignerArgs.add("-R");
        alignerArgs.add(this.pathToReference);

        alignerArgs.add("-I");
        alignerArgs.add(inputBam.getPath());

        final String ext = "bam";
        final String newFileName = Utils.removeExtenstion(inputBam.getPath(), "bam") + "-realigned.bam";
        File outputBamFile = new File(newFileName);

        alignerArgs.add("-targetIntervals");
        alignerArgs.add(intelIntervals.getPath());

        alignerArgs.add("-o");
        alignerArgs.add(outputBamFile.getPath());

        CommandLineGATK.start(new CommandLineGATK(), alignerArgs.toArray(new String[0]));

        return outputBamFile;
    }
}

@@ -40,16 +40,63 @@
 ssing;%0A%0A
+import com.github.sparkcaller.BaseGATKProgram;%0A
 import c
@@ -330,16 +330,40 @@
 nIndels 
+extends BaseGATKProgram 
 implemen
@@ -405,50 +405,8 @@
 e%3E %7B
-%0A    final private String pathToReference;
 %0A%0A  
@@ -454,31 +454,85 @@
 ence
-) %7B%0A        this.pathTo
+, String extraArgs) %7B%0A        super(%22IndelRealigner%22, extraArgs);%0A        set
 Refe
@@ -536,19 +536,17 @@
 eference
- = 
+(
 pathToRe
@@ -552,24 +552,25 @@
 eference
+)
 ;%0A    %7D%0A
     publ
@@ -561,16 +561,17 @@
 ;%0A    %7D%0A
+%0A
     publ
@@ -748,273 +748,20 @@
     
-ArrayList%3CString%3E alignerArgs = new ArrayList%3CString%3E();%0A        alignerArgs.add(%22-T%22);%0A        alignerArgs.add(%22IndelRealigner%22);%0A%0A        alignerArgs.add(%22-R%22);%0A        alignerArgs.add(this.pathToReference);%0A%0A        alignerArgs.add(%22-I%22);%0A        alignerArgs.add
+setInputFile
 (inp
@@ -783,42 +783,8 @@
 );%0A%0A
-        final String ext = %22bam%22;%0A
     
@@ -936,25 +936,24 @@
 eName);%0A
-%0A
         
 alignerA
@@ -948,270 +948,143 @@
     
-alignerArgs.add(%22-targetIntervals%22);%0A        alignerArgs.add(intelIntervals.getPath());%0A%0A        alignerArgs.add(%22-o%22);%0A        alignerArgs.add(outputBamFile.getPath());%0A%0A        CommandLineGATK.start(new CommandLineGATK(), alignerArgs.toArray(new String%5B0%5D)
+setOutputFile(outputBamFile.getPath());%0A%0A        addArgument(%22-targetIntervals%22, intelIntervals.getPath());%0A%0A        executeProgram(
 );%0A
-%0A
     

Refactor the RealignIndels class so that it uses the BaseGATKProgram.