package com.github.sparkcaller.preprocessing;

import com.github.sparkcaller.BaseGATKProgram;
import com.github.sparkcaller.Utils;
import org.apache.spark.api.java.function.Function;
import scala.Tuple2;

import java.io.File;

/*
 * Use the targets generated by the BQSRTargetGenerator to perform BQSR on the input BAM file.
 * Writes a BAM file with recalibrated bases.
 *
 * See:
 * https://www.broadinstitute.org/gatk/documentation/tooldocs/org_broadinstitute_gatk_tools_walkers_readutils_PrintReads.php
 *
 * For more information.
 *
 */
public class BQSR extends BaseGATKProgram implements Function<Tuple2<File, File>, File> {
    public BQSR(String pathToReference, String extraArgsString, String coresPerNode) {
        super("PrintReads", extraArgsString);
        setReference(pathToReference);
        setThreads(coresPerNode);
    }

    public File call(Tuple2<File, File> bqsrTablePair) throws Exception {
        File bamFile = bqsrTablePair._1;
        File bqsrTable = bqsrTablePair._2;

        setInputFile(bamFile.getPath());
        addArgument("-BQSR", bqsrTable.getPath());

        String outputBamFilename = Utils.removeExtenstion(bamFile.getPath(), "bam") + "-bqsr.bam";
        File outputBam = new File(outputBamFilename);

        setOutputFile(outputBam.getPath());

        executeProgram();
        return outputBam;
    }
}

@@ -179,29 +179,8 @@
 ion;
-%0Aimport scala.Tuple2;
 %0A%0Aim
@@ -576,34 +576,20 @@
 unction%3C
-Tuple2%3CFile, File%3E
+File
 , File%3E 
@@ -629,16 +629,38 @@
 ference,
+ String bqsrTablePath,
  String 
@@ -780,24 +780,69 @@
 Reference);%0A
+        addArgument(%22-BQSR%22, bqsrTablePath);%0A
         setT
@@ -870,16 +870,30 @@
 %0A    %7D%0A%0A
+    @Override%0A
     publ
@@ -909,223 +909,67 @@
 all(
-Tuple2%3CFile, File%3E bqsrTablePair) throws Exception %7B%0A        File bamFile = bqsrTablePair._1;%0A        File bqsrTable = bqsrTablePair._2;%0A%0A        setInputFile(bamFile.getPath());%0A        addArgument(%22-BQSR%22, bqsrTab
+File bamFile) throws Exception %7B%0A        setInputFile(bamFi
 le.g

Make it easier to run BQSR in parallel, as this works when doing it per chromosome.