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;

/*
 * Recalibrate the base quality scores inorder to get more accurate scores.
 *
 * See:
 * https://www.broadinstitute.org/gatk/documentation/tooldocs/org_broadinstitute_gatk_tools_walkers_bqsr_BaseRecalibrator.php
 *
 * For more information.
 *
 */
public class BQSRTargetGenerator extends BaseGATKProgram implements Function<File, Tuple2<File, File>> {

    public BQSRTargetGenerator(String pathToReference, String knownSites, String extraArgs, String coresPerNode) {
        super("BaseRecalibrator", extraArgs);
        setReference(pathToReference);
        addArgument("-knownSites", knownSites);
        setThreads(coresPerNode);
    }

    public Tuple2<File, File> call(File file) throws Exception {
        setInputFile(file.getPath());
        String outputTableFilename = Utils.removeExtenstion(file.getPath(), "bam") + "-recal_data.table";
        File outputTable = new File(outputTableFilename);

        setOutputFile(outputTable.getPath());

        executeProgram();
        return new Tuple2<File, File>(file, outputTable);
    }
}

@@ -127,81 +127,8 @@
 ils;
-%0Aimport org.apache.spark.api.java.function.Function;%0Aimport scala.Tuple2;
 %0A%0Aim
@@ -458,54 +458,8 @@
 gram
- implements Function%3CFile, Tuple2%3CFile, File%3E%3E
  %7B%0A%0A
@@ -762,31 +762,28 @@
 lic 
-Tuple2%3CFile, File%3E call
+File generateTargets
 (Fil
@@ -1103,37 +1103,8 @@
 turn
- new Tuple2%3CFile, File%3E(file,
  out
@@ -1111,17 +1111,16 @@
 putTable
-)
 ;%0A    %7D%0A

Create BQSR targets on a single, merged file, as it is not scatter-gatherable, and is pretty quick on large files anyways.