package com.github.sparkcaller.preprocessing;

import htsjdk.samtools.BAMIndexer;
import htsjdk.samtools.SamReader;
import htsjdk.samtools.SamReaderFactory;
import org.apache.spark.api.java.function.Function;

import java.io.File;

public class BamIndexer implements Function<File, File> {
    // Create an index (.bai) file for the given BAM file.
    public File call(File bamFile) throws Exception {
        final SamReader bamReader = SamReaderFactory.makeDefault()
                                              .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS)
                                              .open(bamFile);
        BAMIndexer.createIndex(bamReader, new File(bamFile.getPath() + ".bai"));

        return bamFile;
    }
}

@@ -201,16 +201,69 @@
 unction;
+%0Aimport org.apache.spark.api.java.function.Function2;
 %0A%0Aimport
@@ -410,17 +410,28 @@
 lic 
-File call
+static void indexBam
 (Fil
@@ -779,31 +779,146 @@
 ));%0A
-%0A        return bamFile
+    %7D%0A%0A    @Override%0A    public File call(File inputBAM) throws Exception %7B%0A        BamIndexer.indexBam(inputBAM);%0A        return inputBAM
 ;%0A  

Make it easier to run the SAM indexer on a single file.