This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Call Gatk From Java Code In A Pipeline

How can I use the GATK tools as an API from a java program? For example to run the unifed genotyper. How can I do the following command line call as a API call?

java -jar GenomeAnalysisTK.jar -T UnifiedGenotyper -R my.fasta -I my.bam- my.vcf

To use a Picard tool as an API I just do the following.

MergeSamFiles mergeSamFiles = new MergeSamFiles();
ArrayList<File> inputFileList = new ArrayList<File>();
inputFileList.add(new File("myFile.bam"));
mergeSamFiles.INPUT = inputFileList;
//set other parameters;
mergeSamFiles.doWork();

I am looking for the samething with GATK.

gatk java api

1 answer

in my version of GATK ( i'm currently looking at an old source) The main class of the GATK is org.broadinstitute.sting.gatk.CommandLineGATK , so you can invoke it in your java program:

String args[]=new String[]{"-T","UnifiedGenotyper","-R ","my.fasta","-I","my.bam- my.vcf"};
CommandLineGATK.main(args);

or, if the CLI exits after 'main':

String args[]=new String[]{"-T","UnifiedGenotyper","-R ","my.fasta","-I","my.bam- my.vcf"};
CommandLineGATK instance = new CommandLineGATK();
CommandLineGATK.start(instance, args);

but I'm not sure embedding the GATK is a good idea.

What I want to do is to make a small pipeline containing BWA (run on a cluster via SGE DRMAA API), Picard, and GATK to process a bulk of data. Calling the GATK command line from java I guess can't be worse than calling it from perl or a shell script.

interesting I didn't know this API. But as far as I can see you'll have to code and reinvent the wheel (e.g: do I really need to realign this FASTQ ? Should I merge those BAMS if the file already exists and is newer that the BAMs ? ) while the venerable Make will run those jobs for you.

Log in to answer this question.